CLI aliases I actually use
Most lists of shell aliases are somebody’s ~/.bashrc pasted wholesale. This
is the smaller list of aliases I’ve kept after culling the ones I stopped
using.
Navigation
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias ~="cd ~"
alias -- -="cd -"
The -- - alias is the one I tell people about and they go “oh” every time.
cd - returns to the previous directory. Aliasing -- - lets you type
-- - and have it work.
Git
alias g="git"
alias gs="git status"
alias gd="git diff"
alias gdc="git diff --cached"
alias gp="git push"
alias gpf="git push --force-with-lease"
alias gl="git log --oneline --graph -20"
--force-with-lease is the only force-push flag I use. It refuses to
overwrite work you haven’t seen.
Kubernetes
alias k="kubectl"
alias kx="kubectl ctx" # uses kubectx if installed
alias kns="kubectl ns"
alias kgp="kubectl get pods"
alias kgpa="kubectl get pods -A"
alias kpf="kubectl port-forward"
Reading & searching
alias ll="ls -lh"
alias la="ls -lhA"
alias tree="tree -C -L 2 -I 'node_modules|.git|dist'"
alias ports="lsof -iTCP -sTCP:LISTEN -P"
alias ip="curl -s ifconfig.me; echo"
ports is the one I use weekly. “What’s listening on this box?” answered in
a single command.
The meta-rule
If I haven’t used an alias in a month, it goes. The point isn’t to have a lot of them — it’s to make the common path take a single keystroke.