If you use the terminal on a regular basis, you know it looks kinda bad. But it's quite understandable, because the shells were made to be useful, not nice-looking. If you want to have a nice terminal, though, nothing can stop you.

We'll be installing Z-Shell, Oh-My-Zsh and powerlevel9k to customize the look and feel of our terminal.

Step 1: Z-Shell

Note: Since macOS 10.15 Catalina, Apple changed the default shell to zsh, so if you happen to be on macOS 10.15 (or greater, for the future), you can skip this section.

zsh is packed with a ton of features; to name a few:

  • Automatic cd: Just type the name of the directory
  • Recursive path expansion: For example “/u/lo/b” expands to “/usr/local/bin”
  • Spelling correction and approximate completion: If you make a minor mistake typing a directory name, ZSH will fix it for you
Linux

To install zsh, open a window of the Terminal and type:

$ sudo apt-get install zsh
# or
$ sudo yum install zsh
# or
$ sudo zypper install zsh
# depending on the installed package manager

After the installation, zsh will be ready.

macOS

To install zsh on macOS, first make sure it isn't installed. If it isn't, or if it's too outdated, you can use Homebrew to install/update it. (To check zsh's version run zsh --version.)

If you don't have Homebrew you can run:

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

After that, you can run:

# install from scratch
$ brew install zsh

# update
$ brew upgrade zsh

to install/update zsh.

Step 2: Oh-My-Zsh

Oh-My-Zsh is a package manager for zsh. It includes various plugins out of the box.
To install OMZ (that's it I'm gonna abbreviate it), you have to run Z-Shell v4.3.9 or higher. If your version is lower, update it.

You have to have git and either curl or wget installed in order to install OMZ. On Linux, you can simply run:

$ sudo apt-get install git curl

and it'll install the missing packages, skipping the up-to-date ones and updating the outdated ones. On macOS, curl is already installed. To install it, you'll have to download and install the command line tools, which you can install by typing:

$ xcode-select --install

If they're already installed, the command will display xcode-select: error: command line tools are already installed, use "Software Update" to install updates and exit. If they aren't installed, a popup window will be shown asking you to download the command line tools. Just accept it and when the download completes, you'll be able to run git by restarting the terminal.

Now that you satisfied the requirements, you'll need to download and install OMZ. To do so, run the following commands: if you're using wget, run:

$ sh -c "$(wget -O- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

Otherwise, if you're using curl, run:

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

If everything goes well, we'll be prompted to change our shell to zsh by default.

Part 3: powerlevel9k

In my experience, powerlevel9k (p9k for the laziest) is the best zsh theme out there. It's fully customizable, it's nice looking and it's modularized, meaning you can add, remove and mix&match modules, as well as adding your owns.

Since we installed OMZ, we can use it to install p9k, as such:

$ git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k

Once you've installed it, you'll have to install the fonts. In my personal experience, the best ones for p9k are Nerd-Fonts. Since there are a variety of different fonts, and the choosing of one is personal taste, I'll link to the official GitHub page for the complete list:

ryanoasis/nerd-fonts
Iconic font aggregator, collection, & patcher. 3,600+ icons, 40+ patched fonts: Hack, Source Code Pro, more. Glyph collections: Font Awesome, Material Design Icons, Octicons, & more - ryano...

To install one, go here and pick one. Click on the name, then enter `complete` and download the ones that you're interested in (there's a handy readme explaining what each does.)

Now, you can customize your .zshrc to make it look however you want. Here's my .zshrc for instance:

source  ~/powerlevel9k/powerlevel9k.zsh-theme

export ZSH="$HOME/.oh-my-zsh"

ZSH_THEME="powerlevel9k/powerlevel9k"
POWERLEVEL9K_MODE="nerdfont-complete"
POWERLEVEL9K_PROMPT_ON_NEWLINE=true
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(os_icon user dir_writable dir vcs)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status command_execution_time root_indicator background_jobs time disk_usage ram)
#POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
#POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX=""
#POWERLEVEL9K_USER_ICON="\uF415" # 
POWERLEVEL9K_ROOT_ICON="\uF09C"
#POWERLEVEL9K_SUDO_ICON=$'\uF09C' # 
POWERLEVEL9K_TIME_FORMAT="%D{%H:%M}"
#POWERLEVEL9K_VCS_GIT_ICON='\uF408 '
#POWERLEVEL9K_VCS_GIT_GITHUB_ICON='\uF408 '

ZSH_DISABLE_COMPFIX=true

ENABLE_CORRECTION="true"
COMPLETION_WAITING_DOTS="true"

plugins=(
  git
  iterm2
  macports
  man
  osx
  python
  composer
  zsh-syntax-highlighting
#   zsh-autosuggestions
)

source $ZSH/oh-my-zsh.sh

alias suroot='sudo -E -s'

# source ~/.bash_profile

if [ -f ~/.bash_profile ]; then
    . ~/.bash_profile;
fi

export DEFAULT_USER="$USER"

# source /Users/samplasion/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
source $(dirname $(gem which colorls))/tab_complete.sh

ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=244"

alias colors "~/colors.sh"
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
alias ls='colorls'

source ~/.iterm2_shell_integration.zsh

alias mountesp="sudo mkdir /Volumes/ESP && sudo mount -t msdos /dev/disk0s1 /Volumes/ESP"

which is a modified version of hacck's config.

My terminal
This is how it looks like

Notice the line ZSH_THEME="powerlevel9k/powerlevel9k". It's important you use it to set the theme to p9k.
Also notice the line POWERLEVEL9K_MODE="nerdfont-complete"; it allows p9k to recognize the fonts and to use the right icons.

Note: I highly recommend installing iTerm 2 if you're on macOS. It's a simple terminal utility replacement. It's more customizable than the stock terminal.

Final considerations

In this post we got from stock to p9k in almost no time. If you know some usefuls tips and tricks, don't hesitate to write them down in the comments. See you in the next post!