zsh

Enhance Your Terminal Appearance with Powerlevel10k in Oh My Zsh

The terminal is one of the most overpowered tools in any developer ecosystem. Whether you are building apps in JavaScript, .NET, Rust, etc., you are going to interact with your system using the terminal in one form or another.

Although there are a wide array of system shells, some of them being default like Bash, Zsh has stood out to being one of the most powerful, easy to use, and feature-rich shell of modern developers.

It is an advanced shell utility that provides low-level and high-level abstraction of the system tools whenever you need them. It also comes packed with an extensive scripting language which allows us to automate from simple to very advanced tasks using a simple syntax.

In this tutorial, we will learn how we can customize our Zsh shell sessions using Oh My Zsh. This includes extensive theme customization, plugins, command-completion, spell correction, programmable command-lien completion, extreme globing and search features, and many more.

What Is Oh My Zsh?

Let us start at the basics and discuss what Oh My Zsh is. In simple terms, Oh My Zsh is a free and open-source, community-driven framework for managing and extending the capabilities of Zsh configuration.

It comes packed with very powerful features such as a simple Zsh configuration which is easier to read and maintain, providing support for custom themes and a wide array of plugins applicable to specific tasks.

What Is Powerlevel10k?

Powerlevel10k is a highly customizable theme for the Zsh shell that is designed to work with the Oh My Zsh framework. It is known for exceptional performance, powerful extensibility, and visual appeal.

Other notable features of Powerlevel10k include the following:

    1. Speed – Powerlevel10k has incredible speed and hence will not slow down your shell on launch. This is because the prompt renders first then the other elements come in later. This means that even in complex plugins, you will not have any issues waiting for your prompt to appear.
    2. Lazy Loading – The Powerlevel10k theme also implements the lazy loading for some features. This means that it only loads the features that are required which increases the performance and startup time.
    3. Some features are loaded lazily which means that they only get loaded when needed, reducing the startup time of the shell.
    4. Configuration Wizard Powerlevel10k comes with a configuration wizard that helps us to set up the prompt by choosing from a variety of styles and options.
    5. Segment Styling – Another powerful feature of the theme is the ability to perform the segmented styling. For example, you can customize the tools such as prompt, etc.
    6. Battery Status – For battery powered devices, Powerlevel10k can display the battery charging status and level.
    7. Background Jobs – It also indicates if there are any background jobs running.
    8. Font Support – It supports various fonts, including Nerd Fonts, which provide additional glyphs for a richer visual experience.
    9. Transient Prompt – Lastly, another notable feature of Powerlevel10k is transient prompt. This is a powerful feature that allows the prompt to collapse after command execution. This helps to save the screen space and keep a clean terminal window.

Installing Zsh

Before we can install Oh My Zsh, we need to ensure that we have the Zsh shell installed on our system. Depending on your target system, this may come as the default shell.

However, in this post, we will demonstrate the installation on an Ubuntu 23.04. Hence, we first need to install it.

We can do this using “apt” as shown in the following commands:

$ sudo apt-get update
$ sudo apt install zsh

 

Once installed, we can proceed and set Zsh as the new default shell for the current user by running the following command:

$ chsh

 
This prompts you to select which shell you wish to set as the default. Proceed to enter the path to the Zsh binary as your preferred default shell.

Installing Oh My Zsh

Once we have Zsh installed and configured, we can proceed to setup Oh My Zsh. We can do this using curl or wget as shown in the following commands:

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

 
If you prefer to use wget, run the command as follows:

sh -c "$(wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"

 
Once you run either of the previous commands, it should download the Oh My Zsh installer and configure it on your shell. This automatically comes with the default plugins, functions, and the default theme.

Installing Powerlevel10k

The next step is to install the Powerlevel10k theme. Before doing so, we need to install a custom font that supports all the features that are provided by the theme. This includes glyphs, custom icons, and more.

For maximum compatibility, it is advisable to install one of the available Nerd Fonts as it comes with everything you need to work with the theme.

https://github.com/ryanoasis/nerd-fonts

Once installed, you can go ahead and clone the theme repository to the themes folder of your Oh My Zsh.

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

 
Next, edit the “.zshrc” file and set the ZSH_THEME entry to Powerlevel10k.

ZSH_THEME="powerlevel10k/powerlevel10k"

 

Initial Configuration

Upon installation, you need to run the configuration wizard to help configure the initial setup for the theme.

Run the command as follows:

$ p10k configure

 
This prompts you for all the features that you wish to enable.

The configuration wizard creates “~/.p10k.zsh” based on the selected preferences. You can perform additional customization by editing the file. You will find a ton of documentation and comments in the file to help you in your configuration needs.

FAQs

The following are some useful FAQs that you might encounter when installing and configuring the Powerlevel10k theme:

    • Why don’t icons, glyphs, or powerline symbols render?

If the icons, glyphs, and symbols don’t render, install the recommended fonts, restart the terminal shell, and re-run the “p10k configure” command.

    • How do I add the username and/or hostname to prompt?

To modify the username/hostname parameters, edit the “~/.p10k.zsh” configuration file.

Near the beginning of this file, you will find the key parameters that control which segments are displayed in your prompt.

Conclusion

In this tutorial, we covered the fundamentals of installing and configuring the Powerlevel10k theme for Oh My Zsh.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list