I’m doing Blogvent, a challenge to blog every day through December 25th. Today’s prompt is:

Day 3: A snippet from your dotfiles. Walk through a .gitconfig setting, shell alias, or editor keybinding that saves keystrokes every day.

Shorter commands are easier to remember and harder to mess up.

An alias I’ve used for years is typeless:

# ~/.zshrc

alias typeless='history -n 1 | sort | uniq -c | sort -nr | head -n 20'

typeless searches my Zsh terminal history, counts every command, and sorts them by frequency of use. Here’s an example output:

$ typeless
  4 gap
  3 typeless
  3 j dots
  3 echo "test"
  2 vim .zshrc
  2 vim
  2 typeless | head
  2 mux dots
  2 j hugo

These are mostly aliases– gap is aliased to git add --patch, mux is aliased to tmux new-session -s <name>, etc. As a guideline, you want to see abstractions here: aliases, functions, or specialized tool calls.

When I started doing this years ago, I’d see full commands:

$ typeless
  5 git add .
  4 cd ..
  3 git commit && git push origin
  3 git checkout .
  2 ssh jake@db-replica-02.example.com
  2 git pull --rebase
  2 kubectl describe pod my-production-pod
  2 git status
  1 cd ~/

To address the first result, perhaps I could alias git add . to ga. Or the second result, could I alias cd .. to .., which I’ve done in my dotfiles. Shorter commands are easier to remember and harder to mess up. Identifying valuable ones, writing them, and using them, is how you get really fast at the terminal.

An important detail: typeless only works if Zsh records duplicated commands. Enable that with these settings:

# ~/.zshrc

unsetopt HIST_IGNORE_DUPS
unsetopt HIST_IGNORE_ALL_DUPS
unsetopt HIST_SAVE_NO_DUPS
unsetopt HIST_EXPIRE_DUPS_FIRST

Note: You can see what I plan to write about each remaining day of Blogvent in the list of prompts.