Supercharge your Mac terminal with Oh My ZSH


August 15, 2019


The z-shell (or zsh) is an alternative to the bash shell most Mac and Linux developers are familiar with. On top of providing a bunch of extra functionality, it also gives you an easy way to customise and theme it to your liking.

Heres a taste of what to expect 3960C0E1 4AEC 4A16 998A 7E5C97CB416D

  • Improved TAB autocompletion.
  • Auto-correction for misspelled commands, files or directories.
  • Theming and improved colours make debugging in the terminal much easier on the eyes.
  • And probably most useful - Improved command history. Just start typing the first few letters of a command then press up until you find that command in your history. Filtering out any commands that don’t start with those few letters.

Before we get set up we’ll need to have Homebrew installed. Homebrew is a package manager for macOS, similar to apt for linux systems. It simplifies the installation of many software packages by automatically installing any dependancies and managing PATH variables.

Other prerequisites include having npm and git installed.

Homebrew

Open your terminal and run this command.

/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

Improved Terminal App

To unlock the full theming capabilities of zsh you will need an upgrade on the default MacOS Terminal app Here are the two popular choices - iTerm2, or Hyper.

If you intend to do an absolute ton of work in the terminal. If you intend to edit a ton of text files using the terminal I would recommend you go the route of iTerm2. Its lighter weight and also has some nicer feature for more power users.

Find the iTerm2 installation guide here - iTerm2 - macOS Terminal Replacement

Hyper is my app of choice though. It looks absolutely fantastic and also provides some of the more useful improvements including an improved right click menu, better split tabs and improved copy paste.

Download HyperJS from Hyper™

Installing the z-shell

Now that we have Homebrew set up we can install the z-shell with this simple command

brew install zsh zsh-completions

We then need to set zsh to be our default shell.

chsh -s /bin/zsh

To test your install, restart your terminal and run zsh --version. Some version details should be displayed below the command.

Oh My ZSH

Oh My ZSH is what we use to manage our z-shell configuration and theming. Its a very popular Github repository with almost 10k stars, so finding support if you ever run into any minor issues should be a breeze.

Start the install with this curl command in your terminal.

sh -c “$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)”

Once installed you may need to restart your terminal to see any changes. For now the UI changes are minor, but let us test it out by trying this nifty shortcut.

Previously to change directory you would go cd <directory>. ZSH makes cd optional - so now all we need to do is type <directory> .

This is just the tip of the iceberg when it comes to what we can do with our improved shell.

Theming ZSH

ZSH makes it incredibly easy to update the look of your shell. You can find hundreds of community published themes here or here.

To get my exact look we need to install the Pure theme. This is done slightly differently than below - but you can get pretty close using just this method.

Generally changing theme is as simple as changing one line in the ~/.zshrc file. By default the theme is set to robbyrussel.

You can change it by going to your home directory with

cd ~

And then opening up the .zshrc file. Edit it straight in your terminal with vim if you are comfortable doing that. Otherwise open up the directory in finder with

open .

Then open the .zshrc file with any text editor. By default the .zshrc file is hidden. You can view hidden files with this shortcut - Shift (⇧) + Command (⌘) + Full Stop (.)

Now replace this line with the theme of your choice

ZSH_THEME="<your theme of choice>"

Save the file and restart your terminal. If you’ve done everything correctly you should be seeing your new themed terminal.

Improved syntax highlighting

Syntax highlighting allows the terminal to give you live feedback if it knows the commands you are typing. Green commands exists, red don’t - pretty much simple as that. This can be very useful to catch typos, or quickly check if you have some commands installed or not.

Helps you spot those typos easily
Helps you spot those typos easily

Syntax highlighting with zsh is again another one-liner

brew install zsh-syntax-highlighting

Pure theme

Pure adds some extra functionality as well as a beautifully clean theme. Most of the functionality revolves around adding improved git information.

Pure shows you your current git branch, any changes to commit, and whether you’re ahead or behind the remote
Pure shows you your current git branch, any changes to commit, and whether you’re ahead or behind the remote

To install Pure, first set your

ZSH_THEME=“” in your ~/.zshrc file (check above for how to do this).

Next run

npm install —global pure-prompt

The initialise the prompt system with

# .zshrc autoload -U promptinit; promptinit prompt pure

Restart, and viola, you should have a sleek theme with improved git integration.