Zsh/Guide

This guide details some of the configuration for zsh.

Installing zsh
To install under Gentoo, we need to emerge zsh itself  and the zsh auto completion scripts :

Entering zsh
When you start for the first time, you get the following message. You can skip this menu as we will create an init file later in this guide.

Introduction
To start zsh for a single session, run. For a more permanent solution, please refer to the chapter on. After the installation, seems to be very simple and rather limited in the area of functionality. To change this, several configuration changes need to be performed.

Advanced Tab-completion
To enable the famous tab-completion system, you need to run the following commands:

Default completion style is quite plain and ugly. If you want to improve its appearance, enter the following commands:

Command correction
It is also a good idea to enable the auto-correction of the commands typed:

Prompts
The prompt may seem quite boring however, but we can fix it easily in several steps. First, we need to initialize advanced prompt support:

Available prompts samples may be printed via the command. Now we can activate our favorite one:

Another option is to create your own prompt. To do this you will need to set the PS1 environment variable.

While it is good to be able to create a custom text prompt, zsh also provides many escape sequences that allow system information to be inserted into the prompt. Some of the escape sequences available are:

These escape sequences may simply be inserted into the environment variable, PS1, and zsh will parse them automatically.

History
Unfortunately, the default zsh configuration in Gentoo does not include command history support. As working with a shell without history is very frustrating, we should enter the following commands:

History won't be saved without the following command:

To prevent history from recording duplicated entries (such as entered many times during single shell session), you can set the   option:

A useful trick to prevent particular entries from being recorded into a history by preceding them with at least one space.

The following command won't be recorded. Note the extra space before it:

Miscellaneous settings
You can set the  option if you want to avoid tedious typing of  command while changing current directory (for example  instead of ).

If standard bash-like globbing does not satisfy you,  option may be set to enable extended globbing (one similar to regular expressions).

When option above is set, you are able to use extended globbing queries such as.

Saving zsh settings
Once we have customized the way we like it, it is a good idea to save these options as the  defaults for the system. One possible way to achieve this is to write our settings in the script. Alternatively, we could make them the defaults for our account only be editing.

Option for users with root privileges
We can change shell for given user with the command.

Alternative for non-root users
If your system administrator (despite gentle requests, that is) refuses to set the shell to zsh for you, you can set to execute  on startup, all you need to do is make a slight modification to your.

Another method of changing shells is to use the command (a utility used to change a user's login shell). A normal user may only change the login shell for his own account. As root, you can change the login shell of any user.