Difference between revisions of "Zsh"

From ArchWiki
Jump to: navigation, search
m ("/path/to/zsh"... seriously?)
m (Sample .zshrc files: Updated the url)
Line 255: Line 255:
Here is a list of {{Filename|.zshrc}} files. Feel free to add your own:
Here is a list of {{Filename|.zshrc}} files. Feel free to add your own:
* Øyvind 'Mr.Elendig' Heggstad <=> Basic setup, with dynamic prompt and window title/hardinfo <=> http://arch.har-ikkje.net/configs/home/dot.zshrc
* Øyvind 'Mr.Elendig' Heggstad <=> Basic setup, with dynamic prompt and window title/hardinfo <=> http://github.com/MrElendig/dotfiles-alice/blob/master/.zshrc

Revision as of 13:09, 14 August 2010

Template:I18n links start Template:I18n entry Template:I18n entry Template:I18n links end Zsh is a powerful shell that operates as both an interactive shell and as a scripting language interpreter. While being compatible with Bash (not by default, only if you issue "emulate sh"), it offers many advantages such as:

  • Faster
  • Improved tab completion
  • Improved globbing
  • Improved array handling
  • Fully customisable

The Zsh FAQ offers more reasons to use Zsh as your shell.

Installation Instructions

Before starting lets find out what shell is currently being used:

$ echo $SHELL


To install the package for Zsh, run:

# pacman -S zsh

Before proceeding with the next step to make Zsh your default shell, you should ensure that it has been installed correctly by running Zsh in a terminal:

$ zsh

You should now see zsh-newuser-install, which will walk you through some basic configuration. If you want to skip this, press q.

Making Zsh your default shell

To change a user's default shell without root access, the chsh command is used. The chsh command can be used to change a user's default shell without root access if the shell is listed in Template:Filename. If you installed Zsh from the repos, Zsh should already have an entry in Template:Filename.

To proceed you need to know the full path for Zsh, so run:

$ which zsh

Change the default shell for the current user:

$ chsh -s `which zsh`
Note: The user needs to logout and log back in, to start using Zsh as their default shell.

After logging back in, the user can verify that Zsh is their default shell by issuing (Zsh also looks different than Bash):

$ echo $SHELL


Although Zsh is usable out of the box, it is almost certainly not set up the way you would like to use it, but due to the sheer amount of customisation available in Zsh, creating a Zsh config can be a daunting and time-consuming experience.

Included below is a sample configuration file, it provides a decent set of default options as well as giving examples of many ways that Zsh can be customised. In order to use this configuration save it as a file named Template:Filename. You can then apply the changes without needing to logout and then back in by running:

$ source ~/.zshrc

Simple .zshrc

Here is a simple Template:Filename, that should be sufficient to get you started:


Command Completion

Perhaps the most compelling feature of Zsh is its advanced autocompletion abilities. At the very least, you will want to enable autocompletion in your Template:Filename. To enable autocompletion, add the following to:


The above configuration includes ssh/scp/sftp hostnames completion but in order for this feature to work you will need to prevent ssh from hashing hosts names in ~/.ssh/known_hosts (Warning: be aware that this makes your computer vulnerable to "Island-hopping" attacks). In that intention, comment the following line or set the value to "no": Template:File And move your ~/.ssh/known_hosts somewhere else so that ssh creates a new one with with un-hashed hostnames (warning: previously known hosts will thus be lost).

For autocompletion with an arrow-key driven interface, add the following to: Template:File

Key Bindings

Zsh doesn't use readline, instead it uses its own and more powerful zle. It doesn't read /etc/inputrc or ~/.inputrc. zle has an emacs mode and a vi mode. By default, it tries to guess whether you want emacs or vi keys from the $EDITOR environment variable. If it's empty, it will default to emacs. You can change this with bindkey -v or bindkey -e.

To get some special keys working: Template:File


There is a quick and easy way to set up a colored prompt in Zsh. Make sure that prompt is set to autload in your Template:Filename. This can be done by adding these lines to:


You can now see available prompts by running the command:

$ prompt -l

To try one of the commands that is listed, use the command prompt followed by the name of the prompt you like. For example, to use the "walters" prompt, you would enter:

$ prompt walters

Advanced .zshrc

This is an example of a more advanced Template:Filename:


There are many more ways that you can customise Zsh, obviously far too many to list here, see the Zsh manual for more information.

Sample .zshrc files

Here is a list of Template:Filename files. Feel free to add your own:


If you decide that Zsh is not the shell for you and you want to return to Bash, you must first change your default shell back to Bash, before removing the Zsh package.

Follow, Zsh#Making Zsh your default shell to change the default shell back to Bash, just replace zsh with bash.

Now you can safely remove the Zsh package.

Warning: Failure to follow the above will result in all kinds of problems.

If you did not follow the above, you can still change the default shell back to Bash by editing /etc/passwd as root. For example:


username:x:1000:1000:Full Name,,,:/home/username:/bin/zsh


username:x:1000:1000:Full Name,,,:/home/username:/bin/bash

External Resources

  • IRC channel: #zsh at irc.freenode.org