zsh

Customizing Your Terminal with Oh My Zsh Themes

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 that are applicable to specific tasks.

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 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 will automatically come with the default plugins, functions, and the default theme.

Configuring Zsh

Once you installed Oh My Zsh, you will find your configuration file for the ZSH shell in “.zshrc” in your home directory.

This is similar to the typical Zsh configuration file but offers a more simplistic syntax which removes the complexity of configuring Zsh to your needs.

You can edit the configuration file using any text editor of your choice.

$ nano  ~/.zshrc

 
Once you have made changes to the configuration, you need to reload it in order for the changes to apply in the current session.

You can do this using the “source” command as follows:

$ source ~/.zshrc

 

Oh My Zsh Themes

Oh My Zsh comes with lots of themes that allow you to quickly configure a new theme for your shell.

By default, Oh My Zsh stores these themes in the “~/.oh-my-zsh/themes” directory. You can use the “ls” command to list the theme as follows:


Before setting a new theme, you may need to preview the theme. You can do this by browsing the theme catalog in the following resource:

https://github.com/ohmyzsh/ohmyzsh/wiki/Themes

Setting a New Theme

Suppose you like the theme called “alanpeabody”. Set the new theme by editing the “.zshrc” file.

$ .zshrc

 
From there, locate the entry as shown in the following:

ZSH_THEME="robbyrussell"

 
Edit the value from “robbyrussell” to the name of the theme that you wish to apply.

ZSH_THEME="alanpeabody"

 
Next, save the changes and reload the new configuration to apply the new theme.

Customizing the Themes

In some cases, you may like some specific features of a theme but you wish to change the others. You can do this by editing the theme file the “.oh-my-zsh/themes” directory.

You can find the file under the “theme_name.zsh-theme” file. Using a text editor, edit the various configurations of the theme.

NOTE: To avoid clobbering the file and damaging the original theme file, you can copy the existing theme and modify it as needed.

Some of the common things that you can customize include the PROMPT and PROMPTS under the same name in the theme file.

Using Plugins

To use a plugin, clone the plugin repository in the “~/.oh-my-zsh/custom/plugins” directory. You can then activate the plugin by adding the plugin name into the plugins array in the “~/.zshrc” configuration file.

The following resource shows the list of all available themes and their functionality:

https://github.com/ohmyzsh/ohmyzsh/wiki/Plugins

FAQs

Now that you learned how to customize your Zsh shell using the Oh My Zsh framework, let us look at some questions that you may have.

    • Is My ZSH Loading Time Slow?

In some cases, you may encounter that the loading time of your Zsh shell has become significantly slow. You can profile the Zsh startup time using the following command:

$ time zsh -i -c exit

 
This returns the total time taken for Zsh to load completely as follows:

zsh -i -c exit  0.04s user 0.02s system 99% cpu 0.060 total

 
Depending on the theme, plugins, custom functions, and extra tools, you may find that this value can take longer. To optimize the slow startup times, reduce the number of plugins that load when starting the shell.

    • How Do I Troubleshoot the ZSH Startup Issues?

If you need to see all the details and activity that happens when you start your Zsh shell, use the following command to enable verbosity:

$ zsh -xv

 
This shows you in details all the tasks that Zsh carries out when starting up. You can use this feature to determine the incorrect configurations and the ways on how to resolve them.

Conclusion

We hope that this tutorial helped you. In this post, you learned everything you need to know about installing and setting up the Oh My Zsh framework in your Linux system.

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