Last Updated: February 25, 2016
· ryrych
Wojtek medium

Measure top 10 shell commands to be more productive

Yesterday I've found an interesting article / primer to bash scripting.

What interested me mostly, though, was command that displays top 10 commands I've used:

history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl |  head -n10

As I have successfully moved from RubyMine IDE to Vim / shell for git operations, it's not a surprise that my top 10 is:

1   163  44.2935%   git
2   50   13.587%    cd
3   32   8.69565%   vagrant
4   17   4.61957%   ember
5   9    2.44565%   .
6   8    2.17391%   cat
7   7    1.90217%   pwd
8   7    1.90217%   ln
9   6    1.63043%   pg_ctl
0   5    1.3587%    ps

Using Vim / shell made me more aware what's going on, about patterns I come across and, in turn, how to optimise them.

Using GitHub pull requests workflow on the project I'm working on, made me create following git aliases:

rb = rebase
rbi = rebase -i
rbc = rebase --continue
rba = rebase --abort
rbm = rebase master

git rbi head~10 is better than: git rebase -i head~10, don't you think?!

There is still a room for improvement with passing last n commits.

The same goes for switching back and forth from feature branch to master after git fetch.

com = checkout master
cb = checkout -

git cb is better than git co - which saves me 1 ONE key stroke!

Today I also noticed that using short aliases like git rbi play nicely with history search (C-R). Searching for full version, e.g rebase -i (or rebase to be faster) returns more ambiguous results. Another small win! ;)

It may seems to be an exaggeration, art for the art's sake, but I don't care.

One keystroke less a day, make my wrist surgeon away!

ā€“ Ryrych W.

Another pattern I used over and over again concerned pushing local feature branch to origin (the same branch name).

git push -u origin feature_some_branch_with_fancy_name

Most often autocompletion is not enough, so I found this command in some gist:

gbn () {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \1/'

With this, it's better:

git push -u origin $(gbn)

If you know about software that counts your commands, especially in Vim, let
me know in the comments!

BTW. you can find more aliases I use on my GitHub repo.

Sat Jun 6 14:18:10 CEST 2015

added info about advantages of using aliases with search history.

Say Thanks
Filed Under