Published on

Improve your shell with Zsh

Authors

Introduction

If you have been working with a shell in your operating system for quite some time now, then you might have noticed that it lacks some features.

I'm sure you might have come across a few instances where the shell throws an error because there's a typo in your command or in other cases you might have thought of customizing your shell by adding themes and plugins for your frameworks to improve the functionality of your shell. Well, Zsh is here to the rescue.

Zsh is a shell designed for interactive use. It's built on the top of Bourne Again Shell (BASH). Zsh shell is very popular because of its features, flexibility, and customizability.

Today we'll be installing Zsh shell and also oh-my-zsh a free and open-source framework for Zsh.

Now Let's dive into the installation.

Step 1: Install requirements

Make sure your system is upto date and have all the requirements installed

terminal
sudo apt update
sudo apt install git curl wget

Step 2: Install Zsh

Now, install zsh shell using your package manager

terminal
sudo apt install zsh

Check if zsh is properly installed

terminal
which zsh

The output is the path to the zsh executable

output
/usr/bin/zsh

Step 3: Change the Shell

Change the bash shell to zsh using chsh and enter the password.

terminal
chsh -s $(which zsh)

chsh (an abbreviation of "change shell") is a command on Unix-like operating systems that is used to change a login shell.

Now logout and login back to the user.

Step 4: Generate ZSH Config file

Once you login back to the user and open the terminal for the first time after the installation you'll be prompted with a message.

generate-zsh-config-file

Select 0. This creates a new .zshrc config file in your home directory.

Step 5: Install oh-my-zsh

Now, let's install the oh-my-zsh framework

oh-my-zsh is installed by running one of the following commands in your terminal. You can install this via the command line with either curl or wget.

The installation script automatically downloads install.sh script and executes

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

OR

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

install-oh-my-zsh

Hold on, now comes the fun part

Step 5: Customization

You can find the oh-my-zsh repository in the home directory as a hidden file.

hidden_folder

Inside themes directory you find a lot of preinstalled themes. Feel free to check it out.

The default theme that oh-my-zsh is shipped with is robbyrussell. I personally use agnoster theme. But you can always choose your own theme.

To change the theme, open the .zshrc configuration file in you home directory using your choice of editor. I'm going to use nano editor for this instance.

terminal
nano ~/.zshrc

Now locate ZSH_THEME=robbyrussell and replace with ZSH_THEME=agnoster

theme

Optional: You can also add new plugins by locating the plugins=(git). Just give a whitespace between each plugin.

plugins

Save and exit the editor by pressing ctrl+x -> y -> enter

Now here's how the new theme looks with a git plugin

example_theme

Go through the oh-my-zsh documentation to try out more Themes, External themes and Plugins. Also try to add your own alias, updating your color scheme in the zshrc config file.

Congrats! You have now successfully installed oh-my-zsh shell with your own theme.