https://wiki.archlinux.org/api.php?action=feedcontributions&user=Samir&feedformat=atomArchWiki - User contributions [en]2024-03-28T11:36:58ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Zsh&diff=516838Zsh2018-04-11T09:16:39Z<p>Samir: /* Bind key to ncurses application */ Corrected misspelled word</p>
<hr />
<div>[[Category:Command shells]]<br />
[[cs:Zsh]]<br />
[[de:Zsh]]<br />
[[es:Zsh]]<br />
[[fa:Zsh]]<br />
[[fr:Zsh]]<br />
[[ja:Zsh]]<br />
[[ru:Zsh]]<br />
[[zh-hans:Zsh]]<br />
[http://zsh.sourceforge.net/Intro/intro_1.html 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 issuing {{ic|emulate sh}}), it offers advantages such as improved [http://zsh.sourceforge.net/Guide/zshguide06.html tab completion] and [http://zsh.sourceforge.net/Doc/Release/Expansion.html globbing].<br />
<br />
The [http://zsh.sourceforge.net/FAQ/zshfaq01.html#l4 Zsh FAQ] offers more reasons to use Zsh.<br />
<br />
== Installation ==<br />
<br />
Before starting users may want to see what shell is currently being used:<br />
<br />
$ echo $SHELL<br />
<br />
[[Install]] the {{Pkg|zsh}} package. For additional completion definitions, install the {{pkg|zsh-completions}} package as well.<br />
<br />
=== Initial configuration ===<br />
<br />
Make sure that Zsh has been installed correctly by running the following in a terminal:<br />
<br />
$ zsh<br />
<br />
You should now see ''zsh-newuser-install'', which will walk you through some basic configuration. If you want to skip this, press {{ic|q}}. If you did not see it, you can invoke it manually with<br />
<br />
$ zsh /usr/share/zsh/functions/Newuser/zsh-newuser-install -f<br />
<br />
=== Making Zsh your default shell ===<br />
<br />
See [[Command-line shell#Changing your default shell]].<br />
<br />
{{Tip|If replacing {{Pkg|bash}}, users may want to move some code from {{ic|~/.bashrc}} to {{ic|~/.zshrc}} (e.g. the prompt and the [[Bash#Aliases|aliases]]) and from {{ic|~/.bash_profile}} to {{ic|~/.zprofile}} (e.g. [[xinit#Autostart X at login|the code that starts the X Window System]]).}}<br />
<br />
== Startup/Shutdown files ==<br />
<br />
{{Tip|See [http://zsh.sourceforge.net/Guide/zshguide02.html A User's Guide to the Z-Shell] for explanation on interactive and login shells, and what to put in your startup files.}}<br />
<br />
{{Note|<br />
* If {{ic|$ZDOTDIR}} is not set, {{ic|$HOME}} is used instead.<br />
* If option {{ic|RCS}} is unset in any of the files, no configuration files will be sourced after that file.<br />
* If option {{ic|GLOBAL_RCS}} is unset in any of the files, no global configuration files ({{ic|/etc/zsh/*}}) will be sourced after that file.<br />
}}<br />
<br />
When starting Zsh, it will source the following files in this order by default:<br />
<br />
* {{ic|/etc/zsh/zshenv}} Used for setting system-wide [[environment variables]]; it should not contain commands that produce output or assume the shell is attached to a tty. This file will '''''always''''' be sourced, this cannot be overridden.<br />
* {{ic|$ZDOTDIR/.zshenv}} Used for setting user's environment variables; it should not contain commands that produce output or assume the shell is attached to a tty. This file will '''''always''''' be sourced.<br />
* {{ic|/etc/zsh/zprofile}} Used for executing commands at start, will be sourced when starting as a '''''login shell'''''. Please note that on Arch Linux, by default it contains [https://projects.archlinux.org/svntogit/packages.git/tree/trunk/zprofile?h=packages/zsh one line] which source the {{ic|/etc/profile}}.<br />
** {{ic|/etc/profile}} This file should be sourced by all Bourne-compatible shells upon login: it sets up {{ic|$PATH}} and other environment variables and application-specific ({{ic|/etc/profile.d/*.sh}}) settings upon login.<br />
* {{ic|$ZDOTDIR/.zprofile}} Used for executing user's commands at start, will be sourced when starting as a '''''login shell'''''.<br />
* {{ic|/etc/zsh/zshrc}} Used for setting interactive shell configuration and executing commands, will be sourced when starting as an '''''interactive shell'''''.<br />
* {{ic|$ZDOTDIR/.zshrc}} Used for setting user's interactive shell configuration and executing commands, will be sourced when starting as an '''''interactive shell'''''.<br />
* {{ic|/etc/zsh/zlogin}} Used for executing commands at ending of initial progress, will be sourced when starting as a '''''login shell'''''.<br />
* {{ic|$ZDOTDIR/.zlogin}} Used for executing user's commands at ending of initial progress, will be sourced when starting as a '''''login shell'''''.<br />
* {{ic|$ZDOTDIR/.zlogout}} Will be sourced when a '''''login shell''''' '''exits'''.<br />
* {{ic|/etc/zsh/zlogout}} Will be sourced when a '''''login shell''''' '''exits'''.<br />
<br />
{{Note|<br />
* The paths used in Arch's {{Pkg|zsh}} package are different from the default ones used in the [[man page]]s ({{Bug|48992}}).<br />
* {{ic|/etc/profile}} is not a part of the regular list of startup files run for Zsh, but is sourced from {{ic|/etc/zsh/zprofile}} in the {{Pkg|zsh}} package. Users should take note that {{ic|/etc/profile}} sets the {{ic|$PATH}} variable which will overwrite any {{ic|$PATH}} variable set in {{ic|$ZDOTDIR/.zshenv}}. To prevent this, please [[#Configuring $PATH|set the $PATH variable]] in {{ic|$ZDOTDIR/.zprofile}}.<br />
}}<br />
<br />
{{Warning|It is not recommended to replace the default [https://projects.archlinux.org/svntogit/packages.git/tree/trunk/zprofile?h&#61;packages/zsh one line] in {{ic|/etc/zsh/zprofile}} with something other, it will break the integrity of other packages which provide some scripts in {{ic|/etc/profile.d/}}.}}<br />
<br />
== Configure Zsh ==<br />
<br />
Although Zsh is usable out of the box, it is almost certainly not set up the way most users would like to use it, but due to the sheer amount of customization available in Zsh, configuring Zsh can be a daunting and time-consuming experience.<br />
<br />
=== Simple .zshrc ===<br />
<br />
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 customized. In order to use this configuration save it as a file named {{ic|.zshrc}}.<br />
<br />
{{Tip|Apply the changes without needing to logout and then back in by running {{ic|source ~/.zshrc}}.}}<br />
<br />
Here is a simple {{ic|.zshrc}}:<br />
<br />
{{hc|~/.zshrc|<br />
autoload -Uz compinit promptinit<br />
compinit<br />
promptinit<br />
<br />
# This will set the default prompt to the walters theme<br />
prompt walters<br />
}}<br />
<br />
=== Configuring $PATH ===<br />
<br />
{{Out of date|{{ic|/etc/profile}} does not overwrite {{ic|$PATH}} anymore, it appends Arch default path to {{ic|$PATH}}.}}<br />
<br />
Normally, the path should be set in {{ic|~/.zshenv}}, but Arch Linux sources {{ic|/etc/profile}} after sourcing {{ic|~/.zshenv}}.<br />
<br />
To prevent your {{ic|$PATH}} being overwritten, set it in {{ic|~/.zprofile}}.<br />
<br />
{{hc|~/.zprofile|2=<br />
typeset -U path<br />
path=(''~/.local/bin'' ''/other/things/in/path'' $path[@])<br />
}}<br />
<br />
See also [http://zsh.sourceforge.net/Guide/zshguide02.html#l24 A User's Guide to the Z-Shell] and the note in [[#Startup/Shutdown files]].<br />
<br />
=== Command completion ===<br />
<br />
Perhaps the most compelling feature of Zsh is its advanced autocompletion abilities. At the very least, enable autocompletion in {{ic|.zshrc}}. To enable autocompletion, add the following to your {{ic|~/.zshrc}}:<br />
<br />
{{hc|~/.zshrc|<br />
autoload -Uz compinit<br />
compinit<br />
}}<br />
<br />
The above configuration includes ssh/scp/sftp hostnames completion but in order for this feature to work, users must not enable ssh's hostname hashing (i.e. option {{ic|HashKnownHosts}} in ssh client configuration).<br />
<br />
For autocompletion with an arrow-key driven interface, add the following to:<br />
<br />
{{hc|~/.zshrc|<br />
zstyle ':completion:*' menu select<br />
}}<br />
<br />
To activate the menu, press {{ic|Tab}} twice.<br />
<br />
For autocompletion of command line switches for aliases, add the following to:<br />
<br />
{{hc|~/.zshrc|<br />
setopt COMPLETE_ALIASES<br />
}}<br />
<br />
=== Key bindings ===<br />
<br />
Zsh does not use [[readline]], instead it uses its own and more powerful Zsh Line Editor, ZLE. It does not read {{ic|/etc/inputrc}} or {{ic|~/.inputrc}}.<br />
<br />
ZLE has an [[emacs]] mode and a [[vi]] mode. If one of the {{ic|$VISUAL}} or {{ic|$EDITOR}} [[environment variables]] contain the string {{ic|vi}} then vi mode will be used; otherwise, it will default to emacs mode. Set the mode explicitly with {{ic|bindkey -e}} or {{ic|bindkey -v}} respectively for emacs mode or vi mode.<br />
<br />
See [http://zshwiki.org/home/zle/bindkeys ZshWiki: zle:bindkeys] for instructions on keybinding setup.<br />
<br />
=== History search ===<br />
<br />
You need to set up [[#Key bindings]] to use this. To enable history search add these lines to {{ic|.zshrc}} file:<br />
<br />
{{hc|~/.zshrc|<nowiki><br />
autoload -Uz up-line-or-beginning-search down-line-or-beginning-search<br />
zle -N up-line-or-beginning-search<br />
zle -N down-line-or-beginning-search<br />
<br />
[[ -n "$key[Up]" ]] && bindkey -- "$key[Up]" up-line-or-beginning-search<br />
[[ -n "$key[Down]" ]] && bindkey -- "$key[Down]" down-line-or-beginning-search<br />
</nowiki>}}<br />
<br />
By doing this, only the past commands matching the current line up to the current cursor position will be shown when {{ic|Up}} or {{ic|Down}} keys are pressed.<br />
<br />
=== Prompts ===<br />
<br />
Zsh supports:<br />
<br />
* left side prompts: {{ic|PS1}} (or {{ic|PROMPT}}), {{ic|PS2}}, {{ic|PS3}}, {{ic|PS4}}.<br />
* right side prompts: {{ic|RPS1}} (or {{ic|RPROMPT}}), {{ic|RPS2}} (or {{ic|RPROMPT2}}).<br />
<br />
See [http://zsh.sourceforge.net/Doc/Release/Parameters.html#Parameters-Used-By-The-Shell Parameters Used By The Shell] or {{man|1|zshparam}} for their explanation.<br />
<br />
==== Prompt themes ====<br />
<br />
There is a quick and easy way to set up a colored prompt in Zsh. Make sure that prompt theme system is set to autoload in {{ic|.zshrc}}. This can be done by adding these lines to:<br />
<br />
{{hc|~/.zshrc|<br />
autoload -Uz promptinit<br />
promptinit<br />
}}<br />
<br />
Available prompt themes are listed by running the command:<br />
<br />
$ prompt -l<br />
<br />
For example, to use the {{ic|walters}} theme, enter:<br />
<br />
$ prompt walters<br />
<br />
To preview all available themes, use this command:<br />
<br />
$ prompt -p<br />
<br />
==== Customized prompt ====<br />
<br />
For users who are dissatisfied with the prompt themes mentioned above (or want to expand their usefulness), Zsh offers the possibility to build a custom prompt. Zsh supports a left- and right-sided prompt additional to the single, left-sided prompt that is common to all shells. Customize it by using {{ic|1=PROMPT=}} with prompt escapes.<br />
<br />
See [http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html Prompt Expansion] for a list of prompt variables and conditional substrings, or take a look at the {{man|1|zshmisc}} manpage.<br />
<br />
===== Colors =====<br />
<br />
Zsh sets colors differently than [[Color_Bash_Prompt|Bash]]. See [http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Visual-effects Visual effects] or {{man|1|zshmisc}} for prompt escapes to set foreground color, background color and other visual effects.<br />
<br />
[http://zsh.sourceforge.net/FAQ/zshfaq03.html#l42 Colors] can be specified by numeric color code or by name (see [http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting Character Highlighting] or {{man|1|zshzle}}). Most terminals support the following colors by name:<br />
<br />
{| class="wikitable"<br />
|-<br />
! colspan="2" | Possible color values<br />
|-<br />
| {{ic|black}} or {{ic|0}} || {{ic|red}} or {{ic|1}}<br />
|-<br />
| {{ic|green}} or {{ic|2}} || {{ic|yellow}} or {{ic|3}}<br />
|-<br />
| {{ic|blue}} or {{ic|4}} || {{ic|magenta}} or {{ic|5}}<br />
|-<br />
| {{ic|cyan}} or {{ic|6}} || {{ic|white}} or {{ic|7}}<br />
|}<br />
<br />
See [https://upload.wikimedia.org/wikipedia/commons/1/15/Xterm_256color_chart.svg xterm-256color chart] for color codes supported by terminal emulators compatible with xterm 256 colors.<br />
<br />
{{Note| Bold text does not necessarily use the same colors as normal text. For example, {{ic|%F{yellow}''text''%f}} looks brown or a very dark yellow, while {{ic|%F{yellow}%B''text''%b%f}} looks like bright or regular yellow.}}<br />
<br />
{{Tip|Prompt escapes can be tested with command {{ic|print -P ''"prompt escapes"''}}, for example:<br />
<br />
$ print -P '%B%F{red}co%F{green}lo%F{blue}rs%f%b'<br />
<br />
}}<br />
<br />
===== Example =====<br />
<br />
This is an example of a two-sided prompt:<br />
<br />
PROMPT='%F{red}%n%f@%F{blue}%m%f %F{yellow}%1~%f %# '<br />
RPROMPT='[%F{yellow}%?%f]'<br />
<br />
And here is how it will be displayed:<br />
<br />
username@host ~ % [0]<br />
<br />
=== Sample .zshrc files ===<br />
<br />
* A package in offical repository named {{Pkg|grml-zsh-config}} comes from https://grml.org/zsh and provides a zshrc file that includes many tweaks for Zshell. This is the default configuration for the [https://www.archlinux.org/download/ monthly ISO releases].<br />
* https://github.com/MrElendig/dotfiles-alice/blob/master/.zshrc - basic setup, with dynamic prompt and window title/hardinfo.<br />
* https://github.com/slashbeast/conf-mgmt-like-a-sir/blob/master/roles/zsh/files/DOTzshrc - zshrc with multiple features, be sure to check out comments into it. Notable features: confirm function to ensure that user want to run poweroff, reboot or hibernate, support for GIT in prompt (done without vcsinfo), tab completion with menu, printing current executed command into window's title bar and more.<br />
<br />
See [[dotfiles#Repositories]] for more.<br />
<br />
=== Configuration Frameworks ===<br />
<br />
* {{App|Antigen|A plugin manager for zsh, inspired by oh-my-zsh and vundle.|https://github.com/zsh-users/antigen|{{AUR|antigen-git}}}}<br />
* {{App|oh-my-zsh|A popular, community-driven framework for managing your Zsh configuration. It comes bundled with a ton of helpful functions, helpers, plugins, themes.|https://github.com/robbyrussell/oh-my-zsh|{{AUR|oh-my-zsh-git}}}}<br />
<br />
:{{Note|For themes to work you may need to set {{ic|setopt NO_GLOBAL_RCS}} in the {{ic|~/.zshenv}} file, otherwise changes to some variables (such as {{ic|$PROMPT}}) may be overwritten.}}<br />
<br />
* {{App|Prezto|A configuration framework for Zsh. It comes with modules, enriching the command line interface environment with sane defaults, aliases, functions, auto completion, and prompt themes.|https://github.com/sorin-ionescu/prezto|{{AUR|prezto-git}}}}<br />
<br />
== Tips and tricks ==<br />
<br />
=== Autostart X at login ===<br />
<br />
See [[xinit#Autostart X at login]].<br />
<br />
=== The "command not found" hook ===<br />
<br />
[[pkgfile]] includes a "command not found" hook that will automatically search the official repositories, when entering an unrecognized command.<br />
<br />
You need to [[source]] the hook to enable it, for example:<br />
<br />
{{hc|~/.zshrc|<br />
source /usr/share/doc/pkgfile/command-not-found.zsh<br />
}}<br />
<br />
=== The ttyctl command ===<br />
<br />
[http://zsh.sourceforge.net/Doc/Release/Shell-Builtin-Commands.html#index-tty_002c-freezing] describes the {{ic|ttyctl}} command in Zsh.<br />
This may be used to "freeze/unfreeze" the terminal.<br />
Many programs change the terminal state, and often do not restore terminal settings on exiting abnormally.<br />
To avoid the need to manually reset the terminal, use the following:<br />
<br />
{{hc|~/.zshrc|<br />
ttyctl -f<br />
}}<br />
<br />
=== Remembering recent directories ===<br />
<br />
==== Dirstack ====<br />
<br />
Zsh can be configured to remember the DIRSTACKSIZE last visited folders. This can then be used to ''cd'' them very quickly. You need to add some lines to your configuration file:<br />
<br />
{{hc|~/.zshrc|<nowiki><br />
DIRSTACKFILE="$HOME/.cache/zsh/dirs"<br />
if [[ -f $DIRSTACKFILE ]] && [[ $#dirstack -eq 0 ]]; then<br />
dirstack=( ${(f)"$(< $DIRSTACKFILE)"} )<br />
[[ -d $dirstack[1] ]] && cd $dirstack[1]<br />
fi<br />
chpwd() {<br />
print -l $PWD ${(u)dirstack} >$DIRSTACKFILE<br />
}<br />
<br />
DIRSTACKSIZE=20<br />
<br />
setopt AUTO_PUSHD PUSHD_SILENT PUSHD_TO_HOME<br />
<br />
## Remove duplicate entries<br />
setopt PUSHD_IGNORE_DUPS<br />
<br />
## This reverts the +/- operators.<br />
setopt PUSHD_MINUS<br />
</nowiki>}}<br />
<br />
Now use<br />
<br />
$ dirs -v<br />
<br />
to print the dirstack. Use {{ic|cd -<NUM>}} to go back to a visited folder. Use autocompletion after the dash. This proves very handy if using the autocompletion menu.<br />
<br />
{{Note|This will not work if you have more than one ''zsh'' session open, and attempt to {{ic|cd}}, due to a conflict in both sessions writing to the same file.}}<br />
<br />
==== cdr ====<br />
<br />
cdr allows you to change the working directory to a previous working directory from a list maintained automatically. It stores all entries in files that are maintained across sessions and (by default) between terminal emulators in the current session.<br />
<br />
See [http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#Recent-Directories Remembering Recent Directories] or {{man|1|zshcontrib}}.<br />
<br />
=== Help command ===<br />
<br />
Zsh {{ic|help}} command is called {{ic|run-help}}. Unlike [[bash]], ''zsh'' does not enable it by default. To use {{ic|help}} in zsh, add following to your {{ic|zshrc}}:<br />
<br />
{{bc|1=<br />
autoload -Uz run-help<br />
unalias run-help<br />
alias help=run-help<br />
}}<br />
<br />
{{ic|run-help}} will invoke ''man'' for external commands. Default keyboard shortcut is {{ic|Alt+h}} or {{ic|Esc+h}}.<br />
<br />
{{ic|run-help}} has helper functions, they need to be enabled separately:<br />
<br />
{{bc|1=<br />
autoload -Uz run-help-git<br />
autoload -Uz run-help-ip<br />
autoload -Uz run-help-openssl<br />
autoload -Uz run-help-p4<br />
autoload -Uz run-help-sudo<br />
autoload -Uz run-help-svk<br />
autoload -Uz run-help-svn<br />
}}<br />
<br />
For example {{ic|run-help git commit}} command will now open the [[man page]] {{man|1|git-commit}} instead of {{man|1|git}}.<br />
<br />
=== Fish-like syntax highlighting ===<br />
<br />
[[Fish]] provides a very powerful shell syntax highlighting. To use this in zsh, you can install {{pkg|zsh-syntax-highlighting}} from offical repository and add following to your zshrc:<br />
<br />
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh<br />
<br />
=== Persistent rehash ===<br />
<br />
Typically, compinit will not automatically find new executables in the {{ic|$PATH}}. For example, after you install a new package, the files in {{ic|/usr/bin/}} would not be immediately or automatically included in the completion. Thus, to have these new executables included, one would run:<br />
<br />
$ rehash<br />
<br />
This 'rehash' can be set to happen automatically.[https://github.com/robbyrussell/oh-my-zsh/issues/3440] Simply include the following in your {{ic|zshrc}}:<br />
<br />
{{hc|~/.zshrc|<br />
zstyle ':completion:*' rehash true<br />
}}<br />
<br />
=== Bind key to ncurses application ===<br />
<br />
Bind a ncurses application to a keystroke, but it will not accept interaction. Use {{ic|BUFFER}} variable to make it work. The following example lets users open ncmpcpp using {{ic|Alt+\}}:<br />
<br />
{{hc|~/.zshrc|2=<br />
ncmpcppShow() { BUFFER="ncmpcpp"; zle accept-line; }<br />
zle -N ncmpcppShow<br />
bindkey '^[\' ncmpcppShow<br />
}}<br />
<br />
An alternate method, that will keep everything you entered in the line before calling application:<br />
<br />
{{hc|~/.zshrc|2=<br />
ncmpcppShow() { ncmpcpp <$TTY; zle redisplay; }<br />
zle -N ncmpcppShow<br />
bindkey '^[\' ncmpcppShow<br />
}}<br />
<br />
=== File manager key binds ===<br />
<br />
Key binds like those used in graphic file managers may come handy. The first comes back in directory history ({{ic|Alt+Left}}), the second let the user go to the parent directory ({{ic|Alt+Up}}). They also display the directory content.<br />
<br />
{{hc|~/.zshrc|<nowiki><br />
cdUndoKey() {<br />
popd<br />
zle reset-prompt<br />
echo<br />
ls<br />
zle reset-prompt<br />
}<br />
<br />
cdParentKey() {<br />
pushd ..<br />
zle reset-prompt<br />
echo<br />
ls<br />
zle reset-prompt<br />
}<br />
<br />
zle -N cdParentKey<br />
zle -N cdUndoKey<br />
bindkey '^[[1;3A' cdParentKey<br />
bindkey '^[[1;3D' cdUndoKey<br />
</nowiki>}}<br />
<br />
=== xterm title ===<br />
<br />
If your terminal emulator supports it you can set its title from Zsh. This allows dynamically changing the the title to display relevant information about the shell state, for example showing the user name and current directory or the currently executing command.<br />
<br />
xterm title is set with [http://tldp.org/HOWTO/Xterm-Title-3.html#ss3.1 xterm escape sequences]. For example:<br />
<br />
$ print -n '\e]2;My xterm title\a'<br />
<br />
will set the title to<br />
<br />
My xterm title<br />
<br />
An simple way to have a dynamic title is to set the title in a hook functions {{ic|precmd}} and {{ic|preexec}}. See [http://zsh.sourceforge.net/Doc/Release/Functions.html#Hook-Functions Hook Functions] or {{man|1|zshmisc}}.<br />
<br />
By using {{ic|print -P}} you can take advantage of prompt escapes.<br />
<br />
{{Tip|Title printing can be split up in multiple commands as long as they are sequential.}}<br />
<br />
{{Note|<br />
* Do not use {{ic|-P}} option of {{ic|print}} when printing variables to prevent them from being parsed as prompt escapes.<br />
* Use {{ic|q}} [http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion-Flags parameter expansion flag] when printing variables to prevent them from being parsed as escape sequences.<br />
}}<br />
<br />
{{hc|~/.zshrc|<nowiki><br />
autoload -Uz add-zsh-hook<br />
<br />
function xterm_title_precmd () {<br />
print -Pn '\e]2;%n@%m %1~\a'<br />
}<br />
<br />
function xterm_title_preexec () {<br />
print -Pn '\e]2;%n@%m %1~ %# '<br />
print -n "${(q)1}\a"<br />
}<br />
<br />
if [[ "$TERM" == (screen*|xterm*|rxvt*) ]]; then<br />
add-zsh-hook -Uz precmd xterm_title_precmd<br />
add-zsh-hook -Uz preexec xterm_title_preexec<br />
fi<br />
</nowiki>}}<br />
<br />
== Uninstallation ==<br />
<br />
Change the default shell before removing the {{Pkg|zsh}} package.<br />
<br />
{{Warning|Failure to follow the below procedure may result in users no longer having access to a working shell.}}<br />
<br />
Run following command:<br />
<br />
$ chsh -s /bin/bash ''user''<br />
<br />
Use it for every user with ''zsh'' set as their login shell (including root if needed). When completed, the {{Pkg|zsh}} package can be removed.<br />
<br />
Alternatively, change the default shell back to Bash by editing {{ic|/etc/passwd}} as root.<br />
<br />
{{Warning|It is strongly recommended to use {{ic|vipw}} when editing {{ic|/etc/passwd}} as it helps prevent invalid entries and/or syntax errors.}}<br />
<br />
For example, change the following:<br />
<br />
''username'':x:1000:1000:''Full Name'',,,:/home/''username'':/bin/zsh<br />
<br />
To this:<br />
<br />
''username'':x:1000:1000:''Full Name'',,,:/home/''username'':/bin/bash<br />
<br />
== See also ==<br />
<br />
* [http://zsh.sourceforge.net/Guide/zshguide.html A User's Guide to ZSH]<br />
* [http://zsh.sourceforge.net/Doc/Release/index-frame.html The Z Shell Manual] (different format available [http://zsh.sourceforge.net/Doc/ here])<br />
* [http://zsh.sourceforge.net/FAQ/zshfaq01.html Zsh FAQ]<br />
* [http://zshwiki.org/home/ Zsh Wiki]<br />
* {{man|1|zsh-lovers}} (available as {{pkg|zsh-lovers}} package)<br />
* [[Gentoo: Zsh/Guide]]<br />
* [http://www.bash2zsh.com/zsh_refcard/refcard.pdf Bash2Zsh Reference Card]</div>Samir