Jake Worth

Alias Terminal Commands

Published: February 10, 2022 2 min read

Our goals in the terminal should be precision and speed. Speed matters because slow typing is friction between thought and action. Any command you type out manually, or even tab-complete, a few times, is a candidate for a shortcut.

We shortcut commands on the terminal with aliases. Here’s how I keep my list of aliases long and my count of terminal keystrokes low.

Typeless Command

I found this trick a long time ago from, I believe, Thoughbot’s Upcase course. Thank you, Thoughtbot. I call it typeless, and it’s been in my .zshrc for years. I run it a few times a month.

# .zshrc

# Find commands I type often so I can alias them
alias typeless='history n 20000 | sed "s/.*  //"  | sort | uniq -c | sort -g | tail -n 100'

What’s happening here? This series of events, via piped commands:

  • “Show the last 20,000 lines of history”
  • “Use the sed stream editor to match just the commands, excluding the history indices”
  • “Sort the commands”
  • “Collapse and count duplicates”
  • “Sort by count of duplicates”
  • “Show the last 100 entries”

To summarize: “Show me the commands that I type most often into the terminal.”

Here are my top ten entries today.

$ typeless

3 gc
3 gnap
3 history
3 history n 20000
3 man sort
4 git st
10 figlet "DONT PUSH"
10 gp
15 git cheddar
33 gap

The goal here is to find commands that are not aliased and aliases them. No command is too small if it would save time. As you can see, my top three commands, gap, git cheddar, and gp, are all aliases themselves:

$ gap # `git add --patch`
$ git cheddar # `git commit --amend -CHEAD`
$ gp # `git push`

That’s a good sign; most of the time I’m typing far fewer characters than someone without these aliases. Here’s how I created one of these aliases:

# .zshrc

alias gap='git add --patch'

Write down your the alias on a Post-It and commit to using it, every time, until muscle memory takes over. Doing this periodically is one of the best investments I’ve made in my programming practice.

Alias Tips

Redditor u/number5 shared a great solution for leveraging the aliases you already have. The library alias-tips analyzes your existing aliases and alerts you when you are missing an opportunity to use one.

$ git status
Alias tip: git st

Here, I entered git status but I’ve already aliased that to git st. Using my existing alias would be faster and leverages the work I’ve already done.

✉️ Get better at programming by learning with me. Subscribe to Jake Worth's Newsletter for bi-weekly ideas, creations, and curated resources from across the world of programming. Join me today!


Blog of Jake Worth, software engineer in Maine.

© 2022 Jake Worth.