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)"
}
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
#Create predefined session with multiple tabs/panes (rss, bluetooth, docker...) tmux-start #Create predefined tmux session with ncmpcpp and ueberzug cover music #Comfort ls = "ls --color=auto" please = "sudo !!" #Quick weather check weatherH='curl -s "wttr.in/HomeCity?2QF"' #Download Youtube playlist videos in separate directory indexed by video order in playlist -> lectures, etc ytPlaylist='yt-dlp -o "%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s"' #Download whole album -> podcasts primarily ytAlbum='yt-dlp -x --audio-format mp3 --split-chapters --embed-thumbnail -o "chapter:%(section_title)s.%(ext)s"' # download video -> extract audio -> show notification ytm() { tsp yt-dlp -x --audio-format mp3 --no-playlist -P "~/Music/downloaded" $1 \ --exec "dunstify -i folder-download -t 3000 -r 2598 -u normal %(filepath)q" } # Provide list of optional packages which can be manually selected pacmanOpts() { typeset -a os for o in `expac -S '%o\n' $1` do read -p "Install ${o}? " r [[ ${r,,} =~ ^y(|e|es)$ ]] && os+=( $o ) done sudo pacman -S $1 ${os[@]} } # fkill - kill process fkill() { pid=$(ps -ef | sed 1d | fzf -m --ansi --color fg:-1,bg:-1,hl:46,fg+:40,bg+:233,hl+:46 --color prompt:166,border:46 --height 40% --border=sharp --prompt="➤ " --pointer="➤ " --marker="➤ " | awk '{print $2}') if [ "x$pid" != "x" ] then kill -${1:-9} $pid fi }
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"
For the newer version of program, that’s why we have the $PATH. You put your program into one of the directories that is in your $PATH variable, then you can access your script or program from any of these like a regular program. Check the directories with
echo "$PATH" | tr ':' '\n'
My custom scripts and programs directory is “~/.local/bin”, but it has to be in the $PATH variable too. Every program and script i put there can be run like any other program. You don’t even need an alias for this specific program in example.
Nuget is a the .NET package manager. Like npm or pip, but for .NET projects.
If you needed it for a published application that strikes me as fairly strange.
I looked through my bash history and it looks like I needed it to build an Xbox eeprom editor for Xemu. Xemu doesn’t (or at least didn’t, I haven’t used newer versions yet) have a built in eeprom editor and editing the Xbox eeprom is required for enabling both wide screen and higher resolutions for the games that support them natively.
I just looked at Xemu’s documentation, and it looks like they’ve added a link to an online eeprom editor, so the editor I used (which they do still link to) is no longer required.
Ah, if you need to build a .NET project that makes sense
alias cd…=“cd …”
I have something similar.
alias "..1=cd .." alias "..2=cd ../.." ... etc
I did have code that would generate these automatically but Idk where it is.
#Create a dir and cd into it mkcd() { mkdir -p "$@" && cd "$@"; }
That’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) } }
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; } temp
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.Pretty sure this only works on x distros?
wl-copy
andwl-paste
are for Wayland FYI.Yep, pretty sure you are right.
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 $@`
I have a few interesting ones.
Download a video:
alias yt="yt-dlp -o '%(title)s-%(id)s.%(ext)s' "
Execute the previous command as root:
alias please='sudo $(fc -n -l -1)'
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.
Execute the previous command as root
Fun fact if you are using bash,
!!
will evaluate to the previous command, so if you miss sudo on some long command, you can also just dosudo !!
.With the added benefit of it looking like you’re yelling at your prompt in order to get it to use sudo.
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
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 use
alias kimg='kitty +kitten icat'
to display images in my terminal pretty simple but nice
I have that one too, but my alias is called icat
alias cls=clear
My first language was QB, so it makes me chuckle.
Also,
alias cim=vim
. If I had a penny…I also have cls aliased to clear! I used to use windows terminal and found myself compulsively typing cls when I moved to linux.
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
Monika from ddlc? :O
JUST MONIKA
Best waifu of history <3
alias sl=“ls“
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
real ones watch the train of shame
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
nmtui
but pretty!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"