# zshcontrib.1   [plain text]

.TH "ZSHCONTRIB" "1" "December 20, 2010" "zsh 4\&.3\&.11"
.SH "NAME"
zshcontrib \- user contributions to zsh
.\" Yodl file: Zsh/contrib.yo
.SH "DESCRIPTION"
.PP
The Zsh source distribution includes a number of items contributed by the
user community\&.  These are not inherently a part of the shell, and some
may not be available in every zsh installation\&.  The most significant of
these are documented here\&.  For documentation on other contributed items
such as shell functions, look for comments in the function source files\&.
.PP
.PP
.SH "UTILITIES"
.PP
.SS "Accessing On\-Line Help"
.PP
The key sequence \fBESC h\fP is normally bound by ZLE to execute the
\fBrun\-help\fP widget (see
\fIzshzle\fP(1))\&.  This invokes the \fBrun\-help\fP command with the command word from the
current input line as its argument\&.  By default, \fBrun\-help\fP is an alias
for the \fBman\fP command, so this often fails when the command word is a
shell builtin or a user\-defined function\&.  By redefining the \fBrun\-help\fP
alias, one can improve the on\-line help provided by the shell\&.
.PP
The \fBhelpfiles\fP utility, found in the \fBUtil\fP directory of the
distribution, is a Perl program that can be used to process the zsh manual
to produce a separate help file for each shell builtin and for many other
shell features as well\&.  The autoloadable \fBrun\-help\fP function, found in
\fBFunctions/Misc\fP, searches for these helpfiles and performs several
other tests to produce the most complete help possible for the command\&.
.PP
There may already be a directory of help files on your system; look in
\fB/usr/share/zsh\fP or \fB/usr/local/share/zsh\fP and subdirectories below
those, or ask your system administrator\&.
.PP
To create your own help files with \fBhelpfiles\fP, choose or create a
directory where the individual command help files will reside\&.  For
example, you might choose \fB~/zsh_help\fP\&.  If you unpacked the zsh
distribution in your home directory, you would use the commands:
.PP
.RS
.nf
\fBmkdir ~/zsh_help
cd ~/zsh_help
man zshall | colcrt \- | \e
perl ~/zsh\-4\&.3\&.11/Util/helpfiles\fP
.fi
.RE
.PP
Next, to use the \fBrun\-help\fP function, you need to add lines something
like the following to your \fB\&.zshrc\fP or equivalent startup file:
.PP
.RS
.nf
\fBunalias run\-help
autoload run\-help
HELPDIR=~/zsh_help\fP
.fi
.RE
.PP
The \fBHELPDIR\fP parameter tells \fBrun\-help\fP where to look for the help
files\&.  If your system already has a help file directory installed, set
\fBHELPDIR\fP to the path of that directory instead\&.
.PP
Note that in order for \fBautoload run\-help\fP\&' to work, the \fBrun\-help\fP
file must be in one of the directories named in your \fBfpath\fP array (see
\fIzshparam\fP(1))\&.  This should already be the case if you have a standard zsh
installation; if it is not, copy \fBFunctions/Misc/run\-help\fP to an
appropriate directory\&.
.PP
.SS "Recompiling Functions"
.PP
If you frequently edit your zsh functions, or periodically update your zsh
installation to track the latest developments, you may find that function
digests compiled with the \fBzcompile\fP builtin are frequently out of date
with respect to the function source files\&.  This is not usually a problem,
because zsh always looks for the newest file when loading a function, but
it may cause slower shell startup and function loading\&.  Also, if a digest
file is explicitly used as an element of \fBfpath\fP, zsh won\&'t check whether
any of its source files has changed\&.
.PP
The \fBzrecompile\fP autoloadable function, found in \fBFunctions/Misc\fP, can
be used to keep function digests up to date\&.
.PP
.PD 0
.TP
.PD 0
\fBzrecompile\fP [ \fB\-qt\fP ] [ \fIname\fP \&.\&.\&. ]
.TP
.PD
\fBzrecompile\fP [ \fB\-qt\fP ] \fB\-p\fP \fIargs\fP [ \fB\-\fP\fB\-\fP \fIargs\fP \&.\&.\&. ]
This tries to find \fB*\&.zwc\fP files and automatically re\-compile them if at
least one of the original files is newer than the compiled file\&.  This
works only if the names stored in the compiled files are full paths or are
relative to the directory that contains the \fB\&.zwc\fP file\&.
.RS
.PP
In the first form, each \fIname\fP is the name of a compiled file or a
directory containing \fB*\&.zwc\fP files that should be checked\&.  If no
arguments are given, the directories and \fB*\&.zwc\fP files in \fBfpath\fP are
used\&.
.PP
When \fB\-t\fP is given, no compilation is performed, but a return status of
zero (true) is set if there are files that need to be re\-compiled and
non\-zero (false) otherwise\&.  The \fB\-q\fP option quiets the chatty output
that describes what \fBzrecompile\fP is doing\&.
.PP
Without the \fB\-t\fP option, the return status is zero if all files that
needed re\-compilation could be compiled and non\-zero if compilation for at
least one of the files failed\&.
.PP
If the \fB\-p\fP option is given, the \fIargs\fP are interpreted as one
or more sets of arguments for \fBzcompile\fP, separated by \fB\-\fP\fB\-\fP\&'\&.
For example:
.PP
.RS
.nf
\fBzrecompile \-p \e
\-R ~/\&.zshrc \-\- \e
\-M ~/\&.zcompdump \-\- \e
~/zsh/comp\&.zwc ~/zsh/Completion/*/_*\fP
.fi
.RE
.PP
This compiles \fB~/\&.zshrc\fP into \fB~/\&.zshrc\&.zwc\fP if that doesn\&'t exist or
if it is older than \fB~/\&.zshrc\fP\&. The compiled file will be marked for
reading instead of mapping\&. The same is done for \fB~/\&.zcompdump\fP and
\fB~/\&.zcompdump\&.zwc\fP, but this compiled file is marked for mapping\&. The
last line re\-creates the file \fB~/zsh/comp\&.zwc\fP if any of the files
matching the given pattern is newer than it\&.
.PP
Without the \fB\-p\fP option, \fBzrecompile\fP does not create function digests
that do not already exist, nor does it add new functions to the digest\&.
.RE
.RE
.PP
The following shell loop is an example of a method for creating function
digests for all functions in your \fBfpath\fP, assuming that you have write
permission to the directories:
.PP
.RS
.nf
\fBfor ((i=1; i <= $#fpath; ++i)); do dir=$fpath[i]
zwc=${dir:t}\&.zwc if [[$dir == (\&.|\&.\&.) || $dir == (\&.|\&.\&.)/* ]]; then continue fi files=($dir/*(N\-\&.))
if [[ \-w $dir:h && \-n$files ]]; then
files=(${${(M)files%/*/*}#/})
if ( cd $dir:h && zrecompile \-p \-U \-z$zwc $files ); then fpath[i]=$fpath[i]\&.zwc
fi
fi
done\fP
.fi
.RE
.PP
The \fB\-U\fP and \fB\-z\fP options are appropriate for functions in the default
zsh installation \fBfpath\fP; you may need to use different options for your
personal function directories\&.
.PP
Once the digests have been created and your \fBfpath\fP modified to refer to
them, you can keep them up to date by running \fBzrecompile\fP with no
arguments\&.
.PP
.SS "Keyboard Definition"
.PP
The large number of possible combinations of keyboards, workstations,
terminals, emulators, and window systems makes it impossible for zsh to
have built\-in key bindings for every situation\&.  The \fBzkbd\fP utility,
found in Functions/Misc, can help you quickly create key bindings for your
configuration\&.
.PP
Run \fBzkbd\fP either as an autoloaded function, or as a shell script:
.PP
.RS
.nf
\fBzsh \-f ~/zsh\-4\&.3\&.11/Functions/Misc/zkbd\fP
.fi
.RE
.PP
When you run \fBzkbd\fP, it first asks you to enter your terminal type; if
the default it offers is correct, just press return\&.  It then asks you to
press a number of different keys to determine characteristics of your
keyboard and terminal; \fBzkbd\fP warns you if it finds anything out of the
ordinary, such as a Delete key that sends neither \fB^H\fP nor \fB^?\fP\&.
.PP
The keystrokes read by \fBzkbd\fP are recorded as a definition for an
associative array named \fBkey\fP, written to a file in the subdirectory
\fB\&.zkbd\fP within either your \fBHOME\fP or \fBZDOTDIR\fP directory\&.  The name
of the file is composed from the \fBTERM\fP, \fBVENDOR\fP and \fBOSTYPE\fP
parameters, joined by hyphens\&.
.PP
You may read this file into your \fB\&.zshrc\fP or another startup file with
the \fBsource\fP\&' or \fB\&.\fP' commands, then reference the \fBkey\fP parameter
in bindkey commands, like this:
.PP
.RS
.nf
\fBsource ${ZDOTDIR:\-$HOME}/\&.zkbd/$TERM\-$VENDOR\-$OSTYPE [[ \-n${key[Left]} ]] && bindkey "${key[Left]}" backward\-char [[ \-n${key[Right]} ]] && bindkey "${key[Right]}" forward\-char # etc\&.\fP .fi .RE .PP Note that in order for \fBautoload zkbd\fP\&' to work, the \fBzkdb\fP file must be in one of the directories named in your \fBfpath\fP array (see \fIzshparam\fP(1))\&. This should already be the case if you have a standard zsh installation; if it is not, copy \fBFunctions/Misc/zkbd\fP to an appropriate directory\&. .PP .SS "Dumping Shell State" .PP Occasionally you may encounter what appears to be a bug in the shell, particularly if you are using a beta version of zsh or a development release\&. Usually it is sufficient to send a description of the problem to one of the zsh mailing lists (see \fIzsh\fP(1)), but sometimes one of the zsh developers will need to recreate your environment in order to track the problem down\&. .PP The script named \fBreporter\fP, found in the \fBUtil\fP directory of the distribution, is provided for this purpose\&. (It is also possible to \fBautoload reporter\fP, but \fBreporter\fP is not installed in \fBfpath\fP by default\&.) This script outputs a detailed dump of the shell state, in the form of another script that can be read with \fBzsh \-f\fP\&' to recreate that state\&. .PP To use \fBreporter\fP, read the script into your shell with the \fB\&.\fP\&' command and redirect the output into a file: .PP .RS .nf \fB\&. ~/zsh\-4\&.3\&.11/Util/reporter > zsh\&.report\fP .fi .RE .PP You should check the \fBzsh\&.report\fP file for any sensitive information such as passwords and delete them by hand before sending the script to the developers\&. Also, as the output can be voluminous, it\&'s best to wait for the developers to ask for this information before sending it\&. .PP You can also use \fBreporter\fP to dump only a subset of the shell state\&. This is sometimes useful for creating startup files for the first time\&. Most of the output from reporter is far more detailed than usually is necessary for a startup file, but the \fBaliases\fP, \fBoptions\fP, and \fBzstyles\fP states may be useful because they include only changes from the defaults\&. The \fBbindings\fP state may be useful if you have created any of your own keymaps, because \fBreporter\fP arranges to dump the keymap creation commands as well as the bindings for every keymap\&. .PP As is usual with automated tools, if you create a startup file with \fBreporter\fP, you should edit the results to remove unnecessary commands\&. Note that if you\&'re using the new completion system, you should \fInot\fP dump the \fBfunctions\fP state to your startup files with \fBreporter\fP; use the \fBcompdump\fP function instead (see \fIzshcompsys\fP(1))\&. .PP .PD 0 .TP .PD \fBreporter\fP [ \fIstate\fP \&.\&.\&. ] Print to standard output the indicated subset of the current shell state\&. The \fIstate\fP arguments may be one or more of: .RS .PP .PD 0 .TP \fBall\fP Output everything listed below\&. .TP \fBaliases\fP Output alias definitions\&. .TP \fBbindings\fP Output ZLE key maps and bindings\&. .TP \fBcompletion\fP Output old\-style \fBcompctl\fP commands\&. New completion is covered by \fBfunctions\fP and \fBzstyles\fP\&. .TP \fBfunctions\fP Output autoloads and function definitions\&. .TP \fBlimits\fP Output \fBlimit\fP commands\&. .TP \fBoptions\fP Output \fBsetopt\fP commands\&. .TP \fBstyles\fP Same as \fBzstyles\fP\&. .TP \fBvariables\fP Output shell parameter assignments, plus \fBexport\fP commands for any environment variables\&. .TP \fBzstyles\fP Output \fBzstyle\fP commands\&. .PD .PP If the \fIstate\fP is omitted, \fBall\fP is assumed\&. .RE .PP With the exception of \fBall\fP\&', every \fIstate\fP can be abbreviated by any prefix, even a single letter; thus \fBa\fP is the same as \fBaliases\fP, \fBz\fP is the same as \fBzstyles\fP, etc\&. .RE .PP .SS "Manipulating Hook Functions" .PP .PD 0 .TP .PD \fBadd\-zsh\-hook\fP [\-dD] \fIhook\fP \fIfunction\fP Several functions are special to the shell, as described in the section SPECIAL FUNCTIONS, see \fIzshmisc\fP(1), in that they are automatic called at a specific point during shell execution\&. Each has an associated array consisting of names of functions to be called at the same point; these are so\-called hook functions\&'\&. The shell function \fBadd\-zsh\-hook\fP provides a simple way of adding or removing functions from the array\&. .RS .PP \fIhook\fP is one of \fBchpwd\fP, \fBperiodic\fP, \fBprecmd\fP or \fBpreexec\fP, the special functions in question\&. .PP \fIfunctions\fP is name of an ordinary shell function\&. If no options are given this will be added to the array of functions to be executed in the given context\&. .PP If the option \fB\-d\fP is given, the \fIfunction\fP is removed from the array of functions to be executed\&. .PP If the option \fB\-D\fP is given, the \fIfunction\fP is treated as a pattern and any matching names of functions are removed from the array of functions to be executed\&. .RE .RE .PP .SH "REMEMBERING RECENT DIRECTORIES" .PP The function \fBcdr\fP allows you to change the working directory to a previous working directory from a list maintained automatically\&. It is similar in concept to the directory stack controlled by the \fBpushd\fP, \fBpopd\fP and \fBdirs\fP builtins, but is more configurable, and as it stores all entries in files it is maintained across sessions and (by default) between terminal emulators in the current session\&. (The \fBpushd\fP directory stack is not actually modified or used by \fBcdr\fP unless you configure it to do so as described in the configuration section below\&.) .PP .SS "Installation" .PP The system works by means of a hook function that is called every time the directory changes\&. To install the system, autoload the required functions and use the \fBadd\-zsh\-hook\fP function described above: .PP .RS .nf \fBautoload \-Uz chpwd_recent_dirs cdr add\-zsh\-hook add\-zsh\-hook chpwd chpwd_recent_dirs\fP .fi .RE .PP Now every time you change directly interactively, no matter which command you use, the directory to which you change will be remembered in most\-recent\-first order\&. .PP .SS "Use" .PP All direct user interaction is via the \fBcdr\fP function\&. .PP The argument to cdr is a number \fIN\fP corresponding to the \fIN\fPth most recently changed\-to directory\&. 1 is the immediately preceeding directory; the current directory is remembered but is not offered as a destination\&. Note that if you have multiple windows open 1 may refer to a directory changed to in another window; you can avoid this by having per\-terminal files for storing directory as described for the \fBrecent\-dirs\-file\fP style below\&. .PP If you set the \fBrecent\-dirs\-default\fP style described below \fBcdr\fP will behave the same as \fBcd\fP if given a non\-numeric argument, or more than one argument\&. The recent directory list is updated just the same however you change directory\&. .PP If the argument is omitted, 1 is assumed\&. This is similar to \fBpushd\fP\&'s behaviour of swapping the two most recent directories on the stack\&. .PP Completion for the argument to \fBcdr\fP is available if compinit has been run; menu selection is recommended, using: .PP .RS .nf \fBzstyle \&':completion:*:*:cdr:*:*' menu selection\fP .fi .RE .PP to allow you to cycle through recent directories; the order is preserved, so the first choice is the most recent directory before the current one\&. The verbose style is also recommended to ensure the directory is shown; this style is on by default so no action is required unless you have changed it\&. .PP .SS "Options" .PP The behaviour of \fBcdr\fP may be modified by the following options\&. .PP .PD 0 .TP .PD \fB\-l\fP lists the numbers and the corresponding directories in abbreviated form (i\&.e\&. with \fB~\fP substitution reapplied), one per line\&. The directories here are not quoted (this would only be an issue if a directory name contained a newline)\&. This is used by the completion system\&. .TP \fB\-r\fP sets the variable \fBreply\fP to the current set of directories\&. Nothing is printed and the directory is not changed\&. .TP \fB\-e\fP allows you to edit the list of directories, one per line\&. The list can be edited to any extent you like; no sanity checking is performed\&. Completion is available\&. No quoting is necessary (except for newlines, where I have in any case no sympathy); directories are in unabbreviated from and contain an absolute path, i\&.e\&. they start with \fB/\fP\&. Usually the first entry should be left as the current directory\&. .PP .SS "Configuration" .PP Configuration is by means of the styles mechanism that should be familiar from completion; if not, see the description of the \fBzstyle\fP command in see \fIzshmodules\fP(1)\&. The context for setting styles should be \fB\&':chpwd:*'\fP in case the meaning of the context is extended in future, for example: .PP .RS .nf \fBzstyle \&':chpwd:*' recent\-dirs\-max 0\fP .fi .RE .PP sets the value of the \fBrecent\-dirs\-max\fP style to 0\&. In practice the style name is specific enough that a context of \&'*' should be fine\&. .PP An exception is \fBrecent\-dirs\-insert\fP, which is used exclusively by the completion system and so has the usual completion system context (\fB\&':completion:*'\fP if nothing more specific is needed), though again \fB\&'*'\fP should be fine in practice\&. .PP .PD 0 .TP .PD \fBrecent\-dirs\-default\fP If true, and the command is expecting a recent directory index, and either there is more than one argument or the argument is not an integer, then fall through to "cd"\&. This allows the lazy to use only one command for directory changing\&. Completion recognises this, too; see recent\-dirs\-insert for how to control completion when this option is in use\&. .TP \fBrecent\-dirs\-file\fP The file where the list of directories is saved\&. The default is \fB${ZDOTDIR:\-$HOME}/\&.chpwd\-recent\-dirs\fP, i\&.e\&. this is in your home directory unless you have set the variable \fBZDOTDIR\fP to point somewhere else\&. Directory names are saved in \fB$\&'\fP\fI\&.\&.\&.\fP\fB'\fP quoted
form, so each line in the file can be supplied directly to the shell as an
argument\&.
.RS
.PP
The value of this style may be an array\&.  In this case, the first
file in the list will always be used for saving directories while any
other files are left untouched\&.  When reading the recent directory
list, if there are fewer than the maximum number of entries in the
first file, the contents of later files in the array will be appended
with duplicates removed from the list shown\&.  The contents of the two
files are not sorted together, i\&.e\&. all the entries in the first file
are shown first\&.  The special value \fB+\fP can appear in the list to
indicate the default file should be read at that point\&.  This allows
effects like the following:
.PP
.RS
.nf
\fBzstyle \&':chpwd:*' recent\-dirs\-file \e
~/\&.chpwd\-recent\-dirs\-${TTY##*/} +\fP .fi .RE .PP Recent directories are read from a file numbered according to the terminal\&. If there are insufficient entries the list is supplemented from the default file\&. .PP It is possible to use \fBzstyle \-e\fP to make the directory configurable at run time: .PP .RS .nf \fBzstyle \-e \&':chpwd:*' recent\-dirs\-file pick\-recent\-dirs\-file pick\-recent\-dirs\-file() { if [[$PWD = ~/text/writing(|/*) ]]; then
reply=(~/\&.chpwd\-recent\-dirs\-writing)
else
reply=(+)
fi
}\fP
.fi
.RE
.PP
In this example, if the current directory is \fB~/text/writing\fP or a
directory under it, then use a special file for saving recent
directories, else use the default\&.
.RE
.TP
\fBrecent\-dirs\-insert\fP
Used by completion\&.  If \fBrecent\-dirs\-default\fP is true, then setting
this to \fBtrue\fP causes the actual directory, rather than its index, to
be inserted on the command line; this has the same effect as using
the corresponding index, but makes the history clearer and the line
easier to edit\&.  With this setting, if part of an argument was
already typed, normal directory completion rather than recent
directory completion is done; this is because recent directory
completion is expected to be done by cycling through entries menu
fashion\&.
.RS
.PP
If the value of the style is \fBalways\fP, then only recent directories will
be completed; in that case, use the \fBcd\fP command when you want to
complete other directories\&.
.PP
If the value is \fBfallback\fP, recent directories will be tried first, then
normal directory completion is performed if recent directory completion
failed to find a match\&.
.PP
Finally, if the value is \fBboth\fP then both sets of completions are
presented; the usual tag mechanism can be used to distinguish results, with
recent directories tagged as \fBrecent\-dirs\fP\&.  Note that the recent
directories inserted are abbreviated with directory names where appropriate\&.
.RE
.TP
\fBrecent\-dirs\-max\fP
The maximum number of directories to save to the file\&.  If
this is zero or negative there is no maximum\&.  The default is 20\&.
Note this includes the current directory, which isn\&'t offered,
so the highest number of directories you will be offered
is one less than the maximum\&.
.TP
\fBrecent\-dirs\-prune\fP
This style is an array determining what directories should (or should
not) be added to the recent list\&.  Elements of the array can include:
.RS
.PP
.PD 0
.TP
.PD
\fBparent\fP
Prune parents (more accurately, ancestors) from the recent list\&.
If present, changing directly down by any number of directories
causes the current directory to be overwritten\&.  For example,
changing from ~pws to ~pws/some/other/dir causes ~pws not to be
left on the recent directory stack\&.  This only applies to direct
changes to descendant directories; earlier directories on the
list are not pruned\&.  For example, changing from ~pws/yet/another
to ~pws/some/other/dir does not cause ~pws to be pruned\&.
.TP
\fBpattern:\fIpattern\fP\fP
Gives a zsh pattern for directories that should not be
added to the recent list (if not already there)\&.  This element
can be repeated to add different patterns\&.  For example,
\fB\&'pattern:/tmp(|/*)'\fP stops \fB/tmp\fP or its descendants
from being added\&.  The \fBEXTENDED_GLOB\fP option is always turned on
for these patterns\&.
.RE
.TP
\fBrecent\-dirs\-pushd\fP
If set to true, \fBcdr\fP will use \fBpushd\fP instead of \fBcd\fP to change the
directory, so the directory is saved on the directory stack\&.  As the
directory stack is completely separate from the list of files saved
by the mechanism used in this file there is no obvious reason to do
this\&.
.PP
.SS "Use with dynamic directory naming"
.PP
It is possible to refer to recent directories using the dynamic directory
name syntax that appeared in zsh version 4\&.3\&.7\&.  If you create and
autoload a function \fBzsh_directory_name\fP containing the following code,
\fB~[1]\fP will refer to the most recent directory other than $PWD, and so on\&. This also includes completion\&. .PP .RS .nf \fBif [[$1 = n ]]; then
if [[ $2 = <\-> ]]; then # Recent directory typeset \-ga reply autoload \-Uz cdr cdr \-r if [[ \-n${reply[$2]} ]]; then reply=(${reply[$2]}) return 0 else reply=() return 1 fi fi elif [[$1 = c ]]; then
if [[ $PREFIX = <\-> || \-z$PREFIX ]]; then
typeset \-a keys values
values=(${${(f)"$(cdr \-l)"}/ ##/:}) keys=(${values%%:*})
_describe \-t dir\-index \&'recent directory index' values keys \-V unsorted \-S']'
return
fi
fi
return 1\fP
.fi
.RE
.PP
.SS "Details of directory handling"
.PP
This section is for the curious or confused; most users will not
need to know this information\&.
.PP
Recent directories are saved to a file immediately and hence are
preserved across sessions\&.  Note currently no file locking is applied:
the list is updated immediately on interactive commands and nowhere else
(unlike history), and it is assumed you are only going to change
directory in one window at once\&.  This is not safe on shared accounts,
but in any case the system has limited utility when someone else is
changing to a different set of directories behind your back\&.
.PP
To make this a little safer, only directory changes instituted from the
command line, either directly or indirectly through shell function calls
(but not through subshells, evals, traps, completion functions and the
like) are saved\&.  Shell functions should use \fBcd \-q\fP or \fBpushd \-q\fP to
avoid side effects if the change to the directory is to be invisible at the
command line\&.  See the contents of the function \fBchpwd_recent_dirs\fP for
more details\&.
.PP
.SH "GATHERING INFORMATION FROM VERSION CONTROL SYSTEMS"
.PP
In a lot of cases, it is nice to automatically retrieve information from
version control systems (VCSs), such as subversion, CVS or git, to be able
to provide it to the user; possibly in the user\&'s prompt\&. So that you can
instantly tell which branch you are currently on, for example\&.
.PP
In order to do that, you may use the \fBvcs_info\fP function\&.
.PP
The following VCSs are supported, showing the abbreviated name by which
they are referred to within the system:
.PD 0
.TP
Bazaar (\fBbzr\fP)
http://bazaar\-vcs\&.org/
.TP
Codeville (\fBcdv\fP)
http://codeville\&.org/
.TP
Concurrent Versioning System (\fBcvs\fP)
http://www\&.nongnu\&.org/cvs/
.TP
Darcs (\fBdarcs\fP)
http://darcs\&.net/
.TP
Git (\fBgit\fP)
http://git\-scm\&.com/
.TP
GNU arch (\fBtla\fP)
http://www\&.gnu\&.org/software/gnu\-arch/
.TP
Mercurial (\fBhg\fP)
http://mercurial\&.selenic\&.com/
.TP
Monotone (\fBmtn\fP)
http://monotone\&.ca/
.TP
Perforce (\fBp4\fP)
http://www\&.perforce\&.com/
.TP
Subversion (\fBsvn\fP)
http://subversion\&.tigris\&.org/
.TP
SVK (\fBsvk\fP)
http://svk\&.bestpractical\&.com/
.PD
.PP
There is also support for the patch management system \fBquilt\fP
(http://savannah\&.nongnu\&.org/projects/quilt)\&. See \fBQuilt Support\fP
below for details\&.
.PP
To load \fIvcs_info\fP:
.PP
.RS
.nf
\fBautoload \-Uz vcs_info\fP
.fi
.RE
.PP
It can be used in any existing prompt, because it does not require any
\fB$psvar\fP entries to be left available\&. .PP .SS "Quickstart" .PP To get this feature working quickly (including colors), you can do the following (assuming, you loaded \fIvcs_info\fP properly \- see above): .PP .RS .nf \fBzstyle \&':vcs_info:*' actionformats '%F{5}(%f%s%F{5})%F{3}\-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f ' zstyle \&':vcs_info:*' formats '%F{5}(%f%s%F{5})%F{3}\-%F{5}[%F{2}%b%F{5}]%f ' zstyle \&':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r' precmd () { vcs_info } PS1=\&'%F{5}[%F{2}%n%F{5}] %F{3}%3~${vcs_info_msg_0_}%f%# '\fP
.fi
.RE
.PP
Obviously, the last two lines are there for demonstration\&. You need to
call \fIvcs_info\fP from your \fIprecmd\fP function\&. Once that is done you need
a \fBsingle quoted\fP \fI\&'${vcs_info_msg_0_}'\fP in your prompt\&. .PP To be able to use \fI\&'${vcs_info_msg_0_}'\fP directly in your prompt like
this, you will need to have the \fBPROMPT_SUBST\fP option enabled\&.
.PP
Now call the \fBvcs_info_printsys\fP utility from the command line:
.PP
.RS
.nf
\fB% vcs_info_printsys
## list of supported version control backends:
## disabled systems are prefixed by a hash sign (#)
bzr
cdv
cvs
darcs
git
hg
mtn
p4
svk
svn
tla
## flavours (cannot be used in the enable or disable styles; they
## are enabled and disabled with their master [git\-svn \-> git])
## they *can* be used in contexts: \&':vcs_info:git\-svn:*'\&.
git\-p4
git\-svn
hg\-git
hg\-hgsubversion
hg\-hgsvn\fP
.fi
.RE
.PP
You may not want all of these because there is no point in running the
code to detect systems you do not use\&.  So there is a way to disable
some backends altogether:
.PP
.RS
.nf
\fBzstyle \&':vcs_info:*' disable bzr cdv darcs mtn svk tla\fP
.fi
.RE
.PP
You may also pick a few from that list and enable only those:
.PP
.RS
.nf
\fBzstyle \&':vcs_info:*' enable git cvs svn\fP
.fi
.RE
.PP
If you rerun \fBvcs_info_printsys\fP after one of these commands, you will
see the backends listed in the \fIdisable\fP style (or backends not in the
\fIenable\fP style \- if you used that) marked as disabled by a hash sign\&.
That means the detection of these systems is skipped \fBcompletely\fP\&. No
wasted time there\&.
.PP
.SS "Configuration"
.PP
The \fIvcs_info\fP feature can be configured via \fIzstyle\fP\&.
.PP
First, the context in which we are working:
.RS
.nf
\fB:vcs_info:<vcs\-string>:<user\-context>:<repo\-root\-name>\fP
.fi
.RE
.PP
.PD 0
.TP
.PD
\fB<vcs\-string>\fP
is one of: git, git\-svn, git\-p4, hg, hg\-git, hg\-hgsubversion, hg\-hgsvn,
darcs, bzr, cdv, mtn, svn, cvs, svk, tla or p4\&. When hooks are active the
hooks name is added after a +\&'\&. (See \fBHooks in vcs_info\fP below\&.)
.TP
\fB<user\-context>\fP
is a freely configurable string, assignable by
the user as the first argument to \fIvcs_info\fP (see its description
below)\&.
.TP
\fB<repo\-root\-name>\fP
is the name of a repository in which you want a
style to match\&. So, if you want a setting specific to \fI/usr/src/zsh\fP,
with that being a CVS checkout, you can set \fB<repo\-root\-name>\fP to
\fIzsh\fP to make it so\&.
.PP
There are three special values for \fB<vcs\-string>\fP: The first is named
\fI\-init\-\fP, that is in effect as long as there was no decision what VCS
backend to use\&. The second is \fI\-preinit\-\fP; it is used \fBbefore\fP
\fIvcs_info\fP is run, when initializing the data exporting variables\&. The
third special value is \fIformats\fP and is used by the \fBvcs_info_lastmsg\fP
for looking up its styles\&.
.PP
The initial value of \fB<repo\-root\-name>\fP is \fI\-all\-\fP and it is replaced
with the actual name, as soon as it is known\&. Only use this part of the
context for defining the \fIformats\fP, \fIactionformats\fP or
\fIbranchformat\fP styles, as it is guaranteed that \fB<repo\-root\-name>\fP is
set up correctly for these only\&. For all other styles, just use \fB\&'*'\fP
instead\&.
.PP
There are two pre\-defined values for \fB<user\-context>\fP:
.PD 0
.TP
\fBdefault\fP
the one used if none is specified
.TP
\fBcommand\fP
used by vcs_info_lastmsg to lookup its styles
.PD
.PP
You can of course use \fB\&':vcs_info:*'\fP to match all VCSs in all
user\-contexts at once\&.
.PP
This is a description of all styles that are looked up\&.
.PP
.PD 0
.TP
.PD
\fBformats\fP
A list of formats, used when actionformats is not used
(which is most of the time)\&.
.TP
\fBactionformats\fP
A list of formats, used if there is a special
action going on in your current repository; like an interactive rebase or
a merge conflict\&.
.TP
\fBbranchformat\fP
Some backends replace \fI%b\fP in the formats and
actionformats styles above, not only by a branch name but also by a
revision number\&. This style lets you modify how that string should look\&.
.TP
\fBnvcsformats\fP
These "formats" are exported when we didn\&'t detect
a version control system for the current directory\&. This is useful if you
want \fIvcs_info\fP to completely take over the generation of your prompt\&.
You would do something like \fBPS1=\&'${vcs_info_msg_0_}'\fP to accomplish that\&. .TP \fBhgrevformat\fP \fBhg\fP uses both a hash and a revision number to reference a specific changeset in a repository\&. With this style you can format the revision string (see \fIbranchformat\fP) to include either or both\&. It\&'s only useful when \fIget\-revision\fP is true\&. .TP \fBmax\-exports\fP Defines the maximum number of \fIvcs_info_msg_*_\fP variables \fIvcs_info\fP will export\&. .TP \fBenable\fP A list of backends you want to use\&. Checked in the \fI\-init\-\fP context\&. If this list contains an item called \fBNONE\fP no backend is used at all and \fIvcs_info\fP will do nothing\&. If this list contains \fBALL\fP \fIvcs_info\fP will use all known backends\&. Only with \fBALL\fP in \fBenable\fP will the \fBdisable\fP style have any effect\&. \fBALL\fP and \fBNONE\fP are case insensitive\&. .TP \fBdisable\fP A list of VCSs you don\&'t want \fIvcs_info\fP to test for repositories (checked in the \fI\-init\-\fP context, too)\&. Only used if \fBenable\fP contains \fBALL\fP\&. .TP \fBdisable\-patterns\fP A list of patterns that are checked against \fB$PWD\fP\&. If a pattern
matches, \fIvcs_info\fP will be disabled\&. This style is checked in the
\fI:vcs_info:\-init\-:*:\-all\-\fP context\&.
.RS
.PP
Say, \fB~/\&.zsh\fP is a directory under version control, in which you do
not want \fIvcs_info\fP to be active, do:
.RS
.nf
\fBzstyle \&':vcs_info:*' disable\-patterns "$HOME/\&.zsh(|/*)"\fP .fi .RE .RE .TP \fBuse\-quilt\fP If enabled, the \fBquilt\fP support code is active in addon\&' mode\&. See \fBQuilt Support\fP for details\&. .TP \fBquilt\-standalone\fP If enabled, standalone\&' mode detection is attempted if no VCS is active in a given directory\&. See \fBQuilt Support\fP for details\&. .TP \fBquilt\-patch\-dir\fP Overwrite the value of the \fI$QUILT_PATCHES\fP environment variable\&. See
\fBQuilt Support\fP for details\&.
.TP
\fBquiltcommand\fP
When \fBquilt\fP itself is called in quilt support the value of this style
is used as the command name\&.
.TP
\fBcheck\-for\-changes\fP
If enabled, this style causes the \fB%c\fP and \fB%u\fP format escapes to show
when the working directory has uncommitted changes\&. The strings displayed by
these escapes can be controlled via the \fIstagedstr\fP and \fIunstagedstr\fP
styles\&. The only backends that currently support this option are \fBgit\fP and
\fBhg\fP (\fBhg\fP only supports unstaged)\&.
.RS
.PP
Note, the actions taken if this style is enabled are potentially expensive
(read: they may be slow, depending on how big the current repository is)\&.
Therefore, it is disabled by default\&.
.RE
.TP
\fBstagedstr\fP
This string will be used in the \fB%c\fP escape if there are staged changes in
the repository\&.
.TP
\fBunstagedstr\fP
This string will be used in the \fB%u\fP escape if there are unstaged changes
in the repository\&.
.TP
\fBcommand\fP
This style causes \fIvcs_info\fP to use the supplied string as the command
to use as the VCS\&'s binary\&. Note, that setting this in ':vcs_info:*' is
not a good idea\&.
.RS
.PP
If the value of this style is empty (which is the default), the used binary
name is the name of the backend in use (e\&.g\&. \fIsvn\fP is used in an \fIsvn\fP
repository)\&.
.PP
The \fIrepo\-root\-name\fP part in the context is always the default \fB\-all\-\fP
when this style is looked up\&.
.PP
For example, this style can be used to use binaries from non\-default
installation directories\&. Assume, \fIgit\fP is installed in /usr/bin but
your sysadmin installed a newer version in /usr/bin/local\&. Instead of
changing the order of your \fB$PATH\fP parameter, you can do this: .RS .nf \fBzstyle \&':vcs_info:git:*:\-all\-' command /usr/local/bin/git\fP .fi .RE .RE .TP \fBuse\-server\fP This is used by the Perforce backend (\fBp4\fP) to decide if it should contact the Perforce server to find out if a directory is managed by Perforce\&. This is the only reliable way of doing this, but runs the risk of a delay if the server name cannot be found\&. If the server (more specifically, the \fIhost\fP\fB:\fP\fIport\fP pair describing the server) cannot be contacted, its name is put into the associative array \fBvcs_info_p4_dead_servers\fP and is not contacted again during the session until it is removed by hand\&. If you do not set this style, the \fBp4\fP backend is only usable if you have set the environment variable \fBP4CONFIG\fP to a file name and have corresponding files in the root directories of each Perforce client\&. See comments in the function \fBVCS_INFO_detect_p4\fP for more detail\&. .TP \fBuse\-simple\fP If there are two different ways of gathering information, you can select the simpler one by setting this style to true; the default is to use the not\-that\-simple code, which is potentially a lot slower but might be more accurate in all possible cases\&. This style is used by the \fBbzr\fP and \fBhg\fP backends\&. In the case of \fBhg\fP it will invoke the external hexdump program to parse the binary dirstate cache file; this method will not return the local revision number\&. .TP \fBget\-revision\fP If set to true, vcs_info goes the extra mile to figure out the revision of a repository\&'s work tree (currently for the \fBgit\fP and \fBhg\fP backends, where this kind of information is not always vital)\&. For \fBgit\fP, the hash value of the currently checked out commit is available via the \fB%i\fP expansion\&. With \fBhg\fP, the local revision number and the corresponding global hash are available via \fB%i\fP\&. .TP \fBget\-mq\fP If set to true, the \fBhg\fP backend will look for a Mercurial Queue (\fBmq\fP) patch directory\&. Information will be available via the \fB%m\fP\&' replacement\&. .TP \fBget\-bookmarks\fP If set to true, the \fBhg\fP backend will try to get a list of current bookmarks\&. They will be available via the \fB%m\fP\&' replacement\&. .TP \fBuse\-prompt\-escapes\fP Determines if we assume that the assembled string from \fIvcs_info\fP includes prompt escapes\&. (Used by \fBvcs_info_lastmsg\fP\&.) .TP \fBdebug\fP Enable debugging output to track possible problems\&. Currently this style is only used by \fIvcs_info\fP\&'s hooks system\&. .TP \fBhooks\fP A list style that defines hook\-function names\&. See \fBHooks in vcs_info\fP below for details\&. .PP The default values for these styles in all contexts are: .PP .PD 0 .TP \fBformats\fP " (%s)\-[%b]%u%c\-" .TP \fBactionformats\fP " (%s)\-[%b|%a]%u%c\-" .TP \fBbranchformat\fP "%b:%r" (for bzr, svn, svk and hg) .TP \fBnvcsformats\fP "" .TP \fBhgrevformat\fP "%r:%h" .TP \fBmax\-exports\fP 2 .TP \fBenable\fP ALL .TP \fBdisable\fP (empty list) .TP \fBdisable\-patterns\fP (empty list) .TP \fBcheck\-for\-changes\fP false .TP \fBstagedstr\fP (string: "S") .TP \fBunstagedstr\fP (string: "U") .TP \fBcommand\fP (empty string) .TP \fBuse\-server\fP false .TP \fBuse\-simple\fP false .TP \fBget\-revision\fP false .TP \fBget\-mq\fP true .TP \fBget\-bookmarks\fP false .TP \fBuse\-prompt\-escapes\fP true .TP \fBdebug\fP false .TP \fBhooks\fP (empty list) .TP \fBuse\-quilt\fP false .TP \fBquilt\-standalone\fP false .TP \fBquilt\-patch\-dir\fP empty \- use \fI$QUILT_PATCHES\fP
.TP
\fBquiltcommand\fP
quilt
.PD
.PP
In normal \fBformats\fP and \fBactionformats\fP the following replacements are
done:
.PP
.PD 0
.TP
\fB%s\fP
The VCS in use (git, hg, svn, etc\&.)\&.
.TP
\fB%b\fP
Information about the current branch\&.
.TP
\fB%a\fP
An identifier that describes the action\&. Only makes sense in
\fIactionformats\fP\&.
.TP
\fB%i\fP
The current revision number or identifier\&. For \fBhg\fP
the \fIhgrevformat\fP style may be used to customize the output\&.
.TP
\fB%c\fP
The string from the \fIstagedstr\fP style if there are staged
changes in the repository\&.
.TP
\fB%u\fP
The string from the \fIunstagedstr\fP style if there are
unstaged changes in the repository\&.
.TP
\fB%R\fP
The base directory of the repository\&.
.TP
\fB%r\fP
The repository name\&. If \fB%R\fP is \fI/foo/bar/repoXY\fP, \fB%r\fP
is \fIrepoXY\fP\&.
.TP
\fB%S\fP
A subdirectory within a repository\&. If \fB$PWD\fP is \fI/foo/bar/repoXY/beer/tasty\fP, \fB%S\fP is \fIbeer/tasty\fP\&. .TP \fB%m\fP A "misc" replacement\&. It is at the discretion of the backend to decide what this replacement expands to\&. It is currently used by the \fBhg\fP and \fBgit\fP backends to display patch information from the \fBmq\fP and \fBstgit\fP extensions\&. .PD .PP In \fBbranchformat\fP these replacements are done: .PP .PD 0 .TP \fB%b\fP The branch name\&. .TP \fB%r\fP The current revision number or the \fIhgrevformat\fP style for \fBhg\fP\&. .PD .PP In \fBhgrevformat\fP these replacements are done: .PP .PD 0 .TP \fB%r\fP The current local revision number\&. .TP \fB%h\fP The current 40\-character changeset ID hash identifier\&. .PD .PP In \fBpatch\-format\fP and \fBnopatch\-format\fP these replacements are done: .PP .PD 0 .TP \fB%p\fP The name of the top\-most applied patch\&. .TP \fB%u\fP The number of unapplied patches\&. .TP \fB%n\fP The number of applied patches\&. .TP \fB%c\fP The number of unapplied patches\&. .TP \fB%g\fP The names of active \fBmq\fP guards (\fBhg\fP backend)\&. .TP \fB%G\fP The number of active \fBmq\fP guards (\fBhg\fP backend)\&. .PD .PP Not all VCS backends have to support all replacements\&. For \fBnvcsformats\fP no replacements are performed at all, it is just a string\&. .PP .SS "Oddities" .PP If you want to use the \fB%b\fP (bold off) prompt expansion in \fIformats\fP, which expands \fB%b\fP itself, use \fB%%b\fP\&. That will cause the \fIvcs_info\fP expansion to replace \fB%%b\fP with \fB%b\fP, so that zsh\&'s prompt expansion mechanism can handle it\&. Similarly, to hand down \fB%b\fP from \fIbranchformat\fP, use \fB%%%%b\fP\&. Sorry for this inconvenience, but it cannot be easily avoided\&. Luckily we do not clash with a lot of prompt expansions and this only needs to be done for those\&. .PP .SS "Quilt Support" .PP \fBQuilt\fP is not a version control system, therefore this is not implemented as a backend\&. It can help keeping track of a series of patches\&. People use it to keep a set of changes they want to use on top of software packages (which is tightly integrated into the package build process \- the Debian project does this for a large number of packages)\&. Quilt can also help individual developers keep track of their own patches on top of real version control systems\&. .PP The \fIvcs_info\fP integration tries to support both ways of using quilt by having two slightly different modes of operation: addon\&' mode and standalone\&' mode)\&. .PP For addon\&' mode to become active \fIvcs_info\fP must have already detected a real version control system controlling the directory\&. If that is the case, a directory that holds quilt\&'s patches needs to be found\&. That directory is configurable via the \fIQUILT_PATCHES\&'\fP environment variable\&. If that variable exists its value is used, otherwise the value \fBpatches\&'\fP is assumed\&. The value from \fI$QUILT_PATCHES\fP can be overwritten using the
\fBquilt\-patches\&'\fP style\&. (Note: you can use \fIvcs_info\fP to keep the value
of \fI$QUILT_PATCHES\fP correct all the time via the \fBpost\-quilt\fP hook)\&. .PP When the directory in question is found, quilt is assumed to be active\&. To gather more information, \fIvcs_info\fP looks for a directory called \&.pc\&'; Quilt uses that directory to track its current state\&. If this directory does not exist we know that quilt has not done anything to the working directory (read: no patches have been applied yet)\&. .PP If patches are applied, \fIvcs_info\fP will try to find out which\&. If you want to know which patches of a series are not yet applied, you need to activate the \fBget\-unapplied\fP style in the appropriate context\&. .PP \fIvcs_info\fP allows for very detailed control over how the gathered information is presented (see the below sections, \fBStyles\fP and \fBHooks in vcs_info\fP), all of which are documented below\&. Note there are a number of other patch tracking systems that work on top of a certain version control system (like \fBstgit\fP for \fBgit\fP, or \fBmq\fP for \fBhg\fP); the configuration for systems like that are generally configured the same way as the \fBquilt\fP support\&. .PP If the \fBquilt\fP support is working in addon\&' mode, the produced string is available as a simple format replacement (\fI%Q\fP to be precise), which can be used in \fBformats\fP and \fBactionformats\fP; see below for details)\&. .PP If, on the other hand, the support code is working in standalone\&' mode, \fIvcs_info\fP will pretend as if \fBquilt\fP were an actual version control system\&. That means that the version control system identifier (which otherwise would be something like svn\&' or cvs') will be set to \fB\-quilt\-\fP\&'\&. This has implications on the used style context where this identifier is the second element\&. \fIvcs_info\fP will have filled in a proper value for the "repository\&'s" root directory and the string containing the information about quilt\&'s state will be available as the misc' replacement (and \fI%Q\fP for compatibility with addon\&' mode\&. .PP What is left to discuss is how standalone\&' mode is detected\&. The detection itself is a series of searches for directories\&. You can have this detection enabled all the time in every directory that is not otherwise under version control\&. If you know there is only a limited set of trees where you would like \fIvcs_info\fP to try and look for Quilt in standalone\&' mode to minimise the amount of searching on every call to \fIvcs_info\fP, there are a number of ways to do that: .PP Essentially, standalone\&' mode detection is controlled by a style called \fBquilt\-standalone\fP\&'\&. It is a string style and its value can have different effects\&. The simplest values are: \fBalways\fP\&' to run detection every time \fIvcs_info\fP is run, and \fBnever\fP\&' to turn the detection off entirely\&. .PP If the value of \fBquilt\-standalone\fP is something else, it is interpreted differently\&. If the value is the name of a scalar variable the value of that variable is checked and that value is used in the same always\&'/never' way as described above\&. .PP If the value of \fBquilt\-standalone\fP is an array, the elements of that array are used as directory names under which you want the detection to be active\&. .PP If \fBquilt\-standalone\fP is an associative array, the keys are taken as directory names under which you want the detection to be active, but only if the corresponding value is the string \fBtrue\fP\&'\&. .PP Last, but not least, if the value of \fBquilt\-standalone\fP is the name of a function, the function is called without arguments and the return value decides whether detection should be active\&. A 0\&' return value is true; a non\-zero return value is interpreted as false\&. .PP Note, if there is both a function and a variable by the name of \fBquilt\-standalone\fP, the function will take precedence\&. .PP .SS "Function Descriptions (Public API)" .PP .PD 0 .TP .PD \fBvcs_info\fP [\fIuser\-context\fP] The main function, that runs all backends and assembles all data into \fI${vcs_info_msg_*_}\fP\&. This is the function you want to call from
\fBprecmd\fP if you want to include up\-to\-date information in your prompt (see
\fBVariable description\fP below)\&. If an argument is given, that string will be
used instead of \fBdefault\fP in the \fBuser\-context\fP field of the style
context\&.
.TP
\fBvcs_info_lastmsg\fP
Outputs the last \fI${vcs_info_msg_*_}\fP value\&. Takes into account the value of the \fBuse\-prompt\-escapes\fP style in \fI\&':vcs_info:formats:command:\-all\-'\fP\&. It also only prints \fBmax\-exports\fP values\&. .TP \fBvcs_info_printsys\fP [\fIuser\-context\fP] Prints a list of all supported version control systems\&. Useful to find out possible contexts (and which of them are enabled) or values for the \fIdisable\fP style\&. .TP \fBvcs_info_setsys\fP Initializes \fIvcs_info\fP\&'s internal list of available backends\&. With this function, you can add support for new VCSs without restarting the shell\&. .PP All functions named VCS_INFO_* are for internal use only\&. .PP .SS "Variable Description" .PP .PD 0 .TP .PD \fB${vcs_info_msg_N_}\fP (Note the trailing underscore)
Where \fIN\fP is an integer, e\&.g\&., \fIvcs_info_msg_0_\fP\&. These variables
are the storage for the informational message the last \fIvcs_info\fP call
has assembled\&. These are strongly connected to the \fBformats\fP,
\fBactionformats\fP and \fBnvcsformats\fP styles described above\&. Those styles
are lists\&. The first member of that list gets expanded into
\fI${vcs_info_msg_0_}\fP, the second into \fI${vcs_info_msg_1_}\fP
and the Nth into \fI${vcs_info_msg_N\-1_}\fP\&. These parameters are exported into the environment\&. (See the \fBmax\-exports\fP style above\&.) .PP All variables named VCS_INFO_* are for internal use only\&. .PP .SS "Hooks in vcs_info" .PP Hooks are places in \fIvcs_info\fP where you can run your own code\&. That code can communicate with the code that called it and through that, change the system\&'s behaviour\&. .PP For configuration, hooks change the style context: .RS .nf \fB:vcs_info:<vcs\-string>+<hook\-name>:<user\-context>:<repo\-root\-name>\fP .fi .RE .PP To register functions to a hook, you need to list them in the \fBhooks\fP style in the appropriate context\&. .PP Example: .RS .nf \fBzstyle \&':vcs_info:*+foo:*' hooks bar baz\fP .fi .RE .PP This registers functions to the hook foo\&' for all backends\&. In order to avoid namespace problems, all registered function names are prepended by a +vi\-\&', so the actual functions called for the foo' hook are \fB+vi\-bar\fP\&' and \fB+vi\-baz\fP'\&. .PP If something seems weird, you can enable the debug\&' boolean style in the proper context and the hook\-calling code will print what it tried to execute and whether the function in question existed\&. .PP When you register more than one function to a hook, all functions are executed one after another until one function returns non\-zero or until all functions have been called\&. .PP You may pass data between functions via an associative array, \fBuser_data\fP\&. For example: .RS .nf \fB +vi\-git\-myfirsthook(){ user_data[myval]=$myval
}
+vi\-git\-mysecondhook(){
# do something with ${user_data[myval]} }\fP .fi .RE .PP There are a number of variables that are special in hook contexts: .PP .PD 0 .TP .PD \fBret\fP The return value that the hooks system will return to the caller\&. The default is an integer zero\&'\&. If and how a changed \fBret\fP value changes the execution of the caller depends on the specific hook\&. See the hook documentation below for details\&. .TP \fBhook_com\fP An associated array which is used for bidirectional communication from the caller to hook functions\&. The used keys depend on the specific hook\&. .TP \fBcontext\fP The active context of the hook\&. Functions that wish to change this variable should make it local scope first\&. .TP \fBvcs\fP The current VCS after it was detected\&. The same values as in the enable/disable style are used\&. Available in all hooks except \fBstart\-up\fP\&. .PP Finally, the full list of currently available hooks: .PP .PD 0 .TP .PD \fBstart\-up\fP Called after starting \fIvcs_info\fP but before the VCS in this directory is determined\&. It can be used to deactivate \fIvcs_info\fP temporarily if necessary\&. When \fBret\fP is set to \fI1\fP, \fIvcs_info\fP aborts and does nothing; when set to \fI2\fP, \fIvcs_info\fP sets up everything as if no version control were active and exits\&. .TP \fBpre\-get\-data\fP Same as \fBstart\-up\fP but after the VCS was detected\&. .TP \fBgen\-hg\-bookmark\-string\fP Called in the Mercurial backend when a bookmark string is generated; the \fBget\-revision\fP and \fBget\-bookmarks\fP styles must be true\&. .RS .PP This hook gets the names of the Mercurial bookmarks that \fIvcs_info\fP collected from hg\&'\&. .PP When setting \fBret\fP to non\-zero, the string in \fB${hook_com[hg\-bookmark\-string]}\fP will be used in the \fI%m\fP escape in
\fBformats\fP and \fBactionformats\fP and will be availabe in the global
\fIbackend_misc\fP array as \fB${backend_misc[bookmarks]}\fP\&. .RE .TP \fBgen\-applied\-string\fP Called in the \fBgit\fP (with \fBstgit\fP), and \fBhg\fP (with \fBmq\fP) backends and in \fBquilt\fP support when the \fIapplied\-string\fP is generated; the \fBuse\-quilt\fP zstyle must be true for \fBquilt\fP (the \fBmq\fP and \fBstgit\fP backends are active by default)\&. .RS .PP This hook gets the names of all applied patches which \fIvcs_info\fP collected so far in the opposite order, which means that the first argument is the top\-most patch and so forth\&. .PP When setting \fBret\fP to non\-zero, the string in \fB${hook_com[applied\-string]}\fP will be used in the \fI%m\fP escape in
\fBformats\fP and \fBactionformats\fP; it will be available in the global
\fIbackend_misc\fP array as \fB$backend_misc[patches]}\fP; and it will be available as \fI%p\fP in the \fBpatch\-format\fP and \fBnopatch\-format\fP styles\&. .RE .TP \fBgen\-unapplied\-string\fP Called in the \fBgit\fP (with \fBstgit\fP), and \fBhg\fP (with \fBmq\fP) backend and in \fBquilt\fP support when the \fIunapplied\-string\fP is generated; the \fBget\-unapplied\fP style must be true\&. .RS .PP This hook gets the names of all unapplied patches which \fIvcs_info\fP collected so far in the opposite order, which mean that the first argument is the patch next\-in\-line to be applied and so forth\&. .PP When setting \fBret\fP to non\-zero, the string in \fB${hook_com[unapplied\-string]}\fP will be available as \fI%u\fP in the
\fBpatch\-format\fP and \fBnopatch\-format\fP styles\&.
.RE
.TP
\fBgen\-mqguards\-string\fP
Called in the \fBhg\fP backend when \fBguards\-string\fP is generated; the
\fBget\-mq\fP style must be true (default)\&.
.RS
.PP
This hook gets the names of any active \fBmq\fP guards\&.
.PP
When setting \fBret\fP to non\-zero, the string in
\fB${hook_com[guards\-string]}\fP will be used in the \fI%g\fP escape in the \fBpatch\-format\fP and \fBnopatch\-format\fP styles\&. .RE .TP \fBpost\-quilt\fP Called after the \fBquilt\fP support is done\&. The following information is passed as arguments to the hook: 1\&. the quilt\-support mode (addon\&' or standalone\&'); 2\&. the directory that contains the patch series; 3\&. the directory that holds quilt\&'s status information (the \&.pc' directory) or the string \fB"\-nopc\-"\fP if that directory wasn\&'t found\&. .RS .PP The hook_com\&' parameter is not used\&. .RE .TP \fBset\-branch\-format\fP Called before \fBbranchformat\fP\&' is set\&. The only argument to the hook is the format that is configured at this point\&. .RS .PP The \fBhook_com\fP\&' keys considered are \fBbranch\fP' and \fBrevision\fP'\&. They are set to the values figured out so far by \fIvcs_info\fP and any change will be used directly when the actual replacement is done\&. .PP If \fBret\fP is set to to non\-zero, the string in \fB${hook_com[branch\-replace]}\fP will be used unchanged as the
\fB%b\fP\&' replacement in the variables set by \fIvcs_info\fP\&.
.RE
.TP
\fBset\-hgrev\-format\fP
Called before a \fBhgrevformat\fP\&' is set\&. The only argument to the
hook is the format that is configured at this point\&.
.RS
.PP
The \fBhook_com\fP\&' keys considered are \fBhash\fP' and \fBlocalrev\fP'\&.
They are set to the values figured out so far by \fIvcs_info\fP and any
change will be used directly when the actual replacement is done\&.
.PP
If \fBret\fP is set to to non\-zero, the string in
\fB${hook_com[rev\-replace]}\fP will be used unchanged as the \fB%i\fP\&' replacement in the variables set by \fIvcs_info\fP\&. .RE .TP \fBset\-message\fP Called each time before a \fBvcs_info_msg_N_\fP\&' message is set\&. It takes two arguments; the first being the N\&' in the message variable name, the second is the currently configured \fBformats\fP or \fBactionformats\fP\&. .RS .PP There are a number of \fBhook_com\fP\&' keys, that are used here: \fBaction\fP\&', \fBbranch\fP', \fBbase\fP', \fBbase\-name\fP', \fBsubdir\fP', \fBstaged\fP\&', \fBunstaged\fP', \fBrevision\fP', \fBmisc\fP', \fBvcs\fP' and one \fBmiscN\fP\&' entry for each backend\-specific data field (\fBN\fP starting at zero)\&. They are set to the values figured out so far by \fIvcs_info\fP and any change will be used directly when the actual replacement is done\&. .PP Since this hook is triggered multiple times (once for each configured \fBformats\fP or \fBactionformats\fP), each of the \fBhook_com\fP\&' keys mentioned above (except for the \fBmiscN\fP entries) has an \fB_orig\fP\&' counterpart, so even if you changed a value to your liking you can still get the original value in the next run\&. Changing the \fB_orig\fP\&' values is probably not a good idea\&. .PP If \fBret\fP is set to to non\-zero, the string in \fB${hook_com[message]}\fP will be used unchanged as the message by
\fIvcs_info\fP\&.
.RE
.RE
.PP
If all of this sounds rather confusing, take a look at the \fBExamples\fP
section below and also in the Misc/vcs_info\-examples file in the Zsh source\&.
They contain some explanatory code\&.
.PP
.SS "Examples"
.PP
Don\&'t use \fIvcs_info\fP at all (even though it's in your prompt):
.RS
.nf
\fBzstyle \&':vcs_info:*' enable NONE\fP
.fi
.RE
.PP
Disable the backends for \fBbzr\fP and \fBsvk\fP:
.RS
.nf
\fBzstyle \&':vcs_info:*' disable bzr svk\fP
.fi
.RE
.PP
Disable everything \fIbut\fP \fBbzr\fP and \fBsvk\fP:
.RS
.nf
\fBzstyle \&':vcs_info:*' enable bzr svk\fP
.fi
.RE
.PP
Provide a special formats for \fBgit\fP:
.RS
.nf
\fBzstyle \&':vcs_info:git:*' formats       ' GIT, BABY! [%b]'
zstyle \&':vcs_info:git:*' actionformats ' GIT ACTION! [%b|%a]'\fP
.fi
.RE
.PP
All \fB%x\fP expansion in all sorts of formats ("formats", "actionformats",
branchformat, you name it) are done using the \fBzformat\fP\&' builtin from
the \fBzsh/zutil\fP\&' module\&. That means you can do everything with these
\fB%x\fP items what zformat supports\&. In particular, if you want something
that is really long to have a fixed width, like a hash in a mercurial
branchformat, you can do this: \fB%12\&.12i\fP\&. That\&'ll shrink the 40 character
hash to its 12 leading characters\&. The form is actually
\fB%\fP\fImin\fP\fB\&.\fP\fImax\fP\fBx\fP\&'\&. More is possible\&.
See the section The zsh/zutil Module\&' in \fIzshmodules\fP(1) for details\&.
.PP
Use the quicker \fBbzr\fP backend
.RS
.nf
\fBzstyle \&':vcs_info:bzr:*' use\-simple true\fP
.fi
.RE
.PP
If you do use \fBuse\-simple\fP, please report if it does the\-right\-thing[tm]\&'\&.
.PP
Display the revision number in yellow for \fBbzr\fP and \fBsvn\fP:
.RS
.nf
\fBzstyle \&':vcs_info:(svn|bzr):*' branchformat '%b%{'${fg[yellow]}'%}:%r'\fP .fi .RE .PP If you want colors, make sure you enclose the color codes in \fB%{\&.\&.\&.%}\fP if you want to use the string provided by \fIvcs_info\fP in prompts\&. .PP Here is how to print the VCS information as a command (not in a prompt): .RS .nf \fBalias vcsi=\&'vcs_info command; vcs_info_lastmsg'\fP .fi .RE .PP This way, you can even define different formats for output via \fBvcs_info_lastmsg\fP in the \&':vcs_info:*:command:*' namespace\&. .PP Now as promised, some code that uses hooks: say, you\&'d like to replace the string svn' by subversion' in \fIvcs_info\fP\&'s \fB%s\fP \fBformats\fP replacement\&. .PP First, we will tell \fIvcs_info\fP to call a function when populating the message variables with the gathered information: .RS .nf \fBzstyle \&':vcs_info:*+set\-message:*' hooks svn2subversion\fP .fi .RE .PP Nothing happens\&. Which is reasonable, since we didn\&'t define the actual function yet\&. To see what the hooks subsystem is trying to do, enable the \fBdebug\fP\&' style: .RS .nf \fBzstyle \&':vcs_info:*+*:*' debug true\fP .fi .RE .PP That should give you an idea what is going on\&. Specifically, the function that we are looking for is \fB+vi\-svn2subversion\fP\&'\&. Note, the \fB+vi\-\fP' prefix\&. So, everything is in order, just as documented\&. When you are done checking out the debugging output, disable it again: .RS .nf \fBzstyle \&':vcs_info:*+*:*' debug false\fP .fi .RE .PP Now, let\&'s define the function: .RS .nf \fB function +vi\-svn2subversion() { [[${hook_com[vcs_orig]} == svn ]] && hook_com[vcs]=subversion
}\fP
.fi
.RE
.PP
Simple enough\&. And it could have even been simpler, if only we had
registered our function in a less generic context\&. If we do it only in
the \fBsvn\fP\&' backend's context, we don't need to test which the active
backend is:
.RS
.nf
\fBzstyle \&':vcs_info:svn+set\-message:*' hooks svn2subversion\fP
.fi
.RE
.RS
.nf
\fB
function +vi\-svn2subversion() {
hook_com[vcs]=subversion
}\fP
.fi
.RE
.PP
And finally a little more elaborate example, that uses a hook to create
a customised bookmark string for the \fBhg\fP backend\&.
.PP
Again, we start off by registering a function:
.RS
.nf
\fBzstyle \&':vcs_info:hg+gen\-hg\-bookmark\-string:*' hooks hgbookmarks\fP
.fi
.RE
.PP
And then we define the \fB+vi\-hgbookmarks\fP function:
.RS
.nf
\fB
function +vi\-hgbookmarks() {
# The default is to connect all bookmark names by
# commas\&. This mixes things up a little\&.
# Imagine, there\&'s one type of bookmarks that is
# special to you\&. Say, because it\&'s *your* work\&.
# Those bookmarks look always like this: "sh/*"
# (because your initials are sh, for example)\&.
# This makes the bookmarks string use only those
# bookmarks\&. If there\&'s more than one, it
# concatenates them using commas\&.
local s i
# The bookmarks returned by hg\&' are available in
# the functions positional parameters\&.
(( $# == 0 )) && return 0 for i in "$@"; do
if [[ $i == sh/* ]]; then [[ \-n$s ]] && s=$s, s=${s}$i fi done # Now, the communication with the code that calls # the hook functions is done via the hook_com[] # hash\&. The key, at which the gen\-hg\-bookmark\-string\&' # hook looks at is hg\-bookmark\-string\&'\&. So: hook_com[hg\-bookmark\-string]=$s
# And to signal, that we want to use the sting we
# just generated, set the special variable ret\&' to
# something other than the default zero:
ret=1
return 0
}
\fP
.fi
.RE
.PP
Some longer examples and code snippets which might be useful are available in
the examples file located at Misc/vcs_info\-examples in the Zsh source
directory\&.
.PP
This concludes our guided tour through zsh\&'s \fIvcs_info\fP\&.
.PP
.SH "PROMPT THEMES"
.PP
.SS "Installation"
.PP
You should make sure all the functions from the \fBFunctions/Prompts\fP
directory of the source distribution are available; they all begin with
the string \fBprompt_\fP\&' except for the special function\fBpromptinit\fP'\&.
You also need the \fBcolors\fP\&' function from \fBFunctions/Misc\fP\&.  All of
these functions may already have been installed on your system; if not,
you will need to find them and copy them\&.  The directory should appear as
one of the elements of the \fBfpath\fP array (this should already be the
case if they were installed), and at least the function \fBpromptinit\fP
should be autoloaded; it will autoload the rest\&.  Finally, to initialize
the use of the system you need to call the \fBpromptinit\fP function\&.  The
following code in your \fB\&.zshrc\fP will arrange for this; assume the
functions are stored in the directory \fB~/myfns\fP:
.PP
.RS
.nf
\fBfpath=(~/myfns $fpath) autoload \-U promptinit promptinit\fP .fi .RE .PP .SS "Theme Selection" .PP Use the \fBprompt\fP command to select your preferred theme\&. This command may be added to your \fB\&.zshrc\fP following the call to \fBpromptinit\fP in order to start zsh with a theme already selected\&. .PP .PD 0 .TP .PD 0 \fBprompt\fP [ \fB\-c\fP | \fB\-l\fP ] .TP .PD 0 \fBprompt\fP [ \fB\-p\fP | \fB\-h\fP ] [ \fItheme\fP \&.\&.\&. ] .TP .PD \fBprompt\fP [ \fB\-s\fP ] \fItheme\fP [ \fIarg\fP \&.\&.\&. ] Set or examine the prompt theme\&. With no options and a \fItheme\fP argument, the theme with that name is set as the current theme\&. The available themes are determined at run time; use the \fB\-l\fP option to see a list\&. The special \fItheme\fP \fBrandom\fP\&' selects at random one of the available themes and sets your prompt to that\&. .RS .PP In some cases the \fItheme\fP may be modified by one or more arguments, which should be given after the theme name\&. See the help for each theme for descriptions of these arguments\&. .PP Options are: .PP .PD 0 .TP \fB\-c\fP Show the currently selected theme and its parameters, if any\&. .TP \fB\-l\fP List all available prompt themes\&. .TP \fB\-p\fP Preview the theme named by \fItheme\fP, or all themes if no \fItheme\fP is given\&. .TP \fB\-h\fP Show help for the theme named by \fItheme\fP, or for the \fBprompt\fP function if no \fItheme\fP is given\&. .TP \fB\-s\fP Set \fItheme\fP as the current theme and save state\&. .PD .RE .TP \fBprompt_\fP\fItheme\fP\fB_setup\fP Each available \fItheme\fP has a setup function which is called by the \fBprompt\fP function to install that theme\&. This function may define other functions as necessary to maintain the prompt, including functions used to preview the prompt or provide help for its use\&. You should not normally call a theme\&'s setup function directly\&. .PP .SH "ZLE FUNCTIONS" .PP .SS "Widgets" .PP These functions all implement user\-defined ZLE widgets (see \fIzshzle\fP(1)) which can be bound to keystrokes in interactive shells\&. To use them, your \fB\&.zshrc\fP should contain lines of the form .PP .RS .nf \fBautoload \fIfunction\fP zle \-N \fIfunction\fP\fP .fi .RE .PP followed by an appropriate \fBbindkey\fP command to associate the function with a key sequence\&. Suggested bindings are described below\&. .PP .PD 0 .TP .PD bash\-style word functions If you are looking for functions to implement moving over and editing words in the manner of bash, where only alphanumeric characters are considered word characters, you can use the functions described in the next section\&. The following is sufficient: .RS .PP .RS .nf \fBautoload \-U select\-word\-style select\-word\-style bash\fP .fi .RE .PP .RE .TP .PD 0 \fBforward\-word\-match\fP, \fBbackward\-word\-match\fP .TP .PD 0 \fBkill\-word\-match\fP, \fBbackward\-kill\-word\-match\fP .TP .PD 0 \fBtranspose\-words\-match\fP, \fBcapitalize\-word\-match\fP .TP .PD 0 \fBup\-case\-word\-match\fP, \fBdown\-case\-word\-match\fP .TP .PD \fBselect\-word\-style\fP, \fBmatch\-word\-context\fP, \fBmatch\-words\-by\-style\fP The eight \fB\-match\fP\&' functions are drop\-in replacements for the builtin widgets without the suffix\&. By default they behave in a similar way\&. However, by the use of styles and the function \fBselect\-word\-style\fP, the way words are matched can be altered\&. .RS .PP The simplest way of configuring the functions is to use \fBselect\-word\-style\fP, which can either be called as a normal function with the appropriate argument, or invoked as a user\-defined widget that will prompt for the first character of the word style to be used\&. The first time it is invoked, the eight \fB\-match\fP functions will automatically replace the builtin versions, so they do not need to be loaded explicitly\&. .PP The word styles available are as follows\&. Only the first character is examined\&. .PP .PD 0 .TP .PD \fBbash\fP Word characters are alphanumeric characters only\&. .TP \fBnormal\fP As in normal shell operation: word characters are alphanumeric characters plus any characters present in the string given by the parameter \fB$WORDCHARS\fP\&.
.TP
\fBshell\fP
Words are complete shell command arguments, possibly including complete
quoted strings, or any tokens special to the shell\&.
.TP
\fBwhitespace\fP
Words are any set of characters delimited by whitespace\&.
.TP
\fBdefault\fP
Restore the default settings; this is usually the same as \fBnormal\fP\&'\&.
.PP
All but \fBdefault\fP\&' can be input as an upper case character, which has
the same effect but with subword matching turned on\&.  In this case, words
with upper case characters are treated specially: each separate run of
upper case characters, or an upper case character followed by any number of
other characters, is considered a word\&.  The style \fBsubword\-range\fP
can supply an alternative character range to the default \fB[:upper:]\fP\&';
the value of the style is treated as the contents of a \fB[\fP\fI\&.\&.\&.\fP\fB]\fP\&'
pattern (note that the outer brackets should not be supplied, only
those surrounding named ranges)\&.
.PP
More control can be obtained using the \fBzstyle\fP command, as described in
\fIzshmodules\fP(1)\&.  Each style is looked up in the
context \fB:zle:\fP\fIwidget\fP where \fIwidget\fP is the name of the
user\-defined widget, not the name of the function implementing it, so in
the case of the definitions supplied by \fBselect\-word\-style\fP the
appropriate contexts are \fB:zle:forward\-word\fP, and so on\&.  The function
\fBselect\-word\-style\fP itself always defines styles for the context
\fB:zle:*\fP\&' which can be overridden by more specific (longer) patterns as
well as explicit contexts\&.
.PP
The style \fBword\-style\fP specifies the rules to use\&.  This may have the
following values\&.
.PP
.PD 0
.TP
.PD
\fBnormal\fP
Use the standard shell rules, i\&.e\&. alphanumerics and \fB$WORDCHARS\fP, unless overridden by the styles \fBword\-chars\fP or \fBword\-class\fP\&. .TP \fBspecified\fP Similar to \fBnormal\fP, but \fIonly\fP the specified characters, and not also alphanumerics, are considered word characters\&. .TP \fBunspecified\fP The negation of specified\&. The given characters are those which will \fInot\fP be considered part of a word\&. .TP \fBshell\fP Words are obtained by using the syntactic rules for generating shell command arguments\&. In addition, special tokens which are never command arguments such as \fB()\fP\&' are also treated as words\&. .TP \fBwhitespace\fP Words are whitespace\-delimited strings of characters\&. .PP The first three of those rules usually use \fB$WORDCHARS\fP, but the value
in the parameter can be overridden by the style \fBword\-chars\fP, which works
in exactly the same way as \fB$WORDCHARS\fP\&. In addition, the style \fBword\-class\fP uses character class syntax to group characters and takes precedence over \fBword\-chars\fP if both are set\&. The \fBword\-class\fP style does not include the surrounding brackets of the character class; for example, \fB\-:[:alnum:]\fP\&' is a valid \fBword\-class\fP to include all alphanumerics plus the characters \fB\-\fP\&' and \fB:\fP'\&. Be careful including \fB]\fP\&', \fB^\fP' and \fB\-\fP' as these are special inside character classes\&. .PP \fBword\-style\fP may also have \fB\-subword\fP\&' appended to its value to turn on subword matching, as described above\&. .PP The style \fBskip\-chars\fP is mostly useful for \fBtranspose\-words\fP and similar functions\&. If set, it gives a count of characters starting at the cursor position which will not be considered part of the word and are treated as space, regardless of what they actually are\&. For example, if .PP .RS .nf \fBzstyle \&':zle:transpose\-words' skip\-chars 1\fP .fi .RE .PP has been set, and \fBtranspose\-words\-match\fP is called with the cursor on the \fIX\fP of \fBfoo\fP\fIX\fP\fBbar\fP, where \fIX\fP can be any character, then the resulting expression is \fBbar\fP\fIX\fP\fBfoo\fP\&. .PP Finer grained control can be obtained by setting the style \fBword\-context\fP to an array of pairs of entries\&. Each pair of entries consists of a \fIpattern\fP and a \fIsubcontext\fP\&. The shell argument the cursor is on is matched against each \fIpattern\fP in turn until one matches; if it does, the context is extended by a colon and the corresponding \fIsubcontext\fP\&. Note that the test is made against the original word on the line, with no stripping of quotes\&. Special handling is done between words: the current context is examined and if it contains the string \fBback\fP, the word before the cursor is considered, else the word after cursor is considered\&. Some examples are given below\&. .PP Here are some examples of use of the styles, actually taken from the simplified interface in \fBselect\-word\-style\fP: .PP .RS .nf \fBzstyle \&':zle:*' word\-style standard zstyle \&':zle:*' word\-chars ''\fP .fi .RE .PP Implements bash\-style word handling for all widgets, i\&.e\&. only alphanumerics are word characters; equivalent to setting the parameter \fBWORDCHARS\fP empty for the given context\&. .PP .RS .nf \fBstyle \&':zle:*kill*' word\-style space\fP .fi .RE .PP Uses space\-delimited words for widgets with the word kill\&' in the name\&. Neither of the styles \fBword\-chars\fP nor \fBword\-class\fP is used in this case\&. .PP Here are some examples of use of the \fBword\-context\fP style to extend the context\&. .PP .RS .nf \fBzstyle \&':zle:*' word\-context "*/*" file "[[:space:]]" whitespace zstyle \&':zle:transpose\-words:whitespace' word\-style shell zstyle \&':zle:transpose\-words:filename' word\-style normal zstyle \&':zle:transpose\-words:filename' word\-chars ''\fP .fi .RE .PP This provides two different ways of using \fBtranspose\-words\fP depending on whether the cursor is on whitespace between words or on a filename, here any word containing a \fB/\fP\&. On whitespace, complete arguments as defined by standard shell rules will be transposed\&. In a filename, only alphanumerics will be transposed\&. Elsewhere, words will be transposed using the default style for \fB:zle:transpose\-words\fP\&. .PP The word matching and all the handling of \fBzstyle\fP settings is actually implemented by the function \fBmatch\-words\-by\-style\fP\&. This can be used to create new user\-defined widgets\&. The calling function should set the local parameter \fBcurcontext\fP to \fB:zle:\fP\fIwidget\fP, create the local parameter \fBmatched_words\fP and call \fBmatch\-words\-by\-style\fP with no arguments\&. On return, \fBmatched_words\fP will be set to an array with the elements: (1) the start of the line (2) the word before the cursor (3) any non\-word characters between that word and the cursor (4) any non\-word character at the cursor position plus any remaining non\-word characters before the next word, including all characters specified by the \fBskip\-chars\fP style, (5) the word at or following the cursor (6) any non\-word characters following that word (7) the remainder of the line\&. Any of the elements may be an empty string; the calling function should test for this to decide whether it can perform its function\&. .PP It is possible to pass options with arguments to \fBmatch\-words\-by\-style\fP to override the use of styles\&. The options are: .PD 0 .TP \fB\-w\fP \fIword\-style\fP .TP \fB\-s\fP \fIskip\-chars\fP .TP \fB\-c\fP \fIword\-class\fP .TP \fB\-C\fP \fIword\-chars\fP .TP \fB\-r\fP \fIsubword\-range\fP .PD .PP For example, \fBmatch\-words\-by\-style \-w shell \-c 0\fP may be used to extract the command argument around the cursor\&. .PP The \fBword\-context\fP style is implemented by the function \fBmatch\-word\-context\fP\&. This should not usually need to be called directly\&. .RE .TP \fBdelete\-whole\-word\-match\fP This is another function which works like the \fB\-match\fP functions described immediately above, i\&.e\&. using styles to decide the word boundaries\&. However, it is not a replacement for any existing function\&. .RS .PP The basic behaviour is to delete the word around the cursor\&. There is no numeric prefix handling; only the single word around the cursor is considered\&. If the widget contains the string \fBkill\fP, the removed text will be placed in the cutbuffer for future yanking\&. This can be obtained by defining \fBkill\-whole\-word\-match\fP as follows: .PP .RS .nf \fBzle \-N kill\-whole\-word\-match delete\-whole\-word\-match\fP .fi .RE .PP and then binding the widget \fBkill\-whole\-word\-match\fP\&. .RE .TP \fBcopy\-earlier\-word\fP This widget works like a combination of \fBinsert\-last\-word\fP and \fBcopy\-prev\-shell\-word\fP\&. Repeated invocations of the widget retrieve earlier words on the relevant history line\&. With a numeric argument \fIN\fP, insert the \fIN\fPth word from the history line; \fIN\fP may be negative to count from the end of the line\&. .RS .PP If \fBinsert\-last\-word\fP has been used to retrieve the last word on a previous history line, repeated invocations will replace that word with earlier words from the same line\&. .PP Otherwise, the widget applies to words on the line currently being edited\&. The \fBwidget\fP style can be set to the name of another widget that should be called to retrieve words\&. This widget must accept the same three arguments as \fBinsert\-last\-word\fP\&. .RE .TP \fBcycle\-completion\-positions\fP After inserting an unambiguous string into the command line, the new function based completion system may know about multiple places in this string where characters are missing or differ from at least one of the possible matches\&. It will then place the cursor on the position it considers to be the most interesting one, i\&.e\&. the one where one can disambiguate between as many matches as possible with as little typing as possible\&. .RS .PP This widget allows the cursor to be easily moved to the other interesting spots\&. It can be invoked repeatedly to cycle between all positions reported by the completion system\&. .RE .TP \fBedit\-command\-line\fP Edit the command line using your visual editor, as in \fBksh\fP\&. .RS .PP .RS .nf \fBbindkey \-M vicmd v edit\-command\-line\fP .fi .RE .RE .TP \fBhistory\-search\-end\fP This function implements the widgets \fBhistory\-beginning\-search\-backward\-end\fP and \fBhistory\-beginning\-search\-forward\-end\fP\&. These commands work by first calling the corresponding builtin widget (see History Control\&' in \fIzshzle\fP(1)) and then moving the cursor to the end of the line\&. The original cursor position is remembered and restored before calling the builtin widget a second time, so that the same search is repeated to look farther through the history\&. .RS .PP Although you \fBautoload\fP only one function, the commands to use it are slightly different because it implements two widgets\&. .PP .RS .nf \fBzle \-N history\-beginning\-search\-backward\-end \e history\-search\-end zle \-N history\-beginning\-search\-forward\-end \e history\-search\-end bindkey \&'\ee^P' history\-beginning\-search\-backward\-end bindkey \&'\ee^N' history\-beginning\-search\-forward\-end\fP .fi .RE .RE .TP \fBhistory\-beginning\-search\-menu\fP This function implements yet another form of history searching\&. The text before the cursor is used to select lines from the history, as for \fBhistory\-beginning\-search\-backward\fP except that all matches are shown in a numbered menu\&. Typing the appropriate digits inserts the full history line\&. Note that leading zeroes must be typed (they are only shown when necessary for removing ambiguity)\&. The entire history is searched; there is no distinction between forwards and backwards\&. .RS .PP With a prefix argument, the search is not anchored to the start of the line; the string typed by the use may appear anywhere in the line in the history\&. .PP If the widget name contains \fB\-end\fP\&' the cursor is moved to the end of the line inserted\&. If the widget name contains \fB\-space\fP\&' any space in the text typed is treated as a wildcard and can match anything (hence a leading space is equivalent to giving a prefix argument)\&. Both forms can be combined, for example: .PP .RS .nf \fBzle \-N history\-beginning\-search\-menu\-space\-end \e history\-beginning\-search\-menu\fP .fi .RE .RE .TP \fBhistory\-pattern\-search\fP The function \fBhistory\-pattern\-search\fP implements widgets which prompt for a pattern with which to search the history backwards or forwards\&. The pattern is in the usual zsh format, however the first character may be \fB^\fP to anchor the search to the start of the line, and the last character may be \fB$\fP to anchor the search to the end of the line\&.  If the
search was not anchored to the end of the line the cursor is positioned
just after the pattern found\&.
.RS
.PP
The commands to create bindable widgets are similar to those in the
example immediately above:
.PP
.RS
.nf
\fBautoload \-U history\-pattern\-search
zle \-N history\-pattern\-search\-backward history\-pattern\-search
zle \-N history\-pattern\-search\-forward history\-pattern\-search\fP
.fi
.RE
.RE
.TP
\fBup\-line\-or\-beginning\-search\fP, \fBdown\-line\-or\-beginning\-search\fP
These widgets are similar to the builtin functions \fBup\-line\-or\-search\fP
and \fBdown\-line\-or\-search\fP:  if in a multiline buffer they move up or
down within the buffer, otherwise they search for a history line matching
the start of the current line\&.  In this case, however, they search for
a line which matches the current line up to the current cursor position, in
the manner of \fBhistory\-beginning\-search\-backward\fP and \fB\-forward\fP, rather
than the first word on the line\&.
.TP
\fBincarg\fP
Typing the keystrokes for this widget with the cursor placed on or to the
left of an integer causes that integer to be incremented by one\&.  With a
numeric prefix argument, the number is incremented by the amount of the
argument (decremented if the prefix argument is negative)\&.  The shell
parameter \fBincarg\fP may be set to change the default increment to
something other than one\&.
.RS
.PP
.RS
.nf
\fBbindkey \&'^X+' incarg\fP
.fi
.RE
.RE
.TP
\fBincremental\-complete\-word\fP
This allows incremental completion of a word\&.  After starting this
command, a list of completion choices can be shown after every character
you type, which you can delete with \fB^H\fP or \fBDEL\fP\&.  Pressing return
accepts the completion so far and returns you to normal editing (that is,
the command line is \fInot\fP immediately executed)\&.  You can hit \fBTAB\fP to
do normal completion, \fB^G\fP to abort back to the state when you started,
and \fB^D\fP to list the matches\&.
.RS
.PP
This works only with the new function based completion system\&.
.PP
.RS
.nf
\fBbindkey \&'^Xi' incremental\-complete\-word\fP
.fi
.RE
.RE
.TP
\fBinsert\-composed\-char\fP
This function allows you to compose characters that don\&'t appear on the
keyboard to be inserted into the command line\&.  The command is followed by
two keys corresponding to ASCII characters (there is no prompt)\&.  For
accented characters, the two keys are a base character followed by a code
for the accent, while for other special characters the two characters
together form a mnemonic for the character to be inserted\&.  The
two\-character codes are a subset of those given by RFC 1345 (see for
example \fBhttp://www\&.faqs\&.org/rfcs/rfc1345\&.html\fP)\&.
.RS
.PP
The function may optionally be followed by up to two characters which
replace one or both of the characters read from the keyboard; if both
characters are supplied, no input is read\&.  For example,
\fBinsert\-composed\-char a:\fP can be used within a widget to insert an a with
umlaut into the command line\&.  This has the advantages over use of a
literal character that it is more portable\&.
.PP
For best results zsh should have been built with support for multibyte
characters (configured with \fB\-\-enable\-multibyte\fP); however, the function
works for the limited range of characters available in single\-byte
character sets such as ISO\-8859\-1\&.
.PP
The character is converted into the local representation and
inserted into the command line at the cursor position\&.
(The conversion is done within the shell, using whatever facilities
the C library provides\&.)  With a numeric argument, the character and its
code are previewed in the status line
.PP
The function may be run outside zle in which case it prints the character
(together with a newline) to standard output\&.  Input is still read from
keystrokes\&.
.PP
See \fBinsert\-unicode\-char\fP for an alternative way of inserting Unicode
characters using their hexadecimal character number\&.
.PP
The set of accented characters is reasonably complete up to Unicode
character U+0180, the set of special characters less so\&.  However, it it
is very sporadic from that point\&.  Adding new characters is easy,
however; see the function \fBdefine\-composed\-chars\fP\&.  Please send any
additions to \fBzsh\-workers@zsh\&.org\fP\&.
.PP
The codes for the second character when used to accent the first are as
follows\&.  Note that not every character can take every accent\&.
.PD 0
.TP
\fB!\fP
Grave\&.
.TP
\fB\&'\fP
Acute\&.
.TP
\fB>\fP
Circumflex\&.
.TP
\fB?\fP
Tilde\&.  (This is not \fB~\fP as RFC 1345 does not assume that
character is present on the keyboard\&.)
.TP
\fB\-\fP
Macron\&.  (A horizontal bar over the base character\&.)
.TP
\fB(\fP
Breve\&.  (A shallow dish shape over the base character\&.)
.TP
\fB\&.\fP
Dot above the base character, or in the case of \fBi\fP no dot,
or in the case of \fBL\fP and \fBl\fP a centered dot\&.
.TP
\fB:\fP
Diaeresis (Umlaut)\&.
.TP
\fBc\fP
Cedilla\&.
.TP
\fB_\fP
Underline, however there are currently no underlined characters\&.
.TP
\fB/\fP
Stroke through the base character\&.
.TP
\fB"\fP
Double acute (only supported on a few letters)\&.
.TP
\fB;\fP
Ogonek\&.  (A little forward facing hook at the bottom right
of the character\&.)
.TP
\fB<\fP
Caron\&.  (A little v over the letter\&.)
.TP
\fB0\fP
Circle over the base character\&.
.TP
\fB2\fP
Hook over the base character\&.
.TP
\fB9\fP
Horn over the base character\&.
.PD
.PP
The most common characters from the Arabic, Cyrillic, Greek and Hebrew
alphabets are available; consult RFC 1345 for the appropriate sequences\&.
In addition, a set of two letter codes not in RFC 1345 are available for
the double\-width characters corresponding to ASCII characters from \fB!\fP
to \fB~\fP (0x21 to 0x7e) by preceding the character with \fB^\fP, for
example \fB^A\fP for a double\-width \fBA\fP\&.
.PP
The following other two\-character sequences are understood\&.
.PP
.PD 0
.TP
.PD
ASCII characters
These are already present on most keyboards:
.PD 0
.TP
\fB<(\fP
Left square bracket
.TP
\fB//\fP
Backslash (solidus)
.TP
\fB)>\fP
Right square bracket
.TP
\fB(!\fP
Left brace (curly bracket)
.TP
\fB!!\fP
Vertical bar (pipe symbol)
.TP
\fB!)\fP
Right brace (curly bracket)
.TP
\fB\&'?\fP
Tilde
.PD
.TP
Special letters
Characters found in various variants of the Latin alphabet:
.PD 0
.TP
\fBss\fP
Eszett (scharfes S)
.TP
\fBD\-\fP, \fBd\-\fP
Eth
.TP
\fBTH\fP, \fBth\fP
Thorn
.TP
\fBkk\fP
Kra
.TP
\fB\&'n\fP
\&'n
.TP
\fBNG\fP, \fBng\fP
Ng
.TP
\fBOI\fP, \fBoi\fP
Oi
.TP
\fByr\fP
yr
.TP
\fBED\fP
ezh
.PD
.TP
Currency symbols
.PD 0
.TP
\fBCt\fP
Cent
.TP
\fBPd\fP
Pound sterling (also lira and others)
.TP
\fBCu\fP
Currency
.TP
\fBYe\fP
Yen
.TP
\fBEu\fP
Euro (N\&.B\&. not in RFC 1345)
.PD
.TP
Punctuation characters
References to "right" quotes indicate the shape (like a 9 rather than 6)
rather than their grammatical use\&.  (For example, a "right" low double
quote is used to open quotations in German\&.)
.PD 0
.TP
\fB!I\fP
Inverted exclamation mark
.TP
\fBBB\fP
Broken vertical bar
.TP
\fBSE\fP
Section
.TP
\fBCo\fP
Copyright
.TP
\fB\-a\fP
Spanish feminine ordinal indicator
.TP
\fB<<\fP
Left guillemet
.TP
\fB\-\fP\fB\-\fP
Soft hyphen
.TP
\fBRg\fP
Registered trade mark
.TP
\fBPI\fP
Pilcrow (paragraph)
.TP
\fB\-o\fP
Spanish masculine ordinal indicator
.TP
\fB>>\fP
Right guillemet
.TP
\fB?I\fP
Inverted question mark
.TP
\fB\-1\fP
Hyphen
.TP
\fB\-N\fP
En dash
.TP
\fB\-M\fP
Em dash
.TP
\fB\-3\fP
Horizontal bar
.TP
\fB:3\fP
Vertical ellipsis
.TP
\fB\&.3\fP
Horizontal midline ellipsis
.TP
\fB!2\fP
Double vertical line
.TP
\fB=2\fP
Double low line
.TP
\fB\&'6\fP
Left single quote
.TP
\fB\&'9\fP
Right single quote
.TP
\fB\&.9\fP
"Right" low quote
.TP
\fB9\&'\fP
Reversed "right" quote
.TP
\fB"6\fP
Left double quote
.TP
\fB"9\fP
Right double quote
.TP
\fB:9\fP
"Right" low double quote
.TP
\fB9"\fP
Reversed "right" double quote
.TP
\fB/\-\fP
Dagger
.TP
\fB/=\fP
Double dagger
.PD
.TP
Mathematical symbols
.PD 0
.TP
\fBDG\fP
Degree
.TP
\fB\-2\fP, \fB+\-\fP, \fB\-+\fP
\- sign, +/\- sign, \-/+ sign
.TP
\fB2S\fP
Superscript 2
.TP
\fB3S\fP
Superscript 3
.TP
\fB1S\fP
Superscript 1
.TP
\fBMy\fP
Micro
.TP
\fB\&.M\fP
Middle dot
.TP
\fB14\fP
Quarter
.TP
\fB12\fP
Half
.TP
\fB34\fP
Three quarters
.TP
\fB*X\fP
Multiplication
.TP
\fB\-:\fP
Division
.TP
\fB%0\fP
Per mille
.TP
\fBFA\fP, \fBTE\fP, \fB/0\fP
For all, there exists, empty set
.TP
\fBdP\fP, \fBDE\fP, \fBNB\fP
Partial derivative, delta (increment), del
(nabla)
.TP
\fB(\-\fP, \fB\-)\fP
Element of, contains
.TP
\fB*P\fP, \fB+Z\fP
Product, sum
.TP
\fB*\-\fP, \fBOb\fP, \fBSb\fP
Asterisk, ring, bullet
.TP
\fBRT\fP, \fB0(\fP, \fB00\fP
Root sign, proportional to, infinity
.PD
.TP
Other symbols
.PD 0
.TP
\fBcS\fP, \fBcH\fP, \fBcD\fP, \fBcC\fP
Card suits: spades, hearts, diamonds,
clubs
.TP
\fBMd\fP, \fBM8\fP, \fBM2\fP, \fBMb\fP, \fBMx\fP, \fBMX\fP
Musical notation:
crotchet (quarter note), quaver (eighth note), semiquavers (sixteenth
notes), flag sign, natural sign, sharp sign
.TP
\fBFm\fP, \fBMl\fP
Female, male
.PD
.TP
Accents on their own
.PD 0
.TP
\fB\&'>\fP
Circumflex (same as caret, \fB^\fP)
.TP
\fB\&'!\fP
Grave (same as backtick, \fB\fP)
.TP
\fB\&',\fP
Cedilla
.TP
\fB\&':\fP
Diaeresis (Umlaut)
.TP
\fB\&'m\fP
Macron
.TP
\fB\&''\fP
Acute
.PD
.RE
.TP
\fBinsert\-files\fP
This function allows you type a file pattern, and see the results of the
expansion at each step\&.  When you hit return, all expansions are inserted
into the command line\&.
.RS
.PP
.RS
.nf
\fBbindkey \&'^Xf' insert\-files\fP
.fi
.RE
.RE
.TP
.PD 0
\fBnarrow\-to\-region [ \-p\fP \fIpre\fP \fB] [ \-P\fP \fIpost\fP \fB]\fP
.TP
.PD 0
\fB[ \-S\fP \fIstatepm\fP \fB| \-R\fP \fIstatepm\fP \fB] [ \-n ] [\fP \fIstart\fP \fIend\fP \fB]\fP)
.TP
.PD
\fBnarrow\-to\-region\-invisible\fP
Narrow the editable portion of the buffer to the region between the cursor
and the mark, which may be in either order\&.  The region may not be empty\&.
.RS
.PP
\fBnarrow\-to\-region\fP may be used as a widget or called as a function from a
user\-defined widget; by default, the text outside the editable area remains
visible\&.  A \fBrecursive\-edit\fP is performed and the original widening
status is then restored\&.  Various options and arguments are available when
it is called as a function\&.
.PP
The options \fB\-p\fP \fIpretext\fP and \fB\-P\fP \fIposttext\fP may be
used to replace the text before and after the display for the duration of
the function; either or both may be an empty string\&.
.PP
If the option \fB\-n\fP is also given, \fIpretext\fP or \fIposttext\fP will only
be inserted if there is text before or after the region respectively which
will be made invisible\&.
.PP
Two numeric arguments may be given which will be used instead of the cursor
and mark positions\&.
.PP
The option \fB\-S\fP \fIstatepm\fP is used to narrow according to the other
options while saving the original state in the parameter with name
\fIstatepm\fP, while the option \fB\-R\fP \fIstatepm\fP is used to restore the
state from the parameter; note in both cases the \fIname\fP of the parameter
is required\&.  In the second case, other options and arguments are
irrelevant\&.  When this method is used, no \fBrecursive\-edit\fP is performed;
the calling widget should call this function with the option \fB\-S\fP,
perform its own editing on the command line or pass control to the user
via \fBzle recursive\-edit\fP\&', then call this function with the option
\fB\-R\fP\&.  The argument \fIstatepm\fP must be a suitable name for an ordinary
parameter, except that parameters beginning with the prefix \fB_ntr_\fP are
reserved for use within \fBnarrow\-to\-region\fP\&.  Typically the parameter will
be local to the calling function\&.
.PP
\fBnarrow\-to\-region\-invisible\fP is a simple widget which calls
\fBnarrow\-to\-region\fP with arguments which replace any text outside the
region with \fB\&.\&.\&.\fP\&'\&.
.PP
The display is restored (and the widget returns) upon any zle command
which would usually cause the line to be accepted or aborted\&.  Hence an
additional such command is required to accept or abort the current line\&.
.PP
The return status of both widgets is zero if the line was accepted, else
non\-zero\&.
.PP
Here is a trivial example of a widget using this feature\&.
.RS
.nf
\fBlocal state
narrow\-to\-region \-p $\&'Editing restricted region\en' \e \-P \&'' \-S state zle recursive\-edit narrow\-to\-region \-R state\fP .fi .RE .RE .TP \fBinsert\-unicode\-char\fP When first executed, the user inputs a set of hexadecimal digits\&. This is terminated with another call to \fBinsert\-unicode\-char\fP\&. The digits are then turned into the corresponding Unicode character\&. For example, if the widget is bound to \fB^XU\fP, the character sequence \fB^XU 4 c ^XU\fP\&' inserts \fBL\fP (Unicode U+004c)\&. .RS .PP See \fBinsert\-composed\-char\fP for a way of inserting characters using a two\-character mnemonic\&. .RE .TP \fBpredict\-on\fP This set of functions implements predictive typing using history search\&. After \fBpredict\-on\fP, typing characters causes the editor to look backward in the history for the first line beginning with what you have typed so far\&. After \fBpredict\-off\fP, editing returns to normal for the line found\&. In fact, you often don\&'t even need to use \fBpredict\-off\fP, because if the line doesn\&'t match something in the history, adding a key performs standard completion, and then inserts itself if no completions were found\&. However, editing in the middle of a line is liable to confuse prediction; see the \fBtoggle\fP style below\&. .RS .PP With the function based completion system (which is needed for this), you should be able to type \fBTAB\fP at almost any point to advance the cursor to the next interesting\&'' character position (usually the end of the current word, but sometimes somewhere in the middle of the word)\&. And of course as soon as the entire line is what you want, you can accept with return, without needing to move the cursor to the end first\&. .PP The first time \fBpredict\-on\fP is used, it creates several additional widget functions: .PP .PD 0 .TP \fBdelete\-backward\-and\-predict\fP Replaces the \fBbackward\-delete\-char\fP widget\&. You do not need to bind this yourself\&. .TP \fBinsert\-and\-predict\fP Implements predictive typing by replacing the \fBself\-insert\fP widget\&. You do not need to bind this yourself\&. .TP \fBpredict\-off\fP Turns off predictive typing\&. .PD .PP Although you \fBautoload\fP only the \fBpredict\-on\fP function, it is necessary to create a keybinding for \fBpredict\-off\fP as well\&. .PP .RS .nf \fBzle \-N predict\-on zle \-N predict\-off bindkey \&'^X^Z' predict\-on bindkey \&'^Z' predict\-off\fP .fi .RE .RE .TP \fBread\-from\-minibuffer\fP This is most useful when called as a function from inside a widget, but will work correctly as a widget in its own right\&. It prompts for a value below the current command line; a value may be input using all of the standard zle operations (and not merely the restricted set available when executing, for example, \fBexecute\-named\-cmd\fP)\&. The value is then returned to the calling function in the parameter \fB$REPLY\fP and the
editing buffer restored to its previous state\&.  If the read was aborted
by a keyboard break (typically \fB^G\fP), the function returns status 1
and \fB$REPLY\fP is not set\&. .RS .PP If one argument is supplied to the function it is taken as a prompt, otherwise \fB? \fP\&' is used\&. If two arguments are supplied, they are the prompt and the initial value of \fB$LBUFFER\fP, and if a third argument is
given it is the initial value of \fB$RBUFFER\fP\&. This provides a default value and starting cursor placement\&. Upon return the entire buffer is the value of \fB$REPLY\fP\&.
.PP
One option is available: \fB\-k\fP \fInum\fP\&' specifies that \fInum\fP
characters are to be read instead of a whole line\&.  The line editor is not
invoked recursively in this case, so depending on the terminal settings
the input may not be visible, and only the input keys are placed in
\fB$REPLY\fP, not the entire buffer\&. Note that unlike the \fBread\fP builtin \fInum\fP must be given; there is no default\&. .PP The name is a slight misnomer, as in fact the shell\&'s own minibuffer is not used\&. Hence it is still possible to call \fBexecuted\-named\-cmd\fP and similar functions while reading a value\&. .RE .TP .PD 0 \fBreplace\-string\fP, \fBreplace\-pattern\fP .TP .PD \fBreplace\-string\-again\fP, \fBreplace\-pattern\-again\fP The function \fBreplace\-string\fP implements three widgets\&. If defined under the same name as the function, it prompts for two strings; the first (source) string will be replaced by the second everywhere it occurs in the line editing buffer\&. .RS .PP If the widget name contains the word \fBpattern\fP\&', for example by defining the widget using the command \fBzle \-N replace\-pattern replace\-string\fP\&', then the matching is performed using zsh patterns\&. All zsh extended globbing patterns can be used in the source string; note that unlike filename generation the pattern does not need to match an entire word, nor do glob qualifiers have any effect\&. In addition, the replacement string can contain parameter or command substitutions\&. Furthermore, a \fB&\fP\&' in the replacement string will be replaced with the matched source string, and a backquoted digit \fB\e\fP\fIN\fP\&' will be replaced by the \fIN\fPth parenthesised expression matched\&. The form \fB\e{\fP\fIN\fP\fB}\fP\&' may be used to protect the digit from following digits\&. .PP If the widget instead contains the word \fBregex\fP\&' (or \fBregexp\fP'), then the matching is performed using regular expressions, respecting the setting of the option \fBRE_MATCH_PCRE\fP (see the description of the function \fBregexp\-replace\fP below)\&. The special replacement facilities described above for pattern matching are available\&. .PP By default the previous source or replacement string will not be offered for editing\&. However, this feature can be activated by setting the style \fBedit\-previous\fP in the context \fB:zle:\fP\fIwidget\fP (for example, \fB:zle:replace\-string\fP) to \fBtrue\fP\&. In addition, a positive numeric argument forces the previous values to be offered, a negative or zero argument forces them not to be\&. .PP The function \fBreplace\-string\-again\fP can be used to repeat the previous replacement; no prompting is done\&. As with \fBreplace\-string\fP, if the name of the widget contains the word \fBpattern\fP\&' or \fBregex\fP', pattern or regular expression matching is performed, else a literal string replacement\&. Note that the previous source and replacement text are the same whether pattern, regular expression or string matching is used\&. .PP For example, starting from the line: .PP .RS .nf \fBprint This line contains fan and fond\fP .fi .RE .PP and invoking \fBreplace\-pattern\fP with the source string \fBf(?)n\fP\&' and the replacement string \fBc\e1r\fP\&' produces the not very useful line: .PP .RS .nf \fBprint This line contains car and cord\fP .fi .RE .PP The range of the replacement string can be limited by using the \fBnarrow\-to\-region\-invisible\fP widget\&. One limitation of the current version is that \fBundo\fP will cycle through changes to the replacement and source strings before undoing the replacement itself\&. .RE .TP \fBsmart\-insert\-last\-word\fP This function may replace the \fBinsert\-last\-word\fP widget, like so: .RS .PP .RS .nf \fBzle \-N insert\-last\-word smart\-insert\-last\-word\fP .fi .RE .PP With a numeric prefix, or when passed command line arguments in a call from another widget, it behaves like \fBinsert\-last\-word\fP, except that words in comments are ignored when \fBINTERACTIVE_COMMENTS\fP is set\&. .PP Otherwise, the rightmost interesting\&'' word from the previous command is found and inserted\&. The default definition of interesting\&'' is that the word contains at least one alphabetic character, slash, or backslash\&. This definition may be overridden by use of the \fBmatch\fP style\&. The context used to look up the style is the widget name, so usually the context is \fB:insert\-last\-word\fP\&. However, you can bind this function to different widgets to use different patterns: .PP .RS .nf \fBzle \-N insert\-last\-assignment smart\-insert\-last\-word zstyle :insert\-last\-assignment match \&'[[:alpha:]][][[:alnum:]]#=*' bindkey \&'\ee=' insert\-last\-assignment\fP .fi .RE .PP If no interesting word is found and the \fBauto\-previous\fP style is set to a true value, the search continues upward through the history\&. When \fBauto\-previous\fP is unset or false (the default), the widget must be invoked repeatedly in order to search earlier history lines\&. .RE .TP \fBtranspose\-lines\fP Only useful with a multi\-line editing buffer; the lines here are lines within the current on\-screen buffer, not history lines\&. The effect is similar to the function of the same name in Emacs\&. .RS .PP Transpose the current line with the previous line and move the cursor to the start of the next line\&. Repeating this (which can be done by providing a positive numeric prefix argument) has the effect of moving the line above the cursor down by a number of lines\&. .PP With a negative numeric prefix argument, requires two lines above the cursor\&. These two lines are transposed and the cursor moved to the start of the previous line\&. Using a numeric prefix less than \-1 has the effect of moving the line above the cursor up by minus that number of lines\&. .RE .TP \fBwhich\-command\fP This function is a drop\-in replacement for the builtin widget \fBwhich\-command\fP\&. It has enhanced behaviour, in that it correctly detects whether or not the command word needs to be expanded as an alias; if so, it continues tracing the command word from the expanded alias until it reaches the command that will be executed\&. .RS .PP The style \fBwhence\fP is available in the context \fB:zle:$WIDGET\fP; this
may be set to an array to give the command and options that will be used to
investigate the command word found\&.  The default is \fBwhence \-c\fP\&.
.RE
.RE
.PP
.SS "Utility Functions"
.PP
These functions are useful in constructing widgets\&.  They
should be loaded with \fBautoload \-U\fP \fIfunction\fP\&' and called
as indicated from user\-defined widgets\&.
.PP
.PD 0
.TP
.PD
\fBsplit\-shell\-arguments\fP
This function splits the line currently being edited into shell arguments
and whitespace\&.  The result is stored in the array \fBreply\fP\&.  The array
contains all the parts of the line in order, starting with any whitespace
before the first argument, and finishing with any whitespace after the last
argument\&.  Hence (so long as the option \fBKSH_ARRAYS\fP is not set)
whitespace is given by odd indices in the array and arguments by
even indices\&.  Note that no stripping of quotes is done; joining together
all the elements of \fBreply\fP in order is guaranteed to produce the
original line\&.
.RS
.PP
The parameter \fBREPLY\fP is set to the index of the word in \fBreply\fP which
contains the character after the cursor, where the first element has index
1\&.  The parameter \fBREPLY2\fP is set to the index of the character under the
cursor in that word, where the first character has index 1\&.
.PP
Hence \fBreply\fP, \fBREPLY\fP and \fBREPLY2\fP should all be made local to
the enclosing function\&.
.PP
See the function \fBmodify\-current\-argument\fP, described below, for
an example of how to call this function\&.
.RE
.TP
\fBmodify\-current\-argument\fP \fIexpr\-using\-\fP\fB$ARG\fP This function provides a simple method of allowing user\-defined widgets to modify the command line argument under the cursor (or immediately to the left of the cursor if the cursor is between arguments)\&. The argument should be an expression which when evaluated operates on the shell parameter \fBARG\fP, which will have been set to the command line argument under the cursor\&. The expression should be suitably quoted to prevent it being evaluated too early\&. .RS .PP For example, a user\-defined widget containing the following code converts the characters in the argument under the cursor into all upper case: .PP .RS .nf \fBmodify\-current\-argument \&'${(U)ARG}'\fP
.fi
.RE
.PP
The following strips any quoting from the current word (whether backslashes
or one of the styles of quotes), and replaces it with single quoting
throughout:
.PP
.RS
.nf
\fBmodify\-current\-argument \&'${(qq)${(Q)ARG}}'\fP
.fi
.RE
.RE
.RE
.PP
.SS "Styles"
.PP
The behavior of several of the above widgets can be controlled by the use
of the \fBzstyle\fP mechanism\&.  In particular, widgets that interact with
the completion system pass along their context to any completions that
they invoke\&.
.PP
.PD 0
.TP
.PD
\fBbreak\-keys\fP
This style is used by the \fBincremental\-complete\-word\fP widget\&. Its value
should be a pattern, and all keys matching this pattern will cause the
widget to stop incremental completion without the key having any further
effect\&. Like all styles used directly by
\fBincremental\-complete\-word\fP, this style is looked up using the
context \fB:incremental\fP\&'\&.
.TP
\fBcompleter\fP
The \fBincremental\-complete\-word\fP and \fBinsert\-and\-predict\fP widgets set
up their top\-level context name before calling completion\&.  This allows
one to define different sets of completer functions for normal completion
and for these widgets\&.  For example, to use completion, approximation and
correction for normal completion, completion and correction for
incremental completion and only completion for prediction one could use:
.RS
.PP
.RS
.nf
\fBzstyle \&':completion:*' completer \e
_complete _correct _approximate
zstyle \&':completion:incremental:*' completer \e
_complete _correct
zstyle \&':completion:predict:*' completer \e
_complete\fP
.fi
.RE
.PP
It is a good idea to restrict the completers used in prediction, because
they may be automatically invoked as you type\&.  The \fB_list\fP and
\fB_menu\fP completers should never be used with prediction\&.  The
\fB_approximate\fP, \fB_correct\fP, \fB_expand\fP, and \fB_match\fP completers may
be used, but be aware that they may change characters anywhere in the word
behind the cursor, so you need to watch carefully that the result is what
you intended\&.
.RE
.TP
\fBcursor\fP
The \fBinsert\-and\-predict\fP widget uses this style, in the context
\fB:predict\fP\&', to decide where to place the cursor after completion has
been tried\&.  Values are:
.RS
.PP
.PD 0
.TP
.PD
\fBcomplete\fP
The cursor is left where it was when completion finished, but only if
it is after a character equal to the one just inserted by the user\&.  If
it is after another character, this value is the same as \fBkey\fP\&'\&.
.TP
\fBkey\fP
The cursor is left
after the \fIn\fPth occurrence of the character just inserted, where
\fIn\fP is the number of times that character appeared in the word
before completion was attempted\&.  In short, this has the effect of
leaving the cursor after the character just typed even if the
completion code found out that no other characters need to be inserted
at that position\&.
.PP
Any other value for this style unconditionally leaves the cursor at the
position where the completion code left it\&.
.RE
.TP
\fBlist\fP
When using the \fBincremental\-complete\-word\fP widget, this style says
if the matches should be listed on every key press (if they fit on the
screen)\&.  Use the context prefix \fB:completion:incremental\fP\&'\&.
.RS
.PP
The \fBinsert\-and\-predict\fP widget uses this style to decide if the
completion should be shown even if there is only one possible completion\&.
This is done if the value of this style is the string \fBalways\fP\&.  In this
case the context is \fB:predict\fP\&' (\fInot\fP \fB:completion:predict\fP')\&.
.RE
.TP
\fBmatch\fP
This style is used by \fBsmart\-insert\-last\-word\fP to provide a pattern
(using full \fBEXTENDED_GLOB\fP syntax) that matches an interesting word\&.
The context is the name of the widget to which \fBsmart\-insert\-last\-word\fP
is bound (see above)\&.  The default behavior of \fBsmart\-insert\-last\-word\fP
is equivalent to:
.RS
.PP
.RS
.nf
\fBzstyle :insert\-last\-word match \&'*[[:alpha:]/\e\e]*'\fP
.fi
.RE
.PP
However, you might want to include words that contain spaces:
.PP
.RS
.nf
\fBzstyle :insert\-last\-word match \&'*[[:alpha:][:space:]/\e\e]*'\fP
.fi
.RE
.PP
Or include numbers as long as the word is at least two characters long:
.PP
.RS
.nf
\fBzstyle :insert\-last\-word match \&'*([[:digit:]]?|[[:alpha:]/\e\e])*'\fP
.fi
.RE
.PP
The above example causes redirections like "2>" to be included\&.
.RE
.TP
\fBprompt\fP
The \fBincremental\-complete\-word\fP widget shows the value of this
style in the status line during incremental completion\&.  The string
value may contain any of the following substrings in the manner of
the \fBPS1\fP and other prompt parameters:
.RS
.PP
.PD 0
.TP
.PD
\fB%c\fP
Replaced by the name of the completer function that generated the
matches (without the leading underscore)\&.
.TP
\fB%l\fP
When the \fBlist\fP style is set,
replaced by \fB\&.\&.\&.\fP\&' if the list of matches is too long to fit on the
screen and with an empty string otherwise\&.  If the \fBlist\fP style is
false\&' or not set, \fB%l\fP' is always removed\&.
.TP
\fB%n\fP
Replaced by the number of matches generated\&.
.TP
\fB%s\fP
Replaced by \fB\-no match\-\fP\&', \fB\-no prefix\-\fP', or an empty string
if there is no completion matching the word on the line, if the
matches have no common prefix different from the word on the line, or
if there is such a common prefix, respectively\&.
.TP
\fB%u\fP
Replaced by the unambiguous part of all matches, if there
is any, and if it is different from the word on the line\&.
.PP
Like \fBbreak\-keys\fP\&', this uses the \fB:incremental\fP' context\&.
.RE
.TP
\fBstop\-keys\fP
This style is used by the \fBincremental\-complete\-word\fP widget\&.  Its value
is treated similarly to the one for the \fBbreak\-keys\fP style (and uses
the same context: \fB:incremental\fP\&')\&.  However, in
this case all keys matching the pattern given as its value will stop
incremental completion and will then execute their usual function\&.
.TP
\fBtoggle\fP
This boolean style is used by \fBpredict\-on\fP and its related widgets in
the context \fB:predict\fP\&'\&.  If set to one of the standard true' values,
predictive typing is automatically toggled off in situations where it is
unlikely to be useful, such as when editing a multi\-line buffer or after
moving into the middle of a line and then deleting a character\&.  The
default is to leave prediction turned on until an explicit call to
\fBpredict\-off\fP\&.
.TP
\fBverbose\fP
This boolean style is used by \fBpredict\-on\fP and its related widgets in
the context \fB:predict\fP\&'\&.  If set to one of the standard true' values,
these widgets display a message below the prompt when the predictive state
is toggled\&.  This is most useful in combination with the \fBtoggle\fP style\&.
The default does not display these messages\&.
.TP
\fBwidget\fP
This style is similar to the \fBcommand\fP style: For widget functions that
use \fBzle\fP to call other widgets, this style can sometimes be used to
override the widget which is called\&.  The context for this style is the
name of the calling widget (\fInot\fP the name of the calling function,
because one function may be bound to multiple widget names)\&.
.RS
.PP
.RS
.nf
\fBzstyle :copy\-earlier\-word widget smart\-insert\-last\-word\fP
.fi
.RE
.PP
Check the documentation for the calling widget or function to determine
whether the \fBwidget\fP style is used\&.
.RE
.RE
.PP
.SH "EXCEPTION HANDLING"
.PP
Two functions are provided to enable zsh to provide exception handling in a
form that should be familiar from other languages\&.
.PP
.PD 0
.TP
.PD
\fBthrow\fP \fIexception\fP
The function \fBthrow\fP throws the named \fIexception\fP\&.  The name is
an arbitrary string and is only used by the \fBthrow\fP and \fBcatch\fP
functions\&.  An exception is for the most part treated the same as a
shell error, i\&.e\&. an unhandled exception will cause the shell to abort all
processing in a function or script and to return to the top level in an
interactive shell\&.
.TP
\fBcatch\fP \fIexception\-pattern\fP
The function \fBcatch\fP returns status zero if an exception was thrown and
the pattern \fIexception\-pattern\fP matches its name\&.  Otherwise it
returns status 1\&.  \fIexception\-pattern\fP is a standard
shell pattern, respecting the current setting of the \fBEXTENDED_GLOB\fP
option\&.  An alias \fBcatch\fP is also defined to prevent the argument to the
function from matching filenames, so patterns may be used unquoted\&.  Note
that as exceptions are not fundamentally different from other shell errors
it is possible to catch shell errors by using an empty string as the
exception name\&.  The shell variable \fBCAUGHT\fP is set by \fBcatch\fP to the
name of the exception caught\&.  It is possible to rethrow an exception by
calling the \fBthrow\fP function again once an exception has been caught\&.
.PP
The functions are designed to be used together with the \fBalways\fP construct
described in
\fIzshmisc\fP(1)\&.  This is important as only this
construct provides the required support for exceptions\&.  A typical example
is as follows\&.
.PP
.RS
.nf
\fB{
# "try" block
# \&.\&.\&. nested code here calls "throw MyExcept"
} always {
# "always" block
if catch MyExcept; then
print "Caught exception MyExcept"
elif catch \&''; then
print "Caught a shell error\&.  Propagating\&.\&.\&."
throw \&''
fi
# Other exceptions are not handled but may be caught further
# up the call stack\&.
}\fP
.fi
.RE
.PP
If all exceptions should be caught, the following idiom might be
preferable\&.
.PP
.RS
.nf
\fB{
# \&.\&.\&. nested code here throws an exception
} always {
if catch *; then
case $CAUGHT in (MyExcept) print "Caught my own exception" ;; (*) print "Caught some other exception" ;; esac fi }\fP .fi .RE .PP In common with exception handling in other languages, the exception may be thrown by code deeply nested inside the try\&' block\&. However, note that it must be thrown inside the current shell, not in a subshell forked for a pipeline, parenthesised current\-shell construct, or some form of command or process substitution\&. .PP The system internally uses the shell variable \fBEXCEPTION\fP to record the name of the exception between throwing and catching\&. One drawback of this scheme is that if the exception is not handled the variable \fBEXCEPTION\fP remains set and may be incorrectly recognised as the name of an exception if a shell error subsequently occurs\&. Adding \fBunset EXCEPTION\fP at the start of the outermost layer of any code that uses exception handling will eliminate this problem\&. .PP .SH "MIME FUNCTIONS" .PP Three functions are available to provide handling of files recognised by extension, for example to dispatch a file \fBtext\&.ps\fP when executed as a command to an appropriate viewer\&. .PP .PD 0 .TP .PD 0 \fBzsh\-mime\-setup\fP [ \fB\-fv\fP ] [ \fB\-l\fP [ \fIsuffix \&.\&.\&.\fP ] ] .TP .PD \fBzsh\-mime\-handler [\-l] \fIcommand arguments \&.\&.\&.\fP\fP These two functions use the files \fB~/\&.mime\&.types\fP and \fB/etc/mime\&.types\fP, which associate types and extensions, as well as \fB~/\&.mailcap\fP and \fB/etc/mailcap\fP files, which associate types and the programs that handle them\&. These are provided on many systems with the Multimedia Internet Mail Extensions\&. .RS .PP To enable the system, the function \fBzsh\-mime\-setup\fP should be autoloaded and run\&. This allows files with extensions to be treated as executable; such files be completed by the function completion system\&. The function \fBzsh\-mime\-handler\fP should not need to be called by the user\&. .PP The system works by setting up suffix aliases with \fBalias \-s\fP\&'\&. Suffix aliases already installed by the user will not be overwritten\&. .PP For suffixes defined in lower case, upper case variants will also automatically be handled (e\&.g\&. \fBPDF\fP is automatically handled if handling for the suffix \fBpdf\fP is defined), but not vice versa\&. .PP Repeated calls to \fBzsh\-mime\-setup\fP do not override the existing mapping between suffixes and executable files unless the option \fB\-f\fP is given\&. Note, however, that this does not override existing suffix aliases assigned to handlers other than \fBzsh\-mime\-handler\fP\&. .PP Calling \fBzsh\-mime\-setup\fP with the option \fB\-l\fP lists the existing mappings without altering them\&. Suffixes to list (which may contain pattern characters that should be quoted from immediate interpretation on the command line) may be given as additional arguments, otherwise all suffixes are listed\&. .PP Calling \fBzsh\-mime\-setup\fP with the option \fB\-v\fP causes verbose output to be shown during the setup operation\&. .PP The system respects the \fBmailcap\fP flags \fBneedsterminal\fP and \fBcopiousoutput\fP, see \fImailcap\fP(4)\&. .PP The functions use the following styles, which are defined with the \fBzstyle\fP builtin command (see \fIzshmodules\fP(1))\&. They should be defined before \fBzsh\-mime\-setup\fP is run\&. The contexts used all start with \fB:mime:\fP, with additional components in some cases\&. It is recommended that a trailing \fB*\fP (suitably quoted) be appended to style patterns in case the system is extended in future\&. Some examples are given below\&. .PD 0 .TP .PD \fBcurrent\-shell\fP If this boolean style is true, the mailcap handler for the context in question is run using the \fBeval\fP builtin instead of by starting a new \fBsh\fP process\&. This is more efficient, but may not work in the occasional cases where the mailcap handler uses strict POSIX syntax\&. .TP \fBexecute\-as\-is\fP This style gives a list of patterns to be matched against files passed for execution with a handler program\&. If the file matches the pattern, the entire command line is executed in its current form, with no handler\&. This is useful for files which might have suffixes but nonetheless be executable in their own right\&. If the style is not set, the pattern \fB*(*) *(/)\fP is used; hence executable files are executed directly and not passed to a handler, and the option \fBAUTO_CD\fP may be used to change to directories that happen to have MIME suffixes\&. .TP \fBfile\-path\fP Used if the style \fBfind\-file\-in\-path\fP is true for the same context\&. Set to an array of directories that are used for searching for the file to be handled; the default is the command path given by the special parameter \fBpath\fP\&. The shell option \fBPATH_DIRS\fP is respected; if that is set, the appropriate path will be searched even if the name of the file to be handled as it appears on the command line contains a \fB/\fP\&'\&. The full context is \fB:mime:\&.\fP\fIsuffix\fP\fB:\fP, as described for the style \fBhandler\fP\&. .TP \fBfind\-file\-in\-path\fP If set, allows files whose names do not contain absolute paths to be searched for in the command path or the path specified by the \fBfile\-path\fP style\&. If the file is not found in the path, it is looked for locally (whether or not the current directory is in the path); if it is not found locally, the handler will abort unless the \fBhandle\-nonexistent\fP style is set\&. Files found in the path are tested as described for the style \fBexecute\-as\-is\fP\&. The full context is \fB:mime:\&.\fP\fIsuffix\fP\fB:\fP, as described for the style \fBhandler\fP\&. .TP \fBflags\fP Defines flags to go with a handler; the context is as for the \fBhandler\fP style, and the format is as for the flags in \fBmailcap\fP\&. .TP \fBhandle\-nonexistent\fP By default, arguments that don\&'t correspond to files are not passed to the MIME handler in order to prevent it from intercepting commands found in the path that happen to have suffixes\&. This style may be set to an array of extended glob patterns for arguments that will be passed to the handler even if they don\&'t exist\&. If it is not explicitly set it defaults to \fB[[:alpha:]]#:/*\fP which allows URLs to be passed to the MIME handler even though they don\&'t exist in that format in the file system\&. The full context is \fB:mime:\&.\fP\fIsuffix\fP\fB:\fP, as described for the style \fBhandler\fP\&. .TP \fBhandler\fP Specifies a handler for a suffix; the suffix is given by the context as \fB:mime:\&.\fP\fIsuffix\fP\fB:\fP, and the format of the handler is exactly that in \fBmailcap\fP\&. Note in particular the \fB\&.\fP\&' and trailing colon to distinguish this use of the context\&. This overrides any handler specified by the \fBmailcap\fP files\&. If the handler requires a terminal, the \fBflags\fP style should be set to include the word \fBneedsterminal\fP, or if the output is to be displayed through a pager (but not if the handler is itself a pager), it should include \fBcopiousoutput\fP\&. .TP \fBmailcap\fP A list of files in the format of \fB~/\&.mailcap\fP and \fB/etc/mailcap\fP to be read during setup, replacing the default list which consists of those two files\&. The context is \fB:mime:\fP\&. A \fB+\fP in the list will be replaced by the default files\&. .TP \fBmailcap\-priorities\fP This style is used to resolve multiple mailcap entries for the same MIME type\&. It consists of an array of the following elements, in descending order of priority; later entries will be used if earlier entries are unable to resolve the entries being compared\&. If none of the tests resolve the entries, the first entry encountered is retained\&. .RS .PP .PD 0 .TP .PD \fBfiles\fP The order of files (entries in the \fBmailcap\fP style) read\&. Earlier files are preferred\&. (Note this does not resolve entries in the same file\&.) .TP \fBpriority\fP The priority flag from the mailcap entry\&. The priority is an integer from 0 to 9 with the default value being 5\&. .TP \fBflags\fP The test given by the \fBmailcap\-prio\-flags\fP option is used to resolve entries\&. .TP \fBplace\fP Later entries are preferred; as the entries are strictly ordered, this test always succeeds\&. .PP Note that as this style is handled during initialisation, the context is always \fB:mime:\fP, with no discrimination by suffix\&. .RE .TP \fBmailcap\-prio\-flags\fP This style is used when the keyword \fBflags\fP is encountered in the list of tests specified by the \fBmailcap\-priorities\fP style\&. It should be set to a list of patterns, each of which is tested against the flags specified in the mailcap entry (in other words, the sets of assignments found with some entries in the mailcap file)\&. Earlier patterns in the list are preferred to later ones, and matched patterns are preferred to unmatched ones\&. .TP \fBmime\-types\fP A list of files in the format of \fB~/\&.mime\&.types\fP and \fB/etc/mime\&.types\fP to be read during setup, replacing the default list which consists of those two files\&. The context is \fB:mime:\fP\&. A \fB+\fP in the list will be replaced by the default files\&. .TP \fBnever\-background\fP If this boolean style is set, the handler for the given context is always run in the foreground, even if the flags provided in the mailcap entry suggest it need not be (for example, it doesn\&'t require a terminal)\&. .TP \fBpager\fP If set, will be used instead of \fB$PAGER\fP or \fBmore\fP to handle
suffixes where the \fBcopiousoutput\fP flag is set\&.  The context is
as for \fBhandler\fP, i\&.e\&. \fB:mime:\&.\fP\fIsuffix\fP\fB:\fP for handling
a file with the given \fIsuffix\fP\&.
.PP
Examples:
.PP
.RS
.nf
\fBzstyle \&':mime:*' mailcap ~/\&.mailcap /usr/local/etc/mailcap
zstyle \&':mime:\&.txt:' handler less %s
zstyle \&':mime:\&.txt:' flags needsterminal\fP
.fi
.RE
.PP
When \fBzsh\-mime\-setup\fP is subsequently run, it will look for
\fBmailcap\fP entries in the two files given\&.  Files of suffix \fB\&.txt\fP
will be handled by running \fBless\fP \fIfile\&.txt\fP\&'\&.  The flag
\fBneedsterminal\fP is set to show that this program must run attached to a
terminal\&.
.PP
As there are several steps to dispatching a command, the following
should be checked if attempting to execute a file by extension
\fB\&.\fP\fIext\fP does not have the expected effect\&.
.PP
The command \fBalias \-s\fP \fIext\fP\&' should show
\fBps=zsh\-mime\-handler\fP\&'\&.  If it shows something else, another suffix
alias was already installed and was not overwritten\&.  If it shows
nothing, no handler was installed:  this is most likely because no
handler was found in the \fB\&.mime\&.types\fP and \fBmailcap\fP combination for
\fB\&.ext\fP files\&.  In that case, appropriate handling should be added to
\fB~/\&.mime\&.types\fP and \fBmailcap\fP\&.
.PP
If the extension is handled by \fBzsh\-mime\-handler\fP but the file is
not opened correctly, either the handler defined for the type is
incorrect, or the flags associated with it are in appropriate\&.  Running
\fBzsh\-mime\-setup \-l\fP will show the handler and, if there are any, the
flags\&.  A \fB%s\fP in the handler is replaced by the file (suitably quoted
if necessary)\&.  Check that the handler program listed lists and can
be run in the way shown\&.  Also check that the flags \fBneedsterminal\fP or
\fBcopiousoutput\fP are set if the handler needs to be run under a
terminal; the second flag is used if the output should be sent to a pager\&.
An example of a suitable \fBmailcap\fP entry for such a program is:
.PP
.RS
.nf
\fBtext/html; /usr/bin/lynx \&'%s'; needsterminal\fP
.fi
.RE
.PP
Running \fBzsh\-mime\-handler \-l\fP \fIcommand line\fP\&' prints the command
line that would be executed, simplified to remove the effect of any
flags, and quoted so that the output can be run as a complete zsh
command line\&.  This is used by the completion system to decide how to
complete after a file handled by \fBzsh\-mime\-setup\fP\&.
.RE
.TP
\fBpick\-web\-browser\fP
This function is separate from the two MIME functions described above
and can be assigned directly to a suffix:
.RS
.PP
.RS
.nf
\fBautoload \-U pick\-web\-browser
alias \-s html=pick\-web\-browser\fP
.fi
.RE
.PP
It is provided as an intelligent front end to dispatch a web browser\&.
It may be run as either a function or a shell script\&.  The status
255 is returned if no browser could be started\&.
.PP
Various styles are available to customize the choice of browsers:
.PP
.PD 0
.TP
.PD
\fBbrowser\-style\fP
The value of the style is an array giving preferences in decreasing order
for the type of browser to use\&.  The values of elements may be
.RS
.PP
.PD 0
.TP
.PD
\fBrunning\fP
Use a GUI browser that is already running when an X Window display is
available\&.  The browsers listed in the \fBx\-browsers\fP style are tried
in order until one is found; if it is, the file will be displayed in
that browser, so the user may need to check whether it has appeared\&.
If no running browser is found, one is not started\&.  Browsers other than
Firefox, Opera and Konqueror are assumed to understand the Mozilla
syntax for opening a URL remotely\&.
.TP
\fBx\fP
Start a new GUI browser when an X Window display is available\&.  Search for
the availability of one of the browsers listed in the \fBx\-browsers\fP style
and start the first one that is found\&.  No check is made for an already
running browser\&.
.TP
\fBtty\fP
Start a terminal\-based browser\&.  Search for the availability of one
of the browsers listed in the \fBtty\-browsers\fP style and start the
first one that is found\&.
.PP
If the style is not set the default \fBrunning x tty\fP is used\&.
.RE
.TP
\fBx\-browsers\fP
An array in decreasing order
of preference of browsers to use when running under the X Window System\&.
The array consists of the command name under which to start the
browser\&.  They are looked up in the context \fB:mime:\fP (which may
be extended in future, so appending \fB*\fP\&' is recommended)\&.  For
example,
.RS
.PP
.RS
.nf
\fBzstyle \&':mime:*' x\-browsers opera konqueror firefox\fP
.fi
.RE
.PP
specifies that \fBpick\-web\-browser\fP should first look for a running
instance of Opera, Konqueror or Firefox, in that order, and if it
fails to find any should attempt to start Opera\&.  The default is
\fBfirefox mozilla netscape opera konqueror\fP\&.
.RE
.TP
\fBtty\-browsers\fP
An array similar to \fBx\-browsers\fP, except that it gives browsers to
use use when no X Window display is available\&.  The default is
\fBelinks links lynx\fP\&.
.TP
\fBcommand\fP
If it is set this style is used to pick the command
used to open a page for a browser\&.  The context is
\fB:mime:browser:new:$browser:\fP to start a new browser or \fB:mime:browser:running:$browser:\fP to open a URL in a browser already
running on the current X display, where \fB$browser\fP is the value matched in the \fBx\-browsers\fP or \fBtty\-browsers\fP style\&. The escape sequence \fB%b\fP in the style\&'s value will be replaced by the browser, while \fB%u\fP will be replaced by the URL\&. If the style is not set, the default for all new instances is equivalent to \fB%b %u\fP and the defaults for using running browsers are equivalent to the values \fBkfmclient openURL %u\fP for Konqueror, \fBfirefox \-new\-tab %u\fP for Firefox, \fBopera \-newpage %u\fP for Opera, and \fB%b \-remote "openUrl(%u)"\fP for all others\&. .RE .RE .PP .SH "MATHEMATICAL FUNCTIONS" .PP .PD 0 .TP .PD \fBzcalc\fP [ \fIexpression\fP \&.\&.\&. ] A reasonably powerful calculator based on zsh\&'s arithmetic evaluation facility\&. The syntax is similar to that of formulae in most programming languages; see the section Arithmetic Evaluation\&' in \fIzshmisc\fP(1) for details\&. The mathematical library \fBzsh/mathfunc\fP will be loaded if it is available; see the section The zsh/mathfunc Module\&' in \fIzshmodules\fP(1)\&. The mathematical functions correspond to the raw system libraries, so trigonometric functions are evaluated using radians, and so on\&. .RS .PP Each line typed is evaluated as an expression\&. The prompt shows a number, which corresponds to a positional parameter where the result of that calculation is stored\&. For example, the result of the calculation on the line preceded by \fB4> \fP\&' is available as \fB$4\fP\&.  The last value
calculated is available as \fBans\fP\&.  Full command line editing, including
the history of previous calculations, is available; the history is saved in
the file \fB~/\&.zcalc_history\fP\&.  To exit, enter a blank line or type \fB:q\fP\&'
on its own (\fBq\fP\&' is allowed for historical compatibility)\&.
.PP
If arguments are given to \fBzcalc\fP on start up, they are used to prime the
first few positional parameters\&.  A visual indication of this is given when
the calculator starts\&.
.PP
The constants \fBPI\fP (3\&.14159\&.\&.\&.) and \fBE\fP (2\&.71828\&.\&.\&.) are provided\&.
Parameter assignment is possible, but note that all parameters will be put
into the global namespace\&.
.PP
The output base can be initialised by passing the option \fB\-#\fP\fIbase\fP\&',
for example \fBzcalc \-#16\fP\&' (the \fB#\fP' may have to be quoted, depending
on the globbing options set)\&.
.PP
The prompt is configurable via the parameter \fBZCALCPROMPT\fP, which
undergoes standard prompt expansion\&.  The index of the current entry is
stored locally in the first element of the array \fBpsvar\fP, which can be
referred to in \fBZCALCPROMPT\fP as \fB%1v\fP\&'\&.  The default prompt is
\fB%1v> \fP\&'\&.
.PP
A few special commands are available; these are introduced by a colon\&.
For backward compatibility, the colon may be omitted for certain
commands\&.  Completion is available if \fBcompinit\fP has been run\&.
.PP
The output precision may be specified within zcalc by special commands
familiar from many calculators\&.
.PD 0
.TP
.PD
\fB:norm\fP
The default output format\&.  It corresponds to the printf \fB%g\fP
specification\&.  Typically this shows six decimal digits\&.
.TP
\fB:sci\fP \fIdigits\fP
Scientific notation, corresponding to the printf \fB%g\fP output format with
the precision given by \fIdigits\fP\&.  This produces either fixed point or
exponential notation depending on the value output\&.
.TP
\fB:fix\fP \fIdigits\fP
Fixed point notation, corresponding to the printf \fB%f\fP output format with
the precision given by \fIdigits\fP\&.
.TP
\fB:eng\fP \fIdigits\fP
Exponential notation, corresponding to the printf \fB%E\fP output format with
the precision given by \fIdigits\fP\&.
.TP
\fB:raw\fP
Raw output:  this is the default form of the output from a math
evaluation\&.  This may show more precision than the number actually
possesses\&.
.PP
Other special commands:
.PD 0
.TP
.PD
\fB:!\fP\fIline\&.\&.\&.\fP
Execute \fIline\&.\&.\&.\fP as a normal shell command line\&.  Note that it
is executed in the context of the function, i\&.e\&. with local variables\&.
Space is optional after \fB:!\fP\&.
.TP
\fB:local\fP \fIarg\fP \&.\&.\&.
Declare variables local to the function\&.  Note that certain variables
are used by the function for its own purposes\&.  Other variables
may be used, too, but they will be taken from or put into the global
scope\&.
.TP
\fB:function\fP \fIname\fP [ \fIbody\fP ]
Define a mathematical function or (with no \fIbody\fP) delete it\&.
The function is defined using \fBzmathfuncdef\fP, see below\&.
.RS
.PP
Note that \fBzcalc\fP takes care of all quoting\&.  Hence for example:
.PP
.RS
.nf
\fBfunction cube $1 *$1 * $1\fP .fi .RE .PP defines a function to cube the sole argument\&. .RE .TP \fB[#\fP\fIbase\fP\fB]\fP This is not a special command, rather part of normal arithmetic syntax; however, when this form appears on a line by itself the default output radix is set to \fIbase\fP\&. Use, for example, \fB[#16]\fP\&' to display hexadecimal output preceded by an indication of the base, or \fB[##16]\fP\&' just to display the raw number in the given base\&. Bases themselves are always specified in decimal\&. \fB[#]\fP\&' restores the normal output format\&. Note that setting an output base suppresses floating point output; use \fB[#]\fP\&' to return to normal operation\&. .PP See the comments in the function for a few extra tips\&. .RE .TP \fBzmathfuncdef\fP [ \fImathfunc\fP [ \fIbody\fP ] ] A convenient front end to \fBfunctions \-M\fP\&. .RS .PP With two arguments, define a mathematical function named \fImathfunc\fP which can be used in any form of arithmetic evaluation\&. \fIbody\fP is a mathematical expression to implement the function\&. It may contain references to position parameters \fB$1\fP, \fB$2\fP, \&.\&.\&. to refer to mandatory parameters and \fB${1:\-\fP\fIdefvalue\fP\fB}\fP \&.\&.\&.
to refer to optional parameters\&.  Note that the forms must be
strictly adhered to for the function to calculate the correct number
of arguments\&.  The implementation is held in a shell function named
\fBzsh_math_func_\fP\fImathfunc\fP; usually the user will not need
to refer to the shell function directly\&.  Any existing function
of the same name is silently replaced\&.
.PP
With one argument, remove the mathematical function \fImathfunc\fP
as well as the shell function implementation\&.
.PP
With no arguments, list all \fImathfunc\fP functions in a form
suitable for restoring the definition\&.
The functions have not necessarily been defined by \fBzmathfuncdef\fP\&.
.RE
.RE
.PP
.SH "USER CONFIGURATION FUNCTIONS"
.PP
The \fBzsh/newuser\fP module comes with a function to aid in configuring
shell options for new users\&.  If the module is installed, this function can
also be run by hand\&.  It is available even if the module\&'s default
behaviour, namely running the function for a new user logging in without
startup files, is inhibited\&.
.PP
.PD 0
.TP
.PD
\fBzsh\-newuser\-install\fP [ \fB\-f\fP ]
The function presents the user with various options for customizing
their initialization scripts\&.  Currently only \fB~/\&.zshrc\fP is handled\&.
\fB$ZDOTDIR/\&.zshrc\fP is used instead if the parameter \fBZDOTDIR\fP is set; this provides a way for the user to configure a file without altering an existing \fB\&.zshrc\fP\&. .RS .PP By default the function exits immediately if it finds any of the files \fB\&.zshenv\fP, \fB\&.zprofile\fP, \fB\&.zshrc\fP, or \fB\&.zlogin\fP in the appropriate directory\&. The option \fB\-f\fP is required in order to force the function to continue\&. Note this may happen even if \fB\&.zshrc\fP itself does not exist\&. .PP As currently configured, the function will exit immediately if the user has root privileges; this behaviour cannot be overridden\&. .PP Once activated, the function\&'s behaviour is supposed to be self\-explanatory\&. Menus are present allowing the user to alter the value of options and parameters\&. Suggestions for improvements are always welcome\&. .PP When the script exits, the user is given the opportunity to save the new file or not; changes are not irreversible until this point\&. However, the script is careful to restrict changes to the file only to a group marked by the lines \fB# Lines configured by zsh\-newuser\-install\fP\&' and \fB# End of lines configured by zsh\-newuser\-install\fP\&'\&. In addition, the old version of \fB\&.zshrc\fP is saved to a file with the suffix \fB\&.zni\fP appended\&. .PP If the function edits an existing \fB\&.zshrc\fP, it is up to the user to ensure that the changes made will take effect\&. For example, if control usually returns early from the existing \fB\&.zshrc\fP the lines will not be executed; or a later initialization file may override options or parameters, and so on\&. The function itself does not attempt to detect any such conflicts\&. .RE .RE .PP .SH "OTHER FUNCTIONS" .PP There are a large number of helpful functions in the \fBFunctions/Misc\fP directory of the zsh distribution\&. Most are very simple and do not require documentation here, but a few are worthy of special mention\&. .PP .SS "Descriptions" .PP .PD 0 .TP .PD \fBcolors\fP This function initializes several associative arrays to map color names to (and from) the ANSI standard eight\-color terminal codes\&. These are used by the prompt theme system (see above)\&. You seldom should need to run \fBcolors\fP more than once\&. .RS .PP The eight base colors are: black, red, green, yellow, blue, magenta, cyan, and white\&. Each of these has codes for foreground and background\&. In addition there are eight intensity attributes: bold, faint, standout, underline, blink, reverse, and conceal\&. Finally, there are six codes used to negate attributes: none (reset all attributes to the defaults), normal (neither bold nor faint), no\-standout, no\-underline, no\-blink, and no\-reverse\&. .PP Some terminals do not support all combinations of colors and intensities\&. .PP The associative arrays are: .PP .PD 0 .TP .PD 0 color .TP .PD colour Map all the color names to their integer codes, and integer codes to the color names\&. The eight base names map to the foreground color codes, as do names prefixed with \fBfg\-\fP\&', such as \fBfg\-red\fP'\&. Names prefixed with \fBbg\-\fP\&', such as \fBbg\-blue\fP', refer to the background codes\&. The reverse mapping from code to color yields base name for foreground codes and the \fBbg\-\fP form for backgrounds\&. .RS .PP Although it is a misnomer to call them colors\&', these arrays also map the other fourteen attributes from names to codes and codes to names\&. .RE .TP .PD 0 fg .TP .PD 0 fg_bold .TP .PD fg_no_bold Map the eight basic color names to ANSI terminal escape sequences that set the corresponding foreground text properties\&. The \fBfg\fP sequences change the color without changing the eight intensity attributes\&. .TP .PD 0 bg .TP .PD 0 bg_bold .TP .PD bg_no_bold Map the eight basic color names to ANSI terminal escape sequences that set the corresponding background properties\&. The \fBbg\fP sequences change the color without changing the eight intensity attributes\&. .PP In addition, the scalar parameters \fBreset_color\fP and \fBbold_color\fP are set to the ANSI terminal escapes that turn off all attributes and turn on bold intensity, respectively\&. .RE .TP \fBfned\fP \fIname\fP Same as \fBzed \-f\fP\&. This function does not appear in the zsh distribution, but can be created by linking \fBzed\fP to the name \fBfned\fP in some directory in your \fBfpath\fP\&. .TP \fBis\-at\-least\fP \fIneeded\fP [ \fIpresent\fP ] Perform a greater\-than\-or\-equal\-to comparison of two strings having the format of a zsh version number; that is, a string of numbers and text with segments separated by dots or dashes\&. If the \fIpresent\fP string is not provided, \fB$ZSH_VERSION\fP is used\&.  Segments are paired left\-to\-right in
the two strings with leading non\-number parts ignored\&.  If one string has
fewer segments than the other, the missing segments are considered zero\&.
.RS
.PP
This is useful in startup files to set options and other state that are
not available in all versions of zsh\&.
.PP
.RS
.nf
\fBis\-at\-least 3\&.1\&.6\-15 && setopt NO_GLOBAL_RCS
is\-at\-least 3\&.1\&.0 && setopt HIST_REDUCE_BLANKS
is\-at\-least 2\&.6\-17 || print "You can\&'t use is\-at\-least here\&."\fP
.fi
.RE
.RE
.TP
\fBnslookup\fP [ \fIarg\fP \&.\&.\&. ]
This wrapper function for the \fBnslookup\fP command requires the
\fBzsh/zpty\fP module (see
\fIzshmodules\fP(1))\&.  It behaves exactly like the standard \fBnslookup\fP
except that it provides customizable prompts (including a right\-side
prompt) and completion of nslookup commands, host names, etc\&. (if you use
the function\-based completion system)\&.  Completion styles may be set with
the context prefix \fB:completion:nslookup\fP\&'\&.
.RS
.PP
See also the \fBpager\fP, \fBprompt\fP and \fBrprompt\fP styles below\&.
.RE
.TP
\fBregexp\-replace\fP \fIvar\fP \fIregexp\fP \fIreplace\fP
Use regular expressions to perform a global search and replace operation
on a variable\&.  If the option \fBRE_MATCH_PCRE\fP is not set, POSIX
extended regular expressions are used, else Perl\-compatible regular
expressions (this requires the shell to be linked against the \fBpcre\fP
library)\&.
.RS
.PP
\fIvar\fP is the name of the variable containing the string to be matched\&.
The variable will be modified directly by the function\&.  The
variables \fBMATCH\fP, \fBMBEGIN\fP, \fBMEND\fP, \fBmatch\fP, \fBmbegin\fP, \fBmend\fP
should be avoided as these are used by the regular expression code\&.
.PP
\fIregexp\fP is the regular expression to match against the string\&.
.PP
\fIreplace\fP is the replacement text\&.  This can contain parameter, command
and arithmetic expressions which will be replaced:  in particular, a
reference to \fB$MATCH\fP will be replaced by the text matched by the pattern\&. .PP The return status is 0 if at least one match was performed, else 1\&. .RE .TP \fBrun\-help\fP \fIcmd\fP This function is designed to be invoked by the \fBrun\-help\fP ZLE widget, in place of the default alias\&. See Accessing On\-Line Help\&' above for setup instructions\&. .RS .PP In the discussion which follows, if \fIcmd\fP is a file system path, it is first reduced to its rightmost component (the file name)\&. .PP Help is first sought by looking for a file named \fIcmd\fP in the directory named by the \fBHELPDIR\fP parameter\&. If no file is found, an assistant function, alias, or command named \fBrun\-help\-\fIcmd\fP\fP is sought\&. If found, the assistant is executed with the rest of the current command line (everything after the command name \fIcmd\fP) as its arguments\&. When neither file nor assistant is found, the external command \fBman\fP \fIcmd\fP\&' is run\&. .PP An example assistant for the "ssh" command: .PP .RS .nf \fBrun\-help\-ssh() { emulate \-LR zsh local \-a args # Delete the "\-l username" option zparseopts \-D \-E \-a args l: # Delete other options, leaving: host command args=(${@:#\-*})
if [[ ${#args} \-lt 2 ]]; then man ssh else run\-help$args[2]
fi
}\fP
.fi
.RE
.PP
Several of these assistants are provided in the \fBFunctions/Misc\fP
directory\&.  These must be autoloaded, or placed as executable scripts in
your search path, in order to be found and used by \fBrun\-help\fP\&.
.PP
.PD 0
.TP
.PD 0
\fBrun\-help\-git\fP
.TP
.PD 0
\fBrun\-help\-svk\fP
.TP
.PD
\fBrun\-help\-svn\fP
Assistant functions for the \fBgit\fP, \fBsvk\fP, and \fBsvn\fP commands\&.
.RE
.TP
\fBtetris\fP
Zsh was once accused of not being as complete as Emacs,
because it lacked a Tetris game\&.  This function was written to
refute this vicious slander\&.
.RS
.PP
This function must be used as a ZLE widget:
.PP
.RS
.nf
\fBautoload \-U tetris
zle \-N tetris
bindkey \fIkeys\fP tetris\fP
.fi
.RE
.PP
To start a game, execute the widget by typing the \fIkeys\fP\&.  Whatever command
line you were editing disappears temporarily, and your keymap is also
temporarily replaced by the Tetris control keys\&.  The previous editor state
is restored when you quit the game (by pressing \fBq\fP\&') or when you lose\&.
.PP
If you quit in the middle of a game, the next invocation of the \fBtetris\fP
widget will continue where you left off\&.  If you lost, it will start a new
game\&.
.RE
.TP
\fBzargs\fP [ \fIoption\fP \&.\&.\&. \fB\-\fP\fB\-\fP ] [ \fIinput\fP \&.\&.\&. ] [ \fB\-\fP\fB\-\fP \fIcommand\fP [ \fIarg\fP \&.\&.\&. ] ]
This function works like GNU xargs, except that instead of reading lines
of arguments from the standard input, it takes them from the command line\&.
This is useful because zsh, especially with recursive glob operators,
often can construct a command line for a shell function that is longer
than can be accepted by an external command\&.
.RS
.PP
The \fIoption\fP list represents options of the \fBzargs\fP command itself,
which are the same as those of \fBxargs\fP\&.  The \fIinput\fP list is the
collection of strings (often file names) that become the arguments of the
\fBcommand\fP, analogous to the standard input of \fBxargs\fP\&.  Finally, the
\fIarg\fP list consists of those arguments (usually options) that are
passed to the \fIcommand\fP each time it runs\&.  The \fIarg\fP list precedes
the elements from the \fBinput\fP list in each run\&.  If no \fIcommand\fP is
provided, then no \fIarg\fP list may be provided, and in that event the
default command is \fBprint\fP\&' with arguments \fB\-r \-\fP\fB\-\fP'\&.
.PP
For example, to get a long \fBls\fP listing of all plain files in the
current directory or its subdirectories:
.PP
.RS
.nf
\fBautoload \-U zargs
zargs \-\- **/*(\&.) \-\- ls \-l\fP
.fi
.RE
.PP
Note that \fB\-\fP\fB\-\fP\&' is used both to mark the end of the \fIoption\fP
list and to mark the end of the \fIinput\fP list, so it must appear twice
whenever the \fIinput\fP list may be empty\&.  If there is guaranteed to be
at least one \fIinput\fP and the first \fIinput\fP does not begin with a
\fB\-\fP\&', then the first \fB\-\fP\fB\-\fP' may be omitted\&.
.PP
In the event that the string \fB\-\fP\fB\-\fP\&' is or may be an \fIinput\fP, the
\fB\-e\fP option may be used to change the end\-of\-inputs marker\&.  Note that
this does \fInot\fP change the end\-of\-options marker\&.  For example, to use
\fB\&.\&.\fP\&' as the marker:
.PP
.RS
.nf
\fBzargs \-e\&.\&. \-\- **/*(\&.) \&.\&. ls \-l\fP
.fi
.RE
.PP
This is a good choice in that example because no plain file can be named
\fB\&.\&.\fP\&', but the best end\-marker depends on the circumstances\&.
.PP
For details of the other \fBzargs\fP options, see \fIxargs\fP(1) or run
\fBzargs\fP with the \fB\-\fP\fB\-help\fP option\&.
.RE
.TP
.PD 0
\fBzed\fP [ \fB\-f\fP ] \fIname\fP
.TP
.PD
\fBzed \-b\fP
This function uses the ZLE editor to edit a file or function\&.
.RS
.PP
Only one \fIname\fP argument is allowed\&.
If the \fB\-f\fP option is given, the name is taken to be that of
a function; if the function is marked for autoloading, \fBzed\fP searches
for it in the \fBfpath\fP and loads it\&.  Note that functions edited this way
are installed into the current shell, but \fInot\fP written back to the
autoload file\&.
.PP
Without \fB\-f\fP, \fIname\fP is the path name of the file to edit, which need
not exist; it is created on write, if necessary\&.
.PP
While editing, the function sets the main keymap to \fBzed\fP and the
vi command keymap to \fBzed\-vicmd\fP\&.  These will be copied from the existing
\fBmain\fP and \fBvicmd\fP keymaps if they do not exist the first time \fBzed\fP
is run\&.  They can be used to provide special key bindings used only in zed\&.
.PP
If it creates the keymap, \fBzed\fP rebinds the return key to insert a line
break and \fB^X^W\fP\&' to accept the edit in the \fBzed\fP keymap, and binds
\fBZZ\fP\&' to accept the edit in the \fBzed\-vicmd\fP keymap\&.
.PP
The bindings alone can be installed by running \fBzed \-b\fP\&'\&.  This is
suitable for putting into a startup file\&.  Note that, if rerun,
this will overwrite the existing \fBzed\fP and \fBzed\-vicmd\fP keymaps\&.
.PP
Completion is available, and styles may be set with the context prefix
\fB:completion:zed\fP\&'\&.
.PP
A zle widget \fBzed\-set\-file\-name\fP is available\&.  This can be called by
name from within zed using \fB\eex zed\-set\-file\-name\fP\&' (note, however, that
because of zed\&'s rebindings you will have to type \fB^j\fP at the end instead
of the return key), or can be bound to a key in either of the \fBzed\fP or
\fBzed\-vicmd\fP keymaps after \fBzed \-b\fP\&' has been run\&.  When the widget is
called, it prompts for a new name for the file being edited\&.  When zed
exits the file will be written under that name and the original file will
be left alone\&.  The widget has no effect with \fBzed \-f\fP\&'\&.
.PP
While \fBzed\-set\-file\-name\fP is running, zed uses the keymap
\fBzed\-normal\-keymap\fP, which is linked from the main keymap in effect
at the time zed initialised its bindings\&.  (This is to make the return key
operate normally\&.)  The result is that if the main keymap has been changed,
the widget won\&'t notice\&.  This is not a concern for most users\&.
.RE
.TP
.PD 0
\fBzcp\fP [ \fB\-finqQvwW\fP ] \fIsrcpat\fP \fIdest\fP
.TP
.PD
\fBzln\fP [ \fB\-finqQsvwW\fP ] \fIsrcpat\fP \fIdest\fP
Same as \fBzmv \-C\fP and \fBzmv \-L\fP, respectively\&.  These functions do not
appear in the zsh distribution, but can be created by linking \fBzmv\fP to
the names \fBzcp\fP and \fBzln\fP in some directory in your \fBfpath\fP\&.
.TP
\fBzkbd\fP
See Keyboard Definition\&'
above\&.
.TP
\fBzmv\fP [ \fB\-finqQsvwW\fP ] [ \-C | \-L | \-M | \-p \fIprogram\fP ] [ \-o \fIoptstring\fP ] \fIsrcpat\fP \fIdest\fP
Move (usually, rename) files matching the pattern \fIsrcpat\fP to
corresponding files having names of the form given by \fIdest\fP, where
\fIsrcpat\fP contains parentheses surrounding patterns which will be
replaced in turn by $1,$2, \&.\&.\&. in \fIdest\fP\&.  For example,
.RS
.PP
.RS
.nf
\fBzmv \&'(*)\&.lis' '$1\&.txt'\fP .fi .RE .PP renames \fBfoo\&.lis\fP\&' to \fBfoo\&.txt\fP', \fBmy\&.old\&.stuff\&.lis\fP' to \fBmy\&.old\&.stuff\&.txt\fP\&', and so on\&. .PP The pattern is always treated as an \fBEXTENDED_GLOB\fP pattern\&. Any file whose name is not changed by the substitution is simply ignored\&. Any error (a substitution resulted in an empty string, two substitutions gave the same result, the destination was an existing regular file and \fB\-f\fP was not given) causes the entire function to abort without doing anything\&. .PP Options: .PP .PD 0 .TP \fB\-f\fP Force overwriting of destination files\&. Not currently passed down to the \fBmv\fP/\fBcp\fP/\fBln\fP command due to vagaries of implementations (but you can use \fB\-o\-f\fP to do that)\&. .TP \fB\-i\fP Interactive: show each line to be executed and ask the user whether to execute it\&. Y\&' or y' will execute it, anything else will skip it\&. Note that you just need to type one character\&. .TP \fB\-n\fP No execution: print what would happen, but don\&'t do it\&. .TP \fB\-q\fP Turn bare glob qualifiers off: now assumed by default, so this has no effect\&. .TP \fB\-Q\fP Force bare glob qualifiers on\&. Don\&'t turn this on unless you are actually using glob qualifiers in a pattern\&. .TP \fB\-s\fP Symbolic, passed down to \fBln\fP; only works with \fB\-L\fP\&. .TP \fB\-v\fP Verbose: print each command as it\&'s being executed\&. .TP \fB\-w\fP Pick out wildcard parts of the pattern, as described above, and implicitly add parentheses for referring to them\&. .TP \fB\-W\fP Just like \fB\-w\fP, with the addition of turning wildcards in the replacement pattern into sequential${1} \&.\&. ${N} references\&. .TP \fB\-C\fP .TP \fB\-L\fP .TP \fB\-M\fP Force \fBcp\fP, \fBln\fP or \fBmv\fP, respectively, regardless of the name of the function\&. .TP \fB\-p\fP \fIprogram\fP Call \fIprogram\fP instead of \fBcp\fP, \fBln\fP or \fBmv\fP\&. Whatever it does, it should at least understand the form \fIprogram\fP \fB\-\fP\fB\-\fP \fIoldname\fP \fInewname\fP\&' where \fIoldname\fP and \fInewname\fP are filenames generated by \fBzmv\fP\&. .TP \fB\-o\fP \fIoptstring\fP The \fIoptstring\fP is split into words and passed down verbatim to the \fBcp\fP, \fBln\fP or \fBmv\fP command called to perform the work\&. It should probably begin with a \fB\-\fP\&'\&. .PD .PP Further examples: .PP .RS .nf \fBzmv \-v \&'(* *)' '${1// /_}'\fP
.fi
.RE
.PP
For any file in the current directory with at least one space in the name,
replace every space by an underscore and display the commands executed\&.
.PP
For more complete examples and other implementation details, see the
\fBzmv\fP source file, usually located in one of the directories named in
your \fBfpath\fP, or in \fBFunctions/Misc/zmv\fP in the zsh distribution\&.
.RE
.TP
\fBzrecompile\fP
See Recompiling Functions\&'
above\&.
.TP
\fBzstyle+\fP \fIcontext\fP \fIstyle\fP \fIvalue\fP [ + \fIsubcontext\fP \fIstyle\fP \fIvalue\fP \&.\&.\&. ]
This makes defining styles a bit simpler by using a single \fB+\fP\&' as a
special token that allows you to append a context name to the previously
used context name\&.  Like this:
.RS
.PP
.RS
.nf
\fBzstyle+ \&':foo:bar' style1 value1 \e
+ \&':baz'     style2 value2 \e
+ \&':frob'    style3 value3\fP
.fi
.RE
.PP
This defines style1\&' with value1' for the context \fB:foo:bar\fP as usual,
but it also defines style2\&' with value2' for the context
\fB:foo:bar:baz\fP and style3\&' with value3' for \fB:foo:bar:frob\fP\&.  Any
\fIsubcontext\fP may be the empty string to re\-use the first context
unchanged\&.
.RE
.RE
.PP
.SS "Styles"
.PP
.PD 0
.TP
.PD
\fBinsert\-tab\fP
The \fBzed\fP function \fIsets\fP this style in context \fB:completion:zed:*\fP\&'
to turn off completion when \fBTAB\fP is typed at the beginning of a line\&.
You may override this by setting your own value for this context and style\&.
.TP
\fBpager\fP
The \fBnslookup\fP function looks up this style in the context
\fB:nslookup\fP\&' to determine the program used to display output that does
not fit on a single screen\&.
.TP
.PD 0
\fBprompt\fP
.TP
.PD
\fBrprompt\fP
The \fBnslookup\fP function looks up this style in the context
\fB:nslookup\fP\&' to set the prompt and the right\-side prompt, respectively\&.
The usual expansions for the \fBPS1\fP and \fBRPS1\fP parameters may be used
(see
EXPANSION OF PROMPT SEQUENCES in \fIzshmisc\fP(1))\&.