‘Jazzing Up’ zsh with oh-my-zsh

How to set-up oh-my-zsh with some helpful plugins and themes.
cli
how-to
Published

2024-05-06

Modified

2024-05-06

This guide will show you how to:

Make sure the following prerequisites are installed before continuing…
  • zsh (needed to install and use oh-my-zsh).
  • git (used here to install plugins and – optionally if you chose to use it – for the git plugin itself).

You can check this by calling zsh --version/git --version in a terminal.

Installation

Follow these steps to install oh-my-zsh:

  1. Retrieve and execute the installation script (located in the main branch of the oh-my-zsh GitHub repo):
sh -c "$(curl -fsSL \
    https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  1. You may then need to restart your terminal session for these changes to take effect.

That’s it, the base installation of oh-my-zsh is then ready to go!

Plugins

oh-my-zsh comes with a wide range of built-in plugins. These are listed on the plugins page of the oh my zsh website.

However, some plugins (mainly custom ones) need to be installed before use. The installing plugins section shows you how to install two such useful plugins: zsh-auto-suggestion and zsh-syntax-highlighting.

The adding/modifying plugins section walks you through how to add new, and change the configuration of, your plugins. This section is applicable to both built-in and custom plugins.

Installing Plugins

Auto-suggestion

The zsh-auto-suggestion plugin recommends commands as you type in the terminal based on your recent history and completions. It can be installed as follows:

  1. Clone the plugin from the GitHub repository into the local custom plugins directory:
git clone https://github.com/zsh-users/zsh-autosuggestions \
    ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
  1. Add the plugin to your oh-my-zsh configuration as outlined in the adding/modifying plugins section.

That’s it! For alternative ways of installing this plugin, see the zsh-auto-suggestion installation instructions.

Syntax Highlighting

The zsh-syntax-highlighting plugin enables command highlighting as you type - available and correctly entered commands are coloured green and unavailable/mistyped commands are red. It can be installed in a similar way to zsh-auto-suggestions:

  1. Clone the plugin from the GitHub repository into the local custom plugins directory:
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git \
    ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
  1. Add the plugin to your oh-my-zsh configuration as outlined in the adding/modifying plugins section.

And you’re done! For alternative ways of installing the plugin, see the zsh-syntax-highlighting installation instructions.

Adding/Modifying Plugin Configuration

You can add built-in/installed custom plugins, or changing your plugin configuration, as follows:

  1. Open your .zshrc config file:
open ~/.zshrc
  1. Find the plugins variable. This should look something like plugins=(... <PLUGIN_NAME> ...). This is a space separated list of activated plugins surrounded by brackets. At the start, this list will likely only contain the git plugin.

  2. Add/remove the name(s) of the plugin(s) you’d like to activate/deactivate. Ensure the list of plugin names is space separated.

  3. Save your .zshrc configuration file, and restart your terminal session for the changes to take effect.

Themes

A list of built-in themes is recorded on the oh-my-zsh website. To change your oh-my-zsh theme, just follow these steps:

  1. Open your .zshrc config file:
open ~/.zshrc
  1. Find the ZSH_THEME variable, and change this to match the name of your theme of choice. At the start, this will likely be set to the default built-in theme robbyrussell.

  2. Save your .zshrc configuration file, and restart your terminal session for the changes to take effect.

Further Reading & Final Thoughts

The oh-my-zsh website is a great place to go for detailed and up-to-date information.

All the available built-in plugins are recorded on the oh-my-zsh website. I find the following plugins helpful: git (aliases), docker (completion support and aliases), gcloud (completion support), python (aliases and virtual environment commands) and terraform (completion support and aliases). This is by no means a complete list though, there are lots to choose from! Try not to add too many plugins at once otherwise you may find the terminal slow, particularly at startup.

All the available built-in themes are listed on the oh-my-zsh website. I use the gnzh theme because it is simple, clean and separates the command line onto a separate line - I personally find that easier to read and scan quickly. Some themes are reportedly more easy to customise, like agnoster, but if you aren’t looking to edit/build your own then the choice of theme is purely personal preference.

If you’re wondering what else oh-my-zsh could offer you, take a look at this great post which gives a quick overview of it’s main offerings. Also, if you’re finding your terminal too slow due to lots of plugins and unnecessary ‘bloat’, you’re definitely not alone! Check out this interesting article which shows you how to set-up an oh-my-zsh-like terminal without using oh-my-zsh.

Hooray

🎉 You made it to the end of the first ever heuristic-pedals blog post! Thanks for your time and I hope you found this helpful! 🎉