diff --git a/users/tao/HOME.nix b/users/tao/HOME.nix index e6b934e..5a28d97 100644 --- a/users/tao/HOME.nix +++ b/users/tao/HOME.nix @@ -22,8 +22,6 @@ in { imports = [ ./boxxy.nix (import ./helix.nix {inherit pkgs inputs;}) - # ./plasma.nix - # ./firefox.nix ]; # home.sessionPath = [ @@ -34,8 +32,18 @@ in { source = ./autostart; recursive = true; }; - home.file.".config/direnv/lib/".source = ./direnv; - home.file.".config/direnv/lib/".recursive = true; + home.file.".config/direnv/lib/" = { + source = ./direnv; + recursive = true; + }; + home.file.".config/nushell/scripts" = { + source = ./nushell/extras; + recursive = true; + }; + home.file.".local/nushell/completions" = { + source = ./nushell/completions; + recursive = true; + }; programs = { bacon = { @@ -80,11 +88,7 @@ in { settings = { color = "gruvbox"; flags = { - battery = - # if lib.strings.hasPrefix "NOlaptop" (builtins.readFile /etc/hostname) - # then true - # else false; - true; + battery = true; hide_time = true; enable_gpu = true; }; @@ -93,7 +97,6 @@ in { direnv = { enable = true; - enableNushellIntegration = true; nix-direnv.enable = true; config = { load_dotenv = true; @@ -127,6 +130,17 @@ in { mpv = { config = { demuxer-max-bytes = "10GiB"; + + alang = "ja,jp,jpn,en,eng"; + slang = "en,eng"; + sub-scale = 0.5; + + hr-seek = "yes"; + + hwdec = "auto"; + vo = "gpu-next"; + + target-colorspace-hint = "auto"; }; }; @@ -149,8 +163,12 @@ in { configFile.source = ./nushell/config.nu; envFile.source = ./nushell/env.nu; # extraConfig = builtins.readFile ./nushell/stuff.nu; - extraConfig = lib.concatStrings (map builtins.readFile (map (x: ./nushell/extras/. + x) (map (x: "/" + x) (builtins.attrNames (builtins.readDir ./nushell/extras))))); + # extraConfig = lib.concatStrings (map builtins.readFile (map (x: ./nushell/extras/. + x) (map (x: "/" + x) (builtins.attrNames (builtins.readDir ./nushell/extras))))); plugins = with pkgs.nushellPlugins; [ + # skim + desktop_notifications + # highlight + # units ]; }; @@ -184,7 +202,6 @@ in { starship = { enable = true; - enableNushellIntegration = true; settings = builtins.fromTOML (builtins.readFile ./starship.toml); }; @@ -213,7 +230,6 @@ in { zoxide = { enable = true; - enableNushellIntegration = true; }; }; diff --git a/users/tao/nushell/extras/completions-jj.nu b/users/tao/nushell/completions/completions-jj.nu similarity index 100% rename from users/tao/nushell/extras/completions-jj.nu rename to users/tao/nushell/completions/completions-jj.nu diff --git a/users/tao/nushell/extras/completions-just.nu b/users/tao/nushell/completions/completions-just.nu similarity index 90% rename from users/tao/nushell/extras/completions-just.nu rename to users/tao/nushell/completions/completions-just.nu index ab10910..27565e1 100644 --- a/users/tao/nushell/extras/completions-just.nu +++ b/users/tao/nushell/completions/completions-just.nu @@ -1,4 +1,4 @@ -def "nu-complete just" [] { +export def "nu-complete just" [] { (^just --dump --unstable --dump-format json | from json).recipes | transpose recipe data | flatten | where {|row| $row.private == false } | select recipe doc parameters | rename value description } diff --git a/users/tao/nushell/config.nu b/users/tao/nushell/config.nu index e409f95..a5660d9 100644 --- a/users/tao/nushell/config.nu +++ b/users/tao/nushell/config.nu @@ -2,82 +2,23 @@ # # version = "0.96.1" -# For more information on defining custom themes, see -# https://www.nushell.sh/book/coloring_and_theming.html -# And here is the theme collection -# https://github.com/nushell/nu_scripts/tree/main/themes -let dark_theme = { - # color for nushell primitives - separator: white - leading_trailing_space_bg: { attr: n } # no fg, no bg, attr none effectively turns this off - header: green_bold - empty: blue - # Closures can be used to choose colors for specific values. - # The value (in this case, a bool) is piped into the closure. - # eg) {|| if $in { 'light_cyan' } else { 'light_gray' } } - bool: light_cyan - int: white - filesize: cyan - duration: white - date: purple - range: white - float: white - string: white - nothing: white - binary: white - cell-path: 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_yellow_bold - shape_filepath: cyan - shape_flag: blue_bold - shape_float: purple_bold - # shapes are used to change the cli syntax highlighting - shape_garbage: { fg: white bg: red attr: b } - shape_glob_interpolation: cyan_bold - shape_globpattern: cyan_bold - shape_int: purple_bold - shape_internalcall: cyan_bold - shape_keyword: 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 - shape_raw_string: light_purple -} +use std/dirs +use theme.nu dark_theme + +use aliases.nu * +use nix.nu * +use stuff.nu * +use tailscale.nu * + +source completions-jj.nu +source completions-just.nu # External completer example # let carapace_completer = {|spans| # carapace $spans.0 nushell ...$spans | from json # } + # The default config record. This is where much of your global configuration is setup. $env.config = { show_banner: false # true or false to enable or disable the welcome banner at startup @@ -194,7 +135,7 @@ $env.config = { reset_application_mode: true } render_right_prompt_on_last_line: false # true or false to enable or disable right prompt to be rendered on last line of the prompt. - use_kitty_protocol: false # enables keyboard enhancement protocol implemented by kitty console, only if your terminal support this. + use_kitty_protocol: true # enables keyboard enhancement protocol implemented by kitty console, only if your terminal support this. highlight_resolved_externals: false # true enables highlighting of external commands in the repl resolved by which. recursion_limit: 50 # the maximum number of times nushell allows recursion before stopping it @@ -822,6 +763,12 @@ $env.config = { } ] } + mkdir ($nu.data-dir | path join "vendor/autoload") starship init nu | save -f ($nu.data-dir | path join "vendor/autoload/starship.nu") -use std/dirs + +source ~/.zoxide.nu +export def --wrapped --env z [...rest] { + zo ...$rest + l +} diff --git a/users/tao/nushell/env.nu b/users/tao/nushell/env.nu index 38db6ec..b38d22c 100644 --- a/users/tao/nushell/env.nu +++ b/users/tao/nushell/env.nu @@ -79,9 +79,9 @@ $env.NU_PLUGIN_DIRS = [ ] # 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 '/home/tao/.local/bin' | prepend '/home/tao/.cargo/bin') +$env.PATH = ($env.PATH | split row (char esep)) -$env.GOPATH = '/home/tao/.go' +# $env.GOPATH = '/home/tao/.go' # $env.CARAPACE_BRIDGES mkdir ~/.cache/carapace diff --git a/users/tao/nushell/extras/alias.nu b/users/tao/nushell/extras/alias.nu deleted file mode 100644 index 8befcb3..0000000 --- a/users/tao/nushell/extras/alias.nu +++ /dev/null @@ -1,82 +0,0 @@ -alias b = btm -alias d = dirs -alias da = dirs add -alias dg = dirs goto -alias dn = dirs next -alias dp = dirs prev -alias dr = dirs drop -alias fetch = fastfetch -alias follow = readlink -f -alias p = pueue -alias snapper = snapper -c home -alias zl = zellij - -alias cringe = sudo bootctl set-oneshot auto-windows - -def h [query?: path] { - (if ($query != null) {sk -1 -q ($query | path basename)} else {sk -1}) - | if ($in != "") { - hx $in - } - # | complete - # | if $in.exit_code == 0 { - # $in.stdout | str trim | hx $in - # } -} - -def srg [] { - sk --ansi -i -c 'rg --color=always --line-number "{}"' -} - -alias j = jj -alias ja = jj log -r 'all()' -alias jc = jj desc -alias jd = jj diff -alias je = jj edit -alias jf = jj git fetch -alias jg = jj git clone --colocate -alias jp = jj git push -alias js = jj status -alias jw = jj workspace update-stale -alias jt = jj log -r @ -T `description` -alias jn = jj next --edit - -def jm --wrapped [-r: string = "@", ...rest] { - mut r = $r - if (jj log -r @ --no-pager --no-graph --template 'if(empty,"empty")' | $in == "empty") { - $r = "@-" - } - jj bookmark set main -r $r ...$rest - jj git push -} - -alias la = ls -a -alias ll = ls -l -alias lal = ls -la -alias ccp = cp -prv -alias mvp = mv-full -pv - -def --env c [path: path = "~"] { - cd $path - l -} - -def l --wrapped [path: path = ".", ...rest] { - ls -t $path ...$rest | insert ext {|row| $row.name | parse "{name}.{ext}" | get ext | get 0? } | sort-by --natural type ext name | reject type ext -} - -alias list-automounts = systemctl list-units --type=automount - -def remount [] { - let reload = list-automounts | detect columns --guess | drop 5 | get DESCRIPTION | input list --multi - for mount in $reload { - sudo systemctl restart $mount - } -} - -def cpedit [file: path] { - mv $file $"($file).sym"; cp $"($file).sym" $file; chmod +w $file -} - -alias core-job = job -alias job = job list diff --git a/users/tao/nushell/extras/aliases.nu b/users/tao/nushell/extras/aliases.nu new file mode 100644 index 0000000..031d3b4 --- /dev/null +++ b/users/tao/nushell/extras/aliases.nu @@ -0,0 +1,82 @@ +export alias b = btm +export alias d = dirs +export alias da = dirs add +export alias dg = dirs goto +export alias dn = dirs next +export alias dp = dirs prev +export alias dr = dirs drop +export alias fetch = fastfetch +export alias follow = readlink -f +export alias p = pueue +export alias snapper = snapper -c home +export alias zl = zellij + +export alias cringe = sudo bootctl set-oneshot auto-windows + +export alias la = ls -a +export alias ll = ls -l +export alias lla = ls -la + +export def --env c [path: path = "~"] { + cd $path + l +} + +export def l --wrapped [path: path = ".", ...rest] { + ls -t $path ...$rest | insert ext {|row| $row.name | parse "{name}.{ext}" | get ext | get 0? } | sort-by --natural type ext name | reject type ext +} + +export def h [query?: path] { + (if ($query != null) {sk -1 -q ($query | path basename)} else {sk -1}) + | if ($in != "") { + hx $in + } + # | complete + # | if $in.exit_code == 0 { + # $in.stdout | str trim | hx $in + # } +} + +export def srg [] { + sk --ansi -i -c 'rg --color=always --line-number "{}"' +} + +export alias j = jj +export alias ja = jj log -r 'all()' +export alias jc = jj desc +export alias jd = jj diff +export alias je = jj edit +export alias jf = jj git fetch +export alias jg = jj git clone --colocate +export alias jp = jj git push +export alias js = jj status +export alias jw = jj workspace update-stale +export alias jt = jj log -r @ -T `description` +export alias jn = jj next --edit + +export def jm --wrapped [-r: string = "@", ...rest] { + mut r = $r + if (jj log -r @ --no-pager --no-graph --template 'if(empty,"empty")' | $in == "empty") { + $r = "@-" + } + jj bookmark set main -r $r ...$rest + jj git push +} + +export alias list-automounts = systemctl list-units --type=automount + +export def remount [] { + let reload = list-automounts | detect columns --guess | drop 5 | get DESCRIPTION | input list --multi + for mount in $reload { + sudo systemctl restart $mount + } +} + +export def cpedit [file: path] { + mv $file $"($file).sym"; cp $"($file).sym" $file; chmod +w $file +} + +export alias core-job = job +export alias job = job list + +export alias mpv-hdr-dv = mpv --target-trc=pq --target-prim=bt.2020 --target-peak=800 diff --git a/users/tao/nushell/extras/nix.nu b/users/tao/nushell/extras/nix.nu index 540560a..693f510 100644 --- a/users/tao/nushell/extras/nix.nu +++ b/users/tao/nushell/extras/nix.nu @@ -1,11 +1,11 @@ -def --wrapped rebuild [--force (-f), subcommand, ...rest] { +export def --wrapped rebuild [--force (-f), subcommand, ...rest] { if not ( df -h | detect columns --guess | where "Mounted on" == "/" or "Mounted on" == "/boot" | get Use% | each {parse "{usage}%" | get usage | into int} | flatten | all {$in < 99} ) and not $force { print "not enough disk space!" return false } - + mut builders = "" if (open /etc/hostname --raw) == "NOlaptop\n" and ($builders != "") { if (ping -c1 -W1 nocomputer | complete | $in.exit_code == 0) { @@ -27,9 +27,9 @@ def --wrapped rebuild [--force (-f), subcommand, ...rest] { } } -alias nd = nix develop +export alias nd = nix develop -def ns [...packages: string] { +export def ns [...packages: string] { let packages = $packages | each {$"nixpkgs#($in)"} nix shell ...$packages } @@ -38,16 +38,17 @@ def ns [...packages: string] { # nix search nixpkgs $package # } -def post-rebuild [] { +export def post-rebuild [] { rm -r ~/.config/helix/runtime/grammars/ hx --grammar fetch; hx --grammar build rustup update } -def get_gen [] { +export def get_gen [] { sudo nix-env --profile /nix/var/nix/profiles/system --list-generations | detect columns --guess -n | last | get column0 } -def bump [...rest] { + +export def bump [...rest] { cd /home/tao/projects/NOflake/ mut r = "@" loop { @@ -57,7 +58,7 @@ def bump [...rest] { } "empty" => { $r = $r + "-" - continue + continue } _ => { jj new -r $r -m "bump (unbuilt)" @@ -73,18 +74,17 @@ def bump [...rest] { if ($build_status and ($curr_gen == $new_gen)) { jj desc -r $r -m $"bump (date now | format date "%Y-%m-%d")" jj bookmark set main -r $r - jj git push --allow-empty-description + jj git push --allow-empty-description } else { jj desc -r $r -m "bump (failed)" } nvd history } -alias rb = rebuild boot -alias rs = rebuild switch +export alias rb = rebuild boot +export alias rs = rebuild switch -def gc [] { +export def gc [] { sudo nix-collect-garbage -d snapper clear } - diff --git a/users/tao/nushell/extras/stuff.nu b/users/tao/nushell/extras/stuff.nu index 87343d1..b302b56 100644 --- a/users/tao/nushell/extras/stuff.nu +++ b/users/tao/nushell/extras/stuff.nu @@ -1,12 +1,12 @@ -def done [] { +export def done [] { toastify send -a "" done } -def "config stuff" [] { +export def "config stuff" [] { hx ~/projects/NOflake/users/tao/nushell/stuff.nu } -def fixme [] { +export def fixme [] { let items = rg "FIXME|TODO" --json | lines | each {from json} @@ -24,26 +24,24 @@ def fixme [] { hx ($items | get $sel | $"($in.text):($in.line_number)") } -source ~/.zoxide.nu -def --wrapped --env z [...rest] { - zo ...$rest - l +export def "snapper list" [] { + snapper --csvout list | from csv | reject config subvolume default user used-space userdata active } -def "snapper list" [] { - snapper --csvout list | from csv | reject config subvolume default user used-space userdata active -} - -def "snapper clear" [] { +export def "snapper clear" [] { let list = snapper --csvout list | from csv | reject config subvolume default user used-space userdata active | skip 1 let first = $list | first let last = $list | last - snapper delete $"($first.number)-($last.number)" + if $first != $last { + snapper delete $"($first.number)-($last.number)" + } else { + snapper delete $first + } } -def "fans" [duty?: int] { +export def "fans" [duty?: int] { match (hostname) { "NOcomputer" => { let mode_path: path = (glob "/sys/devices/platform/nct6775.656/hwmon/hwmon*/pwm2_enable" | get 0) @@ -61,15 +59,15 @@ def "fans" [duty?: int] { } } -alias louder = fans 100 -alias loud = fans -alias quiet = fans 42 +export alias louder = fans 100 +export alias loud = fans +export alias quiet = fans 42 -def asciicam [] { +export def asciicam [] { $env.DISPLAY = null mpv -vo caca av://v4l2:/dev/video0 --demuxer-lavf-o=input_format=mjpeg --profile=low-latency e>| /dev/null } -def sunu [command] { +export def sunu [command] { sudo nu --stdin --commands $command } diff --git a/users/tao/nushell/extras/tailscale.nu b/users/tao/nushell/extras/tailscale.nu index c976eb7..5f3df5d 100644 --- a/users/tao/nushell/extras/tailscale.nu +++ b/users/tao/nushell/extras/tailscale.nu @@ -1,5 +1,5 @@ # see if others see us connecting from a mullvad exit node -def check-mullvad [] { +export def check-mullvad [] { print -n "checking mullvad status" mut check = false mut j = null @@ -13,7 +13,7 @@ def check-mullvad [] { } # switch to a specific exit node, or none -def te [exit_node: string = ""] { +export def te [exit_node: string = ""] { if ($exit_node | is-empty) and (ps | find deluge | is-not-empty) { print "stop summoning first!" return false @@ -25,12 +25,12 @@ def te [exit_node: string = ""] { check-mullvad } else { print "exit node set" - return true + return true } } # list all mullvad exit nodes -def tx [] { +export def tx [] { tailscale exit-node list | lines | drop 4 @@ -42,7 +42,7 @@ tailscale exit-node list } # sort mullvad exit nodes by fastest ping -def tsp [] { +export def tsp [] { tx | where COUNTRY == USA | par-each { @@ -66,18 +66,18 @@ tx } # switch to a random mullvad exit node -def tr [] { +export def tr [] { tx | get (random int 0..($in | length)) | te $in.IP | return $in } -alias t = tailscale -alias ts = tailscale status -alias tu = tailscale up -alias td = tailscale down -alias ta = tailscale exit-node suggest -alias tt = tailscale switch --list | detect columns | input list -d Tailnet | get ID | t switch $in +export alias t = tailscale +export alias ts = tailscale status +export alias tu = tailscale up +export alias td = tailscale down +export alias ta = tailscale exit-node suggest +export alias tt = tailscale switch --list | detect columns | input list -d Tailnet | get ID | t switch $in -alias wno = ssh root@whyfi "etherwake -i br-lan 04:42:1A:E7:62:C3" +export alias wno = ssh root@whyfi "etherwake -i br-lan 04:42:1A:E7:62:C3" diff --git a/users/tao/nushell/extras/theme.nu b/users/tao/nushell/extras/theme.nu new file mode 100644 index 0000000..244cc66 --- /dev/null +++ b/users/tao/nushell/extras/theme.nu @@ -0,0 +1,71 @@ +# For more information on defining custom themes, see +# https://www.nushell.sh/book/coloring_and_theming.html +# And here is the theme collection +# https://github.com/nushell/nu_scripts/tree/main/themes +export const dark_theme = { + # color for nushell primitives + separator: white + leading_trailing_space_bg: { attr: n } # no fg, no bg, attr none effectively turns this off + header: green_bold + empty: blue + # Closures can be used to choose colors for specific values. + # The value (in this case, a bool) is piped into the closure. + # eg) {|| if $in { 'light_cyan' } else { 'light_gray' } } + bool: light_cyan + int: white + filesize: cyan + duration: white + date: purple + range: white + float: white + string: white + nothing: white + binary: white + cell-path: 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_yellow_bold + shape_filepath: cyan + shape_flag: blue_bold + shape_float: purple_bold + # shapes are used to change the cli syntax highlighting + shape_garbage: { fg: white bg: red attr: b } + shape_glob_interpolation: cyan_bold + shape_globpattern: cyan_bold + shape_int: purple_bold + shape_internalcall: cyan_bold + shape_keyword: 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 + shape_raw_string: light_purple +} +