iTerm2, Zsh with Powerlevel9K — Power up your terminal‘s colour scheme and productivity level!

Tired of a terminal with plain 12pt plain black text on plain white background? You can transform it from a monochrome experience to a more colourful one with added productivity features by installing:

iTerm2

If you haven’t already, install the mac package manager homebrew.

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

Install iTerm2 here or through homebrew with the below command. iTerm is is a customisable terminal for mac. This is the terminal that we will add loads of extra options to.

brew cask install iterm2

Zsh

Then install the zsh, an alternative to bash.

brew install zsh

The Z-shell resource file, ~/.zshrc, is a script that is run whenever you start Zsh. This tutorial will add things to this file to configure your terminal.

To change the default shell to Zsh rather than bash, run the change shell command in your terminal.

chsh -s /bin/zsh

Zsh-users have created some useful additions that integrate with it. One of the cool things you can add is syntax highlighting to colour command types — brew install zsh-syntax-highlighting. Another one is auto suggestions, which remember common commands that you can easily re-run —brew install zsh-autosuggestions.

Nerd fonts

To be able to have prompt with extra icons, such as for github, you need to install a special font set. This will show you how to install and configure Nerd Fonts.

There are various options for installing Nerd Fonts. Here is the option to install using homebrew.

brew tap caskroom/fonts
brew cask install font-hack-nerd-font

I have covered this in more detail in my article — Nerd Fonts: How to install, configure, and remove programming fonts on a mac.

Next setup iTerm2 to use the font by going to:

iTerm2 -> Preferences -> Profiles -> Text -> Font -> Change Font

Select the font Hack Regular Nerd Font Complete and adjust the size if your want too. Also check the box for Use a different font for non-ASCII text and select the font again. It should be displaying the new font and icons in the prompt.

Powerlevel9k

There are many themes for for zsh, but my favourite is powerlevel9k.

You need to tell powerlevel9k to use the Nerd Font in your ~/.zshrc.

echo "POWERLEVEL9K_MODE='nerdfont-complete'" >> ~/.zshrc

Next install the powerleve9k theme from github and add the command to load it in your ~/.zshrc.

git clone https://github.com/bhilburn/powerlevel9k.git ~/powerlevel9k
echo 'source ~/powerlevel9k/powerlevel9k.zsh-theme' >> ~/.zshrc

NOTE: The font needs to be set before Powerlevel9k is initialised in your ~/.zshrc.

POWERLEVEL9K_MODE='nerdfont-complete'
source ~/powerlevel9k/powerlevel9k.zsh-theme

Powerlevel9k is highly configurable. To change your setup, open your ~/.zshrc and add in the configuration your prefer. In the screenshots in this post I have used the following setup, which are listed in my ~/.zshrc.

POWERLEVEL9K_MODE='nerdfont-complete'
source ~/powerlevel9k/powerlevel9k.zsh-theme
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ssh dir vcs newline status)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
POWERLEVEL9K_PROMPT_ADD_NEWLINE=true

Programming language prompt sections

Powerlevel9k allows you to create custom prompt sections. One idea for this is to make one for a programming language you use. For more on how to create them for languages, such as JavaScript, Python and Ruby check out Powerlevel9k: personalise your prompt for any programming language.

Colour schemes

There are many iTerm colour schemes out there. One source is iterm2colorschemes, which gives you about 175 choices. Once you have downloaded them, select iTerm -> Preferences -> Profiles -> Colors -> Color Presets -> Import then select the colour scheme you like. The one colour scheme I have used in this article’s pictures is Dracula.

You can make your ls command display coloured file names using your chosen colour scheme using the -G option. Add this as an alias to your ~/.zshrc file using:

echo "alias ls='ls -G'" >> ~/.zshrc
You can make your file lists match the colour scheme you have chosen if you set ‘ls -G’ as an alias for ‘ls’.

Ruby gems

If you code in Ruby — or want to start — there are some colourful Ruby gems that can take this further. Read more about these in my post Lolcat, Colorls, Catpix, and other Ruby Gems to add color to your terminal.

The complete .zshrc

After all of this setup you should have an awesome terminal, which you can customise further to suit your preferences. Here is the setup I use in my own .zshrc

# Load Nerd Fonts with Powerlevel9k theme for Zsh
POWERLEVEL9K_MODE='nerdfont-complete'
source ~/powerlevel9k/powerlevel9k.zsh-theme
# Customise the Powerlevel9k prompts
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ssh dir vcs newline status)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
POWERLEVEL9K_PROMPT_ADD_NEWLINE=true
# Load Zsh tools for syntax highlighting and autosuggestions
HOMEBREW_FOLDER="/usr/local/share"
source "$HOMEBREW_FOLDER/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
source "$HOMEBREW_FOLDER/zsh-autosuggestions/zsh-autosuggestions.zsh"

Find out more

You can see other ideas for configuring your terminal on Powerlevel9k’s page Show Off Your Config. You can even share yours on there too!

Changed your mind? You can always remove this and go back to the default settings. After discussing this in the responses, I’ve written a guide you through this step-by-step.

Read more from ryanwhocodes