ZSH – Pretty, what else is great about it

3
Zsh is touted as a great alternative to bash and all other shells. The shell has many of the features, if not all of bash but with enhancements. It is better, according to its fans, at globbing, editing commands and menu completion features. If you start hopping from bash to other solutions, check out zshell and see if you like it.

Why do lovers love zsh?

As expected, when zsh starts, you see little difference from other shells. Go through a tutorial from the web and see how you like it. One great suggestion is to use oh-my-zsh, it is a community driven collection of tools for zshell. Some of the first things you may notice are automatic cd into directories. Just start typing a directory name and zsh will fill it up. You will also get recursive expansion, a directory name usr/bin can be abbreviated /u/b and zsh will expand it. You also have switch search, this feature lists any available switches for the command you started typing.

How do you install it?

Your distribution comes with bash, most likely, if you want to switch to zshell, you can install it with your package manager.

$ sudo apt install zsh

When that is done, you need to configure it to your own liking. Fortunately, zsh will run a script for you if you have no settings in your home directory.

You can show some standard defaults but to take full advantage of the shell, read through the manual and choose some more features. There are many choices, follow along further down for some options about this.

All these steps only sets up how the script runs, when you have decided to use it as your standard shell, you need more actions. You have several methods to achieve this. Which shell you use as standard is set in the ‘/etc/passwd’ file. You have many users in this file even if only you use this machine. The other users are there to act as special users for specific applications. If you search in it, you can find the gdm user, which runs gdm3 before you login. For this reason, you need to search for your username and check the values. Your shell is the last value in the list, to change the values, you need to be root. Change the value to ‘/bin/zsh’ or ‘/usr/bin/zsh’, check with ‘which zsh’.

You also have a command line utility, chsh. This is necessary if you are not root on the machine. As a regular user run:

$ chsh -s /usr/bin/zsh

The change does not take effect immediately, you must log out and back in first.

Where are the configure files?

For zshell, the designers have made it clear and consistent. The files have the same names but in different locations. The environment variables go in etc/zsh/zshenv and ~.zshenv. These are always read but seldom used. The files for when you login are etc/zsh/zprofile and ~.zshprofile. For the login shell, when you run external commands, the files are etc/zsh/zshlogin and ~.zshlogin respectively. Finally, for your interactive shell you set values in etc/zsh/zlogin and ~.zlogin.

For personal preferences and making your shell work better for you, you should edit your local ~/.zshrc.

How do you get started?

The best thing about zsh is the configuration script that sets some decent defaults. Before you dig deep into the documentation and try to set every detail of the config, try a few frameworks. You will probably run into Oh-My-Zsh, this framework has it almost all. There are both themes and plug-ins available. Get in the habit of checking out what is available and how it works. Many of the plug-ins are for a special need. The Ansible module has aliases for working with Ansible, so consider which ones you install. To find modules, start with the ‘Oh-My-Zsh’ package, mentioned earlier. If you start with the plugins on their GitHub page, you can find many plugins contributed by the community. When you see something you like, just add it to the ‘plugins’ entry in your .zshrc file.


plugins=(git web-search)

Try a few at a time and make sure you don’t add too many, it will slow the start of the shell.

How do you change it to your f(l)avour?

There are also themes to make it look better. They set colour and the prompt, they are also possible to look different depending on how if have logged in on console or ssh. Many of these themes also respond dynamically to git status of the current directory. You can create these themes your self, they are shell scripts that set the prompt and create functions to handle your environment.

Conclusion

Zshell has a definitive learning curve, though not a very steep one. There are also a large community who share generously of their own customisation scripts. As soon as you start working in the shell, it is worth taking a look at the power of the shell. If you are not using the shell yet, get started. Many things seem harder but are simpler after you know some details.

Comments are closed, but trackbacks and pingbacks are open.