New ZSH theme on macOS: Powerlevel10k

Terminal integrations and themes help with a clear UX, CLI command details, and information on the current versions, name, and path, for example showing the Git branch or not-committed changes.

I have been using the Spaceship prompt with Oh-My-ZSH for a while, but never really bothered with changing the configuration. Recently I came around Powerlevel10k and wanted to try it, mainly because it has an "instant prompt" feature - I had experienced slow loading times with pyenv and rbenv.

In this blog post, we'll walk through Oh-My-ZSH, Powerlevel10k, and its installation and configuration, including an icon override and more.

Oh-My-ZSH

If you haven't installed Oh-My-ZSH yet, follow the documentation and my dotfiles customizations and aliases.

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

Install additional ZSH goodies with Homebrew for auto-completion and syntax highlighting:

$ brew install zsh-completions zsh-syntax-highlighting

I'm using a Brewfile to manage the installation.

Powerlevel10k

Follow the installation instructions and download the font files. Double-click them to install, and navigate into the iTerm2 preferences Β into Preferences > Profiles > <select the default marked profile> > Text > Font and search for MesloLGS NF in the dropdown.

Next, clone the theme into the $ZSH_CUSTOM/themes directory. The environment variable is automatically set after installing Oh-My-ZSH.

$ git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

$ vim $HOME/.zshrc

ZSH_THEME="powerlevel10k/powerlevel10k"

$ source $HOME/.zshrc 

The first run of Powerlevel10k also prompts with the configuration wizard described next.

Configuration

There is a lot to configure. Powerlevel10k has an awesome wizard which walks you through the steps, and also shows different UI examples. Customizing my theme was a breeze, really. In case you closed it, run the following command:

p10k configure

I went with Light Rainbow theme to see how it goes. I liked the context separator line, and colorful blocks in the interface.

Theme Icons

You can set and override the OS icon. Since I only use macOS, I decided to look for an alternative default icon: The GitLab Tanuki which I found available in the NerdFonts cheatsheet.

Copying the hex code, and reading about the correct syntax for setting the OS_ICON variable helped modify the .p10k.zsh configuration file.

First, uncomment the os_icon in the POWERLEVEL9K_LEFT_PROMPT_ELEMENTS variable:

$ vim $HOME/.p10k.zsh

  # The list of segments shown on the left. Fill it with the most important segments.
  typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(
    # =========================[ Line #1 ]=========================
    os_icon               # os identifier
    dir                     # current directory
    vcs                     # git status
    # =========================[ Line #2 ]=========================
    newline                 # \n
    # prompt_char           # prompt symbol
  )

Second, uncomment the POWERLEVEL9K_OS_ICON_CONTENT_EXPANSION variable and set its value to the GitLab FontAwesome icon in hex format $'\uF296'.

$ vim $HOME/.p10k.zsh

  #################################[ os_icon: os identifier ]##################################
  # OS identifier color.
  typeset -g POWERLEVEL9K_OS_ICON_FOREGROUND=232
  typeset -g POWERLEVEL9K_OS_ICON_BACKGROUND=7
  # Custom icon.
  typeset -g POWERLEVEL9K_OS_ICON_CONTENT_EXPANSION=$'\uF296'
  # https://www.nerdfonts.com/cheat-sheet

Save and restart ZSH.

$ exec zsh

VoilΓ 

My main things are covered:

  • Pathname
  • Git branch name
  • Kubernetes cluster name
  • Time (a good reminder that it's too late πŸ™ƒ)
  • Command syntax highlighting (this is new for me too)

If there are uncommitted changes, the prompt looks different. Also, when the command returned an error which is reflected with printing the exit code.

Commands can also take a while to execute (or to study the git diff output), which is represented with the 10s and 4s yellow text in the screenshot.

You can find the full configuration in my dotfiles project.

A clear terminal representation is helpful for workshops and live demos during talks, allowing participants to follow more easily. One step further to my KubeCon EU talk in May 2022 :-)