High-Value Shell Aliasing
We can be more efficient at the command line by typing less. We can type less
by making shell aliases. We know which commands to alias by asking the shell:
history | awk '{print $2}' | awk 'BEGIN {FS="|"} {print $1}' | sort | uniq -c | sort -r
This one-liner prints the most-frequently-run shell commands:
573 g
236 vim
164 cd
143 gpush
125 rake
The numbers on the left are counts. The g
alias (which is mapped to git
)
has been typed 573 times. Good thing it's a single character, right?
We should be generally happy with this output because the most-frequently-run
commands are mostly short aliases.
However, we're always looking to for more speed, so we could add these new aliases:
alias c='cd'
alias r='rake'
alias v='vim'
alias gp='git push'
alias gpush='echo "Use gp!" && git push'
Notice that last one. Typing gpush
so many times makes it muscle memory. To
retrain ourselves, we can re-bind that command to a reminder to use the new,
shorter version. Half the battle with new aliases is remembering to use them.
This little trick helps a lot.
Written by Dan Croak
Related protips
10 Responses
For zsh:
cat .histfile | awk '{print $1}' | sort | uniq -c | sort -rn | head
@Kalabro
cat .histfile | awk '{print $1}' | sort | uniq -c | sort -rn | head
Thanks for that
Mine:
install="sudo apt-get install"
remove="sudo apt-get remove"
..="cd .."
cls="clear"
This is all nice, but:
alias c='cd'
Whatever you gain in the extra "d", you lose whenever you ssh to another machine.
Aliases are good and all, but typing 2-4 more chars is rarely the bottleneck for efficient development process,
You could use zsh and just not bother even typing cd, just the path o.0
usefull article. thank you :-)
This gem works well for suggesting aliases and tells you which ones have been taken: https://github.com/paulmars/huffshell
alias ..='cd ..' saves my time exceptionally
My favorite aliases:
alias s='git status'
alias m='git diff' # (m)odifications
alias ds='git diff --staged'
alias a='git add --patch'
alias c='git commit'
alias bb='git branch'
alias co='git checkout'
alias um='git checkout master && git fetch --prune && git pull' # update master
alias rom='git checkout master && git pull && git checkout - && git rebase -i --autosquash master' # rebase onto master
alias b='bundle exec'