Enhance your macOS terminal - p10k
Tags: iterm2, zsh, ohmyzsh, powerlevel10k
Published: 2020-01-03 02:20:48

*This post was originally published at [thbe.org](https://www.thbe.org/posts/2020/01/01/Enhance_your_macOS_terminal_p10k.html).*

In my previous blog post about [**enhancing the MacOS terminal**](https://www.thbe.org/posts/2019/07/23/Enhance_your_macOS_terminal.html) I used the [**powerlevel9k**](https://github.com/Powerlevel9k/powerlevel9k) theme. When I was publishing the article on [**dev.to**](https://dev.to/thbe/enhance-your-macos-terminal-25o7) as well, I was made aware there is a re-implementation of p9k available called [**powerlevel10k**](https://github.com/romkatv/powerlevel10k). p10k is calling itself a fast drop-in replacement for Powerlevel9k. Fast sounds always good so I thought, give it a try.

p10k is able to use the same configuration p9k is using, so if you only install p10k and change the theme in [**oh-my-zsh**](https://github.com/ohmyzsh/ohmyzsh) to p10k without further modifications, everything will look the same as it looked before. The only difference you might notice is that the terminal indeed behaves a little faster. This is, what I did first:

```shell
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k
```

Now where p10k is installed, it needs to be activated in the ZSH configuration:

```bash
# zsh configuration file
#
# Author: Thomas Bendler <code@thbe.org>
# Date:   Tue Sep 24 20:28:27 UTC 2019
[...]
ZSH_THEME="powerlevel10k/powerlevel10k"
[...]
# Configure the prompt content
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(root_indicator context dir vcs)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status command_execution_time ram disk_usage ip)

# Local custom plugins
for item in $(ls -1 ${HOME}/.profile.d/*.plugin.zsh); do
  [ -e "${item}" ] && source "${item}"
done
```

After the restart of my terminal, literally, nothing has changed. It looks like the drop-in replacement part seems to be true. Let's check if we really use p10k now:

```shell
$ set | grep "__p9k_root_dir="
__p9k_root_dir=/Users/thbe/.oh-my-zsh/custom/themes/powerlevel10k
```

So far, so good. But p10k should not only be a drop-in replacement, but it also offers additional functionality that goes beyond the functionality of p9k. One thing I personally like is the fact that p10k separate the configuration from the .zshrc file per default. p10k also comes with a wizard that generates a sample configuration. I started with the lean configuration and adjusted it in a way that it fits my need. This is how my terminal now looks like:

![Customized iTerm2 with p10k](https://thepracticaldev.s3.amazonaws.com/i/2f7ertdh82j2jonpi3p5.png)

The first thing I did was to clean up my .zshrc configuration file. I removed some of my oh-my-zsh plugins because I hadn't used them recently. I also added some and ended up with the following .zshrc configuration file:

```bash
# zsh configuration file
#
# Author: Thomas Bendler <code@thbe.org>
# Date:   Fri Dec 27 23:48:31 CET 2019

# Add local sbin to $PATH.
export PATH="/usr/local/sbin:${PATH}"

# Path to the oh-my-zsh installation.
export ZSH="${HOME}/.oh-my-zsh"

# Use case-sensitive completion.
CASE_SENSITIVE="true"

# Define how often to auto-update (in days).
export UPDATE_ZSH_DAYS=7

# Enable command auto-correction.
ENABLE_CORRECTION="true"

# Display red dots whilst waiting for completion.
COMPLETION_WAITING_DOTS="true"

# Configure history stamp format
HIST_STAMPS="yyyy-mm-dd"

# Plugin configuration
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Add wisely, as too many plugins slow down shell startup.
plugins=(
  ansible
  brew
  bundler
  colored-man-pages
  colorize
  docker
  git
  nmap
  osx
  zsh-navigation-tools
  zsh_reload
)

ZSH_THEME="powerlevel10k/powerlevel10k"

# Load Zsh tools for syntax highlighting and autosuggestions
HOMEBREW_FOLDER="/usr/local/share"
source "${HOMEBREW_FOLDER}/zsh-autosuggestions/zsh-autosuggestions.zsh"
source "${HOMEBREW_FOLDER}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"

# Load oh-my-zsh framework
source "${ZSH}/oh-my-zsh.sh"

# Powerlevel10k configuration
[ -e ${HOME}/.p10k.zsh ] && source ${HOME}/.p10k.zsh

# Local custom plugins
for item in $(ls -1 ${HOME}/.profile.d/*.plugin.zsh); do
  [ -e "${item}" ] && source "${item}"
done
```

The important line from the p10k perspective is:

```bash
[ -e ${HOME}/.p10k.zsh ] && source ${HOME}/.p10k.zsh
```

This line source the p10k configuration that is stored in the .p10k.zsh file. The one that creates the layout shown in the screenshot above is the following:

{% gist https://gist.github.com/thbe/f1fe8565fdfd1c358018a13eb0519cea %}

Currently, the configuration file is quite big but I'm pretty sure not everything in this file is really required. It is more or less based on the generated configuration file using the lean set up. I haven't checked the default values for the configuration content yet but I could imagine a lot of configurations are default and as such, could be removed from the configuration file.

For those who want to know what this part in the .zshrc configuration file is about:

```bash
# Local custom plugins
for item in $(ls -1 ${HOME}/.profile.d/*.plugin.zsh); do
  [ -e "${item}" ] && source "${item}"
done
```

This includes my personal zsh plugins that are currently not available in other frameworks like oh-my-zsh. It seems to be a little challenge to get additional plugins included there. You can see them here:

{% gist https://gist.github.com/thbe/5612c721f2630debb1d991033e0ec932 %}