Getting started with Zsh
Tags: tutorial, terminal, zsh, macos
Published: 2020-07-02 12:01:30

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](https://brew.sh/) installed:

```bash
brew install zsh
```

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

```bash
chsh -s /usr/local/bin/zsh
```

for other OS you can check this link [here](https://github.com/ohmyzsh/ohmyzsh/wiki/Installing-ZSH).

# 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](https://github.com/ohmyzsh/ohmyzsh). Installing Oh My Zsh can be done using either `curl` or `wget`:

- Using `curl`:

```bash
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
```

- Using `wget`:

```bash
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](https://github.com/ohmyzsh/ohmyzsh/wiki/Plugins) and [themes](https://github.com/ohmyzsh/ohmyzsh/wiki/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](https://github.com/ohmyzsh/ohmyzsh/wiki/Plugins). 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:

```bash
# 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](https://github.com/zsh-users/zsh-autosuggestions) & [zsh-syntax-highlighting](https://github.com/zsh-users/zsh-syntax-highlighting) are custom plugins and must be installed manually:

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

```bash
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](https://github.com/ohmyzsh/ohmyzsh/wiki/Themes). In order to enable a theme, you need to set `ZSH_THEME` to the name of the theme in your `~/.zshrc.` for example:

```bash
# 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](https://github.com/romkatv/powerlevel10k).

# 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](http://twitter.com/anesabml), I would like to hear from you.