nushell etc for nomom

This commit is contained in:
Tao Tien 2025-03-08 22:35:46 -08:00
parent 620fe90134
commit 77c3aa4fc1
11 changed files with 1400 additions and 2 deletions

View file

@ -0,0 +1,41 @@
alias xo = xdg-open
# alias h = hx (sk)
alias b = btm
alias cringe = sudo bootctl set-oneshot auto-windows
alias fetch = fastfetch
alias ff = firefox
alias pu = pueue
alias t = task
alias zl = zellij
alias snapper = snapper -c home
alias follow = readlink -f
alias la = ls -a
alias quiet = sudo ectool fanduty 42
alias loud = sudo ectool autofanctrl
alias cp-full = cp
alias cp = cp -prv
alias mv-full = mv
alias mv = mv -pv
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 jm = jj bookmark set main
alias jp = jj git push
alias js = jj status
alias jw = jj workspace update-stale
def jm [-r: string = "@"] {
mut r = $r
if (jj log -r @ --no-pager --no-graph --template 'if(empty,"empty")' | $in == "empty") {
$r = "@-"
}
jj bookmark set main -r $r
jj git push
}

View file

@ -0,0 +1,47 @@
alias nd = nix develop
def ns [package] {
nix shell $"nixpkgs#($package)"
}
def nr [package] {
nix search nixpkgs $package
}
def rebuild --wrapped [subcommand, --builders: string, ...rest] {
mut builders = $builders;
if (open /etc/hostname --raw) == "NOlaptop\n" and ($builders != "") {
if (ping -c1 -W1 nocomputer | complete | $in.exit_code == 0) {
sudo nix store info --store ssh://nocomputer
} else {
$builders = ""
}
}
if ($builders == "") {
sudo systemd-inhibit nice -n19 nixos-rebuild $subcommand --flake . --impure --verbose --builders ""
} else {
sudo systemd-inhibit nice -n19 nixos-rebuild $subcommand --flake . --impure --verbose ...$rest
}
toastify send rebuild done!
}
def post-rebuild [] {
rm -r ~/.config/helix/runtime/grammars/
hx --grammar fetch; hx --grammar build
rustup update
}
def bump --wrapped [...rest] {
cd /home/tao/projects/NOflake/
jj new -m "bump"
nix flake update
# rc2nix | save -f /home/tao/projects/NOflake/users/tao/plasma.nix;
# sudo nix store ping --store ssh://nocomputer
rebuild boot ...$rest
jj new
}
alias rb = rebuild boot
alias rs = rebuild switch
alias gc = nh clean all

View file

@ -0,0 +1,62 @@
# task
def h [query?: path] {
(if ($query != null) {sk -1 -q ($query | path basename)} else {sk -1})
| complete
| if $in.exit_code == 0 {
$in.stdout | str trim | hx $in
}
}
def --env c [path: path = "~"] {
cd $path
l
}
def l [
--all (-a)
--long (-l)
path: path = "."
] {
if $all and $long {
ls -la $path
} else if $all {
ls -a $path
} else if $long {
ls -l $path
} else {
ls $path
}
| sort-by type name -i -n
}
def srg [] {
sk --ansi -i -c 'rg --color=always --line-number "{}"'
}
def "config stuff" [] {
hx ~/projects/NOflake/users/tao/nushell/stuff.nu
}
def deluge-gtk [] {
tsr
deluge-gtk
}
alias deluge = deluge-gtk
def fixme [] {
rg TODO --json
| lines
| each {from json}
| where type == "match"
| get data
| flatten
| each {$"($in.text):($in.line_number)"}
| hx ...$in
}
# source ~/.cache/starship/init.nu
# source ~/.cache/carapace/init.nu
source ~/.zoxide.nu
def --env z [path: string = "~"] {
zo $path
l
}

View file

@ -0,0 +1,77 @@
# see if others see us connecting from a mullvad exit node
def check-mullvad [] {
print -n "checking mullvad status"
mut check = false
mut j = null
while not $check {
print -n "."
$j = (http get https://am.i.mullvad.net/json)
$check = $j.mullvad_exit_ip
}
print ""
print $"connected to ($j.city), ($j.country)"
}
# switch to a specific exit node, or none
def tse [exit_node: string = ""] {
if ($exit_node | is-empty) and (ps | find deluge | is-not-empty) {
return "stop summoning first!"
} else {
tailscale set --exit-node $exit_node
}
if ($exit_node | is-not-empty) {
check-mullvad
}
return "exit node set"
}
# list all mullvad exit nodes
def tsx [] {
tailscale exit-node list
| lines
| drop 4
| skip 1
| to text
| detect columns --guess
| where HOSTNAME =~ mullvad
| reject STATUS
}
# sort mullvad exit nodes by fastest ping
def tsp [] {
tsx
| where COUNTRY == USA
| par-each {
insert ping {
$in.HOSTNAME
| str replace "mullvad.ts.net" "relays.mullvad.net"
| try {
print $"pinging ($in)"
ping -c5 -q $in
| lines
| last
| split row ' '
| get 3
| split row '/'
| get 1
| into float
}
}
}
| sort-by ping
}
# switch to a random mullvad exit node
def tsr [] {
tsx
| get (random int 0..($in | length))
| tse $in.IP
}
alias ts = tailscale
alias tss = tailscale status
alias tsu = tailscale up
alias tsd = tailscale down
alias tsa = tailscale exit-node suggest