3.1. Terminal - ZSH#

It is an alternative to bash, and it is going to be the default shell on macOS starting from Catalina 10.5.

3.1.1. Z Shell#

zsh is a shell derived from the Bourne shell sh, like bash we discussed here. It is the reason why they both share a lot of features. If you already know how to use bash (cd, mv, touch, mkdir, …), don’t worry, you won’t start from scratch again. Note that to make it your default shell, you can use:

chsh -s $(which zsh)

Note

You can use any shell interactively, and if you write a script, you can specify the shell using a shebang (#!/usr/bin/env bash for bash) at the beginning of your shell scripts.

Here are some interesting features of zsh (see next section to activate all of them):

  • Completion (builtin and improved with zsh-completions): just use tab to complete your command line

    • recursive path completion: no need to write the full directory/file names

    • command arguments completion: zsh suggests arguments to the command you wrote with a description of each option (for example, git we saw here)

    • command arguments flags: same as the previous feature, but for flags

    • variable expansion:

  • Better history navigation: you can search for a command in your history with any substring of this command using up and down arrows (with history-substring-search)

  • Autosuggestion: the last command starting by what you write is suggested and you can use tab to autocomplete it (with zsh-autosuggestions)

  • Plugin and theme support: zsh is known for its plugin managers that allows installing/activating the previously cited plugins and many others, but it is also known for its highly customizable prompt. We are going to see how to benefit from them in the following.

3.1.2. Plugin managers#

As we have seen, some features are available via plugins. You could install them by hand, each repository explains how to do it. Usually you have to download them, source them in your .zshrc and set some variables. But it can be tricky because the order in which you source them matters, and having a lot of plugins can add a delay when starting a new shell session.

Another possibility is to use a plugin manager. There are a lot of them (see reference), I personally use Zim that I find fast and easy to use. Besides, it is well-maintained, and the maintainers were quite helpful when I had a question. I tried to use a few other plugin managers, most of them are great, but some added a delay when starting a new shell session, and that is how I tried Zim, which is marketed as fast. I was also convinced by the fact they thought about how their project should grow.

The installation process is quite simple, and default configuration should give you most of the features described previously. To add or remove modules, you need to add a line with zmodule in .zimrc and run zimfw install. See documentation here.

3.1.3. Prompts#

The benefit in customizing your prompt is that it allows you to display more information. git, that we introduced in here), is the usual first example. You can display the current branch, and if there are modifications to be committed. But you can also display timing between commands, battery level, and a lot of other information. I personally like to keep it simple, but you do you 😉

Similarly to plugins, you could define a customized prompt by hand. But the risk is to add a delay each time you enter a command because of the loading time of the prompt.

Similar problem, similar solution: people have already defined optimized prompts that allow for customization while avoiding delay most of the time. Two popular prompts are Spaceship ZSH and Powerlevel10k. I personally use the latter at the moment, but they are both fast, customizable and easy to use. The installation process is quite straightforward, and the configuration is done interactively.

Here is an example with Powerlevel10k where I show current folder, current git status (notice the ?1, which means there is one file not tracked), python virtual environment, time, and a custom prompt that shows ⭐ with my display.

3.1.4. References#

Z Shell

Plugin managers

Prompts