DEV Community

Cover image for Enhance your macOS terminal - p10k
thbe
thbe

Posted on • Originally published at thbe.org

Enhance your macOS terminal - p10k

This post was originally published at thbe.org.

In my previous blog post about enhancing the MacOS terminal I used the powerlevel9k theme. When I was publishing the article on dev.to as well, I was made aware there is a re-implementation of p9k available called 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 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:

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k
Enter fullscreen mode Exit fullscreen mode

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

# 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
Enter fullscreen mode Exit fullscreen mode

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:

$ set | grep "__p9k_root_dir="
__p9k_root_dir=/Users/thbe/.oh-my-zsh/custom/themes/powerlevel10k
Enter fullscreen mode Exit fullscreen mode

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

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:

# 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
Enter fullscreen mode Exit fullscreen mode

The important line from the p10k perspective is:

[ -e ${HOME}/.p10k.zsh ] && source ${HOME}/.p10k.zsh
Enter fullscreen mode Exit fullscreen mode

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:

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:

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

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:

Top comments (0)