Last Updated: September 09, 2019
·
4.489K
· croaky

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.

10 Responses
Add your response

For zsh:
cat .histfile | awk '{print $1}' | sort | uniq -c | sort -rn | head

over 1 year ago ·

@Kalabro
cat .histfile | awk '{print $1}' | sort | uniq -c | sort -rn | head

Thanks for that

over 1 year ago ·

Mine:
install="sudo apt-get install"
remove="sudo apt-get remove"
..="cd .."
cls="clear"

over 1 year ago ·

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,

over 1 year ago ·

You could use zsh and just not bother even typing cd, just the path o.0

over 1 year ago ·

usefull article. thank you :-)

over 1 year ago ·

Thanks for this reminder. You may also want to check fasd for "frecency-based" file/path searching, which is an absolute time saver for me.

Here's my protip about it, for that matter :)

over 1 year ago ·

This gem works well for suggesting aliases and tells you which ones have been taken: https://github.com/paulmars/huffshell

over 1 year ago ·

alias ..='cd ..' saves my time exceptionally

over 1 year ago ·

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'

over 1 year ago ·