Upgrade your Terminal experience with Zsh, Oh My Zsh, and powerlevel10k!

kjdeluna
8 min readJan 5, 2022

Life is boring without colors. And so is your terminal. What could go wrong with adding some aesthetics in your terminal?

Or what about functionality-wise? Do you have long terminal commands that you use in a daily basis? Do you often forget where you’ve placed your files?

You came to the right place!

Goal:

Customize my Terminal to be more aesthetically beautiful, more descriptive, and more functional — autocomplete a command, navigate easily between directories, and be able to have multiple panes in just a single terminal

This is how my terminal currently looks like:

FIgure 1. Ugly, boring, unproductive initial look of my Terminal

Let’s start!

1. Discard Bash, Use zsh
In most Linux and Mac terminals, the default you’ll have is Bash. Bash is great but there’s something better: zsh. Why? Plugins. But we will go to that later. For now, let’s install zsh with your system’s default package manager

(required)MacOS:        brew install zsh
Ubuntu/Zorin: apt install zsh
CentOS: yum install zsh
Fedora: dnf install zsh

2. Oh My Zsh

While zsh is the program that processes your commands and scripts, Oh My Zsh is the one that manages your zsh configurations, themes, and plugins. Installation is easy!

(required) 
curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh; zsh
Figure 2. Welcome prompt after installing Oh My Zsh

When successfully installed, this welcome prompt should appear in your terminal.

The installation should also give you a prompt of whether to set zsh as your default shell (instead of bash). Try to close and exit your terminal session if this has taken effect but if it hasn’t, I got you! Just run the following command:

(optional) 
chsh -s $(which zsh)
# If above didn't work, you can manually edit it /etc/passwd

3. Powerlevel10k

Now, let’s try to achieve the aesthetic look that we’re aiming for. And you can do this by picking a theme for our Zsh terminal. Choose from a variety of themes here. But what I’ve grown to love is powerlevel10k.

​ ​ ​​​ ​ ​​​ ​ a) Clone the repository for powerlevel10k

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

​ ​ ​​​ ​ ​​​ ​ ​​​b) Change Zsh theme

(required)
nano ~/.zshrc
# Edit ZSH_THEME variable to your desired theme. In this case:
ZSH_THEME="powerlevel10k/powerlevel10k"

​ ​ ​​​ ​ ​​​ ​ ​​​c) Configure Powerlevel10k settings
We’re almost set with the aesthetics! However, we must make sure that we, ourselves, are satisfied with the look for our Terminal. Fortunately, powerlevel10k already comes with an interactive prompt that lets you configure its settings.

(optional)
p10k configure
Figure 3. p10k configure in Action

Once ran, it produces a ~/.p10k.zsh file that includes all the configurations that you’ve chosen in your powerlevel10k prompt. If you’re still unsatisfied with some aesthetics — want a different color for your prompt, display your battery status in your prompt, include an icon, etc., you can configure it further using this file.

​ ​ ​​​ ​ ​​​ ​ d) Download Meslo Nerd Fonts for Powerlevel10k
These fonts are specifically for icons that you will have in your Terminal. If you want a setup with some or a lot of icons, make sure to perform this step.

For iTerm2 and Termux, you would be asked whether to download Meslo Nerd Fonts automatically when you run p10k configure. But with other terminals, you need to proceed with manual installation.

4. Plugins

This is the main highlight of your very customizable zsh — plugins. This is how you increase your productivity.

a) zsh-syntax-highlighting
It’s simply . . . a highlighter. Whilst you’re typing a command, if it is recognized by your shell, it’s highlighted green, otherwise, it’s red. It also gives you hints about syntax errors in your command by highlighting it.

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting# Edit plugins variable in your ~/.zshrc file and add zsh-syntax-highlighting

b) zsh-autosuggestions
This gives you autocomplete suggestions based on your command history (commands that you’ve entered in the past). This is very useful for your most used commands with a lot of options!

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions# Add zsh-autosuggestions to your list of plugins in ~/.zshrc

c) fzf
This is a command-line fuzzy finder that can be used with your recently used commands, files, etc.

git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && ~/.fzf/install# Make sure to answer "Y" to all of the questions in the interactive prompt

Once installed successfully, you should now have an access with Ctrl + R and Ctrl + T key binds. What does these two do?

  • Ctrl + R allows you to perform fuzzy search on your command history
  • Ctrl + T allows you to perform fuzzy search on your files (with your current working directory dictating where to perform the search recursively)

d) autojump
A faster way to navigate your filesystem by maintaining a database of the directories you use the most from the command line

sudo apt install autojump# Add autojump to your list of plugins in ~/.zshrc

e) dirhistory
This plugin simply adds keyboard shortcuts for navigating directory history and hierarchy. Most notable being Alt + [←,→] to go back to previous and next directory respectively.

To use this, you just need to append dirhistory to your list of plugins in ~/.zshrc. Note that your Terminal emulator or your OS might have shortcuts already that corresponds to the button causing for it to not work. This has been observed in Tilix.

f) colorls
Not actually a zsh plugin. It is actually a bash script that colorizes the ls output with color and icons

# Install ruby:
sudo apt install ruby ruby-dev git
# Clone repository
git clone https://github.com/athityakumar/colorls.git
cd colorls
# If you got an error regarding installing colorls with gem,
# this command might fix it for you:
sudo apt-get install libncurses5-dev
sudo gem install colorls
alias lc='colorls -lA --sd'
Figure 4. Plain, boring ls output
Figure 5. Terminal with colorls

5. Further powerlevel10k customization

All your powerlevel10k customization is contained in your ~.p10k.zsh file.

​ ​ ​​​ ​ ​​​ ​ a) Inclusion/Exclusion of Prompt Elements: You can modify the elements in your prompt via POWERLEVEL9K_[LEFT,RIGHT]_PROMPT_ELEMENTS .

​ ​ ​​​ ​ ​​​ ​ ​​​b) Changing of Directory Foreground/Background Color: The parameters you are looking for are called POWERLEVEL9K_DIR_BACKGROUND, POWERLEVEL9K_DIR_FOREGROUND, POWERLEVEL9K_DIR_SHORTENED_FOREGROUND, POWERLEVEL9K_DIR_ANCHOR_FOREGROUND and POWERLEVEL9K_DIR_ANCHOR_BOLD.

​ ​ ​​​ ​ ​​​ ​ ​​​c) Changing your VCS (Git) prompt configuration: How your VCS would look like is being controlled by my_git_formatter function. Some things that you might want to change are icons (branch, untracked, etc.), colors, disable showing of untracked files.

​ ​ ​​​ ​ ​​​ ​ ​​​d) Color Reference Guide: Execute below command to see how the colors would look like in your terminal. This will be useful in customizing your powerlevel10k color configuration

Figure 6. 256 colors and their corresponding color codes
for i in {0..255}; do print -Pn "%K{$i}  %k%F{$i}${(l:3::0:)i}%f " ${${(M)$((i%6)):#3}:+$'\n'}; done

6. Choose your Terminal Emulator and Tmux

So far, in my newly installed ZorinOS, I used Tilix which I am very much satisfied with. It is a terminal emulator that is able to split your terminal window into multiple panes (just like what tmux does). The terminals can be rearranged and split either horizontally or vertically. Tilix can be installed via your OS’ pre-packaged Software Center or via command line:

sudo apt install tilix

In my MacOS, I used iTerm2, which provides very customizable colors and themes. Get iTerm2 here.

To get the multiple pane functionality that Tilix offers, I installed tmux using

brew install tmux

After installing, you may now get the functionality by entering tmux command to your iTerm2

  • Ctrl+B % Split current pane into half horizontally
  • Ctrl+B "Split current pane into half vertically
  • Ctrl+B {←,↑,→,↓} Navigate between your panes
  • Ctrl+B ; Toggle between the current and previous pane

7. Choose your Color Theme

If your still somehow unsatisfied with the colors of your terminal, you might want to change your color theme. For sure, there are already color schemes that have been made by the community to cater for your terminal of choice.

a) Tilix:

  • Make sure that the directory ~/.config/tilix/schemes/ exists. If one or more of these parent directories do not exist, manually create them yourself.
  • Choose a color theme that you like here. Execute their corresponding wget command
  • Launch Tilix. Click on the Hamburger icon and select:
    Preferences > Profiles (Default) > Color > Color Scheme
  • The color theme that you have downloaded via wget must be in the options. Pick that color theme

b) iTerm2

  • Launch iTerm2
  • Clone the iTerm2-Color-Schemes repository
git clone https://github.com/mbadolato/iTerm2-Color-Schemes.git
  • Click on iTerm2 menu title and select:
    Preferences > Profiles > Colors > Color Presets > Import
  • Select the .itermcolors file(s) of the schemes that you’d like to import. The schemes are located in the repository that you have cloned under the schemes folder
  • Click on Color Presets and choose a color scheme

8. FINAL OUTPUT!

You came this far! You’ve done it, congratulations!

With the right tools that we now have, we can be much more productive compared to before. Customizing our terminal setup really requires some effort but the output that we’re aiming is all worth it.

Figure 7. Final terminal UI with neofetch

9) Resources/Further Readings

--

--