How To Add Auto-Suggestion And Syntax Highlighting in MacOS/Linux Terminal

Introducing oh-my-zsh and its plugins

Kevin Jonathan Harnanta
Mac O’Clock
3 min readMar 18, 2020

--

In my previous article, I talked about customizing the Linux terminal. On this article, I will show you how to do the same for the Mac terminal. Auto-suggestion and syntax highlighting are very useful for people who use the terminal often, having to deal with so many different commands and arguments. It’s true that, sometimes, we just forget about previously entered command and their parameter. Also, syntax highlighting is very useful for beginners who are often making mistakes with commands. So in this article, I will continue with auto-suggestion and syntax highlighting.

Oh-my-zsh framework

In my previous article, we already talked about oh-my-zsh, the framework for zsh shell that can manage our zsh configuration. So, to enable auto-suggestion and syntax highlighting we only need to install certain plugins to oh-my-zsh. Please make sure you have oh-my-zsh already installed. After, you can use the following command to download the plugins:

$ git clone https://github.com/zsh-users/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions //auto suggestion$ git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting //syntax highlighting

When the downloading process completes, use your text editor and open .zshrc in your home directory, to change it from:

plugins=(git)

to this:

plugins=(git zsh-autosuggestions zsh-syntax-highlighting)

Next, just close your terminal and reopen it. You now have auto-suggestions enabled:

The terminal suggests previously used commands

You can use the arrow keys to find and fill-in commands:

Filling-in commands

For example, you see my kubectl command above colored blue. This is because the plugin syntax highlighted it.

Plugins for oh-my-zsh

Oh-my-zsh has a lot of plugins to choose from and you can check them out in~/.oh-my-zsh/plugins folder.

You can add any additional plugin you’d like as we added auto-suggestion and syntax highlighting before. For example, I have added a plugin for the kubectl command (which is the utility used to connect to our Kubernetes cluster master) and oh-my-zsh suggests the next parameter of the command like this:

If, for example, you want to choose create as the next param, you can select it and press Enter. By pressing the Tab button, you can see again the newly suggested commands:

You See? Oh-my-zsh is very useful for working with terminal.

That’s it. Thank you for reading my article

--

--