A while ago I made a tiny function in my ~/.zshrc to download a video from the link in my clipboard. I use this nearly every day to share videos with people without forcing them to watch it on whatever site I found it. What’s a script/alias that you use a lot?
# Download clipboard to tmp with yt-dlp
tmpv() {
cd /tmp/ && yt-dlp "$(wl-paste)"
}
I often want to know the status code of a
curlrequest, but I don’t want that extra information to mess with the response body that it prints to stdout.What to do?
Render an image instead, of course!

curlcattakes the same params ascurl, but it uses iTerm2’simgcattool to draw an “HTTP Cat” of the status code.It even sends the image to stderr instead of stdout, so you can still pipe
curlcattojqor something.#!/usr/bin/env zsh stdoutfile=$( mktemp ) curl -sw "\n%{http_code}" $@ > $stdoutfile exitcode=$? if [[ $exitcode == 0 ]]; then statuscode=$( cat $stdoutfile | tail -1 ) if [[ ! -f $HOME/.httpcat$statuscode ]]; then curl -so $HOME/.httpcat$statuscode https://http.cat/$statuscode fi imgcat $HOME/.httpcat$statuscode 1>&2 fi cat $stdoutfile | ghead -n -1 exit $exitcodeNote: This is macOS-specific, as written, but as long as your terminal supports images, you should be able to adapt it just fine.
LOVE this
this one is clean asl
I wrote a script called
please. You inputpleasefollowed by any other command (e.g.please git clone,please wget blahblah) and a robotic voice will say “affirmative,” then the command will run, and when it completes, the robotic voice reads out the exit code (e.g. “completed successfully” or “failed with status 1” etc.)This is useful for when you have a command that takes a long time and you want to be alerted when it’s finished. And it’s a gentleman.
You can also use something like notifyd to generate a pop up for visual feedback :) I can’t remember the exact command right now though. Differs per distro or desktop environment, obviously.
notify-send 'command finished!'works pretty wellAlso,
printf '\a'will output an alert bell character which should make the terminal beep/blink and be highlighted for attention by your wm/compositor if it’s unfocused.I have that aliased to
ato get notified whenever a long running command finishes just by adding;aat the end.
I once experimented with something similar, except it was supported to trigger my smart speaker and drop into another part of the house to tell me.
Honestly, I really need to replace my proprietary smart speaker system with something self-hosted; it’s just I only recently have had the time to start cinsidering.
Here are probably the most useful ones. I prefer for
rmto be interactive so I don’t accidentally delete something important and formkdirto create a parent directory if necessary.alias rm='rm -i' alias mkdir='mkdir -p' alias podup='podman-compose down && podman-compose pull && podman-compose up -d'This extract function (which I didn’t make myself, I got it from when I was using nakeDeb) has been pretty useful too.
function extract() { if [ -f $1 ] ; then case $1 in *.tar.bz2) tar xvjf $1 ;; *.tar.gz) tar xvzf $1 ;; *.bz2) bunzip2 $1 ;; *.rar) unrar x $1 ;; *.gz) gunzip $1 ;; *.tar) tar xvf $1 ;; *.tbz2) tar xvjf $1 ;; *.tgz) tar xvzf $1 ;; *.zip) unzip $1 ;; *.Z) uncompress $1 ;; *.7z) 7z x $1 ;; *.xz) unxz $1 ;; *) echo "'$1' cannot be extracted via >extract<" ;; esac else echo "'$1' is not a valid file" fi }I have a similar docker/podman alias, except I pull first. This greatly reduces downtime between
downandup, which is nice for critical services.Yeah, that makes sense. I don’t have anything critical; just nginx, a book server, a recipe collection, and some other small stuff.
deleted by creator
alias clip='xclip -selection clipboard'When you pipe to this, for example
ls | clip, it will stick the output of the command ran into the clipboard without needing to manually copy the output.I use a KDE variant of this that uses klipper instead (whatever you pipe to this will be available in klipper):
` #!/bin/sh
function copy { if ! tty -s && stdin=$(</dev/stdin) && [[ "$stdin" ]]; then stdin=$stdin$(cat) qdbus6 org.kde.klipper /klipper setClipboardContents "$stdin" exit fi qdbus6 org.kde.klipper /klipper getClipboardContents } copy $@`Pretty sure this only works on x distros?
wl-copyandwl-pasteare for Wayland FYI.Yep, pretty sure you are right.
alias sl=“ls“real ones watch the train of shame
alias sl='ls | while IFS= read -r line; do while IFS= read -r -n1 char; do if [[ -z "$char" ]]; then printf "\n"; else printf "%s" "$char"; sleep 0.05; fi; done <<< "$line"; done'I can’t easily check if it works until I get home to my laptop, but you get the idea
deleted by creator
deleted by creator
#Create a dir and cd into it mkcd() { mkdir -p "$@" && cd "$@"; }Here’s a script I use a lot that creates a temporary directory, cds you into it, then cleans up after you exit. Ctrl-D to exit, and it takes you back to the directory you were in before.
Similar to what another user shared replying to this comment but mine is in bash + does these extra stuff.
#!/bin/bash function make_temp_dir { # create a temporary directory and cd into it. TMP_CURR="$PWD"; TMP_TMPDIR="$(mktemp -d)"; cd "$TMP_TMPDIR"; } function del_temp_dir { # delete the temporary directory once done using it. cd "$TMP_CURR"; rm -r "$TMP_TMPDIR"; } function temp { # create an empty temp directory and cd into it. Ctr-D to exit, which will # delete the temp directory make_temp_dir; bash -i; del_temp_dir; } tempThat’s a helpful one! I also add a function that creates a tmp directory, and cds to it which I frequently use to open a scratch space. I use it a lot for unpacking tar files, but for other stuff too.
(These are nushell functions)
# Create a directory, and immediately cd into it. # The --env flag propagates the PWD environment variable to the caller, which is # necessary to make the directory change stick. def --env dir [dirname: string] { mkdir $dirname cd $dirname } # Create a temporary directory, and cd into it. def --env tmp [ dirname?: string # the name of the directory - if omitted the directory is named randomly ] { if ($dirname != null) { dir $"/tmp/($dirname)" } else { cd (mktemp -d) } }
alias fuck='sudo $(history -p \!\!)'sudo !!Try it, and you will find it just does not provide the same emotional peace.
I like to imagine I’m yelling it. SUDO!!!
:D
Nice
Why not use thefuck which also corrects typos?
Because i’m not a psychopath, just autistic.
I have the same but it’s called “please”
i touch computers since almost 40 years. “Please” stopped being an option somewhere in the early 2000’s.
One of favorites cds to the root of a project directory from a subdirectory,
# Changes to top-level directory of git repository. alias gtop="cd \$(git rev-parse --show-toplevel)"For doing stuff in a directory, I use a replacement for
cdcommand.For aliases:
alias +='git add' alias +p='git add -p' alias +u='git add -u' alias -- -='cd -' alias @='for i in' alias c='cargo' alias date='LANG=C date' alias diff='cdiff' alias gg='git grep -n' alias grep='grep --color=auto' alias ll='ls -o' alias ls='ls -vFT0 --si --color=auto --time-style=long-iso' alias rmd='rmdir'I also have various small scripts and functions:
afor package management (thinkaptbut has simplified arguments which makes it faster to use in usual cases),efor opening file in Emacs,gforgit,sforsudo.
And here’s
,:$ cat ~/.local/bin/, #!/bin/sh if [ $# -eq 0 ]; then paste -sd, else printf '%s\n' "$@" | paste -sd, fiThis tmux wrapper is remarkably convenient:
Usage:
# Usage: t [session-name] # # With no arguments: # Lists existing tmux sessions, or prints "[No sessions]" if none exist. # # With a session name: # Attempts to attach to the named tmux session. # If the session does not exist, creates a new session with that name. # # Examples: # t # Lists all tmux sessions # t dev # Attaches to "dev" session or creates it if it doesn't exist function t { if [[ -z $1 ]]; then tmux ls 2> /dev/null || echo "[No sessions]" else tmux attach -t $@ 2> /dev/null if [[ $? -ne 0 ]]; then tmux new -s $@ fi fi }$ which diffuc diffuc: aliased to diff -uw --color=always$ which grepnir grepnir: aliased to grep -niIr$ cat `which ts` #!/bin/bash if [ "$#" -lt 1 ]; then tmux list-sessions exit fi if ! tmux attach -t "$1" then tmux new-session -s "$1" fihere we go:
dedup:
#!/usr/bin/awk -f !x[$0]++this removes duplicate lines, preserving line order
iter:
#!/usr/bin/bash if [[ "${@}" =~ /$ ]]; then xargs -rd '\n' -I {} "${@}"{} else xargs -rd '\n' -I {} "${@}" {} fiThis executes a command for each line. It can also be used to compare two directories, ie:
du -sh * > sizes; ls | iter du -sh ../kittens/ > sizes2fadeout:
#!/bin/bash # I use this to fade out layered brown noise that I play at a volume of 130% # This takes about 2 minutes to run, and the volume is at zero several seconds before it's done. # ################ # DBUS_SESSION_BUS_ADDRESS is needed so that playerctl can find the dbus to use MPRIS so it can control mpv export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus" # ################ for i in {130..0} do volume=$(echo "scale=3;$i/100" | bc) sleep 2.3 playerctl --player=mpv volume $volume donelbn:
#!/bin/bash #lbn_pid=$(cat ~/.local/state/lbn.pid) if pgrep -fl layered_brown then pkill -f layered_brown else export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus" mpv -ao pulse ~/layered_brown_noise.mp3 >>lbn.log 2>&1 & sleep 3 playerctl -p mpv volume 1.3 >>lbn.log 2>&1 & fiThis plays “layered brown noise” by crysknife. It’s a great sleep aid.
here are some aliases:
alias m='mpc random off; mpc clear' alias mpcc='ncmpcpp' alias thesaurus='dict -d moby-thesaurus' alias wtf='dict -d vera' alias tvplayer='mpv -fs --geometry=768x1366+1366+0'on most of my systems I get tired of constantly
lsing after acdso I combine them:cd(){ cd $1 && ls }(excuse if this doesn’t work, I am writing this from memory)
I also wrote a function to access docker commands quicker on my Truenas system. If passed nothing, it enters the docker jailmaker system, else it passes the command to docker running inside the system.
docker () { if [[ "$1" == "" ]]; then jlmkr shell docker return else sudo systemd-run --pipe --machine docker docker "$@" return fi }I have a few similar shortcuts for programs inside jailmaker and long directories that I got sick of typing out.
I have a collection of about 8 machines around the house (a lot of Raspberry Pi) that I ssh around to from various points.
I have setup scripts named: ssp1 ssp2 ssba ss2p etc. to ssh into the various machines, and of course shared public ssh keys among them to skip the password prompt. So, yes, once you are “in” one machine in my network, if you know this, you are “in” all of them, but… it’s bloody convenient.
I used to have scripts like that, but eventually switched to ssh aliases. You can set up an alias for each machine in
~/.ssh/configwith lines like this:Host p1 HostName 192.168.1.123 Port 22 User piThen access with
ssh p1. Slightly more typing, but avoids adding more commands to your $PATH. Also has the benefit of letting you use the same alias with other ssh-related commands like sftp.












