rewrite nu shit

This commit is contained in:
Schrottkatze 2025-01-01 05:16:08 +01:00
parent f64f61b9b6
commit 2ce0df9880
Signed by: schrottkatze
SSH key fingerprint: SHA256:FPOYVeBy3QP20FEM42uWF1Wa/Qhlk+L3S2+Wuau/Auo
6 changed files with 101 additions and 96 deletions

View file

@ -0,0 +1,28 @@
alias gnix = cd ~/nix-configs;
alias grepo = cd ~/Documents/repos;
alias wh = wormhole-rs;
alias gg = gitui;
alias ga = git add;
alias gc = git commit;
alias gca = git commit --all;
alias gp = git push;
alias gl = git pull;
alias gs = git status;
alias clip = xclip -selection c;
alias cr = cargo run;
alias cl = cargo clippy;
alias cb = cargo build;
alias cch = cargo check;
alias togglecaps = xdotool key Caps_Lock;
alias TOGGLECAPS = togglecaps;
alias bash = echo $"(ansi red)no, fuck that shit!";
alias sh = echo $"(ansi red)no, fuck that shit!";
alias zsh = echo $"(ansi red)no, fuck that shit!";
alias fish = echo $"(ansi red)no, fuck that shit!";
alias px = pulsemixer;

103
modules/shell/nu/config.nu Normal file
View file

@ -0,0 +1,103 @@
let colors = {
separator: white
leading_trailing_space_bg: { attr: n } # no fg, no bg, attr none effectively turns this off
header: green_bold
empty: blue
bool: light_cyan
int: white
filesize: cyan
duration: white
date: purple
range: white
float: white
string: white
nothing: white
binary: white
cellpath: white
row_index: green_bold
record: white
list: white
block: white
hints: dark_gray
search_result: {bg: red fg: white}
shape_and: purple_bold
shape_binary: purple_bold
shape_block: blue_bold
shape_bool: light_cyan
shape_closure: green_bold
shape_custom: green
shape_datetime: cyan_bold
shape_directory: cyan
shape_external: cyan
shape_externalarg: green_bold
shape_external_resolved: light_cyan_bold
shape_filepath: cyan
shape_flag: blue_bold
shape_float: purple_bold
shape_garbage: { fg: white bg: red attr: b}
shape_globpattern: cyan_bold
shape_int: purple_bold
shape_internalcall: cyan_bold
shape_list: cyan_bold
shape_literal: blue
shape_match_pattern: green
shape_matching_brackets: { attr: u }
shape_nothing: light_cyan
shape_operator: yellow
shape_or: purple_bold
shape_pipe: purple_bold
shape_range: yellow_bold
shape_record: cyan_bold
shape_redirection: purple_bold
shape_signature: green_bold
shape_string: green
shape_string_interpolation: cyan_bold
shape_table: blue_bold
shape_variable: purple
shape_vardecl: purple
}
$env.config = {
show_banner: false # true or false to enable or disable the welcome banner at startup
ls: {
use_ls_colors: true # use the LS_COLORS environment variable to colorize output
}
rm: {
always_trash: true
}
table: {
mode: reinforced # basic, compact, compact_double, light, thin, with_love, rounded, reinforced, heavy, none, other
header_on_separator: true # show header text on separator/border line
}
history: {
max_size: 1_000_000_000 # Session has to be reloaded for this to take effect
isolation: false
}
completions: {
algorithm: "fuzzy" # prefix or fuzzy
sort: "smart"
}
cursor_shape: {
emacs: line # block, underscore, line, blink_block, blink_underscore, blink_line (line is the default)
vi_insert: line # block, underscore, line , blink_block, blink_underscore, blink_line (block is the default)
vi_normal: block # block, underscore, line, blink_block, blink_underscore, blink_line (underscore is the default)
}
color_config: $colors # if you want a more interesting theme, you can replace the empty record with `$dark_theme`, `$light_theme` or another custom record
footer_mode: 25 # always, never, number_of_rows, auto
float_precision: 2 # the precision for displaying floats in tables
buffer_editor: "" # command that will be used to edit the current line buffer with ctrl+o, if unset fallback to $env.EDITOR and $env.VISUAL
use_ansi_coloring: true
bracketed_paste: true # enable bracketed paste, currently useless on windows
edit_mode: vi # emacs, vi
use_kitty_protocol: true
hooks: {
pre_execution: [{ $env.CMD_COUNT = $env.CMD_COUNT + 1; }] # run before the repl input is run
}
}

View file

@ -0,0 +1,67 @@
# open nix shell with a bunch of programs
def nsp [
...programs: string
] {
nix shell ...($programs | each {|it| $"nixpkgs#($it)" })
}
# do a nix run of a nix package
def nr [
program: string
] {
nix run $"nixpkgs#($program)"
}
# do a recursive line count of a file extension
def lcr [
file_extension: string
] {
ls **/*
| where name ends-with $".($file_extension)"
| par-each {|file|
open $file.name
| lines --skip-empty
| length }
| math sum
}
# get parsed git log
def glog [
amount: int
] {
git log --pretty=%h»¦«%s»¦«%aN»¦«%aE»¦«%aD -n $amount
| lines
| split column "»¦«" commit subject name email date
}
# open typst IDE ish setup
def typed [
name: string
] {
touch $"($name).typ"
typst compile $"($name).typ"
mprocs --names Editor,Viewer,Notify $"hx '($name).typ'" $"while true; do mupdf-x11 '($name).pdf' && break; done" $"while inotifywait -e modify '($name).pdf' ; do pkill -HUP mupdf; done"
}
# figure out when the next event is
def nev [ unit = day ] {
( ( open Docs/dates.csv
| update datetime {|it| $it.datetime | into datetime }
| first
).datetime - (date now)
)
| into duration
| format duration $unit
}
# open chromium with bahn.expert opened and ready
# TODO: intermediate stations
def bx [from: string to: string] {
let map = open ~/Docs/ril100map.json;
let start = $map | get ($from | str upcase) | first;
let dest = $map | get ($to | str upcase) | first;
let url = $"https://bahn.expert/routing/($start)/($dest)/0/";
print $url;
^bash -c $"nohup chromium '($url)' &";
}

83
modules/shell/nu/env.nu Normal file
View file

@ -0,0 +1,83 @@
# Nushell Environment Config File
#
# version = "0.84.0"
source /home/jade/.config/nushell/shell-startup.nu;
$env.STARSHIP_SHELL = "nu";
$env.CMD_COUNT = 0;
def create_right_prompt [] {
# create a right prompt in magenta with green separators and am/pm underlined
let time_segment = ([
(ansi reset)
(ansi purple)
(date now | format date '%Y/%m/%d %R')
]) | str join;
let last_exit_code = if ($env.LAST_EXIT_CODE != 0) {([
(ansi rb)
($env.LAST_EXIT_CODE)
] | str join)
} else { "" }
([$last_exit_code, (char space), $time_segment] | str join)
}
# Use nushell functions to define your right and left prompt
$env.PROMPT_COMMAND = {||
starship prompt --cmd-duration $env.CMD_DURATION_MS $'--status=($env.LAST_EXIT_CODE)'
| lines
| filter { is-not-empty }
| update 0 {|item|
let len = (term size | get columns) - ($item | ansi strip | str length --grapheme-clusters) - (create_right_prompt | ansi strip | str length --grapheme-clusters);
# $item | append (flag $TRANS "-" $len) | str join
let deco = if ($env.CMD_COUNT == 0) {
flag $TRANS "=" $len
} else if ($env.CMD_COUNT | is even) {
flag $LESBIAN "-" $len
} else {
flag $TRANS "-" $len
};
$item | append $deco | str join
}
| str join "\n"
}
$env.PROMPT_COMMAND_RIGHT = {|| create_right_prompt }
# The prompt indicators are environmental variables that represent
# the state of the prompt
$env.PROMPT_INDICATOR = {|| "> " }
$env.PROMPT_INDICATOR_VI_INSERT = {|| ": " }
$env.PROMPT_INDICATOR_VI_NORMAL = {|| "> " }
$env.PROMPT_MULTILINE_INDICATOR = {|| "::: " }
# Specifies how environment variables are:
# - converted from a string to a value on Nushell startup (from_string)
# - converted from a value back to a string when running external commands (to_string)
# Note: The conversions happen *after* config.nu is loaded
$env.ENV_CONVERSIONS = {
"PATH": {
from_string: { |s| $s | split row (char esep) | path expand --no-symlink }
to_string: { |v| $v | path expand --no-symlink | str join (char esep) }
}
"Path": {
from_string: { |s| $s | split row (char esep) | path expand --no-symlink }
to_string: { |v| $v | path expand --no-symlink | str join (char esep) }
}
}
# Directories to search for scripts when calling source or use
$env.NU_LIB_DIRS = [
# ($nu.default-config-dir | path join 'scripts') # add <nushell-config-dir>/scripts
]
# Directories to search for plugin binaries when calling register
$env.NU_PLUGIN_DIRS = [
# ($nu.default-config-dir | path join 'plugins') # add <nushell-config-dir>/plugins
]
# To add entries to PATH (on Windows you might use Path), you can use the following pattern:
# $env.PATH = ($env.PATH | split row (char esep) | prepend '/some/path')

View file

@ -0,0 +1,72 @@
def "is even" [] {
$in mod 2 == 0
}
# TODO: flag stuff as module to be used in other stuff in shell
const TRANS = [ 5BCEFA F5A9B8 FFFFFF F5A9B8 5BCEFA ];
const LESBIAN = [ D52D00 EF7627 FF9A56 FFFFFF D162A4 B55690 A30262 ];
const ENBY = [ FCF434 FFFFFF 9C59D1 2C2C2C ];
def flag [
colors: list<string>
character = "="
width = -1,
] {
use std;
let out_size = if ($width == -1) {
term size | get columns
} else { $width };
let col_size = $out_size / ($colors | length) | math floor;
mut rest = $out_size - ($col_size * ($colors | length));
mut cols = $colors | wrap color | insert width $col_size | flatten;
let last = ($colors | length) - 1;
if not ($rest | is even) {
$rest = $rest - 1;
$cols = (if not ($colors | length | is even) {
$cols | update (($colors | length) / 2 | math floor) { $in | update width {|w| ($w.width + 1)}}
} else {
$cols | update $last { $in | update width {|w| ($w.width + 1)}}
});
};
std assert ($rest | is even);
let amount = $rest / 2;
$cols = ($cols | update 0 { $in | update width {|w| (($w.width | into int) + $amount) } } | update $last { $in | update width {|w| ($w.width + $amount) } });
$cols | each {|col|
$character | std repeat ($col.width | into int) | prepend (ansi {fg: $"#($col.color)" }) | str join
} | prepend (ansi attr_bold) | append (ansi reset) | str join
}
def main [] {
print (flag $LESBIAN);
let next_events = open ~/Docs/dates.csv
| update datetime {|ev| $ev.datetime | into datetime }
| sort-by datetime
| filter {|ev| ($ev.datetime > (date now))};
let evstr = if ($next_events | is-not-empty) {
let ev = $next_events | first;
$" | Next Event: (ansi attr_bold)($ev.event)(ansi reset) in (ansi attr_bold)(tfmt ($ev.datetime - (date now)))s(ansi reset)"
} else "";
print $"Hi jade, you're on HRT for (ansi reset)(ansi attr_bold)((date now) - ('2024-02-18T20:53' | into datetime) | format duration month)s(ansi reset) now!($evstr)";
}
def tfmt [dur: duration] {
if ($dur < 1hr) {
return ($dur | format duration min);
} else if ($dur < 1day) {
return ($dur | format duration hr);
} else {
return ($dur | format duration day);
}
}