loading...
Cover image for Intro to ZSH

Intro to ZSH

thetinygoat profile image Sachin Saini 惻3 min read

Intro

If you are familiar with command line chances are you are using the default shell that came with your operating system that is bash. While there is nothing wrong with bash its kind of ugly looking out of the box and if you are inclined enough you can make bash do all the things zsh can but who's got the time for that?

So today we are going to look at zsh(Z Shell). Zsh too is kinda bland out of the box but the ecosystem around it makes it awesome.

All your bash scripts will still work with zsh so no need to worry about it.

Let's get started.

Setup

First we need to install zsh, i am using Fedora(a linux distro) you can follow the steps for your operating system.

sudo dnf install zsh

This will install zsh for us.

Now let's create a config file for zsh in our home directory.

touch ~/.zshrc

Now that we are all setup let's get to the good part. Zsh has a plugin system, you can add and remove plugins as your hear desires, but managing these plugins can be a bit of a cumbersome task.

Enter Antigen, Antigen is a plugin manager for zsh which makes it a breeze to manage and install new plugins without all the hassle, now let's install Antigen.

You can follow the instructions on the Antigen github page but i'm also writing them here.

First let's download it.

curl -L git.io/antigen > ~/.antigen.zsh

Now let's tell zsh to use antigen by adding it to the config file. Add the following line to ~/.zshrc.

source ~/.antigen.zsh
# Note: make sure to add the correct path to your zshrc file.

Now you are all setup but you might have noticed that your shell still looks the same. That's because you haven't changed your default shell from bash to zsh, let's do it now.

chsh -s /bin/zsh
# Note: don't use sudo

this will change your default shell, now log out and log back in to see the changes.

Customization

Now that you are all setup let's spice up our shell.

Oh My Zsh

You might think of oh my zsh as a collection of plugins. It's a community run project and there are hundreds of plugins to fulfill your needs.

now that we are done with our oh my zsh primer let's tell antigen to use oh my zsh to fetch plugins, open up your zshrc file and add the following lines to it.

antigen use oh-my-zsh # tell antigen to use oh my zsh
# all your antigen config goes here
antigen apply # apply the changes

Setup a kickass theme

You can get a full list of themes here.
once you have chosen a theme tell antigen to use that theme.

antigen theme your-theme-name
# example : antigen theme robbyrussel

Setup some plugins

While themes are good, you need to get some work done on your machine and plugins can help you do them faster and be more productive. Some of the plugins i use are git plugin and the syntax highlighting plugin. dont go overboard with plugins as they can slow down your shell.

antigen bundle git # git plugin
antigen bundle zsh-users/zsh-syntax-highlighting # syntax highlighting plugin

the git plugin can save you a lot of time, for example it has aliases for almost all the git commands, for example:
gst => git status
gp => git push
gaa => git add .
gcl => git clone
gc => git commit

you can find the complete list here.

Full config file

source ~/.antigen.zsh
# Load the oh-my-zsh's library
antigen use oh-my-zsh
antigen bundle git
antigen bundle zsh-users/zsh-syntax-highlighting
# Load the theme
antigen theme gianu
# Tell antigen that you're done
antigen apply

Some tips

One of the things i found hard was to manage my zshrc file along with other dotfiles (config files), one simple solution i used was to use git to manage my config files and host them on github, that way i will have access to my config files everywhere

you can find my config files here.

Thanks for reading :)

Posted on by:

thetinygoat profile

Sachin Saini

@thetinygoat

Currently a student, love to post about all things tech.

Discussion

markdown guide
 

One thing worth mentioning and which was not at all obvious until I made the dive into zsh is that it is fully bash-compatible.

I was concerned that Iā€™d have to re-write a lot of shell scripts to work with zsh but that was absolutely not the case. Switching (and adding Oh My Zsh!) took literally fifteen minutes.

 

Good point! I tried Fish and Fish has some incompatibilities

 

Hi Scott, thanks for pointing that out, I'll update the article :)

 

Combine that with fzf and ripgrep and you have a kickass shell!

 

You don't need antigen to install oh-my-zsh. It's can be install by wget or curl. Look here ohmyz.sh/

To highlight syntax you can try hyper.io/
Also hyper supports multiple windows without tabs.

 

Hi Eugen, I'm aware that you don't need antigen to use oh my zsh but my point for using antigen was ease of use.

Hyper is an excellent choice but I like to stick with the default terminal :)