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 don't have anything too fancy. I use [theFuck(https://github.com/nvbn/thefuck) to handle typos, and I have some variables set to common directories that I use.
I made this one to find binaries in NixOs and other systems
get_bin_path() {
paths=${2:-$PATH}
for dr in $(echo $paths | tr ':' '\n') ; do
if [ -f "$dr/$1" ] ; then
echo "$dr/$1"
return 0
fi
done
return 1
}
Then I made this one to, if I have a shell o
opened inside neovim it will tell the neovim process running the shell to open a file on it, instead of starting a new process
_nvim_con() {
abs_path=$(readlink --canonicalize "$@" | sed s'| |\\ |'g)
$(get_bin_path nvim) --server $NVIM --remote-send "<ESC>:edit $abs_path<CR>"
exit
}
# start host and open file
_nvim_srv() {
$(get_bin_path nvim) --listen $HOME/.cache/nvim/$$-server.pipe $@
}
if [ -n "$NVIM" ] ; then
export EDITOR="_nvim_con"
else
export EDITOR="_nvim_srv"
fi
Lastly this bit:
which if it detects a file and a line number split by a : it will open the file and jump to the line
_open() {
path_parts=$(readlink --canonicalize "$@" | sed s'| |\\ |'g | sed 's/:/\t/' )
file=$(echo "$path_parts" | awk ' { print $1 }' )
line=$(echo "$path_parts" | awk ' { print $2 }' )
if [ -n "$line" ] ; then
# has line number
if [ -n "$NVIM" ] ; then
$(get_bin_path nvim) --server $NVIM --remote-send "<ESC>:edit $file<CR>:+$line<CR>"
exit
else
$(get_bin_path nvim) --listen $HOME/.cache/nvim/$$-server.pipe $file "+:$line"
fi
else
$EDITOR $file
fi
}
alias nvim="_open"
git() {
if [ "$1" = "cd" ]; then
shift
cd "./$(command git rev-parse --show-cdup)$*"
else
command git "$@"
fi
}
This lets you run git cd to go to the root of your repo, or git cd foo/bar to go to a path relative to that root. You can't do it as an alias because it's conditional, and you can't do it as a git-cd command because that wouldn't affect the current shell.
on most of my systems I get tired of constantly lsing after a cd so 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.
alias nmtui="NEWT_COLORS='root=black,black;window=black,black;border=white,black;listbox=white,black;label=blue,black;checkbox=red,black;title=green,black;button=white,red;actsellistbox=white,red;actlistbox=white,gray;compactbutton=white,gray;actcheckbox=white,blue;entry=lightgray,black;textbox=blue,black' nmtui"
well i have a script. ive named it "shazam". it either creates or attachs to a tmux session named after the base name of the dir (first arg or current working directory). i also have "fzf-shazam" as the same suggests itll open a fzf finder to choose a dir to "shazam"
To save videos from certain streaming sites that are not supported by yt-dlp, I catch the M3U playlist used by the page and with that I use this script that gets ffmpeg to put together the pieces into a single file.
#!/bin/bash
if [ "$1" == "-h" ] || [ $# -lt 2 ]; then
echo Download a video from a playlist into a single file
echo usage: $(basename $0) PLAYLIST OUTPUT_VID
exit
fi
nbparts=$(grep ^[^#] $1 | wc -l)
echo -e "\e[38;5;202m Downloading" $(( nbparts - 1 )) "parts \e[00m"
time ffmpeg -hide_banner -allowed_extensions ALL -protocol_whitelist file,http,https,tcp,tls,crypto -i $1 -codec copy $2
I wrote a script called please. You input please followed 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.
Well, my full functions.sh won't fit in a comment, so here's 2 of my more unique functions that makes life a little easier when contributing to busy OSS projects:
# Git fork sync functions
# Assumes standard convention: origin = your fork, upstream = original repo
## Sync fork with upstream before starting work
gss() {
# Safety checks
if ! git rev-parse --git-dir >/dev/null 2>&1; then
echo "❌ Not in a git repository"
return 1
fi
# Check if we're in a git operation state
local git_dir=$(git rev-parse --git-dir)
if [[ -f "$git_dir/rebase-merge/interactive" ]] || [[ -d "$git_dir/rebase-apply" ]] || [[ -f "$git_dir/MERGE_HEAD" ]]; then
echo "❌ Git operation in progress. Complete or abort current rebase/merge first:"
echo " git rebase --continue (after resolving conflicts)"
echo " git rebase --abort (to cancel rebase)"
echo " git merge --abort (to cancel merge)"
return 1
fi
# Check for uncommitted changes
if ! git diff-index --quiet HEAD -- 2>/dev/null; then
echo "❌ You have uncommitted changes. Commit or stash them first:"
git status --porcelain
echo ""
echo "💡 Quick fix: git add . && git commit -m 'WIP' or git stash"
return 1
fi
# Check for required remotes
if ! git remote get-url upstream >/dev/null 2>&1; then
echo "❌ No 'upstream' remote found. Add it first:"
echo " git remote add upstream <upstream-repo-url>"
return 1
fi
if ! git remote get-url origin >/dev/null 2>&1; then
echo "❌ No 'origin' remote found. Add it first:"
echo " git remote add origin <your-fork-url>"
return 1
fi
local current_branch=$(git branch --show-current)
# Ensure we have a main branch locally
if ! git show-ref --verify --quiet refs/heads/main; then
echo "❌ No local 'main' branch found. Create it first:"
echo " git checkout -b main upstream/main"
return 1
fi
echo "🔄 Syncing fork with upstream..."
echo " Current branch: $current_branch"
# Fetch with error handling
if ! git fetch upstream; then
echo "❌ Failed to fetch from upstream. Check network connection and remote URL."
return 1
fi
echo "📌 Updating local main..."
if ! git checkout main; then
echo "❌ Failed to checkout main branch"
return 1
fi
if ! git reset --hard upstream/main; then
echo "❌ Failed to reset main to upstream/main"
return 1
fi
echo "⬆️ Pushing updated main to fork..."
if ! git push origin main; then
echo "❌ Failed to push main to origin. Check push permissions."
return 1
fi
echo "🔀 Rebasing feature branch on updated main..."
if ! git checkout "$current_branch"; then
echo "❌ Failed to checkout $current_branch"
return 1
fi
if ! git rebase main; then
echo "❌ Rebase failed due to conflicts. Resolve them and continue:"
echo " 1. Edit conflicted files"
echo " 2. git add <resolved-files>"
echo " 3. git rebase --continue"
echo " Or: git rebase --abort to cancel"
return 1
fi
echo "✅ Ready to work on branch: $current_branch"
}
## Sync fork and push feature branch
gsp() {
# Safety checks
if ! git rev-parse --git-dir >/dev/null 2>&1; then
echo "❌ Not in a git repository"
return 1
fi
local git_dir=$(git rev-parse --git-dir)
if [[ -f "$git_dir/rebase-merge/interactive" ]] || [[ -d "$git_dir/rebase-apply" ]] || [[ -f "$git_dir/MERGE_HEAD" ]]; then
echo "❌ Git operation in progress. Complete or abort first."
return 1
fi
if ! git diff-index --quiet HEAD -- 2>/dev/null; then
echo "❌ You have uncommitted changes. Commit or stash them first:"
git status --porcelain
return 1
fi
if ! git remote get-url upstream >/dev/null 2>&1; then
echo "❌ No 'upstream' remote found"
return 1
fi
if ! git remote get-url origin >/dev/null 2>&1; then
echo "❌ No 'origin' remote found"
return 1
fi
local current_branch=$(git branch --show-current)
# Prevent pushing from main
if [[ "$current_branch" == "main" ]]; then
echo "❌ Cannot push from main branch. Switch to your feature branch first:"
echo " git checkout <your-feature-branch>"
return 1
fi
# Show what we're about to do
echo "⚠️ About to sync and push branch: $current_branch"
echo " This will:"
echo " • Fetch latest changes from upstream"
echo " • Rebase your branch on updated main"
echo " • Force-push to your fork (updates PR)"
echo ""
read -p "Continue? [y/N]: " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "❌ Operation cancelled"
return 0
fi
echo "🔄 Final sync with upstream..."
if ! git fetch upstream; then
echo "❌ Failed to fetch from upstream"
return 1
fi
echo "📌 Updating local main..."
if ! git checkout main; then
echo "❌ Failed to checkout main"
return 1
fi
if ! git reset --hard upstream/main; then
echo "❌ Failed to reset main"
return 1
fi
if ! git push origin main; then
echo "❌ Failed to push main to origin"
return 1
fi
echo "🔀 Rebasing feature branch..."
if ! git checkout "$current_branch"; then
echo "❌ Failed to checkout $current_branch"
return 1
fi
if ! git rebase main; then
echo "❌ Rebase failed. Resolve conflicts and try again:"
echo " git add <resolved-files> && git rebase --continue"
echo " Then run 'gsp' again"
return 1
fi
echo "🚀 Pushing feature branch to fork..."
if ! git push origin "$current_branch" --force-with-lease; then
echo "❌ Failed to push to origin. The branch may have been updated."
echo " Run 'git pull origin $current_branch' and try again"
return 1
fi
echo "✅ Feature branch $current_branch successfully pushed to fork"
}
# 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
}
Optional: connect a storage device (local partition, USB drive, etc) for persistent storage
Modify cfg/cfg.sh if it's the first time using the tool
Run setup.sh to configure the environment into a familiar/productive state
The tools are flexible on hardware (more directed toward x64 systems at this time), and I (almost) never have to worry about OS upgrades. Just boot into a newer live OS image once it's ready. They are still a work-in-progress and still have a few customizations that I should abstract for more general use, but it's FOSS in case anyone has merge requests, issues, suggestions, etc.
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 often want to know the status code of a curl request, 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!
curlcat takes the same params as curl, but it uses iTerm2's imgcat tool to draw an "HTTP Cat" of the status code.
It even sends the image to stderr instead of stdout, so you can still pipe curlcat to jq or 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 $exitcode
Note: This is macOS-specific, as written, but as long as your terminal supports images, you should be able to adapt it just fine.
I alias traditional stuff to better, usually drop-in versions of that thing on computers that have the better thing. I often forget which systems have the better thing, so this helps me get the better experience if I was able to install it at some point. For example I alias cat to bat, or top to htop, or dig to drill, etc.
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.
this removes duplicate lines, preserving line order
iter:
#!/usr/bin/bash
if [[ "${@}" =~ /$ ]]; then
xargs -rd '\n' -I {} "${@}"{}
else
xargs -rd '\n' -I {} "${@}" {}
fi
This executes a command for each line. It can also be used to compare two directories, ie:
du -sh * > sizes; ls | iter du -sh ../kittens/ > sizes2
fadeout:
#!/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
done
This 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'
Hey OP, consider using $XDG_RUNTIME_DIR instead of /tmp. It's now the more proper place for these kinds of things to avoid permission issues, although I'm sure you're on a single user system like most people. I have clipboard actions set to download with yt-dlp :)
My favorite aliases are:
alias dff='findmnt -D -t nosquashfs,notmpfs,nodevtmpfs,nofuse.portal,nocifs,nofuse.kio-fuse'
Here are probably the most useful ones. I prefer for rm to be interactive so I don't accidentally delete something important and for mkdir to 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
}
Here is on that I actually don't use, but want to use it in scripts. It is meant to be used by piping it. It's simple branch with user interaction. I don't even know if there is a standard program doing exactly that already.
# usage: yesno [prompt]
# example:
# yesno && echo yes
# yesno Continue? && echo yes || echo no
yesno() {
local prompt
local answer
if [[ "${#}" -gt 0 ]]; then
prompt="${*} "
fi
read -rp "${prompt}[y/n]: " answer
case "${answer}" in
[Yy0]*) return 0 ;;
[Nn1]*) return 1 ;;
*) return 2 ;;
esac
}
I use Clevis to auto-unlock my encrypted root partition with my TPM; this means when my boot partition is updated (E.G a kernel update), I have to update the PCR register values in my TPM. I do it with my little script /usr/bin/update_pcr:
I run it with sudo and this handles it for me. The only issue is I can't regenerate the binding immediately after the update; I have to reboot, manually enter my password to decrypt the drive, and then do it.
Now, if I were really fancy and could get it to correctly update the TPM binding immediately after the update, I would have something like an apt package shim with a hook that does it seamlessly. Honestly, I'm surprised that distributions haven't developed robust support for this; the technology is clearly available (I'm using it), but no one seems to have made a user-friendly way for the common user to have TPM encryption in the installer.
I've only used aliases twice so far. The first was to replace yt-dlp with a newer version because the version that comes pre-installed in Linux Mint is too outdated to download videos from YouTube. The second was because I needed something called "Nuget". I don't remember exactly what Nuget is but I think it was a dependency for some application I tried several months ago.
alias yt-dlp='/home/j/yt-dlp/yt-dlp'
alias nuget="mono /usr/local/bin/nuget.exe"
Delete all the Docker things. I do this surprisingly often:
alias docker-nuke="docker system prune --all --volumes --force"
This is a handy one for detecting a hard link
function is-hardlink {
count=$(stat -c %h -- "${1}")
if [ "${count}" -gt 1 ]; then
echo "Yes. There are ${count} links to this file."
else
echo "Nope. This file is unique."
fi
}
I run this one pretty much every day. Regardless of the distro I'm using, it Updates All The Things:
function up {
if [[ $(command -v yay) ]]; then
yay -Syu --noconfirm
yay -Yc --noconfirm
elif [[ $(command -v apt) ]]; then
sudo apt update
sudo apt upgrade -y
sudo apt autoremove -y
fi
flatpak update --assumeyes
flatpak remove --unused --assumeyes
}
I maintain an aliases file in GitLab with all the stuff I have in my environment if anyone is curious.
it's somewhat vibe coded but the one i probably use the most is this one to swap between speakers and headset. the device name to look for is just put directly in there, it'd take some adjustment to run it on different machines. this is in my .bashrc:
# switch sinks
toggle_audio() {
# Find headset sink ID dynamically
headset_id=$(pactl list sinks short | grep "Plantronics" | awk '{print $1}')
# Find speakers sink ID dynamically
speakers_id=$(pactl list sinks short | grep "pci-0000_05_00.6" | awk '{print $1}')
# Get current default sink
current_sink=$(pactl get-default-sink)
# Get current sink ID
current_id=$(pactl list sinks short | grep "$current_sink" | awk '{print $1}')
# Toggle between the two
if [ "$current_id" = "$headset_id" ]; then
pactl set-default-sink "$speakers_id"
echo "Switched to speakers (Sink $speakers_id)"
else
pactl set-default-sink "$headset_id"
echo "Switched to headset (Sink $headset_id)"
fi
}
generally i try not to use too many custom things because for work i regularly work on all kinds of different servers and i've just been too lazy to set up some solution to keep it all in sync. someday....
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:
a for package management (think apt but has simplified arguments
which makes it faster to use in usual cases),
e for opening file in Emacs,
g for git,
s for sudo.
And here’s ,:
$ cat ~/.local/bin/,
#!/bin/sh
if [ $# -eq 0 ]; then
paste -sd,
else
printf '%s\n' "$@" | paste -sd,
fi
This one is just a basic mirror fixing thing cuz sometimes I go a while without updating pacman:
alias fixpkg='rate-mirrors --protocol https arch | sudo tee /etc/pacman.d/mirrorlist && sudo pacman -Syy'
This function I made to create virtual audio sinks so I can route audios via qpw and play earrape into discord calls if I want XD
create_vsink() {
local sink_name=${1:-vsink} # Default sink name is 'vsink' if no input is provided
local description=${2:-"Virtual Sink"} # Default description
pactl load-module module-null-sink sink_name="$sink_name" sink_properties=device.des>
echo "Virtual sink '$sink_name' created with description '$description'."
}
Simple parser function I made that makes a whole repo using my git key so it's not just locally created I kinda forgot why I made it tbh:
git_clone() {
local url="${1#https://}" # Remove "https://" if present
git clone "https://$git_key@$url"
}
Awesome mpv function I made that allows for real time pitch+speed shifting via hotkeys and is flexible with extra parameters and shit:
Automatic audio router for firefox audio streams that uses the aforementioned create_sink function to make a specific sink that I can use carla on to mix and make cool shit out of haha
firefox_crush() {
create_vsink CrunchSink "CrunchSink"
firefox --name firefox-vc &
(while true; do
SINK_INPUT_ID=$(pactl list sink-inputs short | grep "firefox" | awk '{print $1}')
if [[ -n "$SINK_INPUT_ID" ]]; then
pactl move-sink-input "$SINK_INPUT_ID" CrunchSink
break
fi
sleep 0.25
done) &
}
I usually set up an alias or script to update everything on my system. For example, on Ubuntu, I would do this: alias sysup='snap refresh && apt update && apt upgrade'
And on Arch, I do this: alias sysup ='flatpak update && paru'
Funny enough you'd need to use sudo to run this on Ubuntu, but not in the Arch example because paru being neat
3 of these, 1 for each of my headless vm's/computers that's just an SSH command
dcompose(d/pull) - docker compose (down/pull)
3 scripts that are just docker compose up/down/pull, as scripts (remind me in 6 hours and I will post the scripts) so that it will CD to my compose folder, execute the command (with option for naming specific containers or blank for all) and then CD back to the directory I started in.
I have started my daily drawing journey which i still am bad at it. To create a new .kra files files every day I use this
#/usr/bin/bash
days=$(</var/home/monika/scripts/days)
echo "$days"
file_name=/var/home/monika/Pictures/Art/day$days.kra
if [ -f $file_name ]; then
echo file is present
else
if [[ $days%7 -eq 0 ]]; then
echo "Week completed"
fi
cp "/var/home/monika/scripts/duplicate.kra" $file_name
flatpak run org.kde.krita $file_name
echo $(($days + 1)) >/var/home/monika/scripts/days
fi
My desktop text editor has an autosave feature, but it only works after you've manually saved the file. All I wanted is something like the notes app on my phone, where I can jot down random thoughts without worrying about naming a new file. So here's the script behind my text editor shortcut, which creates a new text file in ~/.drafts, names it with the current date, adds a suffix if the file already exists, and finally opens the editor:
#!/bin/bash
name=/home/defacto/.drafts/"`date +"%Y%m%d"`"_text
if [[ -e "$name" || -L "$name" ]] ; then
i=1
while [[ -e "$name"_$i || -L "$name"_$i ]] ; do
let i++
done
name="$name"_$i
fi
touch -- "$name"
pluma "$name" #replace pluma with your editor of choice
Because using docker can sometimes cause ownership issues if not properly configured in your docker-compose.yml, I just added an alias to ~/.zshrc to rectify that.
-edit-
Only run this script in your user owned directories, e.g. anything from ~/ (or /home/<your_username>) you might otherwise cause ownership issues for your system.
## Set ownership of files/folders recursively to current user
alias iownyou="sudo chown -R $USER:$GROUP"
For me it's pretty basic. It's mostly aliases for nix related commands, like rebuild-switch, updating, garbage collecting, because those nix commands are pretty lenghty, especially with having to point to your flake and everything. I'm thinking of maybe adding an alias for cyanrip (cli cd ripper), because i recently ripped my entire cd collection, but going forward if i buy another cd every now and then, i'll probably end up forgetting about which flags i used.
Similar to yours OP I copy many URLs and then run my script that takes the number of URLs I copied eg 5,and downloads them with yt-dlp and GNU parallel to ~/Videos