Linux

ZSH Essential Plugins

Introduction

Zsh a.k.a Z shell is the super set of Bourne Shell. First version of this shell was written by Paul Falstad at Princeton and named it Z-shell after his professor Zhong Shao. Zsh comes with many interesting plugins, themes and features like advanced tab-completion. Even Apple recently announced that the Zsh will be the default shell for upcoming macOS Catalina. In this article, we will take a look on some interesting plugins of Z-shell.

Antigen – Plugin Manager For ZSH

Before starting with plugins, lets first take a look on plugin manager. Antigen is one of the popular Zsh plugin manager inspired from Pathogen, a vim-plugin-manager. Antigen can be used with Zsh having version greater than 4.3.11. ( Source of antigen can be found here – for geeks only). All plugins we will see in this article, can be installed using antigen. But before plugins, lets install antigen first.

1. Download antigen script.

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

2. Load antigen script in Zsh. For this, open ~/.zshrc file and add below line.

source /path/to/antigen.zsh

Essential Library oh-my-zsh

oh-my-zsh is an opensource library to configure Zsh. We can easily enabled it with help of antigen. Add the below line in your ~/.zshrc after loading antigen-script.

antigen use oh-my-zsh

The reason we are going after oh-my-zsh is its ecosystem. oh-my-zsh comes with the huge set of plugins and themes per say. Below are few of them. All of these plugins can be installed by adding below line in ~/.zshrc after loading antigen.

antigen bundle <plugin-name>
e.g.
antigen bundle git
antigen bundle pip

git

This plugin gives the tons of easy, meaningful shortcuts for git commands. e.g. ga for git add.

pip

This is very helpful plugin for python developers. It provides auto-completion for pip commands.

command-not-found

This plugins provides feedback on commands based on cache of existing programs.

common-aliases

This plugins provides aliases for popular commands like ls, grep etc. List of all these aliases can be found here.

autojump (j), z, v & fasd

If you’re are the command-line-junkie, you might be already familiar with autojump. This little package helps in navigation by fuzzily matching keywords you entered to history-of-cd-command. So for example if you do cd /home/foo/bar/baz, next time just type j baz and will be jumped in /home/foo/bar/baz. Cool right ?

But autojump is not the only plugin which helps in navigation. Similar to autojump there is z and fasd tools. z is improvement over autojump by using Mozilla’s frecency algorithm. (See this comment if you’re interested in comparison and horrible stuffs like algorithms. ). fasd is improvement over autojump, z and v. Below is the short list of aliases bundled with fasd.

alias a='fasd -a'        # any
alias s='fasd -si'       # show / search / select
alias d='fasd -d'        # directory
alias f='fasd -f'        # file
alias sd='fasd -sid'     # interactive directory selection
alias sf='fasd -sif'     # intecomesractive file selection
alias z='fasd_cd -d'     # cd, same functionality as j in autojump
alias zz='fasd_cd -d -i' # cd with interactive selection

If you want use autojump, install package autojump using your linux-package-manager and then enable plugin using antigen. For z, you don’t need any external package, just enable via antigen. For fasd, you need fasd package. After installing package, enable fasd plugin using antigen.

External Plugins

git-extra-commands

This plugin provides aliases for additional git commands. To enable plugin add below line in ~/.zshrc.

antigen bundle unixorn/git-extra-commands

zsh-navigation-tools

Using this plugin, we can run fuzzy-search in command history by entering multiple words. This is another must-have plugin. You can find list of all additional options here. To enable this, plugin add below line in ~/.zshrc.

antigen bundle psprint/zsh-navigation-tools

auto-ls

How cool is it to run ls whenever you change directory ? If you’re like me running ls every time on changing directory this is must have plugin. As name implies, it will show list of files and folder on changing directory. Enable this plugin by adding below line in ~/.zshrc.

antigen bundle desyncr/auto-ls

zsh-syntax-highlighting

Fish Shell is very popular for its visuals. If you want to enable Fish Shell like syntax-highlighting, use this plugin by adding below line in ~/.zshrc. This plugin must be added as the last bundle in your zshrc to work.

antigen bundle zsh-users/zsh-syntax-highlighting

zsh-you-should-use

So many aliases, how to remember them all ? There is plugin for this too. This plugin will suggest you the existing alias whenever you enter command. Enable it using below line in ~/.zshrc.

antigen bundle MichaelAquilina/zsh-you-should-use

Themes

As mentioned before, with oh-my-zsh, we get access to tons of theme. List of all these themes can be found here. To enable any of theme, add below line in your ~/.zshrc.

antigen theme <theme-name>

Final Antigen Config

So our final Antigen Config will be something like below. Make sure to change first line with proper path and theme as per your taste.

source /absolute/path/to/antigen.zsh

# Load the oh-my-zsh's library.
antigen use oh-my-zsh

# plugins with oh-my-zsh
antigen bundle git
antigen bundle command-not-found
antigen bundle common-aliases
# antigen bundle autojump
# antigen bundle z
antigen bundle fasd

# external plugins
antigen bundle unixorn/git-extra-commands
antigen bundle psprint/zsh-navigation-tools
antigen bundle desyncr/auto-ls
antigen bundle MichaelAquilina/zsh-you-should-use
antigen bundle zsh-users/zsh-syntax-highlighting # must be last plugin to get effect

# theme
antigen theme blinks

# apply config
antigen apply

Hope you guys like this article ! Feel free to add your suggestions in comment box.

Leave a Reply