Customise your shell for speed with Oh My ZSH!

3 minute read

Shells and Oh My ZSH!

Have we come a long way since the times sh (the “Bourne shell’, named after its developer) was created in the 70s? There’s Bash (the “Bourne again shell”, 1989), which is essentially an extension with a bit more stuff and is meant as its replacement. The Z shell (zsh) is not much more recent, it was created in 1990 by P Falstad and takes the name from the username of a Professor at Yale where he was studying at the time 1. It has more fancy features like command completion, command history and is in general quite customisable.

Now, Oh my ZSH! is an open source project that brings even more customisability and fancyness to your Z Shell, including lots of ways to speed up your workflow. With it, your terminal can get way better. The tool is especially useful for working with git as it adds a few very convenient ways to use it quicker. Honestly, it’s a great tool.

Install

I’m on MacOS and the ZSH is already there. You can install Oh My ZSH! as

sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

All will be in the ./oh-my-zsh folder.

Changing shell

Once you do, you’ll be using the Z shell. Note that in changing shell (assuming you were using Bash before) to ZSH you’d have to port your Bash profile settings to it as ~/.bash_profile isn’t automatically sourced by zsh. The user profile for zsh is in ~/.zshrc, add stuff here.

The first noticeable change is colour and a bit more wording in your terminal prompt. That’s a theme, that you can choose and/or customise.

Themes

Oh My ZSH! comes with a few themes you can choose from, the default one being robbyrussell, the creator’s preferred one, in the image here from my terminal.

It tells me where I am but also on which git branch, and the X indicates that there are uncommitted files. You can also customise a theme even further, themes are in ~/.oh-my-zsh/themes/

Aliases and tab completion

The shell comes with some aliases done for you which you can list by typing alias. For instance, .. stands for cd .., plus common git commands are aliased for shortness: ga is for git add, to name one.

Tab completion over commands is enabled: for instance typing ls -[TAB] will give you a list of flags you can choose from by navigating to with the arrows. Which is quite cool if you tend to forget commands you don’t use very often.

Plugins

The tool comes with a few plugins that you can enable in the ~/zshrc profile file by adding lines like plugins=(git colored-man-pages). Plugins are located in ~/.oh-my-zsh/plugins/. Of the existing ones, I’ve enabled

  • colored-man-pages: adds a bit of useful colour to man pages, useful for reading
  • git (which comes enabled by default): it gives a few aliases for git commands and a few bespoke commands for convenience, for instance current_branch will print which branch you’re in
  • history: this one is also quite good, lets you get more out of the history command; you can invoke your history with alias h but, even better, perform a grep-base search on your history by typing hsi <what to search>, it’s awesome
  • web-search: allows you to search on Google/Bing/Yahoo/Duckduckgo by typing from the terminal, it will open the browser with the results; say you for instance type google RuntimeError: you must first build vocabulary before training the model, very useful to search for stacktrace errors from the terminal directly!

Plugins like brew, pip, docker, aws add autocompletion to the respective tools, which all come in handy if you do data science, say. There’s a bunch of other ones which are useful for specific languages/workflows.

You can also add external plugins by cloning their repo inside ~/.oh-my-zsh/plugins/ and again adding them to the profile. Of external plugins you can enable, I’ve personally chosen zsh-suggestions, which allows commands to be suggested to you while you type: a grayed out completed text will appear as you type that you can then quickly accept by pressing the arrow (see image). It is based on the usage you make of commands so especially for stuff that you use very often it is damn useful.

Other commands

  • d lists folders you’ve been using
  • alias the aliases set up
  1. Says the godly Wikipedia 

Leave a Comment