nushell refactoring
This commit is contained in:
parent
636dddce81
commit
2b3862bf01
9 changed files with 162 additions and 137 deletions
|
|
@ -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
|
||||
82
users/tao/nushell/extras/aliases.nu
Normal file
82
users/tao/nushell/extras/aliases.nu
Normal 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
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,8 +0,0 @@
|
|||
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
|
||||
}
|
||||
|
||||
# Just: A Command Runner
|
||||
export extern "just" [
|
||||
...recipe: string@"nu-complete just", # Recipe(s) to run, may be with argument(s)
|
||||
]
|
||||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue