nushell refactoring

This commit is contained in:
Tao Tien 2026-03-27 22:48:34 -07:00
parent 636dddce81
commit 2b3862bf01
9 changed files with 162 additions and 137 deletions

View file

@ -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.".config/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;
};
};

View file

@ -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
}

View file

@ -825,3 +825,8 @@ $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
use aliases.nu *
use nix.nu *
use stuff.nu *
use tailscale.nu *

View file

@ -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

View file

@ -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

View file

@ -1,4 +1,4 @@
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 {
@ -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 {
@ -80,11 +81,10 @@ def bump [...rest] {
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
}

View file

@ -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,30 @@ def fixme [] {
hx ($items | get $sel | $"($in.text):($in.line_number)")
}
source ~/.zoxide.nu
def --wrapped --env z [...rest] {
# source ~/.zoxide.nu
export def --wrapped --env z [...rest] {
zo ...$rest
l
}
def "snapper list" [] {
export 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 +65,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
}

View file

@ -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
@ -30,7 +30,7 @@ def te [exit_node: string = ""] {
}
# 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"