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)"
}
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"It’s
nmtuibut pretty!I’ve stolen a bunch of Git aliases from somewhere (I don’t remember where), here are the ones I ended up using the most:
g=git ga='git add' gau='git add --update' gcfu='git commit --fixup' gc='git commit --verbose' 'gc!'='git commit --verbose --amend' gcmsg='git commit --message' gca='git com gd='git diff' gf='git fetch' gl='git pull' gst='git status' gstall='git stash --all' gstaa='git stash apply' gp='git push' 'gpf!'='git push --force-with-lease' grb='git rebase' grba='git rebase --abort' grbc='git rebase --continue'I also often use
ls='eza' md='mkdir -p' mcd() { mkdir -p "$1" && cd "$1" }And finally some Nix things:
b='nix build' bf='nix build -f' bb=nix build -f .' s='nix shell' sf='nix shell -f' snp='nix shell np#' d='nix develop' df='nix develop -f'This makes me want spacemacs for the terminal
I replaced rm with trash-put, just in case I realize I need some files that I removed down the line.
alias rm='trash-put'Official author don’t recommend it due to different semantics. But honestly for my own personal use case its fine for me.
Also I like to alias xclip:
alias clippy='xclip -selection clipboard' # cat things.txt | clippyLittle tip: In case you need to use
rmdirectly, even with the alias in effect, you can put a backslah in front of the command to use its original meaning:\rm filenameoooh so does that apply to any command/user binary on the system?
I’m not sure what you mean with the question. If you have any alias like
alias rm='ls -l'in your .bashrc in example, then you cannot use the original commandrmanymore, as it is aliased to something else. I’m speaking about the terminal, when you enter the command. However, if you put a backslash in front of it like\rmin the terminal, then the alias for it is ignored and the original command is executed instead.Edit: Made a more clear alias example.
Oh ty ty that answers my question! I am fairly new to being a poweruser on linux so I may have worded that wrong XD
Official author don’t recommend it due to different semantics. But honestly for my own personal use case its fine for me.
I don’t recommend that either. If you get used to that ‘rm’ doesn’t actually remove files and then your alias is missing for whatever reason it’ll bite you in the rear at some point. And obviously the same hazard goes with a ton of other commands too.
Agree, comes down to risk acceptance honestly.
I accepted the risk that comes with it. Same with some other aliases on equally hazardous commands.
git() { if [ "$1" = clone ]; then shift set -- clone --recursive "$@" fi command git "$@" }Is this just meant to make git clone always clone recursively?
Can’t you do this with aliases in your .gitconfig?
yes it is. idk😄 i have a similar one for github-cli
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 choicedeleted by creator
Polls for potential zombie processes:
# Survive the apocalypse function zombies () { ps -elf | grep tsc | awk '{print $2}' | while read pid; do lsof -p $pid | grep cwd | awk '{printf "%-20s ", $2; $1=""; print $9}' done } export -f zombies alias zeds="watch -c -e -n 1 zombies"Ooooou I got a couple :3
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:
mpv_pitch() { if [[ -z "$1" ]]; then echo "Usage: mpv_pitch <file> [mpv-options]" return 1 fi local file="$1" shift mpv --input-conf=/dev/stdin "$file" "$@" <<EOF SHIFT+RIGHT add audio-pitch-correction 0; add pitch 0.01; add speed 0.01 # Decrease pit> SHIFT+LEFT add audio-pitch-correction 0; add pitch -0.01; add speed -0.01 # Increase pit> EOF }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) & }jmpd(jump directory): fuzzy finds and opens directory with fzf
# fish shell function jmpd set _selection $(fzf --walker=dir); if test -n "$_selection" cd "$_selection"; end endTo answer your question realistically I did
history | sed "s/.* //" | sort | uniq -c | sort -nwhich returned as first non standard command
lrwhich from mygrep lr ~/.bashrcisalias lr="ls -lrth"A few days ago I posted a one-liner to do the same thing too. It will resolve aliases from your history and expand program paths to its fullpath. I thought you might be interested: https://beehaw.org/post/20584479
type -P $(awk '{print $1}' ~/.bash_history | sort -u) | sortThanks for sharing, always nice to learn alternative ways to do so!
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…
For docker: I’m not following best practices. I have a giant docker compose file for my entire home lab, this is how I update things:
alias dockpull="docker compose pull" alias dockup="docker compose up -d --remove-orphans"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 $2This 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 }alias bat="batcat" alias msc="ncmpcpp" alias xcp="xclip -selection clipboard" alias wgq="sudo wg-quick"also a couple to easily power on/off my 4g modem







