Scott Whittaker

Frontend Developer

Day job React | side projects Svelte

ZSH - Advanced History

I have been using oh my zsh for a few years now and did not know about the advanced history feature provided by zsh. I found out about this handy little tip via Command Line Power User by Wes Bos, a free video series about using the command line.

History Lesson

The up and down arrow keys are used in order to cycle through recent commands in the terminal. This is handy but what if you are looking for a specific command that was entered an hour ago perhaps? In this case you would have to press the up key multiple times until the command you are looking for is found.

For example, lets say an hour ago we fetched some data via the command line from SWAPI using HTTPPie as follows…

http swapi.co/api/
http swapi.co/api/planets/1/

An hour passes and you would like to run the same command(s) again, but in the intervening time you may have entered 20 other commands. Instead of pressing the up key 20 times, you can type part of the command you are looking for and then hit the up key. For example, type…

http

Now press the up key and notice that the last command beginning with http is loaded for you. Keep pressing up/down to cycle through recent http commands.

http swapi.co/api/planets/1/
http swapi.co/api/

Note that you do not have to type the full command http, you can shorten that to ht or even h to get recent commands beginning with those characters.

Conclusion

How did I not accidentally discover that feature? I will be saving myself a few seconds per day now.