Saving keystrokes with aliases & scripts

Apr 15, 2017

I run git often. Really often. These are the 10 programs I’ve run most often in the past month, and how many times I ran them.

Command Count
g 1,726
vim 366
ag 250
cd 238
ll 231
sudo 133
hub 87
hr 86
exit 79
make 67

(That’s an average of 56 times a day for g, and I use several computers regularly, so these numbers are slightly lower than the reality.)

Of course g is an alias for git. Saving 2 keystrokes on every command might not seem like much, but as you can see from how often I run it, that adds up.

Of course, I also do certain operations in Git more often than others. I have fairly standard entries in my gitconfig for these as well, so I can type g c for git commit, g o for git checkout, etc.

All of this is fairly standard stuff you’d find in a lot of people’s dotfiles. But I also noticed that I tend to run git status more than most other commands: it’s a common part of my workflow to review where I’m at before I think about committing or switching branches. Many Linux programs are written to, by default, tell you “the state of the world” if you don’t explicitly tell them to do something else, but Git doesn’t. So I have a small shell script that makes it behave like it does. My g command isn’t actually an alias, but a shell function:

g () {
  if [[ $# > 0 ]]; then
    git $@
    git status

So when I run g without any arguments, that’s equivalent to running git status.

This is a small, simple way I speed up my workflow everyday. Maybe you also have things you’re typing repeatedly you don’t need to.