← Go back

3 Simple Ways to Set up Autocompletion in The Terminal

· 2 min read

We often use quite complex commands in our terminals. We usually either search for them over and over again, save them somewhere to refer to later, or try to remember them. However, there is another option — to use autocompletion in terminal based on the history of used commands. It’s much easier to set up than you might expect, and it can really save your time and boost productivity.

Example of autocompletion in terminal

1. Built-in Unix “reverse-i-search”

Unix system terminal stores the history of recent commands.

For Windows users the new version of Powershell also supports this too.

Example of 'history' command output

So we can quickly search in that history list using CTRL+Ror also called “reverse-i-search”:

Example of 'reverse-i-search' in terminal

As you type more the autocomplete will be precising or you can also press CTRL+R to search for other matching commands.

By default terminal, history will store the last 500 commands, but you can manually set size by setting in your .bash_profile:

HISTFILESIZE=1000000000
HISTSIZE=1000000

2. OhMyZsh & zsh-autosuggestions plugin

Another possible option is to use OhMyZsh instead of a built-in shell. It is a kind of shell on steroids that has a bunch of additional configurations, one of which is a zsh-autosuggestions plugin.

  1. First, install OhMyZsh using official installation instructions
  2. Then, add the zsh-autosuggestions plugin using installation instructions

Example of autocompletion in terminal using zsh-autosuggestions plugin

3. Fish-shell

Another alternative to the built-in shell is fish-shell, and it is available for macOS, Windows, and Linux. The installation process is as easy as running one command or downloading and running their installer.

Example of autocompletion in terminal using 'fish'

Summary

I definitely would suggest using at least one of the above options on your everyday work in the terminal, because it worths it. Also, you can combine some of them, like using OhMyZh autosuggestions with built-in reverse-i-search/CTRL+R.

— P.S: If you find this article interesting, feel free to follow me on Medium as well as on Twitter.

© 2021 Erzhan Torokulov