nix-configs/modules/shell/nu/custom_commands.nu
2025-01-01 05:16:08 +01:00

67 lines
1.6 KiB
Text

# 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)' &";
}