bash is a wonderful shell but there are better alternatives for day-to-day use. One of these alternatives is zsh (pronounced “Z-shell”). zsh provides a more robust tab completion, easier navigation through directories and a larger selection of plugins, among many other. At the same time, it retains compatibility with bash features such as Word Designators or Modifiers.
In this exercise, you will install zsh and configure it with predefined themes and plugins.
Pretty much everything you will install in Ubuntu (at least while you're still new to this) will be done via apt. apt is a CommandLine Interface (CLI) for the package management system (think Windows Store, but better). First thing you must do after a fresh install is to update your information about the packages available for download. Once you do, you'll be able to do a term search and install whatever you please.
$ sudo apt update $ apt search zsh
Note a few things:
apt update
) with “administrator privileges”. Updating your local package information is a sensitive operation that not every user should be able to do. But just searching for a packet (without installing it) is a harmless operation, so no need for sudo there.apt search zsh
command returns a rather long list. This is because apt performs an approximate search in both the available package names and descriptions. If you want an exact match, try using a regular expression such as ^zsh$ which should be interpreted as: “beginning of the line, followed by the string 'zsh', followed by the end of the line”.Anyway, moving forward we will want to use a popular collection of zsh configurations called oh-my-zsh. As such, we will need to install a few dependencies first:
$ sudo apt install curl wget git zsh fonts-powerline
These are pretty well known tools and you are very likely to use them again; here is a short description of each one:
With this out of the way, let's download oh-my-zsh and copy their template configuration file in your HOME directory. Then change your user's default shell to zsh:
$ git clone https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh $ cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc $ chsh -s $(which zsh)
Things to note here:
-a
flag when you run ls. This directory contains all the sample themes, plugins and auto-complete scripts that zsh will use, so don't delete it.$(which zsh)
: this is called Command Substitution. Before the main command (i.e.: chsh) is executed, bash will interpret which zsh
separately. It's output to stdout (in this case, /usr/bin/zsh, the location of zsh) will replace $(…)
. So the final form of the command you gave, after substitutions, will be chsh -s /usr/bin/zsh
.Notice how your zsh theme is different from the one in the GIF above? That's because your default is robbyrussell and that is agnoster (with a few tweaks). Take a look here and choose a theme that suits you. Then, edit .zshrc. When you're done editing the config file and you've saved the changes, source it for them to take effect:
$ source ~/.zshrc
Finally, let's add a few plugins to our shell by editing the plugins variable in .zshrc. Note that plugins is a bash array and the elements are space-separated, not comma-separated.
cd ..
Some bash / zsh shortcuts that can work well with zsh-autosuggestions: