the shell spellbook

134 aliases, 8 git aliases, 9 functions
last updated: 2022-11-09T09:09:18+00:00

This page holds a collection of shell aliases and functions I use regularly. I will soon write a sync script to automatically update my alias collection on every computer I use to turn this into an over-engineered alias management system.

This is generated using jinja2 from a YAML file of mine. Note that some aliases might have a strange escaping because I escape them using Python's shlex module.

contents

back to top

basic

Rather basic aliases that you might already have built into your shell.

chmod

Why isn't this the default?!

alias chmod='chmod --preserve-root'

chown

Why isn't this the default?!

alias chown='chown --preserve-root'

hd

alias hd='hexdump -C'

ka

alias ka=killall

l

alias l='ls -lah'

la

alias la='ls -lAh'

ll

alias ll='ls -lh'

md

alias md=mkdir

mdp

alias mdp='mkdir -p'

rd

alias rd=rmdir
back to top

docker

Docker-related shortcuts.

dccp

alias dccp='docker container cp'

dco

alias dco=docker-compose

dcp

alias dcp='docker container prune'

dcpf

alias dcpf='docker container prune -f'

de

alias de='docker exec'

dei

alias dei='docker exec -it'

di

alias di='docker inspect'

dip

alias dip='docker image prune'

dipf

alias dipf='docker image prune -f'

dk

alias dk='docker kill'

dka

alias dka='docker ps -q | xargs docker kill'

dl

alias dl='docker logs'

dlf

alias dlf='docker logs -f'

dlft

alias dlft='docker logs -f --tail'

dlt

alias dlt='docker logs --tail'

dn

alias dn='docker network'

dnc

alias dnc='docker network create'

dnp

alias dnp='docker network prune'

dnpf

alias dnpf='docker network prune -f'

dp

alias dp='docker ps'

dpq

alias dpq='docker ps -q'

dr

alias dr='docker run'

dri

alias dri='docker run -it'

drmi

alias drmi='docker rmi'

drmia

alias drmia='docker images -q | xargs docker rmi'

dsp

alias dsp='docker system prune'

dspf

alias dspf='docker system prune -f'
back to top

fun

Aliases of questionable usefulness, mostly for puns, private jokes, or showing off.

:q

For when I get confused between Vim and a shell.

alias :q=exit

:q!

alias ':q!'=exit

:wq

alias :wq=exit

aliasless

In honour of ~aliasless!

alias aliasless='alias | less'

git cofe

A common spelling I have seen on the fediverse.

git config --global alias.cofe coffee

git coffee

git config --global alias.coffee '!curl -L https://git.io/coffee'

git covfefe

Thanks, Trump.

git config --global alias.covfefe coffee

cowanxiety

For the big bad moo-ds.

alias cowanxiety='figlet -f big -w 999999 | cowthink -nw'

cowscream

For the big moo-ds.

alias cowscream='figlet -f big -w 999999 | cowsay -nw'

fullwidth

Convert normal character to their full-width equivalents. Great for vaporware-style text, or for messing up some terminals.

alias fullwidth='sed "y/!\"#\$%&'"'"'()*+,-.\/0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\]^_\`abcdefghijklmnopqrstuvwxyz{|}~¢£¬¯¦¥ /!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~¢£¬ ̄¦¥ /"'

git gud

Mac- and Linux-compatible.

git config --global alias.gud '!xdg-open http://lmgtfy.com/\?s\=d\&iie\=1\&q\=how+to+use+git 2>/dev/null || open http://lmgtfy.com/\?s\=d\&iie\=1\&q\=how+to+use+git'

git joke

git config --global alias.joke '!curl -s https://raw.githubusercontent.com/EugeneKay/git-jokes/lulz/Jokes.txt | shuf | head -n1'

nuke

alias nuke='kill -9'

please

For when you want to be polite with your terminal.

alias please=sudo

git poule

French pun: the french noun «poule» (chicken) is pronounced in the same way as the english verb "pull".

git config --global alias.poule pull

scream

alias scream='tr '"'"'[[:lower:]]'"'"' '"'"'[[:upper:]]'"'"''

sl

I like trains, but not too much.

alias sl='sl -e'

whisper

alias whisper='tr '"'"'[[:upper:]]'"'"' '"'"'[[:lower:]]'"'"''
back to top

git

Git-related shortcuts.

ga

alias ga='git add'

gaa

alias gaa='git add -A'

gapa

alias gapa='git add --patch'

gb

alias gb='git branch'

gbd

alias gbd='git branch -d'

gbD

alias gbD='git branch -D'

gbdo

1
2
3
function gbdo () {
git push origin -d $@ && git branch -D $@
}

gbs

alias gbs='git bisect'

gbs!

alias 'gbs!'='git bisect start'

gbsb

alias gbsb='git bisect bad'

gbsg

alias gbsg='git bisect good'

gbsr

alias gbsr='git bisect reset'

gbss

alias gbss='git bisect skip'

gc

alias gc='git commit'

gca

alias gca='git commit -a'

gcaan

alias gcaan='git commit --amend -a --no-edit'

gcaans

alias gcaans='git commit --amend -a -s --no-edit'

gcam

alias gcam='git commit -a -m'

gcams

alias gcams='git commit -a -s -m'

gcan

alias gcan='git commit --amend --no-edit'

gcans

alias gcans='git commit --amend -s --no-edit'

gcas

alias gcas='git commit -a -s'

gch

alias gch='git checkout'

gchb

alias gchb='git checkout -b'

gchm

alias gchm='git checkout master'

gcm

alias gcm='git commit -m'

gcms

alias gcms='git commit -s -m'

gcp

alias gcp='git cherry-pick'

gcpa

alias gcpa='git cherry-pick --abort'

gcpc

alias gcpc='git cherry-pick --continue'

gcs

alias gcs='git commit -s'

gd

alias gd='git diff'

gds

alias gds='git diff --staged'

gf

alias gf='git fetch'

gfp

alias gfp='git fetch --prune'

gg

For when you give up with command-line Git.

alias gg='git gui'

gl

Yet another git log alias. You will probably want to customize it with your own format.

alias gl='git log --graph --pretty=format:'"'"'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'"'"' --abbrev-commit --all'

gm

alias gm='git merge'

gma

alias gma='git merge --abort'

got

For when you type your aliases so fast you miss a key.

alias got=git

gp

alias gp='git push'

gpf

alias gpf='git push --force-with-lease'

gpfo

alias gpfo='git push --force-with-lease origin'

gpmr

Git push with options for automatically creating a GitLab merge request with a given title.

 1
2
3
4
5
6
7
8
9
10
11
function gpmr () {
[ "$#" -le 0 ] && echo "Usage: $0 <title> <other options>" && return 1
local title=$1
shift
git push -u origin \
-o merge_request.create \
-o merge_request.target=master \
-o merge_request.remove_source_branch \
-o merge_request.title="$title" \
$*
}

gpu

alias gpu='git push -u origin'

gr

alias gr='git remote'

gra

alias gra='git remote add'

grb

alias grb='git rebase'

grba

alias grba='git rebase --abort'

grbc

alias grbc='git rebase --continue'

grbi

alias grbi='git rebase -i'

grbm

alias grbm='git rebase master'

grbs

alias grbs='git rebase --skip'

grh

alias grh='git reset'

grhh

alias grhh='git reset --hard'

grl

alias grl='git reflog'

grmv

alias grmv='git remote rename'

grpo

alias grpo='git remote prune origin'

grrm

alias grrm='git remote remove'

gs

alias gs='git status'

gst

alias gst='git stash'

gsta

alias gsta='git stash push'

gstam

alias gstam='git stash push -m'

gstd

alias gstd='git stash clear'

gstl

alias gstl='git stash list'

gstp

alias gstp='git stash pop'

gsts

alias gsts='git stash show --text'

gt

alias gt='git tag'

gtd

alias gtd='git tag -d'

gtf

alias gtf='git tag -f'

gut

You can also have a function that looks for 'status' in the argument, and prints 'hungry' for gut status.

alias gut=git

git wdiff

Word diffs can be quite useful when reviewing changes on repos full of text, and not code!

git config --global alias.wdiff 'diff --word-diff'

git wshow

Just like my git wdiff alias, but for git show.

git config --global alias.wshow 'show --word-diff'
back to top

python

Python-related shortcuts.

./maange.py

Yet another fat finger autocorrector, but for Django.

alias ./maange.py=./manage.py

./maange.Py

alias ./maange.Py=./manage.py

cdp

alias cdp=cdproject

prunetmpenv

Using virtualenvwrapper's mktmpenv, then not deactivating properly, results in useless environments piling up!

alias prunetmpenv='rmvirtualenv $(wk | grep ^tmp-)'

wk

alias wk=workon
back to top

specific

Aliases that are quite specific to my own setup.

flushall

Clear all of the local Redis database!

alias flushall='echo FLUSHALL | redis-cli'

nuketheswap

Named after a private joke at work. Cleans up your swap.

Be careful not to run this if you do not have enough space in RAM or if you still have some programs eating up your RAM: this could freeze your machine.

alias nuketheswap='sudo swapoff -a; sudo swapon -a'

oneplus

I have KDEConnect installed on my OnePlus One, and I often use its not-so-comfortable CLI.

alias oneplus='kdeconnect-cli -n '"'"'OnePlus One'"'"''

shutdown

As an i3 user, the easiest way for me to shut the computer down is to use shutdown now. I can use i3's launcher to do that, or I can just run that in any terminal that I already have opened. As I often leave an SSH connection to tilde.town opened for a while when my home computer is running, sometimes I accidentally try to shut the town down!

Luckily, it does not let me do that because there are other users logged on, but I set an alias just to avoid the little scare I can get from that.

alias shutdown=exit

ssh

Used in my Termux setup because the ssh-agent compatible ssh is ssha.

alias ssh=ssha
back to top

uncategorized

https

An alias for HTTPie to use HTTPS more quickly

alias https='http --default-scheme=https'

mkcd

Stolen from some reply on StackExchange.

 1
2
3
4
5
6
7
8
9
10
function mkcd () {
case "$1" in
*/..|*/../) cd -- "$1";;
/*/../*) (cd "${1%/../*}/.." && mkdir -p "./${1##*/../}") && cd -- "$1";;
/*) mkdir -p "$1" && cd "$1";;
*/../*) (cd "./${1%/../*}/.." && mkdir -p "./${1##*/../}") && cd "./$1";;
../*) (cd .. && mkdir -p "${1#.}") && cd "$1";;
*) mkdir -p "./$1" && cd "./$1";;
esac
}

moon

alias moon='curl --fail -s "https://wttr.in/moon"'

oxo

1
2
3
function oxo () {
curl -F"file=@$1" https://0x0.st
}

shorten

1
2
3
function shorten () {
curl -F"shorten=$1" https://ttm.sh
}

sqlite

alias sqlite=sqlite3

translate

Lets you use Google Translate right from your terminal! I initially wrote this because I was writing some wiki pages over SSH from a Windows XP laptop, which definitely was not happy with opening a web browser and loading all of Google Translate each time I was confused about a word.

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function translate () {
if [ "$#" -lt 2 ]; then
echo "Usage: translate [<source language>] <destination language> <text>"
return 1
elif [ "$#" -gt 2 ]; then
local sl="$1"
shift
fi
local hl="$1"
shift
curl -Gsf \
--data-urlencode "sl=$sl" \
--data-urlencode "hl=$hl" \
--data-urlencode "q=$*" \
'https://translate.google.com/m' \
| sed -n '/"result-container"/ s|^.*<div class="result-container">\([^>]*\)</div>.*$|\1\n|p'
}

ttm

1
2
3
function ttm () {
curl -F"file=@$1" https://ttm.sh
}

ttmu

1
2
3
function ttmu () {
curl -F"url=$1" https://ttm.sh
}

unzst

Because I always forget how to extract .tar.zst archives.

alias unzst='tar -I zstd -xf'

weather

alias weather='curl --fail -s "https://wttr.in/?format=v2"'

ytdl

alias ytdl=youtube-dl

ytmp3

I mostly only ever use youtube-dl to fill my music library. You can use this as ytmp3 dQw4w9WgXcQ to use the video's original title, or ytmp3 dQw4w9WgXcQ "We Are Number One" to use your own.

1
2
3
function ytmp3 () {
youtube-dl -x --audio-format mp3 -o "${2:-%(title)s}.%(ext)s" "$1"
}