Last Updated:

Spice up your CLI! Part 2: oh-my-zsh, themes & plugins

⏮ Click here for Part 1: iTerm2 & ZSH

In Part 2 of this series, we'll be installing oh-my-zsh, selecting a theme and using some new plugins.

What is oh-my-zsh?

oh-my-zsh is a framework for managing your ZSH configuration. It has support for themes and hundreds of user-contributed plugins.

How to install oh-my-zsh on MacOS

Note: this will overwrite your existing .zshrc file - you may want to back this up first!

To install oh-my-zsh:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

If you're security-conscious, you probably don't want run arbitrary scripts straight off the internet without inspecting them first. If this is you, you can retrieve the install script without executing it, in order to inspect it before you execute it:

wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh

less ./install.sh

If you're happy with what the install script is doing, you can then execute it with:

sh ./install.sh

oh-my-zsh will now be installed to ~/.oh-my-zsh

More sane ZSH defaults

By default, ZSH does not alias the rm and cp commands to prompt for overwrites or deleting files. For added safety, I prefer to have a prompt before copying over, or deleting a files/directories, so I add these to my .zshrc file:

alias rm='rm -i'
alias cp='cp -i'

 

Picking an oh-my-zsh theme

Once oh-my-zsh is installed, the first thing you can try it is a new theme! You can preview the available themes by going to the oh-my-zsh Github project's Themes wiki.

I personally like to use the obraun theme. To change your theme, edit your .zshrc file with your favourite editor, updating the ZSH_THEME= line to the theme that you wish to use. Once you've saved that, reload your ZSH config:

source ~/.zshrc

Your new theme should now be visible!

Some cool oh-my-zsh plugins to get you started

By default, oh-my-zsh comes with a few hundred plugins! To enable a plugin, edit your .zshrc file, and update the plugins= line to a space-separated list of plugins you wish to enable (eg: plugins=( x y z )).

Each time you modify your .zshrc file, you will need to reload the changes:
source ~/.zshrc

For the sake of simplicity, let's start off with just a few plugins:

git

The git plugin provides shortened commands (aliases) for many of the full git commands. To see the list of shortened commands, check out the git plugin on Github. 

autojump

Autojump is a tool that remembers which directories that you commonly change to, and once you've built up a database of directories that you use, you can use autojump to quickly change to them instead of having to type out the full path each time. 

You'll first need to install autojump:

brew install autojump

Remember, as per Part 1 of this series, you need to run the rehash command whenever you install new executables/binaries to your $PATH.

Once installed, enable the plugin by adding autojump to to the plugins in your ~/.zshrc file and then reloading your ZSH config.

Autojump will be alised to the j command - when you have built up a list of commonly used directories, you can use this command to quickly change to them. For example, if you have been acessing ~/Code/example-project, you can now typej example to autojump to this directory.

zsh-syntax-highlighting

This plugin enables syntax highlighting on the CLI. This makes reading commands on the CLI a bit easier with the use of colours.

This is not a default oh-my-zsh plugin, so you will need to install it first:

cd ~/.oh-my-zsh/plugins
git clone https://github.com/zsh-users/zsh-syntax-highlighting

Once that git repo is cloned to your plugins directory, you can enable it in your .zshrc file, and then remember to reload your ZSH config.

Summary

You should now have ZSH and oh-my-zsh installed, chosen a theme as well as added some plugins! There's an extensive list of plugins that you can browse in the oh-my-zsh Github repo - have a look here and you may find many plugins applicable to your environment or project. Additionally, you can find even more plugins from the zsh-users Github page.

⏭ Click here for Part 3, where we can learn some useful shortcuts and MacOS-specific commands!