ZSH - Your terminal on steroids!

ZSH - Your terminal on steroids!

ZSH, also called the Z shell, is an extended version of the Bourne Shell (sh), with plenty of new features, and support for plugins and themes. Since it’s based on the same shell like Bash, ZSH has many of the same features, and switching over is a breeze.

The Z-Shell, zsh for short, is a command interpreter for UNIX systems, or in UNIX jargon, a shell because it wraps around the commands you use. More than that, however, zsh is a particularly powerful shell, and it’s free, and under regular maintenance, with lots of interactive features allowing you to do the maximum work with the minimum fuss. Of course, for that, you need to know what the shell can do and how, and that’s what this guide is for.

So Why Use It?

ZSH has too many features to list here, some just minor improvements to Bash, but here are some of the major ones:

  • Automatic cd: Just type the name of the directory
  • Recursive path expansion: For example “/u/lo/b” expands to “/usr/local/bin”
  • Spelling correction and approximate completion: If you make a minor mistake typing a directory name, ZSH will fix it for you
  • Plugin and theme support: ZSH includes many different plugin frameworks

Plugin and theme support is probably the coolest feature of ZSH and is what we’ll focus on here.

Installing ZSH

Installing Oh-My-Zsh

Oh-My-Zsh is the most popular plugin framework for ZSH, and it comes with many built-in plugins and themes as well. There are also a couple of other plugin frameworks, including Antigen, which is a full package manager for ZSH, but Oh-My-Zsh has loads of plugins built right in and does its job well.

Oh-My-Zsh has a simple install script you can run:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

From there, you can enable and disable plugins by adding them to your .zshrc file, located in your ~ directory.

Themes

There are plenty of themes to go around, but spaceship-prompt is one that I find fancy. It adds integration with git and command history, incredible customization, and wraps it all up in a slick interface based on the powerline plugin for vim.

To set up spaceship-prompt (if you installed Oh-My-Zsh) just clone the repository into the .oh-my-zsh custom themes folder:

git clone https://github.com/denysdovhan/spaceship-prompt.git "$ZSH_CUSTOM/themes/spaceship-prompt" --depth=1
ln -s "$ZSH_CUSTOM/themes/spaceship-prompt/spaceship.zsh-theme" "$ZSH_CUSTOM/themes/spaceship.zsh-theme"

Then you need to enable it in .zshrc:

ZSH_THEME="spaceship"

After that, source your .zshrc, and you should see the changes applied.

source ~/.zshrc

You can find the full documentation for spaceship-prompt on the repo.

Plugins

Oh My Zsh comes with a shitload of plugins for you to take advantage of. You can take a look in the plugins directory and/or the wiki to see what's currently available. Enabling Plugins

Once you spot a plugin (or several) that you'd like to use with Oh My Zsh, you'll need to enable them in the .zshrc file. You'll find the zshrc file in your $HOME directory. Open it with your favorite text editor and you'll see a spot to list all the plugins you want to load.

This is an example of how the plugin config apparently looks like in zshrc file -

plugins=(
  git
  bundler
  dotenv
  osx
  rake
  rbenv
  ruby
)

My two favourite and most used plugins are -

  1. zsh-autosuggestions - This suggests the commands by looking on the previous history of commands typed and location of the command being executed. To install -
git clone https://github.com/zsh-users/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions
  1. zsh-syntax-highlighting - This highlights the commands to clearly show it's various parts To install -
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting

After installing them, just add them to plugins section of .zshrc and source it.

plugins=(git zsh-autosuggestions zsh-syntax-highlighting)

Remeber, the plugins are super fun to add, but the more you add, the more your terminal will take time to fire up! So make sure that you add only the plugins that are absolutely necessary to you!

This is my .zshrc file for reference!

Thank you for reading! Comment if you face any difficulties in setting up your perfect zsh config!

Did you find this article valuable?

Support Shubhank Saxena by becoming a sponsor. Any amount is appreciated!