y-xc0w
Last Updated: February 25, 2016
·
4.197K
· croaky
8e2b996de3842c6ef7e68a82fa5f01f5

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.

Say Thanks
Respond

10 Responses
Add your response

11079
E0bcb315f3745d5cc747daa3c4c05c9a

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

over 1 year ago ·
11110
2af4ea9bb6380b59d05d2b9b6d8112e9

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

Thanks for that

over 1 year ago ·
11120
8b56ce1deeddca5aed7773b927980194

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

over 1 year ago ·
11141

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 ·
11199
6abd9004f3e9d949b6120ba81496784b

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

over 1 year ago ·
11211
F8c4fdde8545731ac4a77b52e4896595

usefull article. thank you :-)

over 1 year ago ·
11237
10ca55864735b3ccefb16bd93a1596a7

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 ·
11273
792463f9b4dfb9a0a9cb181a68dced78

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

over 1 year ago ·
11281
C9d3823e79bae04bb12f702335d6d312

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

over 1 year ago ·
11308
Ava smile

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 ·
Filed Under