Written by Amar Panjwani
Technical Writer
Z Shell (zsh) is a popular alternative to the default command line bash shell with improved features like recursive path expansion, automatic spelling correction, and plug-in and theme support.
This guide will walk you through the process of installing and configuring zsh, including how to change themes and enable the time-saving autosuggestions plug-in.
Complete the following steps prior to getting started:
- Install Git:
sudo apt install curl wget git
- Install Zsh:
sudo apt install zsh
- Install Oh My Zsh:
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
You should now see the following prompt asking if you'd like to change your defaut shell to zsh. Type y
to confirm.
Take a look at your new command line and you should notice the difference right away.
If for any reason you need to switch back to the bash shell, use the following command:
chsh -s $(which bash)
Proceed to log out and back into your session for the change to take effect.
Run echo $SHELL
to confirm the output is /bin/bash
By default, the zsh theme is set to robbyrussell
, the name of the founder of Oh My Zsh. However, this is rather plain and there are over 100+ included themes with a wider assortment of colors and styles to choose from.
For example, here are 3 uniquely different themes to choose from:
- jonathan
- xiong-chiamiov
- agnoster
Follow these steps to change themes to jonathan
:
- Open your zsh configuration file:
vi ~/.zshrc
-
Press
i
to enter Insert Mode. -
Change the ending of the line reading:
ZSH_THEME="robbyrussell"
to
ZSH_THEME="jonathan"
-
Press
ESC
to leave Insert Mode and enter Command Mode. -
Type
:wq
+ENTER
to save and quit. -
Reload the command line:
source ~/.zshrc
-
Check out your newly themed command line and repeat steps 1-6 with a few more themes to find the best fit.
-
To see the full list of locally available zsh themes, follow these steps:
a. Change directories to the zsh themes folder:
cd ~/.oh-my-zsh/themes
b. List the names of all the available themes:
ls
The autosuggestions plug-in is quite possibly the single most time-saving tool when coding. Instead of having to type the same command over and over again in full, this plug-in automatically suggests the rest of your command as you are typing, without even having to press TAB
.
For example, instead of having to type git push origin main
every single time you wish to push a new commit, you can instead type git push
and the command line will automatically show a preview of the rest of the suggested command based on your shell's history.
Follow these steps to install and enable the autosuggestions plug-in:
- Change directories to the oh-my-zsh plug-ins location:
cd ~/.oh-my-zsh/plugins/
- Clone the autosuggestions plugin packages:
git clone https://github.com/zsh-users/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions
-
Edit the zsh configuration file:
a. Type
vi ~/.zshrc
b. Press
i
to enter Insert Mode.c. Update the line beginning with
plugins=(git)
toplugins=(git zsh-autosuggestions)
d. Press
ESC
to leave Insert Mode and enter Command Mode.d. Type
:wq
+ENTER
to save and quit. -
Reload the command line for the changes to take effect:
source ~/.zshrc
- Try it out! Start typing a command you know to be in your shell's history and watch as zsh offers autosuggestions. After seeing a suggestion that you'd like to approve, press the
Right Arrow
key to accept it.
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
Copyright ©️ 2021-2022