To install
# emerge zsh zsh-completion
When you start
$ zsh
This is the Z Shell configuration function for new users, zsh-newuser-install.
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~). This function can help you with a few settings that should
make your use of the shell easier.
You can:
(q) Quit and do nothing. The function will be run again next time.
(0) Exit, creating the file ~/.zshrc containing just a comment.
That will prevent this function being run again.
(1) Continue to the main menu.
--- Type one of the keys in parentheses --- q
To start zsh for a single session, run
To enable the famous
% autoload -U compinit % compinit
Default completion style is quite plain and ugly. If you want to improve its appearance, enter the following commands:
% zstyle ':completion:*:descriptions' format '%U%B%d%b%u' % zstyle ':completion:*:warnings' format '%BSorry, no matches for: %d%b'
It is also a good idea to enable the auto-correction of the commands typed:
% setopt correctall
The prompt may seem quite boring however, but we can fix it easily in several steps. First, we need to initialize advanced prompt support:
% autoload -U promptinit % promptinit
Available prompts samples may be printed via the
(Replace gentoo with the prompt of your choice) % prompt gentoo
Another option is to create your own prompt. To do this you will need to set the PS1 environment variable.
% export PS1="[Test Prompt] > " [Test Prompt] >
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:
| Sequence | Printed |
|---|---|
These escape sequences may simply be inserted into the environment variable, PS1, and zsh will parse them automatically.
% export PS1="[%* - %D] %d %% " [08:44:23 - 06-02-18] /home/username %
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:
% export HISTSIZE=2000 % export HISTFILE="$HOME/.history"(History won't be saved without the following command) % export SAVEHIST=$HISTSIZE
To prevent history from recording duplicated entries (such as
% setopt hist_ignore_all_dups
A useful trick to prevent particular entries from being recorded into a history by preceding them with at least one space.
% setopt hist_ignore_space(This command won't be recorded. Note the extra space before it.) % cat /proc/cpuinfo
You can set the
% setopt autocd
If standard bash-like globbing does not satisfy you,
% setopt extendedglob
When option above is set, you are able to use extended globbing queries
such as
Once we have customized
#!/bin/zsh # completion autoload -U compinit compinit # correction setopt correctall # prompt autoload -U promptinit promptinit prompt gentoo
We can change shell for given user with
# usermod -s /bin/zsh userlogin
If your system administrator (despite gentle requests, that is) refuses to set
the shell to zsh for you, you can set
(Add the following to your ~/.bashrc) exec zsh
Another method of changing shells is to use the
(Replace "username" with your own username) $ chsh -s /bin/zsh username