How To : Powerlevel9k Themes on Ubuntu

Christy Jacob
7 min readMar 22, 2019

--

We’ve all used the default shell on Ubuntu. It’s called bash and looks something like this

A normal boring Terminal

It’s great. It has all the features that you as a developer would need. But we’re gonna make it look a little more interesting. Something like this.

What we’ll be doing today

Let’s Get Started

We are going to install the following tools to help us achieve this look.

  1. ZSH
  2. Oh My Zsh (A Framework for managing your zsh configuration)
  3. Powerlevel9k (A Theme Engine for ZSH)
  4. Nerd-Fonts (Fonts & Glyphs required for many of the ZSH themes)

Installing ZSH

# Install zsh
sudo apt-get install zsh
# Verify your ZSH Version
zsh --version
# Change the default shell from bash to zsh
chsh -s $(which zsh)

Log out of your session and log back in or execute the following command

# Restarts your computer
sudo shutdown -r 0

Once you log back in, press Alt+Ctrl+t and you might be greeted with something like this. If not, just go on to the next step.

This is because , like your ~/.bashrc, zsh uses a ~/.zshrc to store your configurations and you most likely don’t have one yet. I would suggest option (0) since we’ll be replacing the ~/.zshrc file in some time.

Confirm your ZSH Install

# This command should now return /usr/bin/zsh
echo $SHELL

Installing Oh My Zsh

# Clone the repository
git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
# Backup your current ZSH Configuration
cp ~/.zshrc ~/.zshrc.orig

The guys at Oh My Zsh have provided us with sample .zshrc files for us to use and customise . We’ll be using one of the templates provided.

# replace our ~/.zshrc with the one included in the templates.
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
source ~/.zshrc

Your terminal will finally start looking different with a prompt like so

Feel free to explore the ~/.zshrc file. It has a lot of options for customising the shell. We won’t be using most of them so we’ll be removing a lot of those. For the sake of this tutorial we’ll be using the following ~/.zshrc

# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
plugins=(git)source $ZSH/oh-my-zsh.sh

You would find that some of your applications don’t run anymore. This is because your PATH environment variable needs to be updated. Here’s a fix for that.

# Open your .bashrc file and copy all the statements with "export" 
# or "PATH" to your ~/.zshrc file
nano ~/.bashrc
# It should look something like this.

Copy these to your ~/.zshrc file. Your ~/.zshrc file should now look like this

Save the file. Now we get to the fun part.

Installing Powerlevel9k

To install custom themes, Oh my Zsh requires the themes to be in a specific directory as mentioned in the docs

# Clone the powerline9k repo and save it in the directory as 
# specified in Oh My Zsh docs
git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k

Now select this theme in your ~/.zshrc file.

# Set ZSH_THEME in ~/.zshrc and save the file
ZSH_THEME="powerlevel9k/powerlevel9k"

Your ~/.zshrc file should now look like this

# Your PATH Exports# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
ZSH_THEME="powerlevel9k/powerlevel9k"plugins=(git)source $ZSH/oh-my-zsh.sh

Now reload the shell with

source ~/.zshrc

Powerlevel9k will now be enabled.

Installing Nerd-fonts

# Download the fonts using wget
wget https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/Hack/Regular/complete/Hack%20Regular%20Nerd%20Font%20Complete.ttf

Open the file you just downloaded and click Install

Once installed it’s time to enable it in your terminal. Open your terminal and go to Edit -> Profile Preferences -> General -> Text Appearance. Enable Custom Font and look for Hack Nerd Font Regular in the list and select it.

Now your terminal should start looking like this.

Now enable nerd-fonts in your ~/.zshrc by adding the following line after you load the theme.

POWERLEVEL9K_MODE='nerdfont-complete'

Your config file should now look like this

# Your PATH Exports# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
ZSH_THEME="powerlevel9k/powerlevel9k"
POWERLEVEL9K_MODE='nerdfont-complete'
plugins=(git)source $ZSH/oh-my-zsh.sh

Reload your shell and you have glyphs!

Terminal after setting powerlevel9k mode

Let’s Customise

In your terminal go to Edit -> Profile Preferences -> Colors -> Built-in schemes -> White on Black

Our terminal now looks like this

Once we understand the elements in the layout we can easily customise any aspect of our shell.

We will refer to each of the elements labelled in black as segments. Some segments have state while others don’t. For example, the VCS segment has states like CLEAN, UNTRACKED & MODIFIED whereas the OS_ICON segment has no state.

You can find a list of all the segments here & a list of segments with state, here. To customise a segment, we make use of properties that take the general form

POWERLEVEL9K_<name-of-segment>_<state>_[BACKGROUND|FOREGROUND]

Suppose you wanted the Version Control System to turn green when all your changes have been committed, you would do something like this

POWERLEVEL9K_VCS_CLEAN_FOREGROUND=017 # navyblue
POWERLEVEL9K_VCS_CLEAN_BACKGROUND=040 # green3a

Let’s now define what segments we need in our LEFT_PROMPT_ELEMENTS and RIGHT_PROMPT_ELEMENTS

# Your PATH Exports# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
ZSH_THEME="powerlevel9k/powerlevel9k"
POWERLEVEL9K_MODE='nerdfont-complete'
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(os_icon context dir newline status)POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(vcs)plugins=(git)source $ZSH/oh-my-zsh.sh

Restart your shell and cd into a git repo.

You can find the colours supported by Powelevel9k here. We’ll be using the numeric code for these colors in our config file.

Let’s give our LEFT_PROMPT_ELEMENTS some color. Copy this into your ~/.zshrc files

# Your PATH Exports# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
ZSH_THEME="powerlevel9k/powerlevel9k"
POWERLEVEL9K_MODE='nerdfont-complete'
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(os_icon context dir newline status)POWERLEVEL9K_OS_ICON_BACKGROUND=024 #navyblue
POWERLEVEL9K_OS_ICON_FOREGROUND=202 #orangered1
POWERLEVEL9K_CONTEXT_TEMPLATE='%n'
POWERLEVEL9K_CONTEXT_DEFAULT_FOREGROUND=249 # white
POWERLEVEL9K_DIR_HOME_FOREGROUND=249
POWERLEVEL9K_DIR_HOME_SUBFOLDER_FOREGROUND=249
POWERLEVEL9K_DIR_ETC_FOREGROUND=249
POWERLEVEL9K_DIR_DEFAULT_FOREGROUND=249
POWERLEVEL9K_DIR_HOME_BACKGROUND=024 #deepskyblue4a
POWERLEVEL9K_DIR_HOME_SUBFOLDER_BACKGROUND=024 #deepskyblue4a
POWERLEVEL9K_DIR_ETC_BACKGROUND=024 #deepskyblue4a
POWERLEVEL9K_DIR_DEFAULT_BACKGROUND=024 #deepskyblue4a
POWERLEVEL9K_SHORTEN_DIR_LENGTH=1
POWERLEVEL9K_HOME_ICON=''
POWERLEVEL9K_HOME_SUB_ICON=''
#POWERLEVEL9K_FOLDER_ICON=''
POWERLEVEL9K_STATUS_VERBOSE=true
POWERLEVEL9K_STATUS_CROSS=true
POWERLEVEL9K_STATUS_OK_BACKGROUND=017
POWERLEVEL9K_STATUS_ERROR_BACKGROUND=017
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(vcs)plugins=(git)source $ZSH/oh-my-zsh.sh

Now that’s better! Let’s make similar changes to the RIGHT_PROMPT_ELEMENTS. Copy the following into your ~/.zshrc

# Your PATH Exports# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
ZSH_THEME="powerlevel9k/powerlevel9k"
POWERLEVEL9K_MODE='nerdfont-complete'
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(os_icon context dir newline status)POWERLEVEL9K_OS_ICON_BACKGROUND=024 #navyblue
POWERLEVEL9K_OS_ICON_FOREGROUND=202 #orangered1
POWERLEVEL9K_CONTEXT_TEMPLATE='%n'
POWERLEVEL9K_CONTEXT_DEFAULT_FOREGROUND=249 # white
POWERLEVEL9K_DIR_HOME_FOREGROUND=249
POWERLEVEL9K_DIR_HOME_SUBFOLDER_FOREGROUND=249
POWERLEVEL9K_DIR_ETC_FOREGROUND=249
POWERLEVEL9K_DIR_DEFAULT_FOREGROUND=249
POWERLEVEL9K_DIR_HOME_BACKGROUND=024 #deepskyblue4a
POWERLEVEL9K_DIR_HOME_SUBFOLDER_BACKGROUND=024 #deepskyblue4a
POWERLEVEL9K_DIR_ETC_BACKGROUND=024 #deepskyblue4a
POWERLEVEL9K_DIR_DEFAULT_BACKGROUND=024 #deepskyblue4a
POWERLEVEL9K_SHORTEN_DIR_LENGTH=1
POWERLEVEL9K_HOME_ICON=''
POWERLEVEL9K_HOME_SUB_ICON=''
#POWERLEVEL9K_FOLDER_ICON=''
POWERLEVEL9K_STATUS_VERBOSE=true
POWERLEVEL9K_STATUS_CROSS=true
POWERLEVEL9K_STATUS_OK_BACKGROUND=017
POWERLEVEL9K_STATUS_ERROR_BACKGROUND=017
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(vcs)POWERLEVEL9K_VCS_CLEAN_FOREGROUND=017 # navyblue
POWERLEVEL9K_VCS_CLEAN_BACKGROUND=040 # green3a
POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND=017 # navyblue
POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND=220 # gold1
POWERLEVEL9K_VCS_MODIFIED_FOREGROUND=236 #grey19
POWERLEVEL9K_VCS_MODIFIED_BACKGROUND=160 #red3a
POWERLEVEL9K_SHOW_CHANGESET=true
plugins=(git)source $ZSH/oh-my-zsh.sh

We’ve only covered the basics but this should be a good starting point to understand how you can customise your shell to your liking. Oh My Zsh has tons of plugins that make your workflow much more seamless. You can create your own segments to display custom information as well.

I will be attaching all the links I referred to and where you can go from here. I’m really excited to see your configs! Do share them in the comments.

Also, this is my first article on Medium and I would love to hear your feedback!

References & Further Reading

  1. https://github.com/robbyrussell/oh-my-zsh
  2. https://github.com/bhilburn/powerlevel9k
  3. https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt#special-segment-colors
  4. https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
  5. https://github.com/bhilburn/powerlevel9k/wiki/Show-Off-Your-Config
  6. https://github.com/bhilburn/powerlevel9k/wiki/User-Segments

--

--