oh-my-zsh or how to improve your Terminal

As developers, we spent most of our time on the Terminal, and some of us prefer to run everything from it instead of access cPanels or Administration screens to handle our sites (MySQL client to manage the MySQL server, WP-CLI for WP, Drush for Drupal, you name it!) The problem with those of us who like to do everything from Terminal starts when we use commands that require lots of flags.  A good example is a Git log command; if you want to print a pretty log (summarize commit meta in a single line,) this is how the command will look like:

$ git log --graph --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit

As you can see, it isn’t a very easy to remember set of flags.  And this is only for one Git task.  Now imagine trying to remember lots of flags for many other commands (binaries) running on your system.  This is where oh-my-zsh can give us a hand.

Let’s start with the basics: install ZSH.  ZSH is an advanced *nix shell.  Its installation will depend on the system you are running, and for this post Homebrew for macOS will be the package manager used as an example to install it:

$ brew install zsh

Simple, right? After that, it is necessary to set ZSH as the default shell for the Terminal:

$ chsh -s /bin/zsh

That’s all requirements to install oh-my-zsh.  The official document documentation describes oh-my-zsh as a “framework for managing your zsh configuration”.  Basically, it is a set of thems and plugins available for your Terminal and installing it is very straightforward:

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

It will be install on the ~./oh-my-zsh path, and its configuration file can be found under the ~/.zshrc file; is in this file where a theme can be set and plugins can be enabled.  In it, there are many directories, but the more important ones are plugins and themes: the files within the themes directory (without the zsh-theme extension) is how it should be set on the oh-my-zsh configuration file.  As an example, if the gallois theme wants to be set, the way to do it is:

ZSH_THEME="gallois"

Within the plugin directory, each plugin will be group in a directory, and this is how enabling a plugin looks like on the oh-my-zsh configuration file:

plugins=(git)

Once this Git plugin is enabled, the Git command mentioned above can be reduced to the alias:

$ glol

Pretty awesome, right?  There’s a lot of plugins and if you don’t find the one that suits your needs, you can come up with your one and create PR to the oh-my-zsh project to share it with the community.

oh-my-zsh is a great set of resources for developers improve their Terminal and make them even more productive with it.


Tagged: , , ,