cat paw on a keyboard

Level your productivity up with your shell’s history and aliases

Days ago I came across a blog post teaching about using your shell's history more intensively to boost productivity. I wanted to reflect on my own usage, and share some of my tips and tricks.

Over the time, I created a lot of aliases useful to me, and I also reused some from the community. In the end I accumulate so much aliases that I can't remember them all 🙂

I would spare keystrokes each time I use my favorite commands if I could remember the relevant aliases that would help me boosting my productivity :-), aliases which already exist on my local profile. Disclaimer: I'm bad a remembering them, my memory is full of other useless crap like passwords and movie quotes from pop culture.

Hence, I decided to develop a function to help identifying every possible undervalued aliases, based on my shell history. This function looks for the top commands I have used lastly and it lists aliases I could use to replace my commands and thus boost my productivity.

In my dotfiles, I named this function suggest_aliases.

Why is such function useful to me ? Let me explain with a concrete example:

In the past days or weeks, I frequently used some commands like git stash or ls -latr. Of course I have aliases for those commands, for instance the git plugin for Oh My Zsh provides useful aliases for git stash.

In this situation, my tool lists all the aliases matching to the commands I've given in my example above.

Here is a demo of the result it produces:

❯ suggest_aliases 30
==========  alias recommendations  ==========
 ✔ there is an alias for ls -latr :
 ➜ ltr='ls -latr'
 ✔ there is an alias for git stash :
 ➜ gsta='git stash push'
 ➜ gstaa='git stash apply'
 ➜ gstall='git stash --all'
 ➜ gstc='git stash clear'
 ➜ gstd='git stash drop'
 ➜ gstl='git stash list'
 ➜ gstp='git stash pop'
 ➜ gsts='git stash show --text'

This utility function returns several candidate aliases based on my recent commands usage. The parameter it takes is the size of the input data that is be used by the tool. The bigger the number, the more results are returned.

On a complementary note, Oh My Zsh includes the plugin alias-finder, which makes learning new aliases easier.

Example:

$ alias-finder "git pull"
gl='git pull'
g=git

For my taste, I've a different workflow to find such aliases, which returns more results:

Example:

❯ ag "git pull"
ggpull='git pull origin "$(git_current_branch)"'
gl='git pull'
glum='git pull upstream master'
gup='git pull --rebase'
gupa='git pull --rebase --autostash'
gupav='git pull --rebase --autostash -v'
gupv='git pull --rebase -v'

where ag is an alias for

alias | grep -i

In this case it returns the aliases provided by the git plugin for Oh My Zsh because that's what I get on my system. If I had created custom aliases for git pull, it would have listed them as well.

Finally, here is a demo of all the commands used previously 😉

That's all, folks. I hope this was helpful 😉 ! I would love to know if you get similar tips & tricks, if you do please share them 🙂 .

Links:

2 thoughts on “Level your productivity up with your shell’s history and aliases

  1. It’s handy & helpful! Thanks for showing “ag” alias, seems like something which resolves my problems with alias-finder in Oh my zash 😉 This short demo/gif session is useful and brings a more interactive way of experience with your blog, definitely keep it! One tip: you can make this clip a little bit shorter (almost 9 minutes can be compressed to 6 minutes and you know, it’s this feeling of spending 10 minutes on watching sth or 5 minutes). Especially when you can’t speed-up the clip by yourself (like the 1.75 option in yt).

  2. Glad you enjoyed the article :-). You made a point regarding the length of the screencast, I’ll keep the idea but with way shorter and independent demos ! Thank you for the feedback 😉

Comments are closed.