DEV Community

Cover image for Getting started with Zsh
Anes Abismail
Anes Abismail

Posted on • Updated on • Originally published at anesabml.github.io

Getting started with Zsh

A Shell is a user interface to access the operating system's services, it receives input from the user and executes programs based on that input. To put in simple words a shell is a program that takes input commands from the keyboard and sends them to the operating system to execute.

On most operating systems a program called Bash (Bourne Again Shell) acts as the default shell. But there are other shell programs that can be installed in your system that offer more features such as fish and Zsh. In this blog post, I will talk about how to setup Zsh.

What is Zsh:

Zsh, also called Z shell, is a Unix shell that can be used as an alternative to Bash and Fish. It's based on Bourne Shell, allowing it to have the same features as Bash because Bash is also built on top of Bourne Shell, moreover, it has plenty of features and support for plugins and themes.

Zsh features:

Zsh has many features, here is some:

  • Cd (Change directory): just type the name of the directory to change your current directory. eg: instead of cd Downloads, just type Downloads
  • Spelling correction and completion: don't worry if you make a mistake typing the name of a directory, Zsh has spelling correction and completion.
  • Plugins and themes: Zsh has a rich collection of plugins and themes that you can install to enhance your productivity and make your terminal look cool.

Installing Zsh:

macOS:

Starting from macOS Catalina, Zsh is installed as the default shell, so you can skip this part. If you are not running macOS Catalina installing Zsh is as simple as running this command Assuming you have Homebrew installed:

brew install zsh

To set Zsh as your default shell, execute the following command

chsh -s /usr/local/bin/zsh

for other OS you can check this link here.

Installing Oh My Zsh:

Zsh alone doesn't do much it, it just like Bash. To start installing plugins and themes you need a tool to manage Zsh configuration and my favourite tool is Oh My Zsh. Installing Oh My Zsh can be done using either curl or wget:

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

Install plugins and themes:

As stated before Zsh comes with a rich collection of plugins and themes. let's take a look at how we can enable plugins and themes.

Plugins:

List of Oh My Zsh plugins can be found here. If you spot a plugin and you'd like to install, you'll need to enable it in the ~/.zshrc , this file is the configuration for Zsh, you will find it in your HOME directory. Open the files with your favourite text editor and enable your favourites plugins by adding a theme to the plugins array:

# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git colored-man-pages colorize brew osx zsh-syntax-highlighting zsh-autosuggestions)

Note that zsh-autosuggestions & zsh-syntax-highlighting are custom plugins and must be installed manually:

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

Themes:

List of Oh My Zsh themes can be found here. In order to enable a theme, you need to set ZSH_THEME to the name of the theme in your ~/.zshrc. for example:

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
ZSH_THEME="robbyrussell"

My favourite theme is powerlevel10k check it out here.

Conclusion:

Zsh is a powerful tool that can boost your productivity and make you life easier, I hope you enjoyed this small tutorial, if you know other plugins and tricks that improved your productivity with using Zsh feel free to reach out on Twitter, I would like to hear from you.

Top comments (3)

Collapse
 
moopet profile image
Ben Sinclair

I didn't realise you could change to a directory by typing its name. That's cool.

But zsh doesn't have themes - at least not any more than bash does :)

Collapse
 
anesabml profile image
Anes Abismail

I don't really know about themes support in bash, I always used zsh, but I will check it out.
Thank you.

Collapse
 
moopet profile image
Ben Sinclair

I mean that zsh doesn't have theme support at all. oh-my-zsh sets a bunch of prompt preferences using ANSI codes, but you can do that in most shells.