add convenience functinos to nu

Proxied wrappers around messengers and a nifty function to write pngs
from the clipboard to a file with a single terminal command.
This commit is contained in:
Arne Dußin 2025-03-27 15:50:54 +03:00
parent 5bf491847d
commit c5111a4896

View file

@ -20,6 +20,47 @@ def lt [] { ls | sort-by type name -i | grid -c | str trim }
alias j = joshuto
alias e = hx .
alias code = cd ~/dev/
alias naive = naiveproxy .config/naiveproxy.json
def discord [] {
if $env.http_proxy? != null {
webcord --proxy-server=($env.http_proxy)
} else {
webcord
}
}
def element [] {
if $env.http_proxy? != null {
element-desktop --proxy-server=($env.http_proxy)
} else {
element-desktop
}
}
# Save an image from the clipboard to `file` or `clipboard.png` if no parameter is given
def save_png [file: string = "clipboard"] {
# -----
# Check for a png image available in the X clipboard
# ----v
let targets = xclip -selection clipboard -t TARGETS -o # Line separated list of available Atoms
let num_png = $targets | find image/png | length # Count the number of image/png occurences
if $num_png < 1 {
print "There is no valid png image in the clipboard"
return null # Abort
}
# NOTE: Another application may have jumped in here and cleared the clipboard
# selection. This is unlikely but begs for admonition here.
# ----
# Save the png in the clipboard to the file requested
# ---v
let file = $"($file).png" # Append png to the target file name
xclip -selection clipboard -t image/png -o | save $file # Get clipboard png contents and write them to `file`
print $"Clipboard saved to `($file)`"
}
# Go to the repository with the name and start a nix development shell there.
# If no argument is given a nix development shell will be started in the current dir.