Skip to content

Instantly share code, notes, and snippets.

@austintraver
Last active April 7, 2021 08:05
Show Gist options
  • Save austintraver/a89bc733752be4379eaa1daa59fe2368 to your computer and use it in GitHub Desktop.
Save austintraver/a89bc733752be4379eaa1daa59fe2368 to your computer and use it in GitHub Desktop.
Markdown of zshcontrib(1) converted back into `man` format
.TH "ZSHCONTRIB" "1" "February 14, 2020" "" ""
.hy
.SH NAME
.PP
zshcontrib - user contributions to zsh
.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.
.SH UTILITIES
.SS Accessing On-Line Help
.PP
The key sequence \f[B]ESC h\f[R] is normally bound by ZLE to execute the
\f[B]run-help\f[R] widget (see \f[I]zshzle\f[R](1)).
This invokes the \f[B]run-help\f[R] command with the command word from the
current input line as its argument.
By default, \f[B]run-help\f[R] is an alias for the \f[B]man\f[R] command, so
this often fails when the command word is a shell builtin or a user-defined
function.
By redefining the \f[B]run-help\f[R] alias, one can improve the on-line help
provided by the shell.
.PP
The \f[B]helpfiles\f[R] utility, found in the \f[B]Util\f[R] 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 \f[B]run-help\f[R] function, found in \f[B]Functions/Misc\f[R],
searches for these helpfiles and performs several other tests to produce the
most complete help possible for the command.
.PP
Help files are installed by default to a subdirectory of
\f[B]/usr/share/zsh\f[R] or \f[B]/usr/local/share/zsh\f[R].
.PP
To create your own help files with \f[B]helpfiles\f[R], choose or create a
directory where the individual command help files will reside.
For example, you might choose \f[B]\[ti]/zsh_help\f[R].
If you unpacked the zsh distribution in your home directory, you would use the
commands:
.RS
.IP
.nf
\f[C]
mkdir \[ti]/zsh_help
perl \[ti]/zsh-5.8/Util/helpfiles \[ti]/zsh_help
\f[R]
.fi
.RE
.PP
The \f[B]HELPDIR\f[R] parameter tells \f[B]run-help\f[R] where to look for the
help files.
When unset, it uses the default installation path.
To use your own set of help files, set this to the appropriate path in one of
your startup files:
.RS
.IP
.nf
\f[C]
HELPDIR=\[ti]/zsh_help
\f[R]
.fi
.RE
.PP
To use the \f[B]run-help\f[R] function, you need to add lines something like the
following to your \f[B].zshrc\f[R] or equivalent startup file:
.RS
.IP
.nf
\f[C]
unalias run-help
autoload run-help
\f[R]
.fi
.RE
.PP
Note that in order for \[ga]\f[B]autoload run-help\f[R]\[aq] to work, the
\f[B]run-help\f[R] file must be in one of the directories named in your
\f[B]fpath\f[R] array (see \f[I]zshparam\f[R](1)).
This should already be the case if you have a standard zsh installation; if it
is not, copy \f[B]Functions/Misc/run-help\f[R] to an appropriate directory.
.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 \f[B]zcompile\f[R] 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 \f[B]fpath\f[R], zsh
won\[aq]t check whether any of its source files has changed.
.PP
The \f[B]zrecompile\f[R] autoloadable function, found in
\f[B]Functions/Misc\f[R], can be used to keep function digests up to date.
.PP
\f[B]zrecompile\f[R] [ \f[B]-qt\f[R] ] [ \f[I]name\f[R] ...
]
.PP
\f[B]zrecompile\f[R] [ \f[B]-qt\f[R] ] \f[B]-p\f[R] \f[I]arg\f[R] ...
[ \f[B]--\f[R] \f[I]arg\f[R] ...
] This tries to find \f[B]*.zwc\f[R] 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 \f[B].zwc\f[R] file.
.RS
.PP
In the first form, each \f[I]name\f[R] is the name of a compiled file or a
directory containing \f[B]*.zwc\f[R] files that should be checked.
If no arguments are given, the directories and \f[B]*.zwc\f[R] files in
\f[B]fpath\f[R] are used.
.PP
When \f[B]-t\f[R] 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 \f[B]-q\f[R] option quiets the chatty output that describes what
\f[B]zrecompile\f[R] is doing.
.PP
Without the \f[B]-t\f[R] 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 \f[B]-p\f[R] option is given, the \f[I]arg\f[R]s are interpreted as one
or more sets of arguments for \f[B]zcompile\f[R], separated by
\[ga]\f[B]--\f[R]\[aq].
For example:
.RS
.IP
.nf
\f[C]
zrecompile -p \[rs]
-R \[ti]/.zshrc -- \[rs]
-M \[ti]/.zcompdump -- \[rs]
\[ti]/zsh/comp.zwc \[ti]/zsh/Completion/*/_*
\f[R]
.fi
.RE
.PP
This compiles \f[B]\[ti]/.zshrc\f[R] into \f[B]\[ti]/.zshrc.zwc\f[R] if that
doesn\[aq]t exist or if it is older than \f[B]\[ti]/.zshrc\f[R].
The compiled file will be marked for reading instead of mapping.
The same is done for \f[B]\[ti]/.zcompdump\f[R] and
\f[B]\[ti]/.zcompdump.zwc\f[R], but this compiled file is marked for mapping.
The last line re-creates the file \f[B]\[ti]/zsh/comp.zwc\f[R] if any of the
files matching the given pattern is newer than it.
.PP
Without the \f[B]-p\f[R] option, \f[B]zrecompile\f[R] does not create function
digests that do not already exist, nor does it add new functions to the digest.
.RE
.PP
The following shell loop is an example of a method for creating function digests
for all functions in your \f[B]fpath\f[R], assuming that you have write
permission to the directories:
.RS
.IP
.nf
\f[C]
for ((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
\f[R]
.fi
.RE
.PP
The \f[B]-U\f[R] and \f[B]-z\f[R] options are appropriate for functions in the
default zsh installation \f[B]fpath\f[R]; you may need to use different options
for your personal function directories.
.PP
Once the digests have been created and your \f[B]fpath\f[R] modified to refer to
them, you can keep them up to date by running \f[B]zrecompile\f[R] with no
arguments.
.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 \f[B]zkbd\f[R] utility, found in \f[B]Functions/Misc\f[R], can help you
quickly create key bindings for your configuration.
.PP
Run \f[B]zkbd\f[R] either as an autoloaded function, or as a shell script:
.RS
.IP
.nf
\f[C]
zsh -f \[ti]/zsh-5.8/Functions/Misc/zkbd
\f[R]
.fi
.RE
.PP
When you run \f[B]zkbd\f[R], 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; \f[B]zkbd\f[R] warns you if it
finds anything out of the ordinary, such as a Delete key that sends neither
\f[B]\[ha]H\f[R] nor \f[B]\[ha]?\f[R].
.PP
The keystrokes read by \f[B]zkbd\f[R] are recorded as a definition for an
associative array named \f[B]key\f[R], written to a file in the subdirectory
\f[B].zkbd\f[R] within either your \f[B]HOME\f[R] or \f[B]ZDOTDIR\f[R]
directory.
The name of the file is composed from the \f[B]TERM\f[R], \f[B]VENDOR\f[R] and
\f[B]OSTYPE\f[R] parameters, joined by hyphens.
.PP
You may read this file into your \f[B].zshrc\f[R] or another startup file with
the \[ga]\f[B]source\f[R]\[aq] or \[ga]\f[B].\f[R]\[aq] commands, then reference
the \f[B]key\f[R] parameter in bindkey commands, like this:
.RS
.IP
.nf
\f[C]
source ${ZDOTDIR:-$HOME}/.zkbd/$TERM-$VENDOR-$OSTYPE
[[ -n ${key[Left]} ]] && bindkey \[dq]${key[Left]}\[dq] backward-char
[[ -n ${key[Right]} ]] && bindkey \[dq]${key[Right]}\[dq] forward-char
# etc.
\f[R]
.fi
.RE
.PP
Note that in order for \[ga]\f[B]autoload zkbd\f[R]\[aq] to work, the
\f[B]zkdb\f[R] file must be in one of the directories named in your
\f[B]fpath\f[R] array (see \f[I]zshparam\f[R](1)).
This should already be the case if you have a standard zsh installation; if it
is not, copy \f[B]Functions/Misc/zkbd\f[R] to an appropriate directory.
.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 \f[I]zsh\f[R](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 \f[B]reporter\f[R], found in the \f[B]Util\f[R] directory of
the distribution, is provided for this purpose.
(It is also possible to \f[B]autoload reporter\f[R], but \f[B]reporter\f[R] is
not installed in \f[B]fpath\f[R] by default.) This script outputs a detailed
dump of the shell state, in the form of another script that can be read with
\[ga]\f[B]zsh -f\f[R]\[aq] to recreate that state.
.PP
To use \f[B]reporter\f[R], read the script into your shell with the
\[ga]\f[B].\f[R]\[aq] command and redirect the output into a file:
.RS
.IP
.nf
\f[C]
\&. \[ti]/zsh-5.8/Util/reporter > zsh.report
\f[R]
.fi
.RE
.PP
You should check the \f[B]zsh.report\f[R] 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\[aq]s best to wait for the developers
to ask for this information before sending it.
.PP
You can also use \f[B]reporter\f[R] 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 \f[B]aliases\f[R], \f[B]options\f[R], and
\f[B]zstyles\f[R] states may be useful because they include only changes from
the defaults.
The \f[B]bindings\f[R] state may be useful if you have created any of your own
keymaps, because \f[B]reporter\f[R] 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
\f[B]reporter\f[R], you should edit the results to remove unnecessary commands.
Note that if you\[aq]re using the new completion system, you should
\f[I]not\f[R] dump the \f[B]functions\f[R] state to your startup files with
\f[B]reporter\f[R]; use the \f[B]compdump\f[R] function instead (see
\f[I]zshcompsys\f[R](1)).
.PP
\f[B]reporter\f[R] [ \f[I]state\f[R] ...
] Print to standard output the indicated subset of the current shell state.
The \f[I]state\f[R] arguments may be one or more of:
.RS
.PP
\f[B]all\f[R]
.PD 0
.P
.PD
Output everything listed below.
.PP
\f[B]aliases\f[R]
.PD 0
.P
.PD
Output alias definitions.
.PP
\f[B]bindings\f[R]
.PD 0
.P
.PD
Output ZLE key maps and bindings.
.PP
\f[B]completion\f[R]
.PD 0
.P
.PD
Output old-style \f[B]compctl\f[R] commands.
New completion is covered by \f[B]functions\f[R] and \f[B]zstyles\f[R].
.PP
\f[B]functions\f[R]
.PD 0
.P
.PD
Output autoloads and function definitions.
.PP
\f[B]limits\f[R]
.PD 0
.P
.PD
Output \f[B]limit\f[R] commands.
.PP
\f[B]options\f[R]
.PD 0
.P
.PD
Output \f[B]setopt\f[R] commands.
.PP
\f[B]styles\f[R]
.PD 0
.P
.PD
Same as \f[B]zstyles\f[R].
.PP
\f[B]variables\f[R]
.PD 0
.P
.PD
Output shell parameter assignments, plus \f[B]export\f[R] commands for any
environment variables.
.PP
\f[B]zstyles\f[R]
.PD 0
.P
.PD
Output \f[B]zstyle\f[R] commands.
.PP
If the \f[I]state\f[R] is omitted, \f[B]all\f[R] is assumed.
.RE
.PP
With the exception of \[ga]\f[B]all\f[R]\[aq], every \f[I]state\f[R] can be
abbreviated by any prefix, even a single letter; thus \f[B]a\f[R] is the same as
\f[B]aliases\f[R], \f[B]z\f[R] is the same as \f[B]zstyles\f[R], etc.
.SS Manipulating Hook Functions
.PP
\f[B]add-zsh-hook\f[R] [ \f[B]-L\f[R] | \f[B]-dD\f[R] ] [ \f[B]-Uzk\f[R] ]
\f[I]hook\f[R] \f[I]function\f[R] Several functions are special to the shell, as
described in the section SPECIAL FUNCTIONS, see \f[I]zshmisc\f[R](1), in that
they are automatically called at specific points during shell execution.
Each has an associated array consisting of names of functions to be called at
the same point; these are so-called \[ga]hook functions\[aq].
The shell function \f[B]add-zsh-hook\f[R] provides a simple way of adding or
removing functions from the array.
.RS
.PP
\f[I]hook\f[R] is one of \f[B]chpwd\f[R], \f[B]periodic\f[R], \f[B]precmd\f[R],
\f[B]preexec\f[R], \f[B]zshaddhistory\f[R], \f[B]zshexit\f[R], or
\f[B]zsh_directory_name\f[R], the special functions in question.
Note that \f[B]zsh_directory_name\f[R] is called in a different way from the
other functions, but may still be manipulated as a hook.
.PP
\f[I]function\f[R] 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.
Functions are invoked in the order they were added.
.PP
If the option \f[B]-L\f[R] is given, the current values for the hook arrays are
listed with \f[B]typeset\f[R].
.PP
If the option \f[B]-d\f[R] is given, the \f[I]function\f[R] is removed from the
array of functions to be executed.
.PP
If the option \f[B]-D\f[R] is given, the \f[I]function\f[R] is treated as a
pattern and any matching names of functions are removed from the array of
functions to be executed.
.PP
The options \f[B]-U\f[R], \f[B]-z\f[R] and \f[B]-k\f[R] are passed as arguments
to \f[B]autoload\f[R] for \f[I]function\f[R].
For functions contributed with zsh, the options \f[B]-Uz\f[R] are appropriate.
.RE
.PP
\f[B]add-zle-hook-widget\f[R] [ \f[B]-L\f[R] | \f[B]-dD\f[R] ] [ \f[B]-Uzk\f[R]
] \f[I]hook\f[R] \f[I]widgetname\f[R]
.PD 0
.P
.PD
Several widget names are special to the line editor, as described in the section
Special Widgets, see \f[I]zshzle\f[R](1), in that they are automatically called
at specific points during editing.
Unlike function hooks, these do not use a predefined array of other names to
call at the same point; the shell function \f[B]add-zle-hook-widget\f[R]
maintains a similar array and arranges for the special widget to invoke those
additional widgets.
.PP
\f[I]hook\f[R] is one of \f[B]isearch-exit\f[R], \f[B]isearch-update\f[R],
\f[B]line-pre-redraw\f[R], \f[B]line-init\f[R], \f[B]line-finish\f[R],
\f[B]history-line-set\f[R], or \f[B]keymap-select\f[R], corresponding to each of
the special widgets \f[B]zle-isearch-exit\f[R], etc.
The special widget names are also accepted as the \f[I]hook\f[R] argument.
.PP
\f[I]widgetname\f[R] is the name of a ZLE widget.
If no options are given this is added to the array of widgets to be invoked in
the given hook context.
Widgets are invoked in the order they were added, with
.RS
.IP
.nf
\f[C]
zle widgetname -Nw -- \[dq]$\[at]\[dq]
\f[R]
.fi
.RE
.PP
Note that this means that the \[ga]\f[B]WIDGET\[aq] special parameter tracks
the\f[R] \f[I]widgetname\f[R]** when the widget function is called, rather than
tracking** the name of the corresponding special hook widget.
.PP
If the option \f[B]-d is given, the \f[BI]\f[I]widgetname\f[BI]\f[B] is removed
from\f[R] the array of widgets to be executed.
.PP
If the option \f[B]-D is given, the \f[BI]\f[I]widgetname\f[BI]\f[B] is treated
as a pattern\f[R] and any matching names of widgets are removed from the array.
.PP
If \f[I]widgetname\f[R]** does not name an existing widget when added to the**
array, it is assumed that a shell function also named \f[I]widgetname\f[R]**
is** meant to provide the implementation of the widget.
This name is therefore marked for autoloading, and the options \f[B]-U, -z and
-k are\f[R] passed as arguments to \f[B]autoload as with add-zsh-hook. The\f[R]
widget is also created with \[ga]\f[B]zle -N
\f[BI]\f[I]widgetname\f[BI]\f[B]\[aq] to cause the\f[R] corresponding function
to be loaded the first time the hook is called.
.PP
The arrays of \f[I]widgetname\f[R]** are currently maintained in zstyle**
contexts, one for each \f[I]hook\f[R]** context, with a style of
\[ga]widgets\[aq].** If the \f[B]-L option is given, this set of styles is
listed with\f[R] \[ga]\f[B]zstyle -L\[aq]. This implementation may change, and
the special widgets\f[R] that refer to the styles are created only if
\f[B]add-zle-hook-widget is\f[R] called to add at least one widget, so if this
function is used for any hooks, then all hooks should be managed only via this
function.
.SH REMEMBERING RECENT DIRECTORIES
.PP
The function \f[B]cdr allows you to change the working directory to a\f[R]
previous working directory from a list maintained automatically.
It is similar in concept to the directory stack controlled by the
\f[B]pushd,\f[R] \f[B]popd and dirs builtins, but is more configurable, and as
it stores\f[R] all entries in files it is maintained across sessions and (by
default) between terminal emulators in the current session.
Duplicates are automatically removed, so that the list reflects the single most
recent use of each directory.
.PP
Note that the \f[B]pushd directory stack is not actually modified or used\f[R]
by \f[B]cdr unless you configure it to do so as described in the\f[R]
configuration section below.
.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
\f[B]add-zsh-hook function described above:\f[R]
.RS
.IP
.nf
\f[C]
autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
add-zsh-hook chpwd chpwd_recent_dirs
\f[R]
.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.
.SS Use
.PP
All direct user interaction is via the \f[B]cdr function.\f[R]
.PP
The argument to cdr is a number \f[I]N\f[R]** corresponding to the
\f[I]\f[BI]N\f[I]\f[R]th most** recently changed-to directory.
1 is the immediately preceding 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 \f[B]recent-dirs-file style below.\f[R]
.PP
If you set the \f[B]recent-dirs-default style described below cdr\f[R] will
behave the same as \f[B]cd if given a non-numeric argument, or more\f[R] 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 \f[B]pushd\[aq]s\f[R] behaviour of swapping the two most
recent directories on the stack.
.PP
Completion for the argument to \f[B]cdr is available if compinit has been\f[R]
run; menu selection is recommended, using:
.RS
.IP
.nf
\f[C]
zstyle \[aq]:completion:*:*:cdr:*:*\[aq] menu selection
\f[R]
.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.
.SS Options
.PP
The behaviour of \f[B]cdr may be modified by the following options.\f[R]
.PP
\f[B]-l\f[R] lists the numbers and the corresponding directories in abbreviated
form (i.e.
with \f[B]\[ti] substitution reapplied), one per line.\f[R] 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.
.PP
\f[B]-r\f[R]
.PD 0
.P
.PD
sets the variable \f[B]reply to the current set of directories. Nothing\f[R] is
printed and the directory is not changed.
.PP
\f[B]-e\f[R]
.PD 0
.P
.PD
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 \f[B]/.\f[R] Usually the first entry should be left as the
current directory.
.PP
\f[B]-p \[aq]\f[BI]\f[I]pattern\f[BI]\f[B]\[aq]\f[R]
.PD 0
.P
.PD
Prunes any items in the directory list that match the given extended glob
pattern; the pattern needs to be quoted from immediate expansion on the command
line.
The pattern is matched against each completely expanded file name in the list;
the full string must match, so wildcards at the end (e.g.
\f[B]\[aq]*removeme*\[aq]) are needed to remove entries with a given\f[R]
substring.
.PP
If output is to a terminal, then the function will print the new list after
pruning and prompt for confirmation by the user.
This output and confirmation step can be skipped by using \f[B]-P instead of
-p.\f[R]
.SS Configuration
.PP
Configuration is by means of the styles mechanism that should be familiar from
completion; if not, see the description of the \f[B]zstyle command in\f[R] see
\f[I]zshmodules\f[R]**(1).
The context for setting styles** should be \f[B]\[aq]:chpwd:*\[aq] in case the
meaning of the context is extended in\f[R] future, for example:
.RS
.IP
.nf
\f[C]
zstyle \[aq]:chpwd:*\[aq] recent-dirs-max 0
\f[R]
.fi
.RE
.PP
sets the value of the \f[B]recent-dirs-max style to 0. In practice the\f[R]
style name is specific enough that a context of \[aq]*\[aq] should be fine.
.PP
An exception is \f[B]recent-dirs-insert, which is used exclusively by the\f[R]
completion system and so has the usual completion system context
(\f[B]\[aq]:completion:*\[aq] if nothing more specific is needed), though
again\f[R] \f[B]\[aq]*\[aq] should be fine in practice.\f[R]
.PP
\f[B]recent-dirs-default\f[R] 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 \[dq]cd\[dq].
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.
.PP
\f[B]recent-dirs-file\f[R]
.PD 0
.P
.PD
The file where the list of directories is saved.
The default is \f[B]${ZDOTDIR:-$HOME}/.chpwd-recent-dirs, i.e. this is in
your\f[R] home directory unless you have set the variable \f[B]ZDOTDIR to
point\f[R] somewhere else.
Directory names are saved in \f[B]$\[aq]\f[R]\f[I]...\f[R]\f[B]\[aq] quoted\f[R]
form, so each line in the file can be supplied directly to the shell as an
argument.
.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 \f[B]+ can appear in the list to\f[R] indicate the default
file should be read at that point.
This allows effects like the following:
.RS
.IP
.nf
\f[C]
zstyle \[aq]:chpwd:*\[aq] recent-dirs-file \[rs]
\[ti]/.chpwd-recent-dirs-${TTY##*/} +
\f[R]
.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 \f[B]zstyle -e to make the directory configurable\f[R] at
run time:
.RS
.IP
.nf
\f[C]
zstyle -e \[aq]:chpwd:*\[aq] recent-dirs-file pick-recent-dirs-file
pick-recent-dirs-file() {
if [[ $PWD = \[ti]/text/writing(|/*) ]]; then
reply=(\[ti]/.chpwd-recent-dirs-writing)
else
reply=(+)
fi
}
\f[R]
.fi
.RE
.PP
In this example, if the current directory is \f[B]\[ti]/text/writing or a\f[R]
directory under it, then use a special file for saving recent directories, else
use the default.
.PP
\f[B]recent-dirs-insert\f[R]
.PD 0
.P
.PD
Used by completion.
If \f[B]recent-dirs-default is true, then setting\f[R] this to \f[B]true causes
the actual directory, rather than its index, to\f[R] 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.
.PP
If the value of the style is \f[B]always, then only recent directories will\f[R]
be completed; in that case, use the \f[B]cd command when you want to\f[R]
complete other directories.
.PP
If the value is \f[B]fallback, recent directories will be tried first, then\f[R]
normal directory completion is performed if recent directory completion failed
to find a match.
.PP
Finally, if the value is \f[B]both then both sets of completions are\f[R]
presented; the usual tag mechanism can be used to distinguish results, with
recent directories tagged as \f[B]recent-dirs. Note that the recent\f[R]
directories inserted are abbreviated with directory names where appropriate.
.PP
\f[B]recent-dirs-max\f[R]
.PD 0
.P
.PD
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\[aq]t offered, so the
highest number of directories you will be offered is one less than the maximum.
.PP
\f[B]recent-dirs-prune\f[R]
.PD 0
.P
.PD
This style is an array determining what directories should (or should not) be
added to the recent list.
Elements of the array can include:
.PP
\f[B]parent\f[R] 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 \[ti]pws to \[ti]pws/some/other/dir causes \[ti]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 \[ti]pws/yet/another to \[ti]pws/some/other/dir does
not cause \[ti]pws to be pruned.
.PP
\f[I]\f[R]pattern:\f[I]\f[R]\f[I]pattern\f[R]
.PD 0
.P
.PD
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, \f[B]\[aq]pattern:/tmp(|/*)\[aq]\f[R]\f[I] stops
\f[R]\f[B]/tmp\f[R]\f[I] or its descendants\f[R] from being added. The
\f[B]EXTENDED_GLOB\f[R]\f[I] option is always turned on\f[R] for these patterns.
.PP
\f[B]recent-dirs-pushd\f[R]
.PD 0
.P
.PD
If set to true, \f[B]cdr\f[R]* will use \f[I]\f[BI]pushd\f[I]\f[R] instead of
\f[I]\f[BI]cd\f[I]\f[R] 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.
.SS Use with dynamic directory naming
.PP
It is possible to refer to recent directories using the dynamic directory name
syntax by using the supplied function \f[B]zsh_directory_name_cdr\f[R] a hook:
.RS
.IP
.nf
\f[C]
autoload -Uz add-zsh-hook
add-zsh-hook -Uz zsh_directory_name zsh_directory_name_cdr
\f[R]
.fi
.RE
.PP
When this is done, \f[B]\[ti][1]\f[R]* will refer to the most recent* directory
other than $PWD, and so on.
Completion after \f[B]\[ti][\f[R]\f[I]...\f[R] also works.
.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 \f[B]cd -q\f[R]* or \f[I]\f[BI]pushd -q\f[I]\f[R] to*
avoid side effects if the change to the directory is to be invisible at the
command line.
See the contents of the function \f[B]chpwd_recent_dirs\f[R]* for* more details.
.SH ABBREVIATED DYNAMIC REFERENCES TO DIRECTORIES
.PP
The dynamic directory naming system is described in the subsection \f[I]Dynamic
named directories of\f[R] the section \f[I]Filename Expansion in expn(1). In
this, a reference to\f[R] \f[B]\[ti][\f[R]\f[I]...\f[R]\f[B]]\f[R]* is expanded
by a function found by the hooks* mechanism.
.PP
The contributed function \f[B]zsh_directory_name_generic\f[R]* provides a*
system allowing the user to refer to directories with only a limited amount of
new code.
It supports all three of the standard interfaces for directory naming:
converting from a name to a directory, converting in the reverse direction to
find a short name, and completion of names.
.PP
The main feature of this function is a path-like syntax, combining abbreviations
at multiple levels separated by \[dq]:\[dq].
As an example, \[ti][g:p:s] might specify:
.PP
\f[B]g\f[R] The top level directory for your git area.
This first component has to match, or the function will return indicating
another directory name hook function should be tried.
.PP
\f[B]p\f[R]
.PD 0
.P
.PD
The name of a project within your git area.
.PP
\f[B]s\f[R]
.PD 0
.P
.PD
The source area within that project.
This allows you to collapse references to long hierarchies to a very compact
form, particularly if the hierarchies are similar across different areas of the
disk.
.PP
Name components may be completed: if a description is shown at the top of the
list of completions, it includes the path to which previous components expand,
while the description for an individual completion shows the path segment it
would add.
No additional configuration is needed for this as the completion system is aware
of the dynamic directory name mechanism.
.SS Usage
.PP
To use the function, first define a wrapper function for your specific case.
We\[aq]ll assume it\[aq]s to be autoloaded.
This can have any name but we\[aq]ll refer to it as zdn_mywrapper.
This wrapper function will define various variables and then call this function
with the same arguments that the wrapper function gets.
This configuration is described below.
.PP
Then arrange for the wrapper to be run as a zsh_directory_name hook:
.RS
.IP
.nf
\f[C]
autoload -Uz add-zsh-hook zsh_diretory_name_generic zdn_mywrapper
add-zsh-hook -U zsh_directory_name zdn_mywrapper
\f[R]
.fi
.RE
.SS Configuration
.PP
The wrapper function should define a local associative array zdn_top.
Alternatively, this can be set with a style called \f[B]mapping\f[R]*.
The* context for the style is **:zdn:**\f[I]wrapper-name where\f[R]
\f[I]wrapper-name is the function calling zsh_directory_name_generic;\f[R] for
example:
.RS
.IP
.nf
\f[C]
zstyle :zdn:zdn_mywrapper: mapping zdn_mywrapper_top
\f[R]
.fi
.RE
.PP
The keys in this associative array correspond to the first component of the
name.
The values are matching directories.
They may have an optional suffix with a slash followed by a colon and the name
of a variable in the same format to give the next component.
(The slash before the colon is to disambiguate the case where a colon is needed
in the path for a drive.
There is otherwise no syntax for escaping this, so path components whose names
start with a colon are not supported.) A special component \f[B]:default:\f[R]*
specifies a variable in the form* \f[I]\f[R]/:\f[I]\f[R]\f[I]var (the path
section is ignored and so is usually empty)\f[R] that will be used for the next
component if no variable is given for the path. Variables referred to within
\f[B]zdn_top\f[R]\f[I] have the same format as\f[R] \f[B]zdn_top\f[R]\f[I]
itself, but contain relative paths.\f[R]
.PP
For example,
.RS
.IP
.nf
\f[C]
local -A zdn_top=(
g \[ti]/git
ga \[ti]/alternate/git
gs /scratch/$USER/git/:second2
:default: /:second1
)
\f[R]
.fi
.RE
.PP
This specifies the behaviour of a directory referred to as
\f[B]\[ti][g:...]\f[R] or \f[B]\[ti][ga:...]\f[R]* or
\f[I]\f[BI]\[ti][gs:...]\f[I]\f[R].
Later path components are optional;* in that case \f[B]\[ti][g]\f[R]* expands to
\f[I]\f[BI]\[ti]/git\f[I]\f[R], and so on.
\f[I]\f[BI]gs\f[I]\f[R] expands* to \f[B]/scratch/$USER/git\f[R]* and uses the
associative array \f[I]\f[BI]second2\f[I]\f[R] to* match the second component;
\f[B]g\f[R]* and \f[I]\f[BI]ga\f[I]\f[R] use the associative array*
\f[B]second1\f[R]* to match the second component.*
.PP
When expanding a name to a directory, if the first component is not \f[B]g\f[R]*
or* \f[B]ga\f[R]* or \f[I]\f[BI]gs\f[I]\f[R], it is not an error; the function
simply returns 1 so that a* later hook function can be tried.
However, matching the first component commits the function, so if a later
component does not match, an error is printed (though this still does not stop
later hooks from being executed).
.PP
For components after the first, a relative path is expected, but note that
multiple levels may still appear.
Here is an example of \f[B]second1\f[R]*:*
.RS
.IP
.nf
\f[C]
local -A second1=(
p myproject
s somproject
os otherproject/subproject/:third
)
\f[R]
.fi
.RE
.PP
The path as found from \f[B]zdn_top\f[R]* is extended with the matching*
directory, so \f[B]\[ti][g:p]\f[R]* becomes
\f[I]\f[BI]\[ti]/git/myproject\f[I]\f[R].
The slash between* is added automatically (it\[aq]s not possible to have a later
component modify the name of a directory already matched).
Only \f[B]os\f[R]* specifies* a variable for a third component, and there\[aq]s
no \f[B]:default:\f[R]\f[I], so it\[aq]s\f[R] an error to use a name like
\f[B]\[ti][g:p:x]\f[R]* or \f[I]\f[BI]\[ti][ga:s:y]\f[I]\f[R] because*
there\[aq]s nowhere to look up the \f[B]x\f[R]* or \f[I]\f[BI]y\f[I]\f[R].*
.PP
The associative arrays need to be visible within this function; the generic
function therefore uses internal variable names beginning \f[B]_zdn_\f[R]* in
order to avoid clashes.
Note that the variable *\f[B]reply\f[R] needs to be passed back to the shell, so
should not be local in the calling function.
.PP
The function does not test whether directories assembled by component actually
exist; this allows the system to work across automounted file systems.
The error from the command trying to use a non-existent directory should be
sufficient to indicate the problem.
.SS Complete example
.PP
Here is a full fictitious but usable autoloadable definition of the example
function defined by the code above.
So \f[B]\[ti][gs:p:s]\f[R]* expands* to
\f[B]/scratch/$USER/git/myscratchproject/top/srcdir\f[R]* (with *\f[B]$USER\f[R]
also expanded).
.RS
.IP
.nf
\f[C]
local -A zdn_top=(
g \[ti]/git
ga \[ti]/alternate/git
gs /scratch/$USER/git/:second2
:default: /:second1
)
local -A second1=(
p myproject
s somproject
os otherproject/subproject/:third
)
local -A second2=(
p myscratchproject
s somescratchproject
)
local -A third=(
s top/srcdir
d top/documentation
)
# autoload not needed if you did this at initialisation...
autoload -Uz zsh_directory_name_generic
zsh_directory_name_generic \[dq]$\[at]
\f[R]
.fi
.RE
.PP
It is also possible to use global associative arrays, suitably named, and set
the style for the context of your wrapper function to refer to this.
Then your set up code would contain the following:
.RS
.IP
.nf
\f[C]
typeset -A zdn_mywrapper_top=(...)
# ... and so on for other associative arrays ...
zstyle \[aq]:zdn:zdn_mywrapper:\[aq] mapping zdn_mywrapper_top
autoload -Uz add-zsh-hook zsh_directory_name_generic zdn_mywrapper
add-zsh-hook -U zsh_directory_name zdn_mywrapper
\f[R]
.fi
.RE
.PP
and the function \f[B]zdn_mywrapper\f[R]* would contain only the following:*
.RS
.IP
.nf
\f[C]
zsh_directory_name_generic \[dq]$\[at]\[dq]
\f[R]
.fi
.RE
.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\[aq]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 \f[B]vcs_info\f[R]* function.*
.PP
The following VCSs are supported, showing the abbreviated name by which they are
referred to within the system:
.PP
Bazaar (\f[B]bzr\f[R]*)*
.PD 0
.P
.PD
\f[B]<https://bazaar.canonical.com/>\f[R]
.PP
Codeville (\f[B]cdv\f[R]*)*
.PD 0
.P
.PD
\f[B]<http://freecode.com/projects/codeville/>\f[R]
.PP
Concurrent Versioning System (\f[B]cvs\f[R]*)*
.PD 0
.P
.PD
\f[B]<https://www.nongnu.org/cvs/>\f[R]
.PP
Darcs (\f[B]darcs\f[R]*)*
.PD 0
.P
.PD
\f[B]<http://darcs.net/>\f[R]
.PP
Fossil (\f[B]fossil\f[R]*)*
.PD 0
.P
.PD
\f[B]<https://fossil-scm.org/>\f[R]
.PP
Git (\f[B]git\f[R]*)*
.PD 0
.P
.PD
\f[B]<https://git-scm.com/>\f[R]
.PP
GNU arch (\f[B]tla\f[R]*)*
.PD 0
.P
.PD
\f[B]<https://www.gnu.org/software/gnu-arch/>\f[R]
.PP
Mercurial (\f[B]hg\f[R]*)*
.PD 0
.P
.PD
\f[B]<https://www.mercurial-scm.org/>\f[R]
.PP
Monotone (\f[B]mtn\f[R]*)*
.PD 0
.P
.PD
\f[B]<https://monotone.ca/>\f[R]
.PP
Perforce (\f[B]p4\f[R]*)*
.PD 0
.P
.PD
\f[B]<https://www.perforce.com/>\f[R]
.PP
Subversion (\f[B]svn\f[R]*)*
.PD 0
.P
.PD
\f[B]<https://subversion.apache.org/>\f[R]
.PP
SVK (\f[B]svk\f[R]*)*
.PD 0
.P
.PD
\f[B]<https://svk.bestpractical.com/>\f[R]
.PP
There is also support for the patch management system \f[B]quilt\f[R]
(*\f[I]<https://savannah.nongnu.org/projects/quilt***>). See\f[R] \f[B]Quilt
Support\f[R] below for details.
.PP
To load \f[B]vcs_info\f[R]*:*
.RS
.IP
.nf
\f[C]
autoload -Uz vcs_info
\f[R]
.fi
.RE
.PP
It can be used in any existing prompt, because it does not require any specific
\f[B]$psvar\f[R]* entries to be available.*
.SS Quickstart
.PP
To get this feature working quickly (including colors), you can do the following
(assuming, you loaded \f[B]vcs_info\f[R]* properly - see above):*
.RS
.IP
.nf
\f[C]
zstyle \[aq]:vcs_info:*\[aq] actionformats \[rs]
\[aq]%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f \[aq]
zstyle \[aq]:vcs_info:*\[aq] formats \[rs]
\[aq]%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{5}]%f \[aq]
zstyle \[aq]:vcs_info:(sv[nk]|bzr):*\[aq] branchformat \[aq]%b%F{1}:%F{3}%r\[aq]
precmd () { vcs_info }
PS1=\[aq]%F{5}[%F{2}%n%F{5}] %F{3}%3\[ti] ${vcs_info_msg_0_}%f%# \[aq]
\f[R]
.fi
.RE
.PP
Obviously, the last two lines are there for demonstration.
You need to call \f[B]vcs_info\f[R]* from your \f[I]\f[BI]precmd\f[I]\f[R]
function.
Once that is done you need* a \f[I]single quoted
\f[R]\f[B]\[aq]${vcs_info_msg_0_}\[aq]\f[R]\f[I] in your prompt.\f[R]
.PP
To be able to use \f[B]\[aq]${vcs_info_msg_0_}\[aq]\f[R]* directly in your
prompt like* this, you will need to have the \f[B]PROMPT_SUBST\f[R]* option
enabled.*
.PP
Now call the \f[B]vcs_info_printsys\f[R]* utility from the command line:*
.RS
.IP
.nf
\f[C]
% vcs_info_printsys
## list of supported version control backends:
## disabled systems are prefixed by a hash sign (#)
bzr
cdv
cvs
darcs
fossil
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: \[aq]:vcs_info:git-svn:*\[aq].
git-p4
git-svn
hg-git
hg-hgsubversion
hg-hgsvn
\f[R]
.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:
.RS
.IP
.nf
\f[C]
zstyle \[aq]:vcs_info:*\[aq] disable bzr cdv darcs mtn svk tla
\f[R]
.fi
.RE
.PP
You may also pick a few from that list and enable only those:
.RS
.IP
.nf
\f[C]
zstyle \[aq]:vcs_info:*\[aq] enable git cvs svn
\f[R]
.fi
.RE
.PP
If you rerun \f[B]vcs_info_printsys\f[R]* after one of these commands, you will*
see the backends listed in the \f[B]disable\f[R]* style (or backends not in the*
\f[B]enable\f[R]* style - if you used that) marked as disabled by a hash sign.*
That means the detection of these systems is skipped \f[I]completely. No\f[R]
wasted time there.
.SS Configuration
.PP
The \f[B]vcs_info\f[R]* feature can be configured via
\f[I]\f[BI]zstyle\f[I]\f[R].*
.PP
First, the context in which we are working:
.RS
.IP
.nf
\f[C]
:vcs_info:vcs-string:user-context:repo-root-name
\f[R]
.fi
.RE
.PP
\f[I]vcs-string\f[R] is one of: \f[B]git\f[R]*, \f[I]\f[BI]git-svn\f[I]\f[R],
\f[I]\f[BI]git-p4\f[I]\f[R], \f[I]\f[BI]hg\f[I]\f[R],
\f[I]\f[BI]hg-git\f[I]\f[R],* \f[B]hg-hgsubversion\f[R]*,
\f[I]\f[BI]hg-hgsvn\f[I]\f[R], \f[I]\f[BI]darcs\f[I]\f[R],
\f[I]\f[BI]bzr\f[I]\f[R], \f[I]\f[BI]cdv\f[I]\f[R], \f[I]\f[BI]mtn\f[I]\f[R],*
\f[B]svn\f[R]*, \f[I]\f[BI]cvs\f[I]\f[R], \f[I]\f[BI]svk\f[I]\f[R],
\f[I]\f[BI]tla\f[I]\f[R], \f[I]\f[BI]p4\f[I]\f[R] or
\f[I]\f[BI]fossil\f[I]\f[R].* This is followed by
\[ga]\f[B].quilt-\f[BI]\f[B]\f[BI]quilt-mode\[aq] in Quilt mode\f[B] (see
\f[R]Quilt Support\f[B]\f[BI] for details)\f[B] and by
\[ga]\f[R]+\f[I]\f[R]\f[I]hook-name\[aq] while hooks are active\f[R] (see
\f[B]Hooks in vcs_info\f[R]\f[I] for details).\f[R]
.RS
.PP
Currently, hooks in quilt mode don\[aq]t add the
\[ga]**.quilt-**\f[I]quilt-mode\[aq] information.\f[R] This may change in the
future.
.RE
.PP
\f[I]user-context\f[R]
.PD 0
.P
.PD
is a freely configurable string, assignable by the user as the first argument to
\f[B]vcs_info\f[R]* (see its description* below).
.PP
\f[I]repo-root-name\f[R]
.PD 0
.P
.PD
is the name of a repository in which you want a style to match.
So, if you want a setting specific to \f[B]/usr/src/zsh\f[R]*,* with that being
a CVS checkout, you can set \f[I]repo-root-name to\f[R] \f[B]zsh\f[R]* to make
it so.*
.PP
There are three special values for \f[I]vcs-string: The first is named\f[R]
\f[B]-init-\f[R]\f[I], that is in effect as long as there was no decision what
VCS\f[R] backend to use.
The second is \f[B]-preinit-\f[R]\f[I]; it is used before\f[R]
\f[B]vcs_info\f[R]* is run, when initializing the data exporting variables.
The* third special value is \f[B]formats\f[R]* and is used by the
*\f[B]vcs_info_lastmsg\f[R] for looking up its styles.
.PP
The initial value of \f[I]repo-root-name is \f[R]\f[B]-all-\f[R]\f[I] and it is
replaced\f[R] with the actual name, as soon as it is known.
Only use this part of the context for defining the \f[B]formats\f[R]*,
\f[I]\f[BI]actionformats\f[I]\f[R] or* \f[B]branchformat\f[R]* styles, as it is
guaranteed that repo-root-name is* set up correctly for these only.
For all other styles, just use \f[B]\[aq]*\[aq]\f[R] instead.
.PP
There are two pre-defined values for \f[I]user-context:\f[R]
.PP
\f[B]default\f[R]
.PD 0
.P
.PD
the one used if none is specified
.PP
\f[B]command\f[R]
.PD 0
.P
.PD
used by vcs_info_lastmsg to lookup its styles
.PP
You can of course use \f[B]\[aq]:vcs_info:*\[aq]\f[R]* to match all VCSs in all*
user-contexts at once.
.PP
This is a description of all styles that are looked up.
.PP
\f[B]formats\f[R] A list of formats, used when actionformats is not used (which
is most of the time).
.PP
\f[B]actionformats\f[R]
.PD 0
.P
.PD
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.
.PP
\f[B]branchformat\f[R]
.PD 0
.P
.PD
Some backends replace \f[B]%b\f[R]* 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.
.PP
\f[B]nvcsformats\f[R]
.PD 0
.P
.PD
These \[dq]formats\[dq] are set when we didn\[aq]t detect a version control
system for the current directory or \f[B]vcs_info\f[R]* was disabled.
This is useful if* you want \f[B]vcs_info\f[R]* to completely take over the
generation of your* prompt.
You would do something like \f[B]PS1=\[aq]${vcs_info_msg_0_}\[aq]\f[R]* to*
accomplish that.
.PP
\f[B]hgrevformat\f[R]
.PD 0
.P
.PD
\f[B]hg\f[R]* 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 \f[B]branchformat\f[R]*)
to include either or both.
It\[aq]s only* useful when \f[B]get-revision\f[R]* is true.
Note, the full 40-character revision id* is not available (except when using the
\f[B]use-simple\f[R]* option) because* executing hg more than once per prompt is
too slow; you may customize this behavior using hooks.
.PP
\f[B]max-exports\f[R]
.PD 0
.P
.PD
Defines the maximum number of \f[B]vcs_info_msg_*_\f[R]* variables
\f[I]\f[BI]vcs_info\f[I]\f[R] will set.*
.PP
\f[B]enable\f[R]
.PD 0
.P
.PD
A list of backends you want to use.
Checked in the \f[B]-init-\f[R]* context.
If* this list contains an item called \f[B]NONE\f[R]* no backend is used at all
and* \f[B]vcs_info\f[R]* will do nothing.
If this list contains \f[I]\f[BI]ALL\f[I]\f[R], \f[I]\f[BI]vcs_info\f[I] will
use all known backends. Only with \f[BI]ALL\f[I]\f[R] in
\f[I]\f[BI]enable\f[I]\f[R] will the* \f[B]disable\f[R]* style have any effect.
\f[I]\f[BI]ALL\f[I]\f[R] and \f[I]\f[BI]NONE\f[I]\f[R] are case insensitive.*
.PP
\f[B]disable\f[R]
.PD 0
.P
.PD
A list of VCSs you don\[aq]t want \f[B]vcs_info\f[R]* to test for* repositories
(checked in the \f[B]-init-\f[R]* context, too).
Only used if* \f[B]enable\f[R]* contains \f[I]\f[BI]ALL\f[I]\f[R].*
.PP
\f[B]disable-patterns\f[R]
.PD 0
.P
.PD
A list of patterns that are checked against \f[B]$PWD\f[R]*.
If a pattern* matches, \f[B]vcs_info\f[R]* will be disabled.
This style is checked in the* \f[B]:vcs_info:-init-:*:-all-\f[R]* context.*
.PP
Say, \f[B]\[ti]/.zsh\f[R]* is a directory under version control, in which you
do* not want \f[B]vcs_info\f[R]* to be active, do:*
.RS
.IP
.nf
\f[C]
zstyle \[aq]:vcs_info:*\[aq] disable-patterns \[dq]${(b)HOME}/.zsh(|/*)\[dq]
\f[R]
.fi
.RE
.PP
\f[B]use-quilt\f[R]
.PD 0
.P
.PD
If enabled, the \f[B]quilt\f[R]* support code is active in \[ga]addon\[aq]
mode.* See \f[B]Quilt Support\f[R]* for details.*
.PP
\f[B]quilt-standalone\f[R]
.PD 0
.P
.PD
If enabled, \[ga]standalone\[aq] mode detection is attempted if no VCS is active
in a given directory.
See \f[B]Quilt Support\f[R]* for details.*
.PP
\f[B]quilt-patch-dir\f[R]
.PD 0
.P
.PD
Overwrite the value of the \f[B]$QUILT_PATCHES\f[R]* environment variable.
See* \f[B]Quilt Support\f[R]* for details.*
.PP
\f[B]quiltcommand\f[R]
.PD 0
.P
.PD
When \f[B]quilt\f[R]* itself is called in quilt support, the value of this
style* is used as the command name.
.PP
\f[B]check-for-changes\f[R]
.PD 0
.P
.PD
If enabled, this style causes the \f[B]%c\f[R]* and \f[I]\f[BI]%u\f[I]\f[R]
format escapes to show* when the working directory has uncommitted changes.
The strings displayed by these escapes can be controlled via the
\f[B]stagedstr\f[R]* and \f[I]\f[BI]unstagedstr\f[I] styles. The only backends
that currently support this option are \f[BI]git\f[I]\f[R],* \f[B]hg\f[R]*, and
\f[I]\f[BI]bzr\f[I]\f[R] (the latter two only support unstaged).*
.PP
For this style to be evaluated with the \f[B]hg\f[R]* backend, the
\f[I]\f[BI]get-revision\f[I] style needs to be set and the
\f[BI]use-simple\f[I]\f[R] style needs to be unset.
The* latter is the default; the former is not.
.PP
With the \f[B]bzr\f[R]* backend, lightweight checkouts only honor this style if*
the \f[B]use-server\f[R]* style is set.*
.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.
.PP
\f[B]check-for-staged-changes\f[R]
.PD 0
.P
.PD
This style is like \f[B]check-for-changes\f[R]*, but it never checks the
worktree* files, only the metadata in the \f[B].${vcs}\f[R]* dir.
Therefore,* this style initializes only the \f[B]%c\f[R]* escape (with
\f[I]\f[BI]stagedstr\f[I]\f[R]) but* not the \f[B]%u\f[R]* escape.
This style is faster than \f[I]\f[BI]check-for-changes\f[I]\f[R].*
.PP
In the \f[B]git\f[R]* backend, this style checks for changes in the index.*
Other backends do not currently implement this style.
.PP
This style is disabled by default.
.PP
\f[B]stagedstr\f[R]
.PD 0
.P
.PD
This string will be used in the \f[B]%c\f[R]* escape if there are staged changes
in* the repository.
.PP
\f[B]unstagedstr\f[R]
.PD 0
.P
.PD
This string will be used in the \f[B]%u\f[R]* escape if there are unstaged
changes* in the repository.
.PP
\f[B]command\f[R]
.PD 0
.P
.PD
This style causes \f[B]vcs_info\f[R]* to use the supplied string as the command*
to use as the VCS\[aq]s binary.
Note, that setting this in \[aq]\f[B]:vcs_info:*\f[R]\f[I]\[aq] is\f[R] not a
good idea.
.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.
\f[B]svn\f[R]* is used in an *\f[B]svn\f[R] repository).
.PP
The \f[B]repo-root-name\f[R]* part in the context is always the default
*\f[B]-all-\f[R] when this style is looked up.
.PP
For example, this style can be used to use binaries from non-default
installation directories.
Assume, \f[B]git\f[R]* is installed in /usr/bin but* your sysadmin installed a
newer version in /usr/local/bin.
Instead of changing the order of your \f[B]$PATH\f[R]* parameter, you can do
this:*
.RS
.IP
.nf
\f[C]
zstyle \[aq]:vcs_info:git:*:-all-\[aq] command /usr/local/bin/git
\f[R]
.fi
.RE
.PP
\f[B]use-server\f[R]
.PD 0
.P
.PD
This is used by the Perforce backend (\f[B]p4\f[R]*) 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 \f[B]host:port\f[R]* pair describing the*
server) cannot be contacted, its name is put into the associative array
\f[B]vcs_info_p4_dead_servers\f[R]* and is not contacted again during the
session* until it is removed by hand.
If you do not set this style, the \f[B]p4\f[R] backend is only usable if you
have set the environment variable \f[B]P4CONFIG\f[R]* to a file name and have
corresponding files in the root* directories of each Perforce client.
See comments in the function \f[B]VCS_INFO_detect_p4\f[R]* for more detail.*
.PP
The Bazaar backend (\f[B]bzr\f[R]*) uses this to permit contacting the server*
about lightweight checkouts, see the \f[B]check-for-changes\f[R]* style.*
.PP
\f[B]use-simple\f[R]
.PD 0
.P
.PD
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 \f[B]bzr\f[R]* and \f[I]\f[BI]hg\f[I]\f[R] backends.
In the case of \f[I]\f[BI]hg\f[I]\f[R] it will invoke* the external hexdump
program to parse the binary dirstate cache file; this method will not return the
local revision number.
.PP
\f[B]get-revision\f[R]
.PD 0
.P
.PD
If set to true, vcs_info goes the extra mile to figure out the revision of a
repository\[aq]s work tree (currently for the \f[B]git\f[R]* and
\f[I]\f[BI]hg\f[I]\f[R] backends,* where this kind of information is not always
vital).
For \f[B]git\f[R]*, the* hash value of the currently checked out commit is
available via the \f[B]%i\f[R] expansion.
With \f[B]hg\f[R]*, the local revision number and the corresponding* global hash
are available via \f[B]%i\f[R]*.*
.PP
\f[B]get-mq\f[R]
.PD 0
.P
.PD
If set to true, the \f[B]hg\f[R]* backend will look for a Mercurial Queue
(\f[I]\f[BI]mq\f[I]\f[R])* patch directory.
Information will be available via the \[ga]\f[B]%m\f[R]*\[aq] replacement.*
.PP
\f[B]get-bookmarks\f[R]
.PD 0
.P
.PD
If set to true, the \f[B]hg\f[R]* backend will try to get a list of current*
bookmarks.
They will be available via the \[ga]\f[B]%m\f[R]*\[aq] replacement.*
.PP
The default is to generate a comma-separated list of all bookmark names that
refer to the currently checked out revision.
If a bookmark is active, its name is suffixed an asterisk and placed first in
the list.
.PP
\f[B]use-prompt-escapes\f[R]
.PD 0
.P
.PD
Determines if we assume that the assembled string from \f[B]vcs_info\f[R]*
includes prompt escapes.
(Used by* \f[B]vcs_info_lastmsg\f[R]*.)*
.PP
\f[B]debug\f[R]
.PD 0
.P
.PD
Enable debugging output to track possible problems.
Currently this style is only used by \f[B]vcs_info\f[R]*\[aq]s hooks system.*
.PP
\f[B]hooks\f[R]
.PD 0
.P
.PD
A list style that defines hook-function names.
See \f[B]Hooks in vcs_info\f[R] below for details.
.PP
\f[B]patch-format\f[R]
.PP
\f[B]nopatch-format\f[R] This pair of styles format the patch information used
by the \f[B]%m\f[R]* expando in* formats and actionformats for the
\f[B]git\f[R]* and \f[I]\f[BI]hg\f[I]\f[R] backends.
The value is* subject to certain \f[B]%\f[R]\f[I]-expansions described
below.\f[R] The expanded value is made available in the global
\f[B]backend_misc\f[R]* array as* \f[B]${backend_misc[patches]}\f[R]* (also if a
\f[I]\f[BI]set-patch-format\f[I]\f[R] hook is used).*
.PP
\f[B]get-unapplied\f[R]
.PD 0
.P
.PD
This boolean style controls whether a backend should attempt to gather a list of
unapplied patches (for example with Mercurial Queue patches).
.PP
Used by the \f[B]quilt\f[R]* and \f[I]\f[BI]hg\f[I]\f[R] backends.*
.PP
The default values for these styles in all contexts are:
.PP
\f[B]formats\f[R]
.PD 0
.P
.PD
\[dq] (%s)-[%b]%u%c-\[dq]
.PP
\f[B]actionformats\f[R]
.PD 0
.P
.PD
\[dq] (%s)-[%b|%a]%u%c-\[dq]
.PP
\f[B]branchformat\f[R]
.PD 0
.P
.PD
\[dq]%b:%r\[dq] (for bzr, svn, svk and hg)
.PP
\f[B]nvcsformats\f[R]
.PD 0
.P
.PD
\[dq]\[dq]
.PP
\f[B]hgrevformat\f[R]
.PD 0
.P
.PD
\[dq]%r:%h\[dq]
.PP
\f[B]max-exports\f[R]
.PD 0
.P
.PD
2
.PP
\f[B]enable\f[R]
.PD 0
.P
.PD
ALL
.PP
\f[B]disable\f[R]
.PD 0
.P
.PD
(empty list)
.PP
\f[B]disable-patterns\f[R]
.PD 0
.P
.PD
(empty list)
.PP
\f[B]check-for-changes\f[R]
.PD 0
.P
.PD
false
.PP
\f[B]check-for-staged-changes\f[R]
.PD 0
.P
.PD
false
.PP
\f[B]stagedstr\f[R]
.PD 0
.P
.PD
(string: \[dq]S\[dq])
.PP
\f[B]unstagedstr\f[R]
.PD 0
.P
.PD
(string: \[dq]U\[dq])
.PP
\f[B]command\f[R]
.PD 0
.P
.PD
(empty string)
.PP
\f[B]use-server\f[R]
.PD 0
.P
.PD
false
.PP
\f[B]use-simple\f[R]
.PD 0
.P
.PD
false
.PP
\f[B]get-revision\f[R]
.PD 0
.P
.PD
false
.PP
\f[B]get-mq\f[R]
.PD 0
.P
.PD
true
.PP
\f[B]get-bookmarks\f[R]
.PD 0
.P
.PD
false
.PP
\f[B]use-prompt-escapes\f[R]
.PD 0
.P
.PD
true
.PP
\f[B]debug\f[R]
.PD 0
.P
.PD
false
.PP
\f[B]hooks\f[R]
.PD 0
.P
.PD
(empty list)
.PP
\f[B]use-quilt\f[R]
.PD 0
.P
.PD
false
.PP
\f[B]quilt-standalone\f[R]
.PD 0
.P
.PD
false
.PP
\f[B]quilt-patch-dir\f[R]
.PD 0
.P
.PD
empty - use \f[B]$QUILT_PATCHES\f[R]
.PP
\f[B]quiltcommand\f[R]
.PD 0
.P
.PD
quilt
.PP
\f[B]patch-format\f[R]
.PD 0
.P
.PD
\f[I]backend dependent\f[R]
.PP
\f[B]nopatch-format\f[R]
.PD 0
.P
.PD
\f[I]backend dependent\f[R]
.PP
\f[B]get-unapplied\f[R]
.PD 0
.P
.PD
false
.PP
In normal \f[B]formats\f[R]* and \f[I]\f[BI]actionformats\f[I]\f[R] the
following replacements are* done:
.PP
\f[B]%s\f[R]
.PD 0
.P
.PD
The VCS in use (git, hg, svn, etc.).
.PP
\f[B]%b\f[R]
.PD 0
.P
.PD
Information about the current branch.
.PP
\f[B]%a\f[R]
.PD 0
.P
.PD
An identifier that describes the action.
Only makes sense in \f[B]actionformats\f[R]*.*
.PP
\f[B]%i\f[R]
.PD 0
.P
.PD
The current revision number or identifier.
For \f[B]hg\f[R] the \f[B]hgrevformat\f[R]* style may be used to customize the
output.*
.PP
\f[B]%c\f[R]
.PD 0
.P
.PD
The string from the \f[B]stagedstr\f[R]* style if there are staged* changes in
the repository.
.PP
\f[B]%u\f[R]
.PD 0
.P
.PD
The string from the \f[B]unstagedstr\f[R]* style if there are* unstaged changes
in the repository.
.PP
\f[B]%R\f[R]
.PD 0
.P
.PD
The base directory of the repository.
.PP
\f[B]%r\f[R]
.PD 0
.P
.PD
The repository name.
If \f[B]%R\f[R]* is \f[I]\f[BI]/foo/bar/repoXY\f[I]\f[R], \f[I]\f[BI]%r\f[I] is
\f[BI]repoXY\f[I]\f[R].*
.PP
\f[B]%S\f[R]
.PD 0
.P
.PD
A subdirectory within a repository.
If \f[B]$PWD\f[R]* is* \f[B]/foo/bar/repoXY/beer/tasty\f[R]*,
\f[I]\f[BI]%S\f[I]\f[R] is \f[I]\f[BI]beer/tasty\f[I]\f[R].*
.PP
\f[B]%m\f[R] A \[dq]misc\[dq] replacement.
It is at the discretion of the backend to decide what this replacement expands
to.
.RS
.PP
The \f[B]hg\f[R]* and \f[I]\f[BI]git\f[I]\f[R] backends use this expando to
display patch information.* \f[B]hg\f[R]* sources patch information from the
\f[I]\f[BI]mq\f[I]\f[R] extensions; \f[I]\f[BI]git\f[I]\f[R] from in-progress*
\f[B]rebase\f[R]* and \f[I]\f[BI]cherry-pick\f[I]\f[R] operations and from the
\f[I]\f[BI]stgit\f[I]\f[R] extension.
The \f[I]\f[BI]patch-format\f[I] and \f[BI]nopatch-format\f[I]\f[R] styles
control the generated string.
The former is used* when at least one patch from the patch queue has been
applied, and the latter otherwise.
.PP
The \f[B]hg\f[R]* backend displays bookmark information in this expando (in
addition* to \f[B]mq\f[R]* information).
See the \f[I]\f[BI]get-mq\f[I]\f[R] and \f[I]\f[BI]get-bookmarks\f[I]\f[R]
styles.
Both* of these styles may be enabled at the same time.
If both are enabled, both resulting strings will be shown separated by a
semicolon (that cannot currently be customized).
.PP
The \f[B]quilt\f[R]* \[ga]standalone\[aq] backend sets this expando to the same
value as the* \f[B]%Q\f[R]* expando.*
.RE
.PP
\f[B]%Q\f[R]
.PD 0
.P
.PD
Quilt series information.
When quilt is used (either in \[ga]addon\[aq] mode or as a \[ga]standalone\[aq]
backend), this expando is set to quilt series\[aq] \f[B]patch-format\f[R]*
string.* The \f[B]set-patch-format\f[R]* hook and
\f[I]\f[BI]nopatch-format\f[I]\f[R] style are honoured.*
.PP
See \f[B]Quilt Support\f[R]* below for details.*
.PP
In \f[B]branchformat\f[R]* these replacements are done:*
.PP
\f[B]%b\f[R]
.PD 0
.P
.PD
The branch name.
.PP
\f[B]%r\f[R]
.PD 0
.P
.PD
The current revision number or the \f[B]hgrevformat\f[R]* style for*
\f[B]hg\f[R]*.*
.PP
In \f[B]hgrevformat\f[R]* these replacements are done:*
.PP
\f[B]%r\f[R]
.PD 0
.P
.PD
The current local revision number.
.PP
\f[B]%h\f[R]
.PD 0
.P
.PD
The current global revision identifier.
.PP
In \f[B]patch-format\f[R]* and \f[I]\f[BI]nopatch-format\f[I]\f[R] these
replacements are done:*
.PP
\f[B]%p\f[R]
.PD 0
.P
.PD
The name of the top-most applied patch; may be overridden by the
\f[B]applied-string\f[R]* hook.*
.PP
\f[B]%u\f[R]
.PD 0
.P
.PD
The number of unapplied patches; may be overridden by the
\f[B]unapplied-string\f[R]* hook.*
.PP
\f[B]%n\f[R]
.PD 0
.P
.PD
The number of applied patches.
.PP
\f[B]%c\f[R]
.PD 0
.P
.PD
The number of unapplied patches.
.PP
\f[B]%a\f[R]
.PD 0
.P
.PD
The number of all patches (\f[B]%a = %n + %c\f[R]*).*
.PP
\f[B]%g\f[R]
.PD 0
.P
.PD
The names of active \f[B]mq\f[R]* guards (\f[I]\f[BI]hg\f[I]\f[R] backend).*
.PP
\f[B]%G\f[R]
.PD 0
.P
.PD
The number of active \f[B]mq\f[R]* guards (\f[I]\f[BI]hg\f[I]\f[R] backend).*
.PP
Not all VCS backends have to support all replacements.
For \f[B]nvcsformats\f[R] no replacements are performed at all, it is just a
string.
.SS Oddities
.PP
If you want to use the \f[B]%b\f[R]* (bold off) prompt expansion in
\f[I]\f[BI]formats\f[I]\f[R],* which expands \f[B]%b\f[R]* itself, use
\f[I]\f[BI]%%b\f[I]\f[R].
That will cause the \f[I]\f[BI]vcs_info\f[I] expansion to replace
\f[BI]%%b\f[I]\f[R] with \f[I]\f[BI]%b\f[I]\f[R], so that zsh\[aq]s prompt
expansion* mechanism can handle it.
Similarly, to hand down \f[B]%b\f[R]* from* \f[B]branchformat\f[R]*, use
\f[I]\f[BI]%%%%b\f[I]\f[R].
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
When one of the \f[B]gen-applied-string\f[R]*,
\f[I]\f[BI]gen-unapplied-string\f[I]\f[R], and* \f[B]set-patch-format\f[R]*
hooks is defined,* applying \f[B]%\f[R]\f[I]-escaping
(\[ga]\f[R]\f[B]foo=${foo//\[aq]%\[aq]/%%}\f[R]\f[I]\[aq]) to the interpolated
values\f[R] for use in the prompt is the responsibility of those hooks
(jointly); when neither of those hooks is defined, \f[B]vcs_info\f[R]* handles
escaping by itself.* We regret this coupling, but it was required for backwards
compatibility.
.SS Quilt Support
.PP
\f[B]Quilt\f[R]* 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 \f[B]vcs_info\f[R]* integration tries to support both ways of using quilt
by* having two slightly different modes of operation: \[ga]addon\[aq] mode and
\[ga]standalone\[aq] mode).
.PP
Quilt integration is off by default; to enable it, set the \f[B]use-quilt\f[R]*
style,* and add \f[B]%Q\f[R]* to your \f[I]\f[BI]formats\f[I]\f[R] or
\f[I]\f[BI]actionformats\f[I]\f[R] style:*
.RS
.IP
.nf
\f[C]
zstyle \[aq]:vcs_info:*\[aq] use-quilt true
\f[R]
.fi
.RE
.PP
Styles looked up from the Quilt support code include
\[ga]**.quilt-\f[I]\f[R]\f[I]quilt-mode\[aq]\f[R] in the \f[I]vcs-string part of
the context, where quilt-mode is either\f[R] \f[B]addon\f[R]\f[I] or
\f[R]\f[B]standalone\f[R]\f[I].\f[R] Example:
**:vcs_info:git.quilt-addon:default:**\f[I]repo-root-name.\f[R]
.PP
For \[ga]addon\[aq] mode to become active \f[B]vcs_info\f[R]* must have already
detected a* real version control system controlling the directory.
If that is the case, a directory that holds quilt\[aq]s patches needs to be
found.
That directory is configurable via the \[ga]\f[B]QUILT_PATCHES\f[R]*\[aq]
environment variable.
If that* variable exists its value is used, otherwise the value
\[ga]\f[B]patches\f[R]*\[aq] is* assumed.
The value from \f[B]$QUILT_PATCHES\f[R]* can be overwritten using the*
\[ga]\f[B]quilt-patches\f[R]*\[aq] style.
(Note: you can use \f[I]\f[BI]vcs_info\f[I]\f[R] to keep the value* of
\f[B]$QUILT_PATCHES\f[R]* correct all the time via the
\f[I]\f[BI]post-quilt\f[I]\f[R] hook).*
.PP
When the directory in question is found, quilt is assumed to be active.
To gather more information, \f[B]vcs_info\f[R]* looks for a directory called
\[ga].pc\[aq];* 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, \f[B]vcs_info\f[R]* 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 \f[B]get-unapplied\f[R]* style in the appropriate context.*
.PP
\f[B]vcs_info\f[R]* allows for very detailed control over how the gathered*
information is presented (see the \f[B]Configuration\f[R]* and \f[I]\f[BI]Hooks
in vcs_info\f[I]\f[R] sections),* 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 \f[B]stgit\f[R]* for
\f[I]\f[BI]git\f[I]\f[R], or \f[I]\f[BI]mq\f[I]\f[R] for
\f[I]\f[BI]hg\f[I]\f[R]); the configuration* for systems like that are generally
configured the same way as the \f[B]quilt\f[R] support.
.PP
If the \f[B]quilt\f[R]* support is working in \[ga]addon\[aq] mode, the produced
string is* available as a simple format replacement (\f[B]%Q\f[R]* to be
precise), which can* be used in \f[B]formats\f[R]* and
\f[I]\f[BI]actionformats\f[I]\f[R]; see below for details).*
.PP
If, on the other hand, the support code is working in \[ga]standalone\[aq] mode,
\f[B]vcs_info\f[R]* will pretend as if \f[I]\f[BI]quilt\f[I]\f[R] were an actual
version control* system.
That means that the version control system identifier (which otherwise would be
something like \[ga]svn\[aq] or \[ga]cvs\[aq]) will be set to
\[ga]\f[B]-quilt-\f[R]\f[I]\[aq]. This has implications on the used style
context where this\f[R] identifier is the second element.
\f[B]vcs_info\f[R]* will have filled in a proper* value for the
\[dq]repository\[aq]s\[dq] root directory and the string containing the
information about quilt\[aq]s state will be available as the \[ga]misc\[aq]
replacement (and \f[B]%Q\f[R]* for compatibility with \[ga]addon\[aq] mode).*
.PP
What is left to discuss is how \[ga]standalone\[aq] 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
\f[B]vcs_info\f[R]* to try and look for Quilt in \[ga]standalone\[aq] mode to
minimise* the amount of searching on every call to \f[B]vcs_info\f[R]*, there
are a number of* ways to do that:
.PP
Essentially, \[ga]standalone\[aq] mode detection is controlled by a style called
\[ga]\f[B]quilt-standalone\f[R]*\[aq].
It is a string style and its value can have different* effects.
The simplest values are: \[ga]\f[B]always\f[R]*\[aq] to run detection every
time* \f[B]vcs_info\f[R]* is run, and \[ga]\f[I]\f[BI]never\f[I]\f[R]\[aq] to
turn the detection off entirely.*
.PP
If the value of \f[B]quilt-standalone\f[R]* 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 \[ga]always\[aq]/\[ga]never\[aq] way
as described above.
.PP
If the value of \f[B]quilt-standalone\f[R]* is an array, the elements of that
array* are used as directory names under which you want the detection to be
active.
.PP
If \f[B]quilt-standalone\f[R]* 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 \[ga]\f[B]true\f[R]*\[aq].*
.PP
Last, but not least, if the value of \f[B]quilt-standalone\f[R]* is the name of
a* function, the function is called without arguments and the return value
decides whether detection should be active.
A \[ga]0\[aq] 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
\f[B]quilt-standalone\f[R]*, the function will take precedence.*
.SS Function Descriptions (Public API)
.PP
\f[B]vcs_info\f[R]* [user-context]* The main function, that runs all backends
and assembles all data into \f[B]${vcs_info_msg_*_}\f[R]\f[I]. This is the
function you want to call from\f[R] \f[B]precmd\f[R]* if you want to include
up-to-date information in your prompt (see* \f[B]Variable Description\f[R]
below).
If an argument is given, that string will be used instead of \f[B]default\f[R]*
in the user-context field of the style* context.
.PP
\f[B]vcs_info_hookadd\f[R]
.PD 0
.P
.PD
Statically registers a number of functions to a given hook.
The hook needs to be given as the first argument; what follows is a list of
hook-function names to register to the hook.
The \[ga]\f[B]+vi-\f[R]\f[I]\[aq] prefix needs to be left out\f[R] here.
See \f[B]Hooks in vcs_info\f[R] below for details.
.PP
\f[B]vcs_info_hookdel\f[R]
.PD 0
.P
.PD
Remove hook-functions from a given hook.
The hook needs to be given as the first non-option argument; what follows is a
list of hook-function names to un-register from the hook.
If \[ga]\f[B]-a\f[R]*\[aq] is used as the first* argument, \f[B]all\f[R]*
occurrences of the functions are unregistered.
Otherwise* only the last occurrence is removed (if a function was registered to
a hook more than once).
The \[ga]\f[B]+vi-\f[R]\f[I]\[aq] prefix needs to be left out here.\f[R] See
\f[B]Hooks in vcs_info\f[R] below for details.
.PP
\f[B]vcs_info_lastmsg\f[R]
.PD 0
.P
.PD
Outputs the last \f[B]${vcs_info_msg_*_}\f[R]* value.* Takes into account the
value of the \f[B]use-prompt-escapes\f[R]* style in*
\f[B]\[aq]:vcs_info:formats:command:-all-\[aq]\f[R]*.
It also only prints *\f[B]max-exports\f[R] values.
.PP
\f[B]vcs_info_printsys\f[R]* [user-context]*
.PD 0
.P
.PD
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 \f[B]disable\f[R]* style.*
.PP
\f[B]vcs_info_setsys\f[R]
.PD 0
.P
.PD
Initializes \f[B]vcs_info\f[R]*\[aq]s internal list of* available backends.
With this function, you can add support for new VCSs without restarting the
shell.
.PP
All functions named \f[B]VCS_INFO_*\f[R]* are for internal use only.*
.SS Variable Description
.PP
\f[B]${vcs_info_msg_\f[BI]\f[I]N\f[BI]\f[B]_}\f[R]* (Note the trailing
underscore)* Where \f[I]N is an integer, e.g.,
\f[R]\f[B]vcs_info_msg_0_\f[R]\f[I]. These variables\f[R] are the storage for
the informational message the last \f[B]vcs_info\f[R]* call* has assembled.
These are strongly connected to the \f[B]formats\f[R]*,*
\f[B]actionformats\f[R]* and \f[I]\f[BI]nvcsformats\f[I]\f[R] styles described
above.
Those styles* are lists.
The first member of that list gets expanded into \f[B]${vcs_info_msg_0_}\f[R]*,
the second into \f[I]\f[BI]${vcs_info_msg_1_}\f[I] and the Nth into
\f[BI]${vcs_info_msg_N-1_}\f[I]\f[R].
(See the *\f[B]max-exports\f[R] style above.)
.PP
All variables named \f[B]VCS_INFO_*\f[R]* are for internal use only.*
.SS Hooks in vcs_info
.PP
Hooks are places in \f[B]vcs_info\f[R]* where you can run your own code.
That* code can communicate with the code that called it and through that, change
the system\[aq]s behaviour.
.PP
For configuration, hooks change the style context:
.RS
.IP
.nf
\f[C]
:vcs_info:vcs-string+hook-name:user-context:repo-root-name
\f[R]
.fi
.RE
.PP
To register functions to a hook, you need to list them in the \f[B]hooks\f[R]
style in the appropriate context.
.PP
Example:
.RS
.IP
.nf
\f[C]
zstyle \[aq]:vcs_info:*+foo:*\[aq] hooks bar baz
\f[R]
.fi
.RE
.PP
This registers functions to the hook \[ga]foo\[aq] for all backends.
In order to avoid namespace problems, all registered function names are
prepended by a \[ga]\f[B]+vi-\f[R]\f[I]\[aq], so the actual functions called for
the \[ga]foo\[aq] hook are\f[R] \[ga]\f[B]+vi-bar\f[R]*\[aq] and
\[ga]\f[I]\f[BI]+vi-baz\f[I]\f[R]\[aq].*
.PP
If you would like to register a function to a hook regardless of the current
context, you may use the \f[B]vcs_info_hookadd\f[R]* function.
To remove* a function that was added like that, the \f[B]vcs_info_hookdel\f[R]*
function* can be used.
.PP
If something seems weird, you can enable the \[ga]debug\[aq] 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.
Context-sensitive hook functions are executed \f[B]before\f[R]* statically
registered ones (the ones added by* \f[B]vcs_info_hookadd\f[R]*).*
.PP
You may pass data between functions via an associative array,
\f[B]user_data\f[R]*.* For example:
.RS
.IP
.nf
\f[C]
+vi-git-myfirsthook(){
user_data[myval]=$myval
}
+vi-git-mysecondhook(){
# do something with ${user_data[myval]}
}
\f[R]
.fi
.RE
.PP
There are a number of variables that are special in hook contexts:
.PP
\f[B]ret\f[R] The return value that the hooks system will return to the caller.
The default is an integer \[ga]zero\[aq].
If and how a changed \f[B]ret\f[R]* value changes* the execution of the caller
depends on the specific hook.
See the hook documentation below for details.
.PP
\f[B]hook_com\f[R]
.PD 0
.P
.PD
An associated array which is used for bidirectional communication from the
caller to hook functions.
The used keys depend on the specific hook.
.PP
\f[B]context\f[R]
.PD 0
.P
.PD
The active context of the hook.
Functions that wish to change this variable should make it local scope first.
.PP
\f[B]vcs\f[R]
.PD 0
.P
.PD
The current VCS after it was detected.
The same values as in the enable/disable style are used.
Available in all hooks except \f[B]start-up\f[R]*.*
.PP
Finally, the full list of currently available hooks:
.PP
\f[B]start-up\f[R] Called after starting \f[B]vcs_info\f[R]* but before the VCS
in this directory is* determined.
It can be used to deactivate \f[B]vcs_info\f[R]* temporarily if* necessary.
When \f[B]ret\f[R]* is set to \f[I]\f[BI]1\f[I]\f[R],
\f[I]\f[BI]vcs_info\f[I]\f[R] aborts and does* nothing; when set to
\f[B]2\f[R]*, \f[I]\f[BI]vcs_info\f[I]\f[R] sets up everything as if no* version
control were active and exits.
.PP
\f[B]pre-get-data\f[R]
.PD 0
.P
.PD
Same as \f[B]start-up\f[R]* but after the VCS was detected.*
.PP
\f[B]gen-hg-bookmark-string\f[R]
.PD 0
.P
.PD
Called in the Mercurial backend when a bookmark string is generated; the
\f[B]get-revision\f[R]* and \f[I]\f[BI]get-bookmarks\f[I]\f[R] styles must be
true.*
.PP
This hook gets the names of the Mercurial bookmarks that \f[B]vcs_info\f[R]*
collected from \[ga]hg\[aq].*
.PP
If a bookmark is active, the key \f[B]${hook_com[hg-active-bookmark]}\f[R]* is*
set to its name.
The key is otherwise unset.
.PP
When setting \f[B]ret\f[R]* to non-zero, the string in*
\f[B]${hook_com[hg-bookmark-string]}\f[R]* will be used in the
\f[I]\f[BI]%m\f[I]\f[R] escape in* \f[B]formats\f[R]* and
\f[I]\f[BI]actionformats\f[I]\f[R] and will be available in the global*
\f[B]backend_misc\f[R]* array as
\f[I]\f[BI]${backend_misc[bookmarks]}\f[I]\f[R].*
.PP
\f[B]gen-applied-string\f[R]
.PD 0
.P
.PD
Called in the \f[B]git\f[R]* (with \f[I]\f[BI]stgit\f[I]\f[R] or during rebase
or merge), and \f[I]\f[BI]hg\f[I] (with \f[BI]mq\f[I]\f[R]) backends and in
\f[I]\f[BI]quilt\f[I]\f[R] support when the \f[I]\f[BI]applied-string\f[I] is
generated; the \f[BI]use-quilt\f[I]\f[R] zstyle must be true for
\f[I]\f[BI]quilt\f[I]\f[R] (the \f[I]\f[BI]mq\f[I] and \f[BI]stgit\f[I]\f[R]
backends are active by default).*
.PP
This hook gets the names of all applied patches which \f[B]vcs_info\f[R]*
collected* so far in the opposite order, which means that the first argument is
the top-most patch and so forth.
.PP
When setting \f[B]ret\f[R]* to non-zero, the string in*
\f[B]${hook_com[applied-string]}\f[R]* will be* available as \f[B]%p\f[R]* in
the \f[I]\f[BI]patch-format\f[I]\f[R] and \f[I]\f[BI]nopatch-format\f[I]\f[R]
styles.* This hook is, in concert with \f[B]set-patch-format\f[R]*, responsible
for* \f[B]%\f[R]\f[I]-escaping that value for use in the prompt.\f[R] (See the
\f[B]Oddities\f[R]* section.)*
.PP
\f[B]gen-unapplied-string\f[R]
.PD 0
.P
.PD
Called in the \f[B]git\f[R]* (with \f[I]\f[BI]stgit\f[I]\f[R] or during rebase),
and \f[I]\f[BI]hg\f[I]\f[R] (with* \f[B]mq\f[R]*) backend and in
\f[I]\f[BI]quilt\f[I]\f[R] support when the
\f[I]\f[BI]unapplied-string\f[I]\f[R] is* generated; the
\f[B]get-unapplied\f[R]* style must be true.*
.PP
This hook gets the names of all unapplied patches which \f[B]vcs_info\f[R]
collected so far in order, which means that the first argument is the patch
next-in-line to be applied and so forth.
.PP
When setting \f[B]ret\f[R]* to non-zero, the string in*
\f[B]${hook_com[unapplied-string]}\f[R]* will be available as
\f[I]\f[BI]%u\f[I]\f[R] in the* \f[B]patch-format\f[R]* and
\f[I]\f[BI]nopatch-format\f[I]\f[R] styles.* This hook is, in concert with
\f[B]set-patch-format\f[R]*, responsible for* \f[B]%\f[R]\f[I]-escaping that
value for use in the prompt.\f[R] (See the \f[B]Oddities\f[R]* section.)*
.PP
\f[B]gen-mqguards-string\f[R]
.PD 0
.P
.PD
Called in the \f[B]hg\f[R]* backend when \f[I]\f[BI]guards-string\f[I]\f[R] is
generated; the* \f[B]get-mq\f[R]* style must be true (default).*
.PP
This hook gets the names of any active \f[B]mq\f[R]* guards.*
.PP
When setting \f[B]ret\f[R]* to non-zero, the string in*
\f[B]${hook_com[guards-string]}\f[R]* will be used in the
\f[I]\f[BI]%g\f[I]\f[R] escape in the* \f[B]patch-format\f[R]* and
\f[I]\f[BI]nopatch-format\f[I]\f[R] styles.*
.PP
\f[B]no-vcs\f[R]
.PD 0
.P
.PD
This hooks is called when no version control system was detected.
.PP
The \[ga]\f[B]hook_com\f[R]*\[aq] parameter is not used.*
.PP
\f[B]post-backend\f[R]
.PD 0
.P
.PD
Called as soon as the backend has finished collecting information.
.PP
The \[ga]\f[B]hook_com\f[R]*\[aq] keys available are as for the
\f[I]\f[BI]set-message\f[I]\f[R] hook.*
.PP
\f[B]post-quilt\f[R]
.PD 0
.P
.PD
Called after the \f[B]quilt\f[R]* support is done.
The following information* is passed as arguments to the hook: 1.
the quilt-support mode (\[ga]addon\[aq] or \[ga]standalone\[aq]); 2.
the directory that contains the patch series; 3.
the directory that holds quilt\[aq]s status information (the \[ga].pc\[aq]
directory) or the string \f[B]\[dq]-nopc-\[dq]\f[R]* if that directory
wasn\[aq]t found.*
.PP
The \[ga]hook_com\[aq] parameter is not used.
.PP
\f[B]set-branch-format\f[R]
.PD 0
.P
.PD
Called before \[ga]\f[B]branchformat\f[R]*\[aq] is set.
The only argument to the* hook is the format that is configured at this point.
.PP
The \[ga]\f[B]hook_com\f[R]*\[aq] keys considered are
\[ga]\f[I]\f[BI]branch\f[I]\f[R]\[aq] and
\[ga]\f[I]\f[BI]revision\f[I]\f[R]\[aq].* They are set to the values figured out
so far by \f[B]vcs_info\f[R]* and any* change will be used directly when the
actual replacement is done.
.PP
If \f[B]ret\f[R]* is set to non-zero, the string in*
\f[B]${hook_com[branch-replace]}\f[R]* will be used unchanged as the*
\[ga]\f[B]%b\f[R]*\[aq] replacement in the variables set by
\f[I]\f[BI]vcs_info\f[I]\f[R].*
.PP
\f[B]set-hgrev-format\f[R]
.PD 0
.P
.PD
Called before a \[ga]\f[B]hgrevformat\f[R]*\[aq] is set.
The only argument to the* hook is the format that is configured at this point.
.PP
The \[ga]\f[B]hook_com\f[R]*\[aq] keys considered are
\[ga]\f[I]\f[BI]hash\f[I]\f[R]\[aq] and
\[ga]\f[I]\f[BI]localrev\f[I]\f[R]\[aq].* They are set to the values figured out
so far by \f[B]vcs_info\f[R]* and any* change will be used directly when the
actual replacement is done.
.PP
If \f[B]ret\f[R]* is set to non-zero, the string in*
\f[B]${hook_com[rev-replace]}\f[R]* will be used unchanged as the*
\[ga]\f[B]%i\f[R]*\[aq] replacement in the variables set by
\f[I]\f[BI]vcs_info\f[I]\f[R].*
.PP
\f[B]pre-addon-quilt\f[R]
.PD 0
.P
.PD
This hook is used when \f[B]vcs_info\f[R]*\[aq]s quilt functionality is active
in \[dq]addon\[dq]* mode (quilt used on top of a real version control system).
It is activated right before any quilt specific action is taken.
.PP
Setting the \[ga]\f[B]ret\f[R]*\[aq] variable in this hook to a non-zero value
avoids any* quilt specific actions from being run at all.
.PP
\f[B]set-patch-format\f[R]
.PD 0
.P
.PD
This hook is used to control some of the possible expansions in
\f[B]patch-format\f[R]* and \f[I]\f[BI]nopatch-format\f[I]\f[R] styles with
patch queue systems such as* quilt, mqueue and the like.
.PP
This hook is used in the \f[B]git\f[R]*, \f[I]\f[BI]hg\f[I]\f[R] and
\f[I]\f[BI]quilt\f[I]\f[R] backends.*
.PP
The hook allows the control of the \f[B]%p\f[R]*
(\f[I]\f[BI]${hook_com[applied]}\f[I]\f[R]) and \f[I]\f[BI]%u\f[I]
(${hook_com[unapplied]}\f[R]) expansion in all backends that use the hook.
With\f[I] the mercurial backend, the \f[BI]%g\f[I]\f[R]
(\f[I]\f[BI]${hook_com[guards]}\f[I]\f[R]) expansion is* controllable in
addition to that.
.PP
If \f[B]ret\f[R]* is set to non-zero, the string in
\f[I]\f[BI]${hook_com[patch-replace]}\f[I] will be used unchanged instead of an
expanded format from \f[BI]patch-format\f[I]\f[R] or*
\f[B]nopatch-format\f[R]*.*
.PP
This hook is, in concert with the \f[B]gen-applied-string\f[R]* or*
\f[B]gen-unapplied-string\f[R]* hooks if they are defined, responsible for*
\f[B]%\f[R]\f[I]-escaping the final \f[R]\f[B]patch-format\f[R]\f[I] value for
use in the prompt.\f[R] (See the \f[B]Oddities\f[R]* section.)*
.PP
\f[B]set-message\f[R]
.PD 0
.P
.PD
Called each time before a
\[ga]\f[B]vcs_info_msg_\f[BI]\f[I]N\f[BI]\f[B]_\f[R]\f[I]\[aq] message is
set.\f[R] It takes two arguments; the first being the \[ga]\f[I]N\[aq] in the
message\f[R] variable name, the second is the currently configured
\f[B]formats\f[R]* or* \f[B]actionformats\f[R]*.*
.PP
There are a number of \[ga]\f[B]hook_com\f[R]*\[aq] keys, that are used here:*
\[ga]\f[B]action\f[R]*\[aq], \[ga]\f[I]\f[BI]branch\f[I]\f[R]\[aq],
\[ga]\f[I]\f[BI]base\f[I]\f[R]\[aq], \[ga]\f[I]\f[BI]base-name\f[I]\f[R]\[aq],
\[ga]\f[I]\f[BI]subdir\f[I]\f[R]\[aq],* \[ga]\f[B]staged\f[R]*\[aq],
\[ga]\f[I]\f[BI]unstaged\f[I]\f[R]\[aq],
\[ga]\f[I]\f[BI]revision\f[I]\f[R]\[aq], \[ga]\f[I]\f[BI]misc\f[I]\f[R]\[aq],
\[ga]\f[I]\f[BI]vcs\f[I]\f[R]\[aq]* and one \[ga]\f[B]miscN\f[R]*\[aq] entry for
each backend-specific data field (\f[I]\f[BI]N\f[I] starting at zero). They are
set to the values figured out so far by \f[BI]vcs_info\f[I]\f[R] 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
\f[B]formats\f[R]* or \f[I]\f[BI]actionformats\f[I]\f[R]), each of the
\[ga]\f[I]\f[BI]hook_com\f[I]\f[R]\[aq] keys mentioned* above (except for the
\f[B]miscN\f[R]* entries) has an \[ga]\f[I]\f[BI]_orig\f[I]\f[R]\[aq]
counterpart,* so even if you changed a value to your liking you can still get
the original value in the next run.
Changing the \[ga]\f[B]_orig\f[R]*\[aq] values is* probably not a good idea.
.PP
If \f[B]ret\f[R]* is set to non-zero, the string in*
\f[B]${hook_com[message]}\f[R]* will be used unchanged as the message by*
\f[B]vcs_info\f[R]*.*
.PP
If all of this sounds rather confusing, take a look at the \f[B]Examples\f[R]*
section below* and also in the \f[B]Misc/vcs_info-examples\f[R]* file in the Zsh
source.* They contain some explanatory code.
.SS Examples
.PP
Don\[aq]t use \f[B]vcs_info\f[R]* at all (even though it\[aq]s in your prompt):*
.RS
.IP
.nf
\f[C]
zstyle \[aq]:vcs_info:*\[aq] enable NONE
\f[R]
.fi
.RE
.PP
Disable the backends for \f[B]bzr\f[R]* and \f[I]\f[BI]svk\f[I]\f[R]:*
.RS
.IP
.nf
\f[C]
zstyle \[aq]:vcs_info:*\[aq] disable bzr svk
\f[R]
.fi
.RE
.PP
Disable everything \f[I]but \f[R]\f[B]bzr\f[R]\f[I] and
\f[R]\f[B]svk\f[R]\f[I]:\f[R]
.RS
.IP
.nf
\f[C]
zstyle \[aq]:vcs_info:*\[aq] enable bzr svk
\f[R]
.fi
.RE
.PP
Provide a special formats for \f[B]git\f[R]*:*
.RS
.IP
.nf
\f[C]
zstyle \[aq]:vcs_info:git:*\[aq] formats \[aq] GIT, BABY! [%b]\[aq]
zstyle \[aq]:vcs_info:git:*\[aq] actionformats \[aq] GIT ACTION! [%b|%a]\[aq]
\f[R]
.fi
.RE
.PP
All \f[B]%x\f[R]* expansion in all sorts of formats
(\f[I]\f[BI]formats\f[I]\f[R], \f[I]\f[BI]actionformats\f[I]\f[R],*
\f[B]branchformat\f[R]*, you name it) are done using the
\[ga]\f[I]\f[BI]zformat\f[I]\f[R]\[aq] builtin from* the
\[ga]\f[B]zsh/zutil\f[R]*\[aq] module.
That means you can do everything with these* \f[B]%x\f[R]* 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: \f[B]%12.12i\f[R]*.
That\[aq]ll shrink the 40 character* hash to its 12 leading characters.
The form is actually
\[ga]\f[B]%\f[BI]\f[I]min\f[BI]\f[B].\f[BI]\f[I]max\f[BI]\f[B]x\f[R]*\[aq].
More is possible.* See the section \[ga]The zsh/zutil Module\[aq] in
\f[I]zshmodules(1) for details.\f[R]
.PP
Use the quicker \f[B]bzr\f[R]* backend*
.RS
.IP
.nf
\f[C]
zstyle \[aq]:vcs_info:bzr:*\[aq] use-simple true
\f[R]
.fi
.RE
.PP
If you do use \f[B]use-simple\f[R]*, please report if it does
\[ga]the-right-thing[tm]\[aq].*
.PP
Display the revision number in yellow for \f[B]bzr\f[R]* and
\f[I]\f[BI]svn\f[I]\f[R]:*
.RS
.IP
.nf
\f[C]
zstyle \[aq]:vcs_info:(svn|bzr):*\[aq] \[rs]
branchformat \[aq]%b%{\[aq]${fg[yellow]}\[aq]%}:%r\[aq]
\f[R]
.fi
.RE
.PP
If you want colors, make sure you enclose the color codes in
\f[B]%{\f[R]\f[I]...\f[R]\f[B]%}\f[R] if you want to use the string provided by
\f[B]vcs_info\f[R]* in prompts.*
.PP
Here is how to print the VCS information as a command (not in a prompt):
.RS
.IP
.nf
\f[C]
alias vcsi=\[aq]vcs_info command; vcs_info_lastmsg\[aq]
\f[R]
.fi
.RE
.PP
This way, you can even define different formats for output via
\f[B]vcs_info_lastmsg\f[R]* in the
\[aq]\f[I]\f[BI]:vcs_info:*:command:*\f[I]\f[R]\[aq] namespace.*
.PP
Now as promised, some code that uses hooks: say, you\[aq]d like to replace the
string \[ga]svn\[aq] by \[ga]subversion\[aq] in \f[B]vcs_info\f[R]*\[aq]s
\f[I]\f[BI]%s\f[I]\f[R] \f[I]\f[BI]formats\f[I]\f[R] replacement.*
.PP
First, we will tell \f[B]vcs_info\f[R]* to call a function when populating* the
message variables with the gathered information:
.RS
.IP
.nf
\f[C]
zstyle \[aq]:vcs_info:*+set-message:*\[aq] hooks svn2subversion
\f[R]
.fi
.RE
.PP
Nothing happens.
Which is reasonable, since we didn\[aq]t define the actual function yet.
To see what the hooks subsystem is trying to do, enable the
\[ga]\f[B]debug\f[R]*\[aq] style:*
.RS
.IP
.nf
\f[C]
zstyle \[aq]:vcs_info:*+*:*\[aq] debug true
\f[R]
.fi
.RE
.PP
That should give you an idea what is going on.
Specifically, the function that we are looking for is
\[ga]\f[B]+vi-svn2subversion\f[R]*\[aq].
Note, the \[ga]\f[I]\f[BI]+vi-\f[I]\f[R]\[aq]* prefix.
So, everything is in order, just as documented.
When you are done checking out the debugging output, disable it again:
.RS
.IP
.nf
\f[C]
zstyle \[aq]:vcs_info:*+*:*\[aq] debug false
\f[R]
.fi
.RE
.PP
Now, let\[aq]s define the function:
.RS
.IP
.nf
\f[C]
function +vi-svn2subversion() {
[[ ${hook_com[vcs_orig]} == svn ]] && hook_com[vcs]=subversion
}
\f[R]
.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 \[ga]\f[B]svn\f[R]*\[aq] backend\[aq]s context, we
don\[aq]t need to test which the active* backend is:
.RS
.IP
.nf
\f[C]
zstyle \[aq]:vcs_info:svn+set-message:*\[aq] hooks svn2subversion
\f[R]
.fi
.RE
.RS
.IP
.nf
\f[C]
function +vi-svn2subversion() {
hook_com[vcs]=subversion
}
\f[R]
.fi
.RE
.PP
And finally a little more elaborate example, that uses a hook to create a
customised bookmark string for the \f[B]hg\f[R]* backend.*
.PP
Again, we start off by registering a function:
.RS
.IP
.nf
\f[C]
zstyle \[aq]:vcs_info:hg+gen-hg-bookmark-string:*\[aq] hooks hgbookmarks
\f[R]
.fi
.RE
.PP
And then we define the \[ga]\f[B]+vi-hgbookmarks\f[R]*\[aq] function:*
.RS
.IP
.nf
\f[C]
function +vi-hgbookmarks() {
# The default is to connect all bookmark names by
# commas. This mixes things up a little.
# Imagine, there\[aq]s one type of bookmarks that is
# special to you. Say, because it\[aq]s *your* work.
# Those bookmarks look always like this: \[dq]sh/*\[dq]
# (because your initials are sh, for example).
# This makes the bookmarks string use only those
# bookmarks. If there\[aq]s more than one, it
# concatenates them using commas.
# The bookmarks returned by \[ga]hg\[aq] are available in
# the function\[aq]s positional parameters.
local s=\[dq]${(Mj:,:)\[at]:#sh/*}\[dq]
# Now, the communication with the code that calls
# the hook functions is done via the hook_com[]
# hash. The key at which the \[ga]gen-hg-bookmark-string\[aq]
# hook looks is \[ga]hg-bookmark-string\[aq]. So:
hook_com[hg-bookmark-string]=$s
# And to signal that we want to use the string we
# just generated, set the special variable \[ga]ret\[aq] to
# something other than the default zero:
ret=1
return 0
}
\f[R]
.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\[aq]s \f[B]vcs_info\f[R]*.*
.SH PROMPT THEMES
.SS Installation
.PP
You should make sure all the functions from the \f[B]Functions/Prompts\f[R]
directory of the source distribution are available; they all begin with the
string \[ga]\f[B]prompt_\f[R]\f[I]\[aq] except for the special
function\[ga]\f[R]\f[B]promptinit\f[R]\f[I]\[aq].\f[R] You also need the
\[ga]\f[B]colors\f[R]*\[aq] and \[ga]\f[I]\f[BI]add-zsh-hook\f[I]\f[R]\[aq]
functions from* \f[B]Functions/Misc\f[R]*.* All these functions may already be
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 \f[B]fpath\f[R]* array
(this should already be the* case if they were installed), and at least the
function \f[B]promptinit\f[R] should be autoloaded; it will autoload the rest.
Finally, to initialize the use of the system you need to call the
\f[B]promptinit\f[R]* function.
The* following code in your \f[B].zshrc\f[R]* will arrange for this; assume the*
functions are stored in the directory \f[B]\[ti]/myfns\f[R]*:*
.RS
.IP
.nf
\f[C]
fpath=(\[ti]/myfns $fpath)
autoload -U promptinit
promptinit
\f[R]
.fi
.RE
.SS Theme Selection
.PP
Use the \f[B]prompt\f[R]* command to select your preferred theme.
This command* may be added to your \f[B].zshrc\f[R]* following the call to
\f[I]\f[BI]promptinit\f[I]\f[R] in* order to start zsh with a theme already
selected.
.PP
\f[B]prompt\f[R]* [ \f[I]\f[BI]-c\f[I]\f[R] | \f[I]\f[BI]-l\f[I]\f[R] ]*
.PP
\f[B]prompt\f[R]* [ \f[I]\f[BI]-p\f[I]\f[R] | \f[I]\f[BI]-h\f[I]\f[R] ] [ theme
\&...
]*
.PP
\f[B]prompt\f[R]* [ \f[I]\f[BI]-s\f[I]\f[R] ] theme [ arg ...
]* Set or examine the prompt theme.
With no options and a \f[I]theme\f[R] argument, the theme with that name is set
as the current theme.
The available themes are determined at run time; use the \f[B]-l\f[R]* option to
see* a list.
The special \f[I]theme \[ga]\f[R]\f[B]random\f[R]\f[I]\[aq] selects at random
one of the\f[R] available themes and sets your prompt to that.
.RS
.PP
In some cases the \f[I]theme may be modified by one or more arguments,\f[R]
which should be given after the theme name.
See the help for each theme for descriptions of these arguments.
.PP
Options are:
.PP
\f[B]-c\f[R]
.PD 0
.P
.PD
Show the currently selected theme and its parameters, if any.
.PP
\f[B]-l\f[R]
.PD 0
.P
.PD
List all available prompt themes.
.PP
\f[B]-p\f[R]
.PD 0
.P
.PD
Preview the theme named by \f[I]theme, or all themes if no\f[R] \f[I]theme is
given.\f[R]
.PP
\f[B]-h\f[R]
.PD 0
.P
.PD
Show help for the theme named by \f[I]theme, or for the\f[R] \f[B]prompt\f[R]*
function if no theme is given.*
.PP
\f[B]-s\f[R]
.PD 0
.P
.PD
Set \f[I]theme as the current theme and save state.\f[R]
.RE
.PP
\f[B]prompt_\f[BI]\f[I]theme\f[BI]\f[B]_setup\f[R]
.PD 0
.P
.PD
Each available \f[I]theme has a setup function which is called by the\f[R]
\f[B]prompt\f[R]* 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\[aq]s setup function directly.
.SS Utility Themes
.PP
\f[B]prompt off\f[R] The theme \[ga]\f[B]off\f[R]*\[aq] sets all the prompt
variables to minimal values with* no special effects.
.PP
\f[B]prompt default\f[R]
.PD 0
.P
.PD
The theme \[ga]\f[B]default\f[R]*\[aq] sets all prompt variables to the same
state as* if an interactive zsh was started with no initialization files.
.PP
\f[B]prompt restore\f[R]
.PD 0
.P
.PD
The special theme \[ga]\f[B]restore\f[R]*\[aq] erases all theme settings and
sets prompt* variables to their state before the first time the
\[ga]\f[B]prompt\f[R]*\[aq] function* was run, provided each theme has properly
defined its cleanup (see below).
.PP
Note that you can undo \[ga]\f[B]prompt off\f[R]*\[aq] and
\[ga]\f[I]\f[BI]prompt default\f[I]\f[R]\[aq] with* \[ga]\f[B]prompt
restore\f[R]*\[aq], but a second restore does not undo the first.*
.SS Writing Themes
.PP
The first step for adding your own theme is to choose a name for it, and create
a file \[ga]\f[B]prompt_\f[BI]\f[I]name\f[BI]\f[B]_setup\f[R]*\[aq] in a
directory in your* \f[B]fpath\f[R]*, such as \f[I]\f[BI]\[ti]/myfns\f[I]\f[R] in
the example above.
The file should* at minimum contain assignments for the prompt variables that
your theme wishes to modify.
By convention, themes use \f[B]PS1\f[R]*, \f[I]\f[BI]PS2\f[I]\f[R],*
\f[B]RPS1\f[R]*, etc., rather than the longer \f[I]\f[BI]PROMPT\f[I]\f[R] and
\f[I]\f[BI]RPROMPT\f[I]\f[R].*
.PP
The file is autoloaded as a function in the current shell context, so it may
contain any necessary commands to customize your theme, including defining
additional functions.
To make some complex tasks easier, your setup function may also do any of the
following:
.PP
Assign \f[B]prompt_opts\f[R] The array \f[B]prompt_opts\f[R]* may be assigned
any of \f[I]\f[BI]\[dq]bang\[dq]\f[I]\f[R], \f[I]\f[BI]\[dq]cr\[dq]\f[I]\f[R],*
\f[B]\[dq]percent\[dq]\f[R]\f[I], \f[R]\f[B]\[dq]sp\[dq]\f[R]\f[I], and/or
\f[R]\f[B]\[dq]subst\[dq]\f[R]\f[I] as values. The corresponding\f[R] setopts
(\f[B]promptbang\f[R]*, etc.) are turned on, all other prompt-related* options
are turned off.
The \f[B]prompt_opts\f[R]* array preserves setopts even* beyond the scope of
\f[B]localoptions\f[R]*, should your function need that.*
.PP
Modify precmd and preexec
.PD 0
.P
.PD
Use of \f[B]add-zsh-hook\f[R]* is recommended.
The \f[I]\f[BI]precmd\f[I]\f[R] and *\f[B]preexec\f[R] hooks are automatically
adjusted if the prompt theme changes or is disabled.
.PP
Declare cleanup
.PD 0
.P
.PD
If your function makes any other changes that should be undone when the theme is
disabled, your setup function may call
.IP
.nf
\f[C]
prompt_cleanup command
\f[R]
.fi
.PP
where \f[I]command should be suitably quoted. If your theme is ever\f[R]
disabled or replaced by another, \f[I]command is executed with
\f[R]\f[B]eval\f[R]\f[I].\f[R] You may declare more than one such cleanup hook.
.PP
Define preview
.PD 0
.P
.PD
Define or autoload a function
\f[B]prompt_\f[BI]\f[I]name\f[BI]\f[B]_preview\f[R]* to display* a simulated
version of your prompt.
A simple default previewer is defined by \f[B]promptinit\f[R]* for themes that
do not define their own.* This preview function is called by \[ga]\f[B]prompt
-p\f[R]*\[aq].*
.PP
Provide help
.PD 0
.P
.PD
Define or autoload a function \f[B]prompt_\f[BI]\f[I]name\f[BI]\f[B]_help\f[R]*
to display* documentation or help text for your theme.
This help function is called by \[ga]\f[B]prompt -h\f[R]*\[aq].*
.SH ZLE FUNCTIONS
.SS Widgets
.PP
These functions all implement user-defined ZLE widgets (see \f[I]zshzle(1))
which can be bound to keystrokes in interactive shells. To use them,\f[R] your
\f[B].zshrc\f[R]* should contain lines of the form*
.RS
.IP
.nf
\f[C]
autoload function
zle -N function
\f[R]
.fi
.RE
.PP
followed by an appropriate \f[B]bindkey\f[R]* command to associate the function*
with a key sequence.
Suggested bindings are described below.
.PP
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
.RS
.IP
.nf
\f[C]
autoload -U select-word-style
select-word-style bash
\f[R]
.fi
.RE
.RE
.PP
\f[B]forward-word-match\f[R]*, *\f[B]backward-word-match\f[R]
.PP
\f[B]kill-word-match\f[R]*, *\f[B]backward-kill-word-match\f[R]
.PP
\f[B]transpose-words-match\f[R]*, *\f[B]capitalize-word-match\f[R]
.PP
\f[B]up-case-word-match\f[R]*, *\f[B]down-case-word-match\f[R]
.PP
\f[B]delete-whole-word-match\f[R]*, *\f[B]select-word-match\f[R]
.PP
\f[B]select-word-style\f[R]*, \f[I]\f[BI]match-word-context\f[I]\f[R],
\f[I]\f[BI]match-words-by-style\f[I] The first eight \[ga]-match\f[R]**\[aq]
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 \f[B]select-word-style\f[R]*,*
the way words are matched can be altered.
\f[B]select-word-match\f[R]* is intended* to be used as a text object in vi mode
but with custom word styles.
For comparison, the widgets described in \f[I]zshzle(1) under Text Objects use
fixed definitions of words, compatible\f[R] with the \f[B]vim\f[R]* editor.*
.RS
.PP
The simplest way of configuring the functions is to use
\f[B]select-word-style\f[R]*, 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 first eight \f[B]-match\f[R]* 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
\f[B]bash\f[R] Word characters are alphanumeric characters only.
.PP
\f[B]normal\f[R]
.PD 0
.P
.PD
As in normal shell operation: word characters are alphanumeric characters plus
any characters present in the string given by the parameter
\f[B]$WORDCHARS\f[R]*.*
.PP
\f[B]shell\f[R]
.PD 0
.P
.PD
Words are complete shell command arguments, possibly including complete quoted
strings, or any tokens special to the shell.
.PP
\f[B]whitespace\f[R]
.PD 0
.P
.PD
Words are any set of characters delimited by whitespace.
.PP
\f[B]default\f[R]
.PD 0
.P
.PD
Restore the default settings; this is usually the same as
\[ga]\f[B]normal\f[R]*\[aq].*
.PP
All but \[ga]\f[B]default\f[R]*\[aq] 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 \f[B]subword-range\f[R] can supply an alternative character range to
the default \[ga]\f[B][:upper:]\f[R]\f[I]\[aq];\f[R] the value of the style is
treated as the contents of a
\[ga]\f[B][\f[R]\f[I]...\f[R]\f[B]]\f[R]\f[I]\[aq]\f[R] pattern (note that the
outer brackets should not be supplied, only those surrounding named ranges).
.PP
More control can be obtained using the \f[B]zstyle\f[R]* command, as described
in* \f[I]zshmodules(1). Each style is looked up in the\f[R] context
\f[I]\f[R]:zle:\f[I]\f[R]\f[I]widget where widget is the name of the\f[R]
user-defined widget, not the name of the function implementing it, so in the
case of the definitions supplied by \f[B]select-word-style\f[R]\f[I] the\f[R]
appropriate contexts are \f[B]:zle:forward-word\f[R]\f[I], and so on. The
function\f[R] \f[B]select-word-style\f[R]* itself always defines styles for the
context* \[ga]\f[B]:zle:*\f[R]\f[I]\[aq] which can be overridden by more
specific (longer) patterns as\f[R] well as explicit contexts.
.PP
The style \f[B]word-style\f[R]* specifies the rules to use.
This may have the* following values.
.PP
\f[B]normal\f[R] Use the standard shell rules, i.e.
alphanumerics and \f[B]$WORDCHARS\f[R]*, unless* overridden by the styles
\f[B]word-chars\f[R]* or \f[I]\f[BI]word-class\f[I]\f[R].*
.PP
\f[B]specified\f[R]
.PD 0
.P
.PD
Similar to \f[B]normal\f[R]*, but only the specified characters, and not also*
alphanumerics, are considered word characters.
.PP
\f[B]unspecified\f[R]
.PD 0
.P
.PD
The negation of specified.
The given characters are those which will \f[I]not be considered part of a
word.\f[R]
.PP
\f[B]shell\f[R]
.PD 0
.P
.PD
Words are obtained by using the syntactic rules for generating shell command
arguments.
In addition, special tokens which are never command arguments such as
\[ga]\f[B]()\f[R]\f[I]\[aq] are also treated as words.\f[R]
.PP
\f[B]whitespace\f[R]
.PD 0
.P
.PD
Words are whitespace-delimited strings of characters.
.PP
The first three of those rules usually use \f[B]$WORDCHARS\f[R]*, but the value*
in the parameter can be overridden by the style \f[B]word-chars\f[R]*, which
works* in exactly the same way as \f[B]$WORDCHARS\f[R]*.
In addition, the style* \f[B]word-class\f[R]* uses character class syntax to
group characters and takes* precedence over \f[B]word-chars\f[R]* if both are
set.
The \f[I]\f[BI]word-class\f[I]\f[R] style* does not include the surrounding
brackets of the character class; for example,
\[ga]\f[B]-:[:alnum:]\f[R]\f[I]\[aq] is a valid \f[R]\f[B]word-class\f[R]\f[I]
to include all\f[R] alphanumerics plus the characters \[ga]\f[B]-\f[R]\f[I]\[aq]
and \[ga]\f[R]\f[B]:\f[R]\f[I]\[aq]. Be careful\f[R] including
\[ga]\f[B]]\f[R]\f[I]\[aq], \[ga]\f[R]\f[B]\[ha]\f[R]\f[I]\[aq] and
\[ga]\f[R]\f[B]-\f[R]\f[I]\[aq] as these are special inside\f[R] character
classes.
.PP
\f[B]word-style\f[R]* may also have \[ga]\f[I]\f[BI]-subword\f[I]\f[R]\[aq]
appended to its value to* turn on subword matching, as described above.
.PP
The style \f[B]skip-chars\f[R]* is mostly useful for* \f[B]transpose-words\f[R]*
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
.RS
.IP
.nf
\f[C]
zstyle \[aq]:zle:transpose-words\[aq] skip-chars 1
\f[R]
.fi
.RE
.PP
has been set, and \f[B]transpose-words-match\f[R]* is called with the cursor on*
the \f[I]X of \f[R]\f[B]foo\f[R]\f[I]X\f[R]\f[B]bar\f[R]*, where X can be any
character, then* the resulting expression is
\f[B]bar\f[R]\f[I]X\f[R]\f[B]foo\f[R]*.*
.PP
Finer grained control can be obtained by setting the style
\f[B]word-context\f[R] to an array of pairs of entries.
Each pair of entries consists of a \f[I]pattern and a subcontext. The shell
argument the cursor is on is\f[R] matched against each \f[I]pattern in turn
until one matches; if it does,\f[R] the context is extended by a colon and the
corresponding \f[I]subcontext.\f[R] 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 \f[B]between\f[R]* the word* is set to a single space;
else if it is contains the string \f[B]back\f[R]*,* the word before the cursor
is considered, else the word after cursor is considered.
Some examples are given below.
.PP
The style \f[B]skip-whitespace-first\f[R]* is only used with the*
\f[B]forward-word\f[R]* widget.
If it is set to true, then \f[I]\f[BI]forward-word\f[I] skips any
non-word-characters, followed by any non-word-characters: this is similar to the
behaviour of other word-orientated widgets, and also that used by other editors,
however it differs from the standard zsh behaviour. When using
\f[BI]select-word-style\f[I]\f[R] the widget* is set in the context
\f[B]:zle:*\f[R]* to \f[I]\f[BI]true\f[I]\f[R] if the word style is*
\f[B]bash\f[R]* and \f[I]\f[BI]false\f[I]\f[R] otherwise.
It may be overridden by setting it in* the more specific context
\f[B]:zle:forward-word*\f[R]\f[I].\f[R]
.PP
It is possible to create widgets with specific behaviour by defining a new
widget implemented by the appropriate generic function, then setting a style for
the context of the specific widget.
For example, the following defines a widget \f[B]backward-kill-space-word\f[R]*
using* \f[B]backward-kill-word-match\f[R]*, the generic widget implementing*
\f[B]backward-kill-word\f[R]* behaviour, and ensures that the new widget* always
implements space-delimited behaviour.
.RS
.IP
.nf
\f[C]
zle -N backward-kill-space-word backward-kill-word-match
zstyle :zle:backward-kill-space-word word-style space
\f[R]
.fi
.RE
.PP
The widget \f[B]backward-kill-space-word\f[R]* can now be bound to a key.*
.PP
Here are some further examples of use of the styles, actually taken from the
simplified interface in \f[B]select-word-style\f[R]*:*
.RS
.IP
.nf
\f[C]
zstyle \[aq]:zle:*\[aq] word-style standard
zstyle \[aq]:zle:*\[aq] word-chars \[aq]\[aq]
\f[R]
.fi
.RE
.PP
Implements bash-style word handling for all widgets, i.e.
only alphanumerics are word characters; equivalent to setting the parameter
\f[B]WORDCHARS\f[R]* empty for the given context.*
.RS
.IP
.nf
\f[C]
style \[aq]:zle:*kill*\[aq] word-style space
\f[R]
.fi
.RE
.PP
Uses space-delimited words for widgets with the word \[ga]kill\[aq] in the name.
Neither of the styles \f[B]word-chars\f[R]* nor \f[I]\f[BI]word-class\f[I]\f[R]
is used in this case.*
.PP
Here are some examples of use of the \f[B]word-context\f[R]* style to extend*
the context.
.RS
.IP
.nf
\f[C]
zstyle \[aq]:zle:*\[aq] word-context \[rs]
\[dq]*/*\[dq] filename \[dq][[:space:]]\[dq] whitespace
zstyle \[aq]:zle:transpose-words:whitespace\[aq] word-style shell
zstyle \[aq]:zle:transpose-words:filename\[aq] word-style normal
zstyle \[aq]:zle:transpose-words:filename\[aq] word-chars \[aq]\[aq]
\f[R]
.fi
.RE
.PP
This provides two different ways of using \f[B]transpose-words\f[R]* depending
on* whether the cursor is on whitespace between words or on a filename, here any
word containing a \f[B]/\f[R]\f[I]. On whitespace, complete arguments as
defined\f[R] 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
\f[B]:zle:transpose-words\f[R]*.*
.PP
The word matching and all the handling of \f[B]zstyle\f[R]* settings is
actually* implemented by the function \f[B]match-words-by-style\f[R]*.
This can be used to* create new user-defined widgets.
The calling function should set the local parameter \f[B]curcontext\f[R]* to
\f[I]\f[R]\f[I]:zle:\f[R]\f[I]\f[R]widget, create the local\f[I] parameter
\f[BI]matched_words\f[I]\f[R] and call \f[I]\f[BI]match-words-by-style\f[I]\f[R]
with no\f[I] arguments. On return, \f[BI]matched_words\f[I]\f[R] will be set to
an array with the\f[I] 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
\f[BI]skip-chars\f[I]\f[R] 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
If the variable \f[B]matched_words\f[R]* is defined by the caller to*
\f[B]match-words-by-style\f[R]* as an associative array (\f[I]\f[BI]local
-A\f[I] matched_words\f[R]), then the seven values given above should be
retrieved* from it as elements named \f[B]start\f[R]*,
\f[I]\f[BI]word-before-cursor\f[I]\f[R],* \f[B]ws-before-cursor\f[R]*,
\f[I]\f[BI]ws-after-cursor\f[I]\f[R], \f[I]\f[BI]word-after-cursor\f[I]\f[R],*
\f[B]ws-after-word\f[R]*, and \f[I]\f[BI]end\f[I]\f[R].
In addition the element* \f[B]is-word-start\f[R]* is 1 if the cursor is on the
start of a word or* subword, or on white space before it (the cases can be
distinguished by testing the \f[B]ws-after-cursor\f[R]* element) and 0
otherwise.
This form is* recommended for future compatibility.
.PP
It is possible to pass options with arguments to \f[B]match-words-by-style\f[R]
to override the use of styles.
The options are:
.PP
\f[B]-w\f[R]
.PD 0
.P
.PD
\f[I]word-style\f[R]
.PP
\f[B]-s\f[R]
.PD 0
.P
.PD
\f[I]skip-chars\f[R]
.PP
\f[B]-c\f[R]
.PD 0
.P
.PD
\f[I]word-class\f[R]
.PP
\f[B]-C\f[R]
.PD 0
.P
.PD
\f[I]word-chars\f[R]
.PP
\f[B]-r\f[R]
.PD 0
.P
.PD
\f[I]subword-range\f[R]
.PP
For example, \f[B]match-words-by-style -w shell -c 0\f[R]* may be used to*
extract the command argument around the cursor.
.PP
The \f[B]word-context\f[R]* style is implemented by the function*
\f[B]match-word-context\f[R]*.
This should not usually need to be called* directly.
.RE
.PP
\f[B]bracketed-paste-magic\f[R]
.PD 0
.P
.PD
The \f[B]bracketed-paste\f[R]* widget (see subsection Miscellaneous in*
\f[I]zshzle(1))\f[R] inserts pasted text literally into the editor buffer rather
than interpret it as keystrokes.
This disables some common usages where the self-insert widget is replaced in
order to accomplish some extra processing.
An example is the contributed \f[B]url-quote-magic\f[R]* widget described
below.*
.PP
The \f[B]bracketed-paste-magic\f[R]* widget is meant to replace
*\f[B]bracketed-paste\f[R] with a wrapper that re-enables these self-insert
actions, and other actions as selected by zstyles.
Therefore this widget is installed with
.RS
.IP
.nf
\f[C]
autoload -Uz bracketed-paste-magic
zle -N bracketed-paste bracketed-paste-magic
\f[R]
.fi
.RE
.PP
Other than enabling some widget processing, \f[B]bracketed-paste-magic\f[R]
attempts to replicate \f[B]bracketed-paste\f[R]* as faithfully as possible.*
.PP
The following zstyles may be set to control processing of pasted text.
All are looked up in the context \[ga]\f[B]:bracketed-paste-magic\f[R]*\[aq].*
.PP
\f[B]active-widgets\f[R] A list of patterns matching widget names that should be
activated during the paste.
All other key sequences are processed as self-insert-unmeta.
The default is \[ga]\f[B]self-*\f[R]\f[I]\[aq] so any user-defined widgets named
with that\f[R] prefix are active along with the builtin self-insert.
.RS
.PP
If this style is not set (explicitly deleted) or set to an empty value, no
widgets are active and the pasted text is inserted literally.
If the value includes \[ga]\f[B]undefined-key\f[R]*\[aq], any unknown sequences
are discarded* from the pasted text.
.RE
.PP
\f[B]inactive-keys\f[R]
.PD 0
.P
.PD
The inverse of \f[B]active-widgets\f[R]*, a list of key sequences that always
use* \f[B]self-insert-unmeta\f[R]* even when bound to an active widget.
Note that* this is a list of literal key sequences, not patterns.
.PP
\f[B]paste-init\f[R]
.PD 0
.P
.PD
A list of function names, called in widget context (but not as widgets).
The functions are called in order until one of them returns a non-zero status.
The parameter \[ga]\f[B]PASTED\f[R]*\[aq] contains the initial state of the*
pasted text.
All other ZLE parameters such as \[ga]\f[B]BUFFER\f[R]*\[aq] have their* normal
values and side-effects, and full history is available, so for example
\f[B]paste-init\f[R]* functions may move words from \f[I]\f[BI]BUFFER\f[I]\f[R]
into* \f[B]PASTED\f[R]* to make those words visible to the
\f[I]\f[BI]active-widgets\f[I]\f[R].*
.PP
A non-zero return from a \f[B]paste-init\f[R]* function does not prevent the*
paste itself from proceeding.
.PP
Loading \f[B]bracketed-paste-magic\f[R]* defines
\f[I]\f[BI]backward-extend-paste\f[I]\f[R], a* helper function for use in
\f[B]paste-init\f[R]*.*
.RS
.IP
.nf
\f[C]
zstyle :bracketed-paste-magic paste-init \[rs]
backward-extend-paste
\f[R]
.fi
.RE
.PP
When a paste would insert into the middle of a word or append text to a word
already on the line, \f[B]backward-extend-paste\f[R]* moves the prefix* from
\f[B]LBUFFER\f[R]* into \f[I]\f[BI]PASTED\f[I]\f[R] so that the
\f[I]\f[BI]active-widgets\f[I]\f[R] see the* full word so far.
This may be useful with \f[B]url-quote-magic\f[R]*.*
.PP
\f[B]paste-finish\f[R]
.PD 0
.P
.PD
Another list of function names called in order until one returns non-zero.
These functions are called \f[I]after the pasted text has been processed\f[R] by
the \f[B]active-widgets\f[R]*, but before it is inserted into
\[ga]\f[I]\f[BI]BUFFER\f[I]\f[R]\[aq].* ZLE parameters have their normal values
and side-effects.
.PP
A non-zero return from a \f[B]paste-finish\f[R]* function does not prevent* the
paste itself from proceeding.
.PP
Loading \f[B]bracketed-paste-magic\f[R]* also defines
\f[I]\f[BI]quote-paste\f[I]\f[R], a helper* function for use in
\f[B]paste-finish\f[R]*.*
.RS
.IP
.nf
\f[C]
zstyle :bracketed-paste-magic paste-finish \[rs]
quote-paste
zstyle :bracketed-paste-magic:finish quote-style \[rs]
qqq
\f[R]
.fi
.RE
.PP
When the pasted text is inserted into \f[B]BUFFER\f[R]*, it is quoted per the*
\f[B]quote-style\f[R]* value.
To forcibly turn off the built-in numeric prefix* quoting of
\f[B]bracketed-paste\f[R]*, use:*
.RS
.IP
.nf
\f[C]
zstyle :bracketed-paste-magic:finish quote-style \[rs]
none
\f[R]
.fi
.RE
.PP
\f[I]Important: During \f[R]\f[B]active-widgets\f[R]\f[I] processing of the
paste (after\f[R] \f[B]paste-init\f[R]* and before
\f[I]\f[BI]paste-finish\f[I]\f[R]), \f[I]\f[BI]BUFFER\f[I]\f[R] starts empty
and* history is restricted, so cursor motions, etc., may not pass outside of the
pasted content.
Text assigned to \f[B]BUFFER\f[R]* by the active widgets* is copied back into
\f[B]PASTED\f[R]* before \f[I]\f[BI]paste-finish\f[I]\f[R].*
.PP
\f[B]copy-earlier-word\f[R]
.PD 0
.P
.PD
This widget works like a combination of \f[B]insert-last-word\f[R]* and*
\f[B]copy-prev-shell-word\f[R]*.
Repeated invocations of the widget retrieve* earlier words on the relevant
history line.
With a numeric argument \f[I]N, insert the Nth word from the history line; N may
be\f[R] negative to count from the end of the line.
.PP
If \f[B]insert-last-word\f[R]* 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 \f[B]widget\f[R]* 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
\f[B]insert-last-word\f[R]*.*
.PP
\f[B]cycle-completion-positions\f[R]
.PD 0
.P
.PD
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.
.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.
.PP
\f[B]delete-whole-word-match\f[R]
.PD 0
.P
.PD
This is another function which works like the \f[B]-match\f[R]* functions*
described immediately above, i.e.
using styles to decide the word boundaries.
However, it is not a replacement for any existing function.
.PP
The basic behaviour is to delete the word around the cursor.
There is no numeric argument handling; only the single word around the cursor is
considered.
If the widget contains the string \f[B]kill\f[R]*, the removed text* will be
placed in the cutbuffer for future yanking.
This can be obtained by defining \f[B]kill-whole-word-match\f[R]* as follows:*
.RS
.IP
.nf
\f[C]
zle -N kill-whole-word-match delete-whole-word-match
\f[R]
.fi
.RE
.PP
and then binding the widget \f[B]kill-whole-word-match\f[R]*.*
.PP
\f[B]up-line-or-beginning-search\f[R]*,
\f[I]\f[BI]down-line-or-beginning-search\f[I]
.PD 0
.P
.PD
These widgets are similar to the builtin functions \f[BI]up-line-or-search\f[I]
and \f[BI]down-line-or-search\f[I]\f[R]: 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
\f[B]history-beginning-search-backward\f[R]* and \f[I]\f[BI]-forward\f[I]\f[R],
rather* than the first word on the line.
.PP
\f[B]edit-command-line\f[R]
.PD 0
.P
.PD
Edit the command line using your visual editor, as in \f[B]ksh\f[R]*.*
.RS
.IP
.nf
\f[C]
bindkey -M vicmd v edit-command-line
\f[R]
.fi
.RE
.PP
\f[B]expand-absolute-path\f[R]
.PD 0
.P
.PD
Expand the file name under the cursor to an absolute path, resolving symbolic
links.
Where possible, the initial path segment is turned into a named directory or
reference to a user\[aq]s home directory.
.PP
\f[B]history-search-end\f[R]
.PD 0
.P
.PD
This function implements the widgets
\f[B]history-beginning-search-backward-end\f[R]* and*
\f[B]history-beginning-search-forward-end\f[R]*.
These commands work by first* calling the corresponding builtin widget (see
\[ga]History Control\[aq] in \f[I]zshzle(1)) and then moving the cursor to the
end of the line. The original cursor\f[R] 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.
.PP
Although you \f[B]autoload\f[R]* only one function, the commands to use it are*
slightly different because it implements two widgets.
.RS
.IP
.nf
\f[C]
zle -N history-beginning-search-backward-end \[rs]
history-search-end
zle -N history-beginning-search-forward-end \[rs]
history-search-end
bindkey \[aq]\[rs]e\[ha]P\[aq] history-beginning-search-backward-end
bindkey \[aq]\[rs]e\[ha]N\[aq] history-beginning-search-forward-end
\f[R]
.fi
.RE
.PP
\f[B]history-beginning-search-menu\f[R]
.PD 0
.P
.PD
This function implements yet another form of history searching.
The text before the cursor is used to select lines from the history, as for
\f[B]history-beginning-search-backward\f[R]* 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.
.PP
With a numeric 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 \[ga]\f[B]-end\f[R]*\[aq] the cursor is moved to the
end of* the line inserted.
If the widget name contains \[ga]\f[B]-space\f[R]*\[aq] any space* in the text
typed is treated as a wildcard and can match anything (hence a leading space is
equivalent to giving a numeric argument).
Both forms can be combined, for example:
.RS
.IP
.nf
\f[C]
zle -N history-beginning-search-menu-space-end \[rs]
history-beginning-search-menu
\f[R]
.fi
.RE
.PP
\f[B]history-pattern-search\f[R]
.PD 0
.P
.PD
The function \f[B]history-pattern-search\f[R]* 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
\f[B]\[ha]\f[R]* to anchor the search to the start of the line, and the last
character* may be \f[B]$\f[R]* 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.
.PP
The commands to create bindable widgets are similar to those in the example
immediately above:
.RS
.IP
.nf
\f[C]
autoload -U history-pattern-search
zle -N history-pattern-search-backward history-pattern-search
zle -N history-pattern-search-forward history-pattern-search
\f[R]
.fi
.RE
.PP
\f[B]incarg\f[R]
.PD 0
.P
.PD
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 argument, the number is incremented by the amount of the argument
(decremented if the numeric argument is negative).
The shell parameter \f[B]incarg\f[R]* may be set to change the default increment
to* something other than one.
.RS
.IP
.nf
\f[C]
bindkey \[aq]\[ha]X+\[aq] incarg
\f[R]
.fi
.RE
.PP
\f[B]incremental-complete-word\f[R]
.PD 0
.P
.PD
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 \f[B]\[ha]H\f[R]* or
\f[I]\f[BI]DEL\f[I]\f[R].
Pressing return* accepts the completion so far and returns you to normal editing
(that is, the command line is \f[I]not immediately executed). You can hit
\f[R]\f[B]TAB\f[R]\f[I] to\f[R] do normal completion, \f[B]\[ha]G\f[R]* to abort
back to the state when you started,* and \f[B]\[ha]D\f[R]* to list the matches.*
.PP
This works only with the new function based completion system.
.RS
.IP
.nf
\f[C]
bindkey \[aq]\[ha]Xi\[aq] incremental-complete-word
\f[R]
.fi
.RE
.PP
\f[B]insert-composed-char\f[R]
.PD 0
.P
.PD
This function allows you to compose characters that don\[aq]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
*\f[I]<http://www.faqs.org/rfcs/rfc1345.html***>).\f[R]
.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, \f[B]insert-composed-char a:\f[R]* 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 \f[B]--enable-multibyte\f[R]*); 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 \f[B]insert-unicode-char\f[R]* 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 is very sporadic from that point.
Adding new characters is easy, however; see the function
\f[B]define-composed-chars\f[R]*.
Please send any* additions to \f[B]<[email protected]>\f[R]*.*
.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.
.PP
\f[B]!\f[R]
.PD 0
.P
.PD
Grave.
.PP
\f[B]\[aq]\f[R]
.PD 0
.P
.PD
Acute.
.PP
\f[B]>\f[R]
.PD 0
.P
.PD
Circumflex.
.PP
\f[B]?\f[R]
.PD 0
.P
.PD
Tilde.
(This is not \f[B]\[ti]\f[R]* as RFC 1345 does not assume that* character is
present on the keyboard.)
.PP
\f[B]-\f[R]
.PD 0
.P
.PD
Macron.
(A horizontal bar over the base character.)
.PP
\f[B](\f[R]
.PD 0
.P
.PD
Breve.
(A shallow dish shape over the base character.)
.PP
\f[B].\f[R]
.PD 0
.P
.PD
Dot above the base character, or in the case of \f[B]i\f[R]* no dot,* or in the
case of \f[B]L\f[R]* and \f[I]\f[BI]l\f[I]\f[R] a centered dot.*
.PP
\f[B]:\f[R]
.PD 0
.P
.PD
Diaeresis (Umlaut).
.PP
\f[B]c\f[R]
.PD 0
.P
.PD
Cedilla.
.PP
\f[B]_\f[R]
.PD 0
.P
.PD
Underline, however there are currently no underlined characters.
.PP
\f[B]/\f[R]
.PD 0
.P
.PD
Stroke through the base character.
.PP
\f[B]\[dq]\f[R]
.PD 0
.P
.PD
Double acute (only supported on a few letters).
.PP
\f[B];\f[R]
.PD 0
.P
.PD
Ogonek.
(A little forward facing hook at the bottom right of the character.)
.PP
\f[B]<\f[R]
.PD 0
.P
.PD
Caron.
(A little v over the letter.)
.PP
\f[B]0\f[R]
.PD 0
.P
.PD
Circle over the base character.
.PP
\f[B]2\f[R]
.PD 0
.P
.PD
Hook over the base character.
.PP
\f[B]9\f[R]
.PD 0
.P
.PD
Horn over the base character.
.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 \f[B]!\f[R] to
\f[B]\[ti]\f[R]* (0x21 to 0x7e) by preceding the character with
\f[I]\f[BI]\[ha]\f[I]\f[R], for* example \f[B]\[ha]A\f[R]* for a double-width
\f[I]\f[BI]A\f[I]\f[R].*
.PP
The following other two-character sequences are understood.
.PP
ASCII characters These are already present on most keyboards:
.PP
\f[B]<(\f[R]
.PD 0
.P
.PD
Left square bracket
.PP
\f[B]//\f[R]
.PD 0
.P
.PD
Backslash (solidus)
.PP
\f[B])>\f[R]
.PD 0
.P
.PD
Right square bracket
.PP
\f[B](!\f[R]
.PD 0
.P
.PD
Left brace (curly bracket)
.PP
\f[B]!!\f[R]
.PD 0
.P
.PD
Vertical bar (pipe symbol)
.PP
\f[B]!)\f[R]
.PD 0
.P
.PD
Right brace (curly bracket)
.PP
\f[B]\[aq]?\f[R]
.PD 0
.P
.PD
Tilde
.PP
Special letters
.PD 0
.P
.PD
Characters found in various variants of the Latin alphabet:
.PP
\f[B]ss\f[R]
.PD 0
.P
.PD
Eszett (scharfes S)
.PP
\f[B]D-\f[R]*, *\f[B]d-\f[R]
.PD 0
.P
.PD
Eth
.PP
\f[B]TH\f[R]*, *\f[B]th\f[R]
.PD 0
.P
.PD
Thorn
.PP
\f[B]kk\f[R]
.PD 0
.P
.PD
Kra
.PP
\f[B]\[aq]n\f[R]
.PD 0
.P
.PD
\[aq]n
.PP
\f[B]NG\f[R]*, *\f[B]ng\f[R]
.PD 0
.P
.PD
Ng
.PP
\f[B]OI\f[R]*, *\f[B]oi\f[R]
.PD 0
.P
.PD
Oi
.PP
\f[B]yr\f[R]
.PD 0
.P
.PD
yr
.PP
\f[B]ED\f[R]
.PD 0
.P
.PD
ezh
.PP
Currency symbols
.PP
\f[B]Ct\f[R]
.PD 0
.P
.PD
Cent
.PP
\f[B]Pd\f[R]
.PD 0
.P
.PD
Pound sterling (also lira and others)
.PP
\f[B]Cu\f[R]
.PD 0
.P
.PD
Currency
.PP
\f[B]Ye\f[R]
.PD 0
.P
.PD
Yen
.PP
\f[B]Eu\f[R]
.PD 0
.P
.PD
Euro (N.B.
not in RFC 1345)
.PP
Punctuation characters
.PD 0
.P
.PD
References to \[dq]right\[dq] quotes indicate the shape (like a 9 rather than 6)
rather than their grammatical use.
(For example, a \[dq]right\[dq] low double quote is used to open quotations in
German.)
.PP
\f[B]!I\f[R]
.PD 0
.P
.PD
Inverted exclamation mark
.PP
\f[B]BB\f[R]
.PD 0
.P
.PD
Broken vertical bar
.PP
\f[B]SE\f[R]
.PD 0
.P
.PD
Section
.PP
\f[B]Co\f[R]
.PD 0
.P
.PD
Copyright
.PP
\f[B]-a\f[R]
.PD 0
.P
.PD
Spanish feminine ordinal indicator
.PP
\f[B]<<\f[R]
.PD 0
.P
.PD
Left guillemet
.PP
\f[B]--\f[R]
.PD 0
.P
.PD
Soft hyphen
.PP
\f[B]Rg\f[R]
.PD 0
.P
.PD
Registered trade mark
.PP
\f[B]PI\f[R]
.PD 0
.P
.PD
Pilcrow (paragraph)
.PP
\f[B]-o\f[R]
.PD 0
.P
.PD
Spanish masculine ordinal indicator
.PP
\f[B]>>\f[R]
.PD 0
.P
.PD
Right guillemet
.PP
\f[B]?I\f[R]
.PD 0
.P
.PD
Inverted question mark
.PP
\f[B]-1\f[R]
.PD 0
.P
.PD
Hyphen
.PP
\f[B]-N\f[R]
.PD 0
.P
.PD
En dash
.PP
\f[B]-M\f[R]
.PD 0
.P
.PD
Em dash
.PP
\f[B]-3\f[R]
.PD 0
.P
.PD
Horizontal bar
.PP
\f[B]:3\f[R]
.PD 0
.P
.PD
Vertical ellipsis
.PP
\f[B].3\f[R]
.PD 0
.P
.PD
Horizontal midline ellipsis
.PP
\f[B]!2\f[R]
.PD 0
.P
.PD
Double vertical line
.PP
\f[B]=2\f[R]
.PD 0
.P
.PD
Double low line
.PP
\f[B]\[aq]6\f[R]
.PD 0
.P
.PD
Left single quote
.PP
\f[B]\[aq]9\f[R]
.PD 0
.P
.PD
Right single quote
.PP
\f[B].9\f[R]
.PD 0
.P
.PD
\[dq]Right\[dq] low quote
.PP
\f[B]9\[aq]\f[R]
.PD 0
.P
.PD
Reversed \[dq]right\[dq] quote
.PP
\f[B]\[dq]6\f[R]
.PD 0
.P
.PD
Left double quote
.PP
\f[B]\[dq]9\f[R]
.PD 0
.P
.PD
Right double quote
.PP
\f[B]:9\f[R]
.PD 0
.P
.PD
\[dq]Right\[dq] low double quote
.PP
\f[B]9\[dq]\f[R]
.PD 0
.P
.PD
Reversed \[dq]right\[dq] double quote
.PP
\f[B]/-\f[R]
.PD 0
.P
.PD
Dagger
.PP
\f[B]/=\f[R]
.PD 0
.P
.PD
Double dagger
.PP
Mathematical symbols
.PP
\f[B]DG\f[R]
.PD 0
.P
.PD
Degree
.PP
\f[B]-2\f[R]*, \f[I]\f[BI]+-\f[I]\f[R], *\f[B]-+\f[R]
.PD 0
.P
.PD
- sign, +/- sign, -/+ sign
.PP
\f[B]2S\f[R]
.PD 0
.P
.PD
Superscript 2
.PP
\f[B]3S\f[R]
.PD 0
.P
.PD
Superscript 3
.PP
\f[B]1S\f[R]
.PD 0
.P
.PD
Superscript 1
.PP
\f[B]My\f[R]
.PD 0
.P
.PD
Micro
.PP
\f[B].M\f[R]
.PD 0
.P
.PD
Middle dot
.PP
\f[B]14\f[R]
.PD 0
.P
.PD
Quarter
.PP
\f[B]12\f[R]
.PD 0
.P
.PD
Half
.PP
\f[B]34\f[R]
.PD 0
.P
.PD
Three quarters
.PP
\f[B]*X\f[R]
.PD 0
.P
.PD
Multiplication
.PP
\f[B]-:\f[R]
.PD 0
.P
.PD
Division
.PP
\f[B]%0\f[R]
.PD 0
.P
.PD
Per mille
.PP
\f[B]FA\f[R]*, \f[I]\f[BI]TE\f[I]\f[R], *\f[B]/0\f[R]
.PD 0
.P
.PD
For all, there exists, empty set
.PP
\f[B]dP\f[R]*, \f[I]\f[BI]DE\f[I]\f[R], *\f[B]NB\f[R]
.PD 0
.P
.PD
Partial derivative, delta (increment), del (nabla)
.PP
\f[B](-\f[R]*, *\f[B]-)\f[R]
.PD 0
.P
.PD
Element of, contains
.PP
\f[B]*P\f[R]*, *\f[B]+Z\f[R]
.PD 0
.P
.PD
Product, sum
.PP
\f[B]*-\f[R]*, \f[I]\f[BI]Ob\f[I]\f[R], *\f[B]Sb\f[R]
.PD 0
.P
.PD
Asterisk, ring, bullet
.PP
\f[B]RT\f[R]*, \f[I]\f[BI]0(\f[I]\f[R], *\f[B]00\f[R]
.PD 0
.P
.PD
Root sign, proportional to, infinity
.PP
Other symbols
.PP
\f[B]cS\f[R]*, \f[I]\f[BI]cH\f[I]\f[R], \f[I]\f[BI]cD\f[I]\f[R], *\f[B]cC\f[R]
.PD 0
.P
.PD
Card suits: spades, hearts, diamonds, clubs
.PP
\f[B]Md\f[R]*, \f[I]\f[BI]M8\f[I]\f[R], \f[I]\f[BI]M2\f[I]\f[R],
\f[I]\f[BI]Mb\f[I]\f[R], \f[I]\f[BI]Mx\f[I]\f[R], *\f[B]MX\f[R]
.PD 0
.P
.PD
Musical notation: crotchet (quarter note), quaver (eighth note), semiquavers
(sixteenth notes), flag sign, natural sign, sharp sign
.PP
\f[B]Fm\f[R]*, *\f[B]Ml\f[R]
.PD 0
.P
.PD
Female, male
.PP
Accents on their own
.PP
\f[B]\[aq]>\f[R]
.PD 0
.P
.PD
Circumflex (same as caret, \f[B]\[ha]\f[R]\f[I])\f[R]
.PP
\f[B]\[aq]!\f[R]
.PD 0
.P
.PD
Grave (same as backtick, \f[B]\[ga]\f[R]\f[I])\f[R]
.PP
\f[B]\[aq],\f[R]
.PD 0
.P
.PD
Cedilla
.PP
\f[B]\[aq]:\f[R]
.PD 0
.P
.PD
Diaeresis (Umlaut)
.PP
\f[B]\[aq]m\f[R]
.PD 0
.P
.PD
Macron
.PP
\f[B]\[aq]\[aq]\f[R]
.PD 0
.P
.PD
Acute
.PP
\f[B]insert-files\f[R]
.PD 0
.P
.PD
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
.IP
.nf
\f[C]
bindkey \[aq]\[ha]Xf\[aq] insert-files
\f[R]
.fi
.RE
.PP
\f[B]insert-unicode-char\f[R]
.PD 0
.P
.PD
When first executed, the user inputs a set of hexadecimal digits.
This is terminated with another call to \f[B]insert-unicode-char\f[R]*.* The
digits are then turned into the corresponding Unicode character.
For example, if the widget is bound to \f[B]\[ha]XU\f[R]*, the character
sequence* \[ga]\f[B]\[ha]XU 4 c \[ha]XU\f[R]*\[aq] inserts
\f[I]\f[BI]L\f[I]\f[R] (Unicode U+004c).*
.PP
See \f[B]insert-composed-char\f[R]* for a way of inserting characters* using a
two-character mnemonic.
.PP
**narrow-to-region **\f[I][ \f[R]\f[B]-p\f[R]\f[I] pre ] [
\f[R]\f[B]-P\f[R]\f[I] post ]\f[R]
.PP
** **\f[I][ \f[R]\f[B]-S\f[R]\f[I] statepm | \f[R]\f[B]-R\f[R]\f[I] statepm | [
\f[R]\f[B]-l\f[R]\f[I] lbufvar ] [ \f[R]\f[B]-r\f[R]\f[I] rbufvar ] ]\f[R]
.PP
** **\f[I][ \f[R]\f[B]-n\f[R]\f[I] ] [ start end ]\f[R]
.PP
\f[B]narrow-to-region-invisible\f[R] 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
\f[B]narrow-to-region\f[R]* 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 \f[B]recursive-edit\f[R]* 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 \f[B]-p\f[R]* pretext and \f[I]\f[BI]-P\f[I]\f[R] posttext 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 \f[B]-n\f[R]* is also given, pretext or posttext 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 \f[B]-S\f[R]* statepm is used to narrow according to the other*
options while saving the original state in the parameter with name \f[I]statepm,
while the option \f[R]\f[B]-R\f[R]\f[I] statepm is used to restore the\f[R]
state from the parameter; note in both cases the \f[I]name of the parameter\f[R]
is required.
In the second case, other options and arguments are irrelevant.
When this method is used, no \f[B]recursive-edit\f[R]* is performed;* the
calling widget should call this function with the option \f[B]-S\f[R]*,* perform
its own editing on the command line or pass control to the user via
\[ga]\f[B]zle recursive-edit\f[R]*\[aq], then call this function with the
option* \f[B]-R\f[R]*.
The argument statepm must be a suitable name for an ordinary* parameter, except
that parameters beginning with the prefix \f[B]_ntr_\f[R]* are* reserved for use
within \f[B]narrow-to-region\f[R]*.
Typically the parameter will* be local to the calling function.
.PP
The options \f[B]-l\f[R]* lbufvar and \f[I]\f[BI]-r\f[I]\f[R] rbufvar may be
used to* specify parameters where the widget will store the resulting text from
the operation.
The parameter \f[I]lbufvar will contain \f[R]\f[B]LBUFFER\f[R] and \f[I]rbufvar
will contain \f[R]\f[B]RBUFFER\f[R]\f[I]. Neither of these two options\f[R] may
be used with \f[B]-S\f[R]\f[I] or \f[R]\f[B]-R\f[R]\f[I].\f[R]
.PP
\f[B]narrow-to-region-invisible\f[R]* is a simple widget which calls*
\f[B]narrow-to-region\f[R]* with arguments which replace any text outside the*
region with \[ga]\f[B]...\f[R]\f[I]\[aq]. It does not take any arguments.\f[R]
.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
.IP
.nf
\f[C]
local state
narrow-to-region -p $\[aq]Editing restricted region\[rs]n\[aq] \[rs]
-P \[aq]\[aq] -S state
zle recursive-edit
narrow-to-region -R state
\f[R]
.fi
.RE
.RE
.PP
\f[B]predict-on\f[R]
.PD 0
.P
.PD
This set of functions implements predictive typing using history search.
After \f[B]predict-on\f[R]*, typing characters causes the editor to look
backward* in the history for the first line beginning with what you have typed
so far.
After \f[B]predict-off\f[R]*, editing returns to normal for the line found.* In
fact, you often don\[aq]t even need to use \f[B]predict-off\f[R]*, because if
the* line doesn\[aq]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 \f[B]toggle\f[R]* style below.*
.PP
With the function based completion system (which is needed for this), you should
be able to type \f[B]TAB\f[R]* at almost any point to advance the cursor* to the
next \[ga]\[ga]interesting\[aq]\[aq] 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 \f[B]predict-on\f[R]* is used, it creates several additional*
widget functions:
.PP
\f[B]delete-backward-and-predict\f[R]
.PD 0
.P
.PD
Replaces the \f[B]backward-delete-char\f[R] widget.
You do not need to bind this yourself.
.PP
\f[B]insert-and-predict\f[R]
.PD 0
.P
.PD
Implements predictive typing by replacing the \f[B]self-insert\f[R]* widget.
You do not need to bind this yourself.*
.PP
\f[B]predict-off\f[R]
.PD 0
.P
.PD
Turns off predictive typing.
.PP
Although you \f[B]autoload\f[R]* only the \f[I]\f[BI]predict-on\f[I]\f[R]
function, it is* necessary to create a keybinding for \f[B]predict-off\f[R]* as
well.*
.RS
.IP
.nf
\f[C]
zle -N predict-on
zle -N predict-off
bindkey \[aq]\[ha]X\[ha]Z\[aq] predict-on
bindkey \[aq]\[ha]Z\[aq] predict-off
\f[R]
.fi
.RE
.PP
\f[B]read-from-minibuffer\f[R]
.PD 0
.P
.PD
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, \f[B]execute-named-cmd\f[R]*).
The value is then* returned to the calling function in the parameter
\f[B]$REPLY\f[R]* and the* editing buffer restored to its previous state.
If the read was aborted by a keyboard break (typically \f[B]\[ha]G\f[R]*), the
function returns status 1* and \f[B]$REPLY\f[R]* is not set.*
.PP
If one argument is supplied to the function it is taken as a prompt, otherwise
\[ga]*\f[I]? \f[R]\f[I]\f[R]\[aq] is used. If two arguments are supplied, they
are the\f[I] prompt and the initial value of \f[BI]$LBUFFER\f[I]\f[R], and if a
third argument is\f[I] given it is the initial value of
\f[BI]$RBUFFER\f[I]\f[R].
This provides a default* value and starting cursor placement.
Upon return the entire buffer is the value of \f[B]$REPLY\f[R]*.*
.PP
One option is available: \[ga]\f[B]-k\f[R]* num\[aq] specifies that num*
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 \f[B]$REPLY\f[R]*, not the entire buffer.
Note that unlike the \f[I]\f[BI]read\f[I]\f[R] builtin* \f[I]num must be given;
there is no default.\f[R]
.PP
The name is a slight misnomer, as in fact the shell\[aq]s own minibuffer is not
used.
Hence it is still possible to call \f[B]executed-named-cmd\f[R]* and* similar
functions while reading a value.
.PP
\f[B]replace-argument\f[R]*, \f[I]\f[BI]replace-argument-edit\f[I]
.PD 0
.P
.PD
The function \f[BI]replace-argument\f[I]\f[R] can be used to replace a command*
line argument in the current command line or, if the current command line is
empty, in the last command line executed (the new command line is not executed).
Arguments are as delimited by standard shell syntax,
.PP
If a numeric argument is given, that specifies the argument to be replaced.
0 means the command name, as in history expansion.
A negative numeric argument counts backward from the last word.
.PP
If no numeric argument is given, the current argument is replaced; this is the
last argument if the previous history line is being used.
.PP
The function prompts for a replacement argument.
.PP
If the widget contains the string \f[B]edit\f[R]*, for example is defined as*
.RS
.IP
.nf
\f[C]
zle -N replace-argument-edit replace-argument
\f[R]
.fi
.RE
.PP
then the function presents the current value of the argument for editing,
otherwise the editing buffer for the replacement is initially empty.
.PP
\f[B]replace-string\f[R]*, *\f[B]replace-pattern\f[R]
.PP
\f[B]replace-string-again\f[R]*, \f[I]\f[BI]replace-pattern-again\f[I] The
function \f[BI]replace-string\f[I]\f[R] 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 \[ga]\f[B]pattern\f[R]*\[aq], for example
by* defining the widget using the command \[ga]\f[B]zle -N replace-pattern\f[R]
replace-string*\[aq], 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 \[ga]\f[B]&\f[R]\f[I]\[aq] in the replacement string will be
replaced with\f[R] the matched source string, and a backquoted digit
\[ga]\f[B]\[rs]\f[R]\f[I]N\[aq] will be\f[R] replaced by the \f[I]Nth
parenthesised expression matched. The form\f[R]
\[ga]\f[B]\[rs]{\f[BI]\f[I]N\f[BI]\f[B]}\f[R]\f[I]\[aq] may be used to protect
the digit from following\f[R] digits.
.PP
If the widget instead contains the word \[ga]\f[B]regex\f[R]*\[aq] (or
\[ga]\f[I]\f[BI]regexp\f[I]\f[R]\[aq]),* then the matching is performed using
regular expressions, respecting the setting of the option
\f[B]RE_MATCH_PCRE\f[R]* (see the description of the* function
\f[B]regexp-replace\f[R]* 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
\f[B]edit-previous\f[R]* in the context ***:zle:\f[I]\f[R]\f[I]widget (for
example,\f[R] \f[B]:zle:replace-string\f[R]\f[I]) to \f[R]\f[B]true\f[R]\f[I].
In addition, a positive\f[R] numeric argument forces the previous values to be
offered, a negative or zero argument forces them not to be.
.PP
The function \f[B]replace-string-again\f[R]* can be used to repeat the previous*
replacement; no prompting is done.
As with \f[B]replace-string\f[R]*, if the name* of the widget contains the word
\[ga]\f[B]pattern\f[R]*\[aq] or \[ga]\f[I]\f[BI]regex\f[I]\f[R]\[aq], 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
In addition, \f[B]replace-string\f[R]* shows the previous replacement above* the
prompt, so long as there was one during the current session; if the source
string is empty, that replacement will be repeated without the widget prompting
for a replacement string.
.PP
For example, starting from the line:
.RS
.IP
.nf
\f[C]
print This line contains fan and fond
\f[R]
.fi
.RE
.PP
and invoking \f[B]replace-pattern\f[R]* with the source string*
\[ga]\f[B]f(?)n\f[R]*\[aq] and* the replacement string
\[ga]\f[B]c\[rs]1r\f[R]*\[aq] produces the not very useful line:*
.RS
.IP
.nf
\f[C]
print This line contains car and cord
\f[R]
.fi
.RE
.PP
The range of the replacement string can be limited by using the
\f[B]narrow-to-region-invisible\f[R]* widget.
One limitation of the current* version is that \f[B]undo\f[R]* will cycle
through changes to the replacement* and source strings before undoing the
replacement itself.
.RE
.PP
\f[B]send-invisible\f[R]
.PD 0
.P
.PD
This is similar to read-from-minibuffer in that it may be called as a function
from a widget or as a widget of its own, and interactively reads input from the
keyboard.
However, the input being typed is concealed and a string of asterisks
(\[ga]\f[B]*\f[R]\f[I]\[aq]) is shown instead. The value is saved in\f[R] the
parameter \f[B]$INVISIBLE\f[R]* to which a reference is inserted into the*
editing buffer at the restored cursor position.
If the read was aborted by a keyboard break (typically \f[B]\[ha]G\f[R]*) or
another escape from editing such* as \f[B]push-line\f[R]*,
\f[I]\f[BI]$INVISIBLE\f[I]\f[R] is set to empty and the original buffer* is
restored unchanged.
.PP
If one argument is supplied to the function it is taken as a prompt, otherwise
\[ga]\f[I]\f[R]Non-echoed text: \f[I]\f[R]\f[I]\[aq] is used (as in emacs). If a
second and\f[R] third argument are supplied they are used to begin and end the
reference to \f[B]$INVISIBLE\f[R]\f[I] that is inserted into the buffer. The
default is to\f[R] open with \f[B]${\f[R]\f[I], then
\f[R]\f[B]INVISIBLE\f[R]\f[I], and close with \f[R]\f[B]}\f[R]\f[I], but
many\f[R] other effects are possible.
.PP
\f[B]smart-insert-last-word\f[R]
.PD 0
.P
.PD
This function may replace the \f[B]insert-last-word\f[R]* widget, like so:*
.RS
.IP
.nf
\f[C]
zle -N insert-last-word smart-insert-last-word
\f[R]
.fi
.RE
.PP
With a numeric argument, or when passed command line arguments in a call from
another widget, it behaves like \f[B]insert-last-word\f[R]*, except that* words
in comments are ignored when \f[B]INTERACTIVE_COMMENTS\f[R]* is set.*
.PP
Otherwise, the rightmost \[ga]\[ga]interesting\[aq]\[aq] word from the previous
command is found and inserted.
The default definition of \[ga]\[ga]interesting\[aq]\[aq] is that the word
contains at least one alphabetic character, slash, or backslash.
This definition may be overridden by use of the \f[B]match\f[R]* style.
The* context used to look up the style is the widget name, so usually the
context is \f[B]:insert-last-word\f[R]*.
However, you can bind this function to* different widgets to use different
patterns:
.RS
.IP
.nf
\f[C]
zle -N insert-last-assignment smart-insert-last-word
zstyle :insert-last-assignment match \[aq][[:alpha:]][][[:alnum:]]#=*\[aq]
bindkey \[aq]\[rs]e=\[aq] insert-last-assignment
\f[R]
.fi
.RE
.PP
If no interesting word is found and the \f[B]auto-previous\f[R]* style is set
to* a true value, the search continues upward through the history.
When \f[B]auto-previous\f[R]* is unset or false (the default), the widget must
be* invoked repeatedly in order to search earlier history lines.
.PP
\f[B]transpose-lines\f[R]
.PD 0
.P
.PD
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.
.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 argument) has
the effect of moving the line above the cursor down by a number of lines.
.PP
With a negative numeric 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 argument less than -1 has the effect of moving the line above
the cursor up by minus that number of lines.
.PP
\f[B]url-quote-magic\f[R]
.PD 0
.P
.PD
This widget replaces the built-in \f[B]self-insert\f[R]* to make it easier to*
type URLs as command line arguments.
As you type, the input character is analyzed and, if it may need quoting, the
current word is checked for a URI scheme.
If one is found and the current word is not already in quotes, a backslash is
inserted before the input character.
.PP
Styles to control quoting behavior:
.PP
\f[B]url-metas\f[R] This style is looked up in the context
\[ga]\f[B]:url-quote-magic:\f[R]\f[I]scheme\[aq]\f[R] (where \f[I]scheme is that
of the current URL, e.g. \[dq]\f[R]\f[B]ftp\f[R]\f[I]\[dq]). The value\f[R] is a
string listing the characters to be treated as globbing metacharacters when
appearing in a URL using that scheme. The default is to quote all zsh extended
globbing characters, excluding \[aq]\f[B]<\f[R]\f[I]\[aq] and\f[R]
\[aq]\f[B]>\f[R]\f[I]\[aq] but including braces (as in brace expansion). See
also\f[R] \f[B]url-seps\f[R]*.*
.PP
\f[B]url-seps\f[R]
.PD 0
.P
.PD
Like \f[B]url-metas\f[R]*, but lists characters that should be considered
command* separators, redirections, history references, etc.
The default is to quote the standard set of shell separators, excluding those
that overlap with the extended globbing characters, but including
\[aq]\f[B]<\f[R]\f[I]\[aq] and\f[R] \[aq]\f[B]>\f[R]\f[I]\[aq] and the first
character of \f[R]\f[B]$histchars\f[R]\f[I].\f[R]
.PP
\f[B]url-globbers\f[R]
.PD 0
.P
.PD
This style is looked up in the context \[ga]\f[B]:url-quote-magic\f[R]*\[aq].
The values* form a list of command names that are expected to do their own
globbing on the URL string.
This implies that they are aliased to use the \[ga]\f[B]noglob\f[R]*\[aq]
modifier.
When the first word on the line matches one of the* values \f[I]and the URL
refers to a local file (see \f[R]\f[B]url-local-schema\f[R]\f[I]),\f[R] only the
\f[B]url-seps\f[R]* characters are quoted; the \f[I]\f[BI]url-metas\f[I]\f[R]
are left* alone, allowing them to affect command-line parsing, completion, etc.
The default values are a literal \[ga]\f[B]noglob\f[R]*\[aq] plus (when the
\f[I]\f[BI]zsh/parameter\f[I] module is available) any commands aliased to the
helper function \[ga]\f[BI]urlglobber\f[I]\f[R]\[aq] or its alias
\[ga]\f[I]\f[BI]globurl\f[I]\f[R]\[aq].*
.PP
\f[B]url-local-schema\f[R]
.PD 0
.P
.PD
This style is always looked up in the context \[ga]\f[B]:urlglobber\f[R]*\[aq],
even* though it is used by both url-quote-magic and urlglobber.
The values form a list of URI schema that should be treated as referring to
local files by their real local path names, as opposed to files which are
specified relative to a web-server-defined document root.
The defaults are \[dq]\f[B]ftp\f[R]*\[dq] and
\[dq]\f[I]\f[BI]file\f[I]\f[R]\[dq].*
.PP
\f[B]url-other-schema\f[R]
.PD 0
.P
.PD
Like \f[B]url-local-schema\f[R]*, but lists all other URI schema upon which*
\f[B]urlglobber\f[R]* and \f[I]\f[BI]url-quote-magic\f[I]\f[R] should act.
If the URI on the* command line does not have a scheme appearing either in this
list or in \f[B]url-local-schema\f[R]*, it is not magically quoted.
The default values are* \[dq]\f[B]http\f[R]*\[dq],
\[dq]\f[I]\f[BI]https\f[I]\f[R]\[dq], and \[dq]\f[I]\f[BI]ftp\f[I]\f[R]\[dq].
When a scheme appears both here* and in \f[B]url-local-schema\f[R]*, it is
quoted differently depending on whether* the command name appears in
\f[B]url-globbers\f[R]*.*
.PP
Loading \f[B]url-quote-magic\f[R]* also defines a helper function
\[ga]\f[I]\f[BI]urlglobber\f[I]\f[R]\[aq]* and aliases
\[ga]\f[B]globurl\f[R]*\[aq] to \[ga]\f[I]\f[BI]noglob
urlglobber\f[I]\f[R]\[aq].
This function takes* a local URL apart, attempts to pattern-match the local file
portion of the URL path, and then puts the results back into URL format again.
.PP
\f[B]vi-pipe\f[R]
.PD 0
.P
.PD
This function reads a movement command from the keyboard and then prompts for an
external command.
The part of the buffer covered by the movement is piped to the external command
and then replaced by the command\[aq]s output.
If the movement command is bound to vi-pipe, the current line is used.
.PP
The function serves as an example for reading a vi movement command from within
a user-defined widget.
.PP
\f[B]which-command\f[R]
.PD 0
.P
.PD
This function is a drop-in replacement for the builtin widget
\f[B]which-command\f[R]*.
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.
.PP
The style \f[B]whence\f[R]* is available in the context
\f[I]\f[BI]:zle:$WIDGET\f[I]\f[R]; 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 \f[B]whence -c\f[R]*.*
.PP
\f[B]zcalc-auto-insert\f[R]
.PD 0
.P
.PD
This function is useful together with the \f[B]zcalc\f[R]* function described
in* the section Mathematical Functions.
It should be bound to a key representing a binary operator such as
\[ga]\f[B]+\f[R]\f[I]\[aq], \[ga]\f[R]\f[B]-\f[R]\f[I]\[aq],
\[ga]\f[R]\f[B]*\f[R]\f[I]\[aq] or \[ga]\f[R]\f[B]/\f[R]\f[I]\[aq]. When running
in zcalc,\f[R] if the key occurs at the start of the line or immediately
following an open parenthesis, the text \f[B]\[dq]ans \[dq]\f[R]* is inserted
before the* representation of the key itself.
This allows easy use of the answer from the previous calculation in the current
line.
The text to be inserted before the symbol typed can be modified by setting the
variable \f[B]ZCALC_AUTO_INSERT_PREFIX\f[R]*.*
.PP
Hence, for example, typing \[ga]\f[B]+12\f[R]*\[aq] followed by return adds 12*
to the previous result.
.PP
If zcalc is in RPN mode (\f[B]-r\f[R]* option) the effect of this binding is*
automatically suppressed as operators alone on a line are meaningful.
.PP
When not in zcalc, the key simply inserts the symbol itself.
.SS Utility Functions
.PP
These functions are useful in constructing widgets.
They should be loaded with \[ga]\f[B]autoload -U\f[R]* function\[aq] and called*
as indicated from user-defined widgets.
.PP
\f[B]split-shell-arguments\f[R] This function splits the line currently being
edited into shell arguments and whitespace.
The result is stored in the array \f[B]reply\f[R]*.
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 \f[B]KSH_ARRAYS\f[R]* 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
\f[B]reply\f[R]* in order is guaranteed to produce the* original line.
.RS
.PP
The parameter \f[B]REPLY\f[R]* is set to the index of the word in
\f[I]\f[BI]reply\f[I]\f[R] which* contains the character after the cursor, where
the first element has index 1.
The parameter \f[B]REPLY2\f[R]* is set to the index of the character under the*
cursor in that word, where the first character has index 1.
.PP
Hence \f[B]reply\f[R]*, \f[I]\f[BI]REPLY\f[I]\f[R] and
\f[I]\f[BI]REPLY2\f[I]\f[R] should all be made local to* the enclosing function.
.PP
See the function \f[B]modify-current-argument\f[R]*, described below, for* an
example of how to call this function.
.RE
.PP
\f[B]modify-current-argument\f[R]* [ expr-using-\f[I]\f[BI]$ARG\f[I]\f[R] | func
]*
.PD 0
.P
.PD
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).
.PP
The argument can be an expression which when evaluated operates on the shell
parameter \f[B]ARG\f[R]*, 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.
.PP
Alternatively, if the argument does not contain the string \f[B]ARG\f[R]*, it*
is assumed to be a shell function, to which the current command line argument is
passed as the only argument.
The function should set the variable \f[B]REPLY\f[R]* to the new value for the
command line argument.* If the function returns non-zero status, so does the
calling function.
.PP
For example, a user-defined widget containing the following code converts the
characters in the argument under the cursor into all upper case:
.RS
.IP
.nf
\f[C]
modify-current-argument \[aq]${(U)ARG}\[aq]
\f[R]
.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:
.RS
.IP
.nf
\f[C]
modify-current-argument \[aq]${(qq)${(Q)ARG}}\[aq]
\f[R]
.fi
.RE
.PP
The following performs directory expansion on the command line argument and
replaces it by the absolute path:
.RS
.IP
.nf
\f[C]
expand-dir() {
REPLY=${\[ti]1}
REPLY=${REPLY:a}
}
modify-current-argument expand-dir
\f[R]
.fi
.RE
.PP
In practice the function \f[B]expand-dir\f[R]* would probably not be defined*
within the widget where \f[B]modify-current-argument\f[R]* is called.*
.SS Styles
.PP
The behavior of several of the above widgets can be controlled by the use of the
\f[B]zstyle\f[R]* mechanism.
In particular, widgets that interact with* the completion system pass along
their context to any completions that they invoke.
.PP
\f[B]break-keys\f[R] This style is used by the
\f[B]incremental-complete-word\f[R]* 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 \f[B]incremental-complete-word\f[R]*, this
style is looked up using the* context \[ga]\f[B]:incremental\f[R]*\[aq].*
.PP
\f[B]completer\f[R]
.PD 0
.P
.PD
The \f[B]incremental-complete-word\f[R]* and
\f[I]\f[BI]insert-and-predict\f[I]\f[R] 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
.IP
.nf
\f[C]
zstyle \[aq]:completion:*\[aq] completer \[rs]
_complete _correct _approximate
zstyle \[aq]:completion:incremental:*\[aq] completer \[rs]
_complete _correct
zstyle \[aq]:completion:predict:*\[aq] completer \[rs]
_complete
\f[R]
.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 \f[B]_list\f[R]* and* \f[B]_menu\f[R]* completers should never be used with
prediction.
The* \f[B]_approximate\f[R]*, \f[I]\f[BI]_correct\f[I]\f[R],
\f[I]\f[BI]_expand\f[I]\f[R], and \f[I]\f[BI]_match\f[I]\f[R] 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.
.PP
\f[B]cursor\f[R]
.PD 0
.P
.PD
The \f[B]insert-and-predict\f[R]* widget uses this style, in the context*
\[ga]\f[B]:predict\f[R]*\[aq], to decide where to place the cursor after
completion has* been tried.
Values are:
.PP
\f[B]complete\f[R] 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
\[ga]\f[B]key\f[R]*\[aq].*
.PP
\f[B]key\f[R]
.PD 0
.P
.PD
The cursor is left after the \f[I]nth occurrence of the character just inserted,
where\f[R] \f[I]n is the number of times that character appeared in the
word\f[R] 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.
.PP
\f[B]list\f[R]
.PD 0
.P
.PD
When using the \f[B]incremental-complete-word\f[R]* widget, this style says* if
the matches should be listed on every key press (if they fit on the screen).
Use the context prefix \[ga]\f[B]:completion:incremental\f[R]*\[aq].*
.PP
The \f[B]insert-and-predict\f[R]* 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 \f[B]always\f[R]*.
In this* case the context is \[ga]\f[B]:predict\f[R]*\[aq] (not
\[ga]\f[I]\f[BI]:completion:predict\f[I]\f[R]\[aq]).*
.PP
\f[B]match\f[R]
.PD 0
.P
.PD
This style is used by \f[B]smart-insert-last-word\f[R]* to provide a pattern*
(using full \f[B]EXTENDED_GLOB\f[R]* syntax) that matches an interesting word.*
The context is the name of the widget to which \f[B]smart-insert-last-word\f[R]
is bound (see above).
The default behavior of \f[B]smart-insert-last-word\f[R] is equivalent to:
.RS
.IP
.nf
\f[C]
zstyle :insert-last-word match \[aq]*[[:alpha:]/\[rs]\[rs]]*\[aq]
\f[R]
.fi
.RE
.PP
However, you might want to include words that contain spaces:
.RS
.IP
.nf
\f[C]
zstyle :insert-last-word match \[aq]*[[:alpha:][:space:]/\[rs]\[rs]]*\[aq]
\f[R]
.fi
.RE
.PP
Or include numbers as long as the word is at least two characters long:
.RS
.IP
.nf
\f[C]
zstyle :insert-last-word match \[aq]*([[:digit:]]?|[[:alpha:]/\[rs]\[rs]])*\[aq]
\f[R]
.fi
.RE
.PP
The above example causes redirections like \[dq]2>\[dq] to be included.
.PP
\f[B]prompt\f[R]
.PD 0
.P
.PD
The \f[B]incremental-complete-word\f[R]* 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 \f[B]PS1\f[R]* and other prompt parameters:*
.PP
\f[B]%c\f[R] Replaced by the name of the completer function that generated the
matches (without the leading underscore).
.PP
\f[B]%l\f[R]
.PD 0
.P
.PD
When the \f[B]list\f[R]* style is set,* replaced by \[ga]\f[B]...\f[R]\f[I]\[aq]
if the list of matches is too long to fit on the\f[R] screen and with an empty
string otherwise.
If the \f[B]list\f[R]* style is* \[ga]false\[aq] or not set,
\[ga]\f[B]%l\f[R]*\[aq] is always removed.*
.PP
\f[B]%n\f[R]
.PD 0
.P
.PD
Replaced by the number of matches generated.
.PP
\f[B]%s\f[R]
.PD 0
.P
.PD
Replaced by \[ga]\f[B]-no match-\f[R]\f[I]\[aq], \[ga]\f[R]\f[B]-no
prefix-\f[R]\f[I]\[aq], or an empty string\f[R] 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.
.PP
\f[B]%u\f[R]
.PD 0
.P
.PD
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 \[ga]\f[B]break-keys\f[R]*\[aq], this uses the
\[ga]\f[I]\f[BI]:incremental\f[I]\f[R]\[aq] context.*
.PP
\f[B]stop-keys\f[R]
.PD 0
.P
.PD
This style is used by the \f[B]incremental-complete-word\f[R]* widget.
Its value* is treated similarly to the one for the \f[B]break-keys\f[R]* style
(and uses * the same context: \[ga]\f[B]:incremental\f[R]*\[aq]).
However, in* this case all keys matching the pattern given as its value will
stop incremental completion and will then execute their usual function.
.PP
\f[B]toggle\f[R]
.PD 0
.P
.PD
This boolean style is used by \f[B]predict-on\f[R]* and its related widgets in*
the context \[ga]\f[B]:predict\f[R]*\[aq].
If set to one of the standard \[ga]true\[aq] 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
\f[B]predict-off\f[R]*.*
.PP
\f[B]verbose\f[R]
.PD 0
.P
.PD
This boolean style is used by \f[B]predict-on\f[R]* and its related widgets in*
the context \[ga]\f[B]:predict\f[R]*\[aq].
If set to one of the standard \[ga]true\[aq] values,* these widgets display a
message below the prompt when the predictive state is toggled.
This is most useful in combination with the \f[B]toggle\f[R]* style.* The
default does not display these messages.
.PP
\f[B]widget\f[R]
.PD 0
.P
.PD
This style is similar to the \f[B]command\f[R]* style: For widget functions
that* use \f[B]zle\f[R]* 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 (\f[I]not the name
of the calling function,\f[R] because one function may be bound to multiple
widget names).
.RS
.IP
.nf
\f[C]
zstyle :copy-earlier-word widget smart-insert-last-word
\f[R]
.fi
.RE
.PP
Check the documentation for the calling widget or function to determine whether
the \f[B]widget\f[R]* style is used.*
.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
\f[B]throw\f[R]* exception* The function \f[B]throw\f[R]* throws the named
exception.
The name is* an arbitrary string and is only used by the \f[B]throw\f[R]* and
*\f[B]catch\f[R] 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.
.PP
\f[B]catch\f[R]* exception-pattern*
.PD 0
.P
.PD
The function \f[B]catch\f[R]* returns status zero if an exception was thrown
and* the pattern \f[I]exception-pattern matches its name. Otherwise it\f[R]
returns status 1.
\f[I]exception-pattern is a standard\f[R] shell pattern, respecting the current
setting of the \f[B]EXTENDED_GLOB\f[R] option.
An alias \f[B]catch\f[R]* 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 \f[B]CAUGHT\f[R]* is set by \f[I]\f[BI]catch\f[I]\f[R] to
the* name of the exception caught.
It is possible to rethrow an exception by calling the \f[B]throw\f[R]* function
again once an exception has been caught.*
.PP
The functions are designed to be used together with the \f[B]always\f[R]*
construct* described in \f[I]zshmisc(1). This is important as only this\f[R]
construct provides the required support for exceptions.
A typical example is as follows.
.RS
.IP
.nf
\f[C]
{
# \[dq]try\[dq] block
# ... nested code here calls \[dq]throw MyExcept\[dq]
} always {
# \[dq]always\[dq] block
if catch MyExcept; then
print \[dq]Caught exception MyExcept\[dq]
elif catch \[aq]\[aq]; then
print \[dq]Caught a shell error. Propagating...\[dq]
throw \[aq]\[aq]
fi
# Other exceptions are not handled but may be caught further
# up the call stack.
}
\f[R]
.fi
.RE
.PP
If all exceptions should be caught, the following idiom might be preferable.
.RS
.IP
.nf
\f[C]
{
# ... nested code here throws an exception
} always {
if catch *; then
case $CAUGHT in
(MyExcept)
print \[dq]Caught my own exception\[dq]
;;
(*)
print \[dq]Caught some other exception\[dq]
;;
esac
fi
}
\f[R]
.fi
.RE
.PP
In common with exception handling in other languages, the exception may be
thrown by code deeply nested inside the \[ga]try\[aq] 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 \f[B]EXCEPTION\f[R]* 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
\f[B]EXCEPTION\f[R] remains set and may be incorrectly recognised as the name of
an exception if a shell error subsequently occurs.
Adding \f[B]unset EXCEPTION\f[R]* at the* start of the outermost layer of any
code that uses exception handling will eliminate this problem.
.SH MIME FUNCTIONS
.PP
Three functions are available to provide handling of files recognised by
extension, for example to dispatch a file \f[B]text.ps\f[R]* when executed as a*
command to an appropriate viewer.
.PP
\f[B]zsh-mime-setup\f[R]* [ \f[I]\f[BI]-fv\f[I]\f[R] ] [ \f[I]\f[BI]-l\f[I]\f[R]
[ suffix ...
] ]*
.PP
\f[B]zsh-mime-handler\f[R]* [ \f[I]\f[BI]-l\f[I]\f[R] ] command argument ...*
These two functions use the files \f[B]\[ti]/.mime.types\f[R]* and
\f[I]\f[BI]/etc/mime.types\f[I]\f[R],* which associate types and extensions, as
well as \f[B]\[ti]/.mailcap\f[R]* and* \f[B]/etc/mailcap\f[R]* 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 \f[B]zsh-mime-setup\f[R]* 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 \f[B]zsh-mime-handler\f[R]* should not need to be called by the*
user.
.PP
The system works by setting up suffix aliases with \[ga]\f[B]alias
-s\f[R]*\[aq].* 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.
\f[B]PDF\f[R]* is automatically handled if* handling for the suffix
\f[B]pdf\f[R]* is defined), but not vice versa.*
.PP
Repeated calls to \f[B]zsh-mime-setup\f[R]* do not override the existing*
mapping between suffixes and executable files unless the option \f[B]-f\f[R] is
given.
Note, however, that this does not override existing suffix aliases assigned to
handlers other than \f[B]zsh-mime-handler\f[R]*.*
.PP
Calling \f[B]zsh-mime-setup\f[R]* with the option \f[I]\f[BI]-l\f[I]\f[R] 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 \f[B]zsh-mime-setup\f[R]* with the option* \f[B]-v\f[R]* causes verbose
output to be shown during the setup operation.*
.PP
The system respects the \f[B]mailcap\f[R]* flags
\f[I]\f[BI]needsterminal\f[I]\f[R] and* \f[B]copiousoutput\f[R]*, see
mailcap(4).*
.PP
The functions use the following styles, which are defined with the
\f[B]zstyle\f[R]* builtin command (see zshmodules(1)).
They should be defined* before \f[B]zsh-mime-setup\f[R]* is run.
The contexts used all* start with \f[B]:mime:\f[R]\f[I], with additional
components in some cases.\f[R] It is recommended that a trailing \f[B]*\f[R]*
(suitably quoted) be appended* to style patterns in case the system is extended
in future.
Some examples are given below.
.PP
For files that have multiple suffixes, e.g.
\f[B].pdf.gz\f[R]*, where the* context includes the suffix it will be looked up
starting with the longest possible suffix until a match for the style is found.
For example, if \f[B].pdf.gz\f[R]* produces a match for the handler, that* will
be used; otherwise the handler for \f[B].gz\f[R]* will be used.
Note* that, owing to the way suffix aliases work, it is always required that
there be a handler for the shortest possible suffix, so in this example
\f[B].pdf.gz\f[R]* can only be handled if \f[I]\f[BI].gz\f[I]\f[R] is also
handled (though* not necessarily in the same way).
Alternatively, if no handling for \f[B].gz\f[R]* on its own is needed, simply
adding the command*
.RS
.IP
.nf
\f[C]
alias -s gz=zsh-mime-handler
\f[R]
.fi
.RE
.PP
to the initialisation code is sufficient; \f[B].gz\f[R]* will not be handled* on
its own, but may be in combination with other suffixes.
.PP
\f[B]current-shell\f[R] If this boolean style is true, the mailcap handler for
the context in question is run using the \f[B]eval\f[R]* builtin instead of by
starting a new* \f[B]sh\f[R]* process.
This is more efficient, but may not work in the occasional* cases where the
mailcap handler uses strict POSIX syntax.
.PP
\f[B]disown\f[R]
.PD 0
.P
.PD
If this boolean style is true, mailcap handlers started in the background will
be disowned, i.e.
not subject to job control within the parent shell.
Such handlers nearly always produce their own windows, so the only likely
harmful side effect of setting the style is that it becomes harder to kill jobs
from within the shell.
.PP
\f[B]execute-as-is\f[R]
.PD 0
.P
.PD
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 \f[B]*(*) *(/)\f[R]* is used;* hence
executable files are executed directly and not passed to a handler, and the
option \f[B]AUTO_CD\f[R]* may be used to change to directories* that happen to
have MIME suffixes.
.PP
\f[B]execute-never\f[R]
.PD 0
.P
.PD
This style is useful in combination with \f[B]execute-as-is\f[R]*.
It is* set to an array of patterns corresponding to full paths to files that
should never be treated as executable, even if the file passed to the MIME
handler matches \f[B]execute-as-is\f[R]*.
This is useful for file* systems that don\[aq]t handle execute permission or
that contain executables from another operating system.
For example, if \f[B]/mnt/windows\f[R]* is a* Windows mount, then
.RS
.IP
.nf
\f[C]
zstyle \[aq]:mime:*\[aq] execute-never \[aq]/mnt/windows/*\[aq]
\f[R]
.fi
.RE
.PP
will ensure that any files found in that area will be executed as MIME types
even if they are executable.
As this example shows, the complete file name is matched against the pattern,
regardless of how the file was passed to the handler.
The file is resolved to a full path using the \f[B]:P\f[R]* modifier described
in* the subsection Modifiers in \f[I]zshexpn(1);\f[R] this means that symbolic
links are resolved where possible, so that links into other file systems behave
in the correct fashion.
.PP
\f[B]file-path\f[R]
.PD 0
.P
.PD
Used if the style \f[B]find-file-in-path\f[R]* 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
\f[B]path\f[R]*.
The shell option \f[I]\f[BI]PATH_DIRS\f[I]\f[R] 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 \[ga]\f[B]/\f[R]\f[I]\[aq].\f[R]
The full context is \f[B]:mime:.\f[BI]\f[I]suffix\f[BI]\f[B]:\f[R]\f[I], as
described for the style\f[R] \f[B]handler\f[R]*.*
.PP
\f[B]find-file-in-path\f[R]
.PD 0
.P
.PD
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 \f[B]file-path\f[R]* 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 \f[B]handle-nonexistent\f[R] style is set.
Files found in the path are tested as described for the style
\f[B]execute-as-is\f[R]*.* The full context is
\f[B]:mime:.\f[BI]\f[I]suffix\f[BI]\f[B]:\f[R]\f[I], as described for the
style\f[R] \f[B]handler\f[R]*.*
.PP
\f[B]flags\f[R]
.PD 0
.P
.PD
Defines flags to go with a handler; the context is as for the \f[B]handler\f[R]*
style, and the format is as for the flags in \f[I]\f[BI]mailcap\f[I]\f[R].*
.PP
\f[B]handle-nonexistent\f[R]
.PD 0
.P
.PD
By default, arguments that don\[aq]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\[aq]t exist.
If it is not explicitly set it defaults to \f[B][[:alpha:]]#:/*\f[R]* which
allows URLs to be passed to the MIME* handler even though they don\[aq]t exist
in that format in the file system.
The full context is \f[B]:mime:.\f[BI]\f[I]suffix\f[BI]\f[B]:\f[R]\f[I], as
described for the style\f[R] \f[B]handler\f[R]*.*
.PP
\f[B]handler\f[R]
.PD 0
.P
.PD
Specifies a handler for a suffix; the suffix is given by the context as
\f[B]:mime:.\f[BI]\f[I]suffix\f[BI]\f[B]:\f[R]\f[I], and the format of the
handler is exactly\f[R] that in \f[B]mailcap\f[R]*.
Note in particular the \[ga]\f[I]\f[BI].\f[I]\f[R]\[aq] and trailing colon* to
distinguish this use of the context.
This overrides any handler specified by the \f[B]mailcap\f[R]* files.
If the handler requires a terminal,* the \f[B]flags\f[R]* style should be set to
include the word \f[I]\f[BI]needsterminal\f[I]\f[R],* or if the output is to be
displayed through a pager (but not if the handler is itself a pager), it should
include \f[B]copiousoutput\f[R]*.*
.PP
\f[B]mailcap\f[R]
.PD 0
.P
.PD
A list of files in the format of \f[B]\[ti]/.mailcap\f[R]* and*
\f[B]/etc/mailcap\f[R]* to be read during setup, replacing the default list*
which consists of those two files.
The context is \f[B]:mime:\f[R]\f[I].\f[R] A \f[B]+\f[R]* in the list will be
replaced by the default files.*
.PP
\f[B]mailcap-priorities\f[R]
.PD 0
.P
.PD
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.
.PP
\f[B]files\f[R] The order of files (entries in the \f[B]mailcap\f[R]* style)
read.
Earlier* files are preferred.
(Note this does not resolve entries in the same file.)
.PP
\f[B]priority\f[R]
.PD 0
.P
.PD
The priority flag from the mailcap entry.
The priority is an integer from 0 to 9 with the default value being 5.
.PP
\f[B]flags\f[R]
.PD 0
.P
.PD
The test given by the \f[B]mailcap-prio-flags\f[R]* option is used to resolve*
entries.
.PP
\f[B]place\f[R]
.PD 0
.P
.PD
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
\f[B]:mime:\f[R]\f[I], with no discrimination by suffix.\f[R]
.PP
\f[B]mailcap-prio-flags\f[R]
.PD 0
.P
.PD
This style is used when the keyword \f[B]flags\f[R]* is encountered in the* list
of tests specified by the \f[B]mailcap-priorities\f[R]* 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.
.PP
\f[B]mime-types\f[R]
.PD 0
.P
.PD
A list of files in the format of \f[B]\[ti]/.mime.types\f[R]* and*
\f[B]/etc/mime.types\f[R]* to be read during setup, replacing the default list*
which consists of those two files.
The context is \f[B]:mime:\f[R]\f[I].\f[R] A \f[B]+\f[R]* in the list will be
replaced by the default files.*
.PP
\f[B]never-background\f[R]
.PD 0
.P
.PD
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\[aq]t require a terminal).
.PP
\f[B]pager\f[R]
.PD 0
.P
.PD
If set, will be used instead of \f[B]$PAGER\f[R]* or \f[I]\f[BI]more\f[I]\f[R]
to handle* suffixes where the \f[B]copiousoutput\f[R]* flag is set.
The context is* as for \f[B]handler\f[R]*, i.e.
\f[I]\f[BI]:mime:.\f[B]\f[R]suffix\f[B]\f[BI]:\f[I]\f[R] for handling* a file
with the given \f[I]suffix.\f[R]
.PP
Examples:
.RS
.IP
.nf
\f[C]
zstyle \[aq]:mime:*\[aq] mailcap \[ti]/.mailcap /usr/local/etc/mailcap
zstyle \[aq]:mime:.txt:\[aq] handler less %s
zstyle \[aq]:mime:.txt:\[aq] flags needsterminal
\f[R]
.fi
.RE
.PP
When \f[B]zsh-mime-setup\f[R]* is subsequently run, it will look for*
\f[B]mailcap\f[R]* entries in the two files given.
Files of suffix \f[I]\f[BI].txt\f[I] will be handled by running
\[ga]\f[BI]less\f[I]\f[R] file.txt\[aq].
The flag* \f[B]needsterminal\f[R]* 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 **.**\f[I]ext does not have
the expected effect.\f[R]
.PP
The command \[ga]\f[B]alias -s\f[R]* ext\[aq] should show*
\[ga]\f[B]ps=zsh-mime-handler\f[R]*\[aq].
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 \f[B].mime.types\f[R]* and \f[I]\f[BI]mailcap\f[I]\f[R]
combination for* \f[B].ext\f[R]* files.
In that case, appropriate handling should be added to*
\f[B]\[ti]/.mime.types\f[R]* and \f[I]\f[BI]mailcap\f[I]\f[R].*
.PP
If the extension is handled by \f[B]zsh-mime-handler\f[R]* 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 \f[B]zsh-mime-setup -l\f[R]* will show the handler and, if there are
any, the* flags.
A \f[B]%s\f[R]* 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 \f[B]needsterminal\f[R]* or* \f[B]copiousoutput\f[R]*
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 \f[B]mailcap\f[R]* entry for such a program is:*
.RS
.IP
.nf
\f[C]
text/html; /usr/bin/lynx \[aq]%s\[aq]; needsterminal
\f[R]
.fi
.RE
.PP
Running \[ga]\f[B]zsh-mime-handler -l\f[R]* command line\[aq] 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 \f[B]zsh-mime-setup\f[R]*.*
.RE
.PP
\f[B]pick-web-browser\f[R]
.PD 0
.P
.PD
This function is separate from the two MIME functions described above and can be
assigned directly to a suffix:
.RS
.IP
.nf
\f[C]
autoload -U pick-web-browser
alias -s html=pick-web-browser
\f[R]
.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
\f[B]browser-style\f[R] 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
\f[B]running\f[R] Use a GUI browser that is already running when an X Window
display is available.
The browsers listed in the \f[B]x-browsers\f[R]* 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.
.PP
\f[B]x\f[R]
.PD 0
.P
.PD
Start a new GUI browser when an X Window display is available.
Search for the availability of one of the browsers listed in the
\f[B]x-browsers\f[R]* style* and start the first one that is found.
No check is made for an already running browser.
.PP
\f[B]tty\f[R]
.PD 0
.P
.PD
Start a terminal-based browser.
Search for the availability of one of the browsers listed in the
\f[B]tty-browsers\f[R]* style and start the* first one that is found.
.PP
If the style is not set the default \f[B]running x tty\f[R]* is used.*
.RE
.PP
\f[B]x-browsers\f[R]
.PD 0
.P
.PD
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 \f[B]:mime:\f[R]* (which may* be extended in
future, so appending \[ga]\f[B]*\f[R]\f[I]\[aq] is recommended). For\f[R]
example,
.RS
.IP
.nf
\f[C]
zstyle \[aq]:mime:*\[aq] x-browsers opera konqueror firefox
\f[R]
.fi
.RE
.PP
specifies that \f[B]pick-web-browser\f[R]* 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 \f[B]firefox mozilla netscape opera konqueror\f[R]*.*
.PP
\f[B]tty-browsers\f[R]
.PD 0
.P
.PD
An array similar to \f[B]x-browsers\f[R]*, except that it gives browsers to* use
when no X Window display is available.
The default is \f[B]elinks links lynx\f[R]*.*
.PP
\f[B]command\f[R]
.PD 0
.P
.PD
If it is set this style is used to pick the command used to open a page for a
browser.
The context is \f[B]:mime:browser\[u1F195]$browser:\f[R]* to start a new browser
or* \f[B]:mime:browser\[u1F3C3]$browser:\f[R]* to open a URL in a browser
already* running on the current X display, where \f[B]$browser\f[R]* is the
value matched* in the \f[B]x-browsers\f[R]* or \f[I]\f[BI]tty-browsers\f[I]\f[R]
style.
The escape sequence* \f[B]%b\f[R]* in the style\[aq]s value will be replaced by
the browser, while \f[I]\f[BI]%u\f[I] will be replaced by the URL. If the style
is not set, the default for all new instances is equivalent to \f[BI]%b
%u\f[I]\f[R] and the defaults for using running* browsers are equivalent to the
values \f[B]kfmclient openURL %u\f[R]* for* Konqueror, \f[B]firefox -new-tab
%u\f[R]* for Firefox, \f[I]\f[BI]opera -newpage %u\f[I] for Opera, and \f[BI]%b
-remote \[dq]openUrl(%u)\[dq]\f[I]\f[R] for all others.*
.SH MATHEMATICAL FUNCTIONS
.PP
\f[B]zcalc\f[R]* [ \f[I]\f[BI]-erf\f[I]\f[R] ] [ expression ...
]* A reasonably powerful calculator based on zsh\[aq]s arithmetic evaluation
facility.
The syntax is similar to that of formulae in most programming languages; see the
section \[ga]Arithmetic Evaluation\[aq] in \f[I]zshmisc(1) for details.\f[R]
.RS
.PP
Non-programmers should note that, as in many other programming languages,
expressions involving only integers (whether constants without a
\[ga]\f[B].\f[R]\f[I]\[aq], variables containing such constants as strings,
or\f[R] variables declared to be integers) are by default evaluated using
integer arithmetic, which is not how an ordinary desk calculator operates.
To force floating point operation, pass the option \f[B]-f\f[R]*;* see further
notes below.
.PP
If the file \f[B]\[ti]/.zcalcrc\f[R]* exists it will be sourced inside the
function* once it is set up and about to process the command line.
This can be used, for example, to set shell options; \f[B]emulate -L zsh\f[R]
and \f[B]setopt extendedglob\f[R]* are in effect at this point.
Any* failure to source the file if it exists is treated as fatal.
As with other initialisation files, the directory \f[B]$ZDOTDIR\f[R]* is used*
instead of \f[B]$HOME\f[R]* if it is set.*
.PP
The mathematical library \f[B]zsh/mathfunc\f[R]* will be loaded if it is*
available; see the section \[ga]The zsh/mathfunc Module\[aq] in
\f[I]zshmodules(1). The mathematical functions\f[R] correspond to the raw system
libraries, so trigonometric functions are evaluated using radians, and so on.
.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
\[ga]\f[I]\f[R]4> \f[I]\f[R]\f[I]\[aq] is available as \f[R]\f[B]$4\f[R]\f[I].
The last value\f[R] calculated is available as \f[B]ans\f[R]\f[I]. Full command
line editing, including\f[R] the history of previous calculations, is available;
the history is saved in the file \f[B]\[ti]/.zcalc_history\f[R]\f[I]. To exit,
enter a blank line or type \[ga]\f[R]\f[B]:q\f[R]*\[aq]* on its own
(\[ga]\f[B]q\f[R]*\[aq] is allowed for historical compatibility).*
.PP
A line ending with a single backslash is treated in the same fashion as it is in
command line editing: the backslash is removed, the function prompts for more
input (the prompt is preceded by \[ga]\f[B]...\f[R]\f[I]\[aq]\f[R] to indicate
this), and the lines are combined into one to get the final result.
In addition, if the input so far contains more open than close parentheses
\f[B]zcalc\f[R]* will prompt for more input.*
.PP
If arguments are given to \f[B]zcalc\f[R]* 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 \f[B]PI\f[R]* (3.14159...) and \f[I]\f[BI]E\f[I]\f[R] (2.71828...)
are provided.* Parameter assignment is possible, but note that all parameters
will be put into the global namespace unless the \f[B]:local\f[R]* special
command is* used.
The function creates local variables whose names start with \f[B]_\f[R]\f[I], so
users should avoid doing so. The variables \f[R]\f[B]ans\f[R]\f[I] (the
last\f[R] answer) and \f[B]stack\f[R]* (the stack in RPN mode) may be referred
to* directly; \f[B]stack\f[R]* is an array but elements of it are numeric.
Various* other special variables are used locally with their standard meaning,
for example \f[B]compcontext\f[R]*, \f[I]\f[BI]match\f[I]\f[R],
\f[I]\f[BI]mbegin\f[I]\f[R], \f[I]\f[BI]mend\f[I]\f[R],
\f[I]\f[BI]psvar\f[I]\f[R].*
.PP
The output base can be initialised by passing the option
\[ga]\f[B]-#\f[BI]\f[B]\f[BI]base\[aq],\f[B] for example \[ga]\f[R]zcalc
-#16\f[B]\f[BI]\[aq] (the \[ga]\f[B]\f[R]#**\f[I]\[aq] may have to be quoted,
depending\f[R] on the globbing options set).
.PP
If the option \[ga]\f[B]-e\f[R]*\[aq] is set, the function runs
non-interactively:* the arguments are treated as expressions to be evaluated as
if entered interactively line by line.
.PP
If the option \[ga]\f[B]-f\f[R]*\[aq] is set, all numbers are treated as
floating* point, hence for example the expression \[ga]\f[B]3/4\f[R]*\[aq]
evaluates to 0.75* rather than 0.
Options must appear in separate words.
.PP
If the option \[ga]\f[B]-r\f[R]*\[aq] is set, RPN (Reverse Polish Notation) mode
is* entered.
This has various additional properties:
.PP
Stack Evaluated values are maintained in a stack; this is contained in an array
named \f[B]stack\f[R]* with the most recent value in
\f[I]\f[BI]${stack[1]}\f[I]\f[R].*
.PP
Operators and functions
.PD 0
.P
.PD
If the line entered matches an operator (\f[B]+\f[R]\f[I],
\f[R]\f[B]-\f[R]\f[I], \f[R]\f[B]*\f[R]\f[I],\f[R] \f[B]/\f[R]\f[I],
\f[R]\f[B]**\f[R]\f[I], \f[R]\f[B]\[ha]\f[R]\f[I], \f[R]\f[B]|\f[R]\f[I] or
\f[R]\f[B]&\f[R]\f[I]) or a function supplied by the\f[R]
\f[B]zsh/mathfunc\f[R]* library, the bottom element or elements of the stack*
are popped to use as the argument or arguments.
The higher elements of stack (least recent) are used as earlier arguments.
The result is then pushed into \f[B]${stack[1]}\f[R]\f[I].\f[R]
.PP
Expressions
.PD 0
.P
.PD
Other expressions are evaluated normally, printed, and added to the stack as
numeric values.
The syntax within expressions on a single line is normal shell arithmetic (not
RPN).
.PP
Stack listing
.PD 0
.P
.PD
If an integer follows the option \f[B]-r\f[R]* with no space, then* on every
evaluation that many elements of the stack, where available, are printed instead
of just the most recent result.
Hence, for example, \f[B]zcalc -r4\f[R]* shows \f[I]\f[BI]$stack[4]\f[I]\f[R] to
\f[I]\f[BI]$stack[1]\f[I]\f[R] each time results* are printed.
.PP
Duplication: \f[B]=\f[R]
.PD 0
.P
.PD
The pseudo-operator \f[B]=\f[R]* causes the most recent element of* the stack to
be duplicated onto the stack.
.PP
\f[B]pop\f[R]
.PD 0
.P
.PD
The pseudo-function \f[B]pop\f[R]* causes the most recent element of* the stack
to be popped.
A \[ga]\f[B]>\f[R]\f[I]\[aq] on its own has the same effect.\f[R]
.PP
\f[I]\f[R]>\f[I]\f[R]\f[I]ident\f[R]
.PD 0
.P
.PD
The expression \f[B]>\f[R]\f[I] followed (with no space) by a shell
identifier\f[R] causes the most recent element of the stack to be popped and
assigned to the variable with that name. The variable is local to the
\f[B]zcalc\f[R]\f[I] function.\f[R]
.PP
\f[I]\f[R]<\f[I]\f[R]\f[I]ident\f[R]
.PD 0
.P
.PD
The expression \f[B]<\f[R]\f[I] followed (with no space) by a shell
identifier\f[R] causes the value of the variable with that name to be pushed
onto the stack. \f[I]ident may be an integer, in which\f[R] case the previous
result with that number (as shown before the \f[B]>\f[R]\f[I] in the standard
\f[R]\f[B]zcalc\f[R]\f[I] prompt) is put on the stack.\f[R]
.PP
Exchange: \f[B]xy\f[R]
.PD 0
.P
.PD
The pseudo-function \f[B]xy\f[R]* causes the most recent two elements of* the
stack to be exchanged.
\[ga]\f[B]<>\f[R]\f[I]\[aq] has the same effect.\f[R]
.PP
The prompt is configurable via the parameter \f[B]ZCALCPROMPT\f[R]*, which*
undergoes standard prompt expansion.
The index of the current entry is stored locally in the first element of the
array \f[B]psvar\f[R]*, which can be* referred to in \f[B]ZCALCPROMPT\f[R]* as
\[ga]\f[I]\f[BI]%1v\f[I]\f[R]\[aq].
The default prompt is* \[ga]**%1v> **\f[I]\[aq].\f[R]
.PP
The variable \f[B]ZCALC_ACTIVE\f[R]* is set within the function and can* be
tested by nested functions; it has the value \f[B]rpn\f[R]* if RPN mode is*
active, else 1.
.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 \f[B]compinit\f[R]* has been run.*
.PP
The output precision may be specified within zcalc by special commands familiar
from many calculators.
.PP
\f[B]:norm\f[R] The default output format.
It corresponds to the printf \f[B]%g\f[R] specification.
Typically this shows six decimal digits.
.PP
\f[B]:sci\f[R]* digits*
.PD 0
.P
.PD
Scientific notation, corresponding to the printf \f[B]%g\f[R]* output format
with* the precision given by \f[I]digits. This produces either fixed point
or\f[R] exponential notation depending on the value output.
.PP
\f[B]:fix\f[R]* digits*
.PD 0
.P
.PD
Fixed point notation, corresponding to the printf \f[B]%f\f[R]* output format
with* the precision given by \f[I]digits.\f[R]
.PP
\f[B]:eng\f[R]* digits*
.PD 0
.P
.PD
Exponential notation, corresponding to the printf \f[B]%E\f[R]* output format
with* the precision given by \f[I]digits.\f[R]
.PP
\f[B]:raw\f[R]
.PD 0
.P
.PD
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:
.PP
**:!\f[I]\f[R]\f[I]line...\f[R] Execute \f[I]line... as a normal shell command
line. Note that it\f[R] is executed in the context of the function, i.e. with
local variables. Space is optional after \f[B]:!\f[R]\f[I].\f[R]
.PP
\f[B]:local\f[R]* arg ...*
.PD 0
.P
.PD
Declare variables local to the function.
Other variables may be used, too, but they will be taken from or put into the
global scope.
.PP
\f[B]:function\f[R]* name [ body ]*
.PD 0
.P
.PD
Define a mathematical function or (with no \f[I]body) delete it.\f[R]
\f[B]:function\f[R]* may be abbreviated to \f[I]\f[BI]:func\f[I]\f[R] or simply
\f[I]\f[BI]:f\f[I]\f[R].* The \f[I]name may contain the same characters as a
shell function name.\f[R] The function is defined using \f[B]zmathfuncdef\f[R]*,
see below.*
.PP
Note that \f[B]zcalc\f[R]* takes care of all quoting.
Hence for example:*
.RS
.IP
.nf
\f[C]
:f cube $1 * $1 * $1
\f[R]
.fi
.RE
.PP
defines a function to cube the sole argument.
Functions so defined, or indeed any functions defined directly or indirectly
using \f[B]functions\f[R] -M*, are available to execute by typing only the name
on the line in RPN* mode; this pops the appropriate number of arguments off the
stack to pass to the function, i.e.
1 in the case of the example \f[B]cube\f[R] function.
If there are optional arguments only the mandatory arguments are supplied by
this means.
.PP
\f[B][#\f[BI]\f[I]base\f[BI]\f[B]]\f[R]
.PD 0
.P
.PD
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
\f[I]base. Use, for example, \[ga]\f[R]\f[B][#16]\f[R]\f[I]\[aq] to display\f[R]
hexadecimal output preceded by an indication of the base, or
\[ga]\f[B][##16]\f[R]\f[I]\[aq]\f[R] just to display the raw number in the given
base.
Bases themselves are always specified in decimal.
\[ga]\f[B][#]\f[R]\f[I]\[aq] restores the normal output format.\f[R] Note that
setting an output base suppresses floating point output; use
\[ga]\f[B][#]\f[R]\f[I]\[aq] to return to normal operation.\f[R]
.PP
\f[B]$\f[R]\f[I]var\f[R]
.PD 0
.P
.PD
Print out the value of var literally; does not affect the calculation. To use
the value of var, omit the leading \[ga]\f[B]$\f[R]\f[I]\[aq].\f[R]
.PP
See the comments in the function for a few extra tips.
.RE
.PP
\f[B]min(\f[BI]\f[I]arg\f[BI]\f[B], ...)\f[R]
.PP
\f[B]max(\f[BI]\f[I]arg\f[BI]\f[B], ...)\f[R]
.PP
\f[B]sum(\f[BI]\f[I]arg\f[BI]\f[B], ...)\f[R]
.PP
\f[B]zmathfunc\f[R] The function \f[B]zmathfunc\f[R]* defines the three
mathematical functions* \f[B]min\f[R]*, \f[I]\f[BI]max\f[I]\f[R], and
\f[I]\f[BI]sum\f[I]\f[R].
The functions \f[I]\f[BI]min\f[I]\f[R] and \f[I]\f[BI]max\f[I]\f[R] take* one or
more arguments.
The function \f[B]sum\f[R]* takes zero or more arguments.* Arguments can be of
different types (ints and floats).
.RS
.PP
Not to be confused with the \f[B]zsh/mathfunc\f[R]* module, described in* the
section \[ga]The zsh/mathfunc Module\[aq] in \f[I]zshmodules(1).\f[R]
.RE
.PP
\f[B]zmathfuncdef\f[R]* [ mathfunc [ body ] ]*
.PD 0
.P
.PD
A convenient front end to \f[B]functions -M\f[R]*.*
.PP
With two arguments, define a mathematical function named \f[I]mathfunc\f[R]
which can be used in any form of arithmetic evaluation.
\f[I]body\f[R] is a mathematical expression to implement the function.
It may contain references to position parameters \f[B]$1\f[R]*,
\f[I]\f[BI]$2\f[I]\f[R], ...* to refer to mandatory parameters and
\f[B]${1:-\f[BI]\f[I]defvalue\f[BI]\f[B]}\f[R]* ...* 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
**zsh_math_func_**\f[I]mathfunc; usually the user will not need\f[R] 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 \f[I]mathfunc\f[R] as well
as the shell function implementation.
.PP
With no arguments, list all \f[I]mathfunc functions in a form\f[R] suitable for
restoring the definition.
The functions have not necessarily been defined by \f[B]zmathfuncdef\f[R]*.*
.SH USER CONFIGURATION FUNCTIONS
.PP
The \f[B]zsh/newuser\f[R]* 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\[aq]s default behaviour, namely running the
function for a new user logging in without startup files, is inhibited.
.PP
\f[B]zsh-newuser-install\f[R]* [ \f[I]\f[BI]-f\f[I]\f[R] ]* The function
presents the user with various options for customizing their initialization
scripts.
Currently only \f[B]\[ti]/.zshrc\f[R]* is handled.* \f[B]$ZDOTDIR/.zshrc\f[R]*
is used instead if the parameter \f[I]\f[BI]ZDOTDIR\f[I]\f[R] is* set; this
provides a way for the user to configure a file without altering an existing
\f[B].zshrc\f[R]*.*
.RS
.PP
By default the function exits immediately if it finds any of the files
\f[B].zshenv\f[R]*, \f[I]\f[BI].zprofile\f[I]\f[R], \f[I]\f[BI].zshrc\f[I]\f[R],
or \f[I]\f[BI].zlogin\f[I]\f[R] in the appropriate* directory.
The option \f[B]-f\f[R]* is required in order to force the function* to
continue.
Note this may happen even if \f[B].zshrc\f[R]* 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\[aq]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 \[ga]\f[B]# Lines configured by
zsh-newuser-install\f[R]*\[aq] and* \[ga]\f[B]# End of lines configured by
zsh-newuser-install\f[R]*\[aq].
In addition,* the old version of \f[B].zshrc\f[R]* is saved to a file with the
suffix* \f[B].zni\f[R]* appended.*
.PP
If the function edits an existing \f[B].zshrc\f[R]*, 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
\f[B].zshrc\f[R]* 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
.SH OTHER FUNCTIONS
.PP
There are a large number of helpful functions in the \f[B]Functions/Misc\f[R]
directory of the zsh distribution.
Most are very simple and do not require documentation here, but a few are worthy
of special mention.
.SS Descriptions
.PP
\f[B]colors\f[R] 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 \f[B]colors\f[R]* more than once.*
.RS
.PP
The eight base colors are: \f[B]black\f[R]*, \f[I]\f[BI]red\f[I]\f[R],
\f[I]\f[BI]green\f[I]\f[R], \f[I]\f[BI]yellow\f[I]\f[R],* \f[B]blue\f[R]*,
\f[I]\f[BI]magenta\f[I]\f[R], \f[I]\f[BI]cyan\f[I]\f[R], and
\f[I]\f[BI]white\f[I]\f[R].
Each of these has codes for* foreground and background.
In addition there are seven intensity attributes: \f[B]bold\f[R]*,
\f[I]\f[BI]faint\f[I]\f[R], \f[I]\f[BI]standout\f[I]\f[R],
\f[I]\f[BI]underline\f[I]\f[R], \f[I]\f[BI]blink\f[I]\f[R],
\f[I]\f[BI]reverse\f[I]\f[R],* and \f[B]conceal\f[R]*.
Finally, there are seven codes used to negate attributes:* \f[B]none\f[R]*
(reset all attributes to the defaults), \f[I]\f[BI]normal\f[I] (neither bold nor
faint), \f[BI]no-standout\f[I]\f[R], \f[I]\f[BI]no-underline\f[I]\f[R],
\f[I]\f[BI]no-blink\f[I]\f[R],* \f[B]no-reverse\f[R]*, and
\f[I]\f[BI]no-conceal\f[I]\f[R].*
.PP
Some terminals do not support all combinations of colors and intensities.
.PP
The associative arrays are:
.PP
\f[B]color\f[R]
.PP
\f[B]colour\f[R] 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 \[ga]\f[B]fg-\f[R]\f[I]\[aq], such as \[ga]\f[R]\f[B]fg-red\f[R]\f[I]\[aq].
Names prefixed\f[R] with \[ga]\f[B]bg-\f[R]\f[I]\[aq], such as
\[ga]\f[R]\f[B]bg-blue\f[R]\f[I]\[aq], refer to the background codes. The\f[R]
reverse mapping from code to color yields base name for foreground codes and the
\f[B]bg-\f[R]* form for backgrounds.*
.RS
.PP
Although it is a misnomer to call them \[ga]colors\[aq], these arrays also map
the other fourteen attributes from names to codes and codes to names.
.RE
.PP
\f[B]fg\f[R]
.PP
\f[B]fg_bold\f[R]
.PP
\f[B]fg_no_bold\f[R] Map the eight basic color names to ANSI terminal escape
sequences that set the corresponding foreground text properties.
The \f[B]fg\f[R]* sequences change* the color without changing the eight
intensity attributes.
.PP
\f[B]bg\f[R]
.PP
\f[B]bg_bold\f[R]
.PP
\f[B]bg_no_bold\f[R] Map the eight basic color names to ANSI terminal escape
sequences that set the corresponding background properties.
The \f[B]bg\f[R]* sequences change the* color without changing the eight
intensity attributes.
.PP
In addition, the scalar parameters \f[B]reset_color\f[R]* and
\f[I]\f[BI]bold_color\f[I]\f[R] are* set to the ANSI terminal escapes that turn
off all attributes and turn on bold intensity, respectively.
.RE
.PP
\f[B]fned\f[R]* [ \f[I]\f[BI]-x\f[I]\f[R] num ] name*
.PD 0
.P
.PD
Same as \f[B]zed -f\f[R]*.
This function does not appear in the zsh* distribution, but can be created by
linking \f[B]zed\f[R]* to the name \f[I]\f[BI]fned\f[I] in some directory in
your \f[BI]fpath\f[I]\f[R].*
.PP
\f[B]is-at-least\f[R]* needed [ present ]*
.PD 0
.P
.PD
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 \f[I]present string is not\f[R] provided, \f[B]$ZSH_VERSION\f[R]* 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.
.PP
This is useful in startup files to set options and other state that are not
available in all versions of zsh.
.RS
.IP
.nf
\f[C]
is-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 \[dq]You can\[aq]t use is-at-least here.\[dq]
\f[R]
.fi
.RE
.PP
\f[B]nslookup\f[R]* [ arg ...
]*
.PD 0
.P
.PD
This wrapper function for the \f[B]nslookup\f[R]* command requires the*
\f[B]zsh/zpty\f[R]* module (see* \f[I]zshmodules(1)). It behaves exactly like
the standard \f[R]\f[B]nslookup\f[R] 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
\[ga]:completion:nslookup\f[I]\f[R]*\[aq].*
.PP
See also the \f[B]pager\f[R]*, \f[I]\f[BI]prompt\f[I]\f[R] and
\f[I]\f[BI]rprompt\f[I]\f[R] styles below.*
.PP
\f[B]regexp-replace\f[R]* var regexp replace*
.PD 0
.P
.PD
Use regular expressions to perform a global search and replace operation on a
variable.
POSIX extended regular expressions are used, unless the option
\f[B]RE_MATCH_PCRE\f[R]* has been set, in which case* Perl-compatible regular
expressions are used (this requires the shell to be linked against the
\f[B]pcre\f[R] library).
.PP
\f[I]var is the name of the variable containing the string to be matched.\f[R]
The variable will be modified directly by the function.
The variables \f[B]MATCH\f[R]*, \f[I]\f[BI]MBEGIN\f[I]\f[R],
\f[I]\f[BI]MEND\f[I]\f[R], \f[I]\f[BI]match\f[I]\f[R],
\f[I]\f[BI]mbegin\f[I]\f[R], *\f[B]mend\f[R] should be avoided as these are used
by the regular expression code.
.PP
\f[I]regexp is the regular expression to match against the string.\f[R]
.PP
\f[I]replace is the replacement text. This can contain parameter, command\f[R]
and arithmetic expressions which will be replaced: in particular, a reference to
\f[B]$MATCH\f[R]* 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.
.PP
\f[B]run-help\f[R]* cmd*
.PD 0
.P
.PD
This function is designed to be invoked by the \f[B]run-help\f[R]* ZLE widget,*
in place of the default alias.
See \[ga]Accessing On-Line Help\[aq] above for setup instructions.
.PP
In the discussion which follows, if \f[I]cmd is a file system path, it is\f[R]
first reduced to its rightmost component (the file name).
.PP
Help is first sought by looking for a file named \f[I]cmd in the directory\f[R]
named by the \f[B]HELPDIR\f[R]* parameter.
If no file is found, an assistant* function, alias, or command named
**run-help-\f[I]\f[R]\f[I]cmd is sought. If\f[R] found, the assistant is
executed with the rest of the current command line (everything after the command
name \f[I]cmd) as its arguments. When\f[R] neither file nor assistant is found,
the external command \[ga]\f[B]man\f[R]\f[I] cmd\[aq] is run.\f[R]
.PP
An example assistant for the \[dq]ssh\[dq] command:
.RS
.IP
.nf
\f[C]
run-help-ssh() {
emulate -LR zsh
local -a args
# Delete the \[dq]-l username\[dq] option
zparseopts -D -E -a args l:
# Delete other options, leaving: host command
args=(${\[at]:#-*})
if [[ ${#args} -lt 2 ]]; then
man ssh
else
run-help $args[2]
fi
}
\f[R]
.fi
.RE
.PP
Several of these assistants are provided in the \f[B]Functions/Misc\f[R]
directory.
These must be autoloaded, or placed as executable scripts in your search path,
in order to be found and used by \f[B]run-help\f[R]*.*
.PP
run-help-git
.PP
run-help-ip
.PP
run-help-openssl
.PP
run-help-p4
.PP
run-help-sudo
.PP
run-help-svk
.PP
\f[B]run-help-svn\f[R] Assistant functions for the \f[B]git\f[R]*,*
\f[B]ip\f[R]*,* \f[B]openssl\f[R]*,* \f[B]p4\f[R]*,* \f[B]sudo\f[R]*,*
\f[B]svk\f[R]*,* and \f[B]svn\f[R]*,* commands.
.PP
\f[B]tetris\f[R]
.PD 0
.P
.PD
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.
.PP
This function must be used as a ZLE widget:
.RS
.IP
.nf
\f[C]
autoload -U tetris
zle -N tetris
bindkey keys tetris
\f[R]
.fi
.RE
.PP
To start a game, execute the widget by typing the \f[I]keys. Whatever
command\f[R] 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
\[ga]\f[B]q\f[R]*\[aq]) or when you lose.*
.PP
If you quit in the middle of a game, the next invocation of the \f[B]tetris\f[R]
widget will continue where you left off.
If you lost, it will start a new game.
.PP
\f[B]tetriscurses\f[R]
.PD 0
.P
.PD
This is a port of the above to zcurses.
The input handling is improved a bit so that moving a block sideways doesn\[aq]t
automatically advance a timestep, and the graphics use unicode block graphics.
.PP
This version does not save the game state between invocations, and is not
invoked as a widget, but rather as:
.RS
.IP
.nf
\f[C]
autoload -U tetriscurses
tetriscurses
\f[R]
.fi
.RE
.PP
\f[B]zargs\f[R]* [ option ...
\f[I]\f[BI]--\f[I]\f[R] ] [ input ...
] [ \f[I]\f[BI]--\f[I]\f[R] command [ arg ...
] ]*
.PD 0
.P
.PD
This function has a similar purpose to GNU xargs.
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.
.PP
The \f[I]option list represents options of the \f[R]\f[B]zargs\f[R]\f[I] command
itself,\f[R] which are the same as those of \f[B]xargs\f[R]*.
The input list is the* collection of strings (often file names) that become the
arguments of the \f[B]command\f[R]*, analogous to the standard input of
\f[I]\f[BI]xargs\f[I]\f[R].
Finally, the* \f[I]arg list consists of those arguments (usually options) that
are\f[R] passed to the \f[I]command each time it runs. The arg list
precedes\f[R] the elements from the \f[B]input\f[R]* list in each run.
If no command is* provided, then no \f[I]arg list may be provided, and in that
event the\f[R] default command is \[ga]\f[B]print\f[R]*\[aq] with arguments
\[ga]\f[I]\f[BI]-r --\f[I]\f[R]\[aq].*
.PP
For example, to get a long \f[B]ls\f[R]* listing of all non-hidden plain files*
in the current directory or its subdirectories:
.RS
.IP
.nf
\f[C]
autoload -U zargs
zargs -- **/*(.) -- ls -ld --
\f[R]
.fi
.RE
.PP
The first and third occurrences of \[ga]\f[B]--\f[R]\f[I]\[aq] are used to mark
the end\f[R] of options for \f[B]zargs\f[R]* and \f[I]\f[BI]ls\f[I]\f[R]
respectively to guard against* filenames starting with
\[ga]\f[B]-\f[R]\f[I]\[aq], while the second is used to separate the\f[R] list
of files from the command to run (\[ga]\f[B]ls -ld --\f[R]\f[I]\[aq]).\f[R]
.PP
The first \[ga]\f[B]--\f[R]\f[I]\[aq] would also be needed if there was a chance
the\f[R] list might be empty as in:
.RS
.IP
.nf
\f[C]
zargs -r -- ./*.back(#qN) -- rm -f
\f[R]
.fi
.RE
.PP
In the event that the string \[ga]\f[B]--\f[R]\f[I]\[aq] is or may be an input,
the\f[R] \f[B]-e\f[R]* option may be used to change the end-of-inputs marker.
Note that* this does \f[I]not change the end-of-options marker. For example, to
use\f[R] \[ga]\f[B]..\f[R]\f[I]\[aq] as the marker:\f[R]
.RS
.IP
.nf
\f[C]
zargs -e.. -- **/*(.) .. ls -ld --
\f[R]
.fi
.RE
.PP
This is a good choice in that example because no plain file can be named
\[ga]\f[B]..\f[R]\f[I]\[aq], but the best end-marker depends on the
circumstances.\f[R]
.PP
The options \f[B]-i\f[R]*, \f[I]\f[BI]-I\f[I]\f[R], \f[I]\f[BI]-l\f[I]\f[R],
\f[I]\f[BI]-L\f[I]\f[R], and \f[I]\f[BI]-n\f[I]\f[R] differ slightly* from their
usage in \f[B]xargs\f[R]*.
There are no input lines for \f[I]\f[BI]zargs\f[I]\f[R] to* count, so
\f[B]-l\f[R]* and \f[I]\f[BI]-L\f[I]\f[R] count through the input list, and
\f[I]\f[BI]-n\f[I] counts the number of arguments passed to each execution of
\f[R]command,\f[I] \f[R]including any arg list. Also, any time
\f[I]\f[BI]-i\f[I]\f[R] or \f[I]\f[BI]-I\f[I]\f[R] is used,\f[I] each \f[R]input
is processed separately as if by \[ga]\f[I]-L\f[R]**
\f[I]\f[BI]1\f[I]\f[R]\[aq].*
.PP
For details of the other \f[B]zargs\f[R]* options, see xargs(1) (but note* the
difference in function between \f[B]zargs\f[R]* and \f[I]\f[BI]xargs\f[I]\f[R])
or run* \f[B]zargs\f[R]* with the \f[I]\f[BI]--help\f[I]\f[R] option.*
.PP
\f[B]zed\f[R]* [ \f[I]\f[BI]-f\f[I]\f[R] [ \f[I]\f[BI]-x\f[I]\f[R] num ] ] name*
.PP
\f[B]zed -b\f[R] This function uses the ZLE editor to edit a file or function.
.RS
.PP
Only one \f[I]name argument is allowed.\f[R] If the \f[B]-f\f[R]* option is
given, the name is taken to be that of* a function; if the function is marked
for autoloading, \f[B]zed\f[R]* searches* for it in the \f[B]fpath\f[R]* and
loads it.
Note that functions edited this way* are installed into the current shell, but
\f[I]not written back to the\f[R] autoload file.
In this case the \f[B]-x\f[R]* option specifies that leading* tabs indenting the
function according to syntax should be converted into the given number of
spaces; \[ga]\f[B]-x 2\f[R]*\[aq] is consistent with the layout* of functions
distributed with the shell.
.PP
Without \f[B]-f\f[R]*, name 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 \f[B]zed\f[R]* and the* vi
command keymap to \f[B]zed-vicmd\f[R]*.
These will be copied from the existing* \f[B]main\f[R]* and
\f[I]\f[BI]vicmd\f[I]\f[R] keymaps if they do not exist the first time
*\f[B]zed\f[R] is run.
They can be used to provide special key bindings used only in zed.
.PP
If it creates the keymap, \f[B]zed\f[R]* rebinds the return key to insert a
line* break and \[ga]\f[B]\[ha]X\[ha]W\f[R]*\[aq] to accept the edit in the
\f[I]\f[BI]zed\f[I]\f[R] keymap, and binds* \[ga]\f[B]ZZ\f[R]*\[aq] to accept
the edit in the \f[I]\f[BI]zed-vicmd\f[I]\f[R] keymap.*
.PP
The bindings alone can be installed by running \[ga]\f[B]zed -b\f[R]*\[aq].
This is* suitable for putting into a startup file.
Note that, if rerun, this will overwrite the existing \f[B]zed\f[R]* and
\f[I]\f[BI]zed-vicmd\f[I]\f[R] keymaps.*
.PP
Completion is available, and styles may be set with the context prefix
\[ga]\f[B]:completion:zed\f[R]*\[aq].*
.PP
A zle widget \f[B]zed-set-file-name\f[R]* is available.
This can be called by* name from within zed using \[ga]\f[B]\[rs]ex
zed-set-file-name\f[R]*\[aq] (note, however, that* because of zed\[aq]s
rebindings you will have to type \f[B]\[ha]j\f[R]* at the end instead* of the
return key), or can be bound to a key in either of the \f[B]zed\f[R]* or*
\f[B]zed-vicmd\f[R]* keymaps after \[ga]\f[I]\f[BI]zed -b\f[I]\f[R]\[aq] 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 \[ga]\f[B]zed -f\f[R]*\[aq].*
.PP
While \f[B]zed-set-file-name\f[R]* is running, zed uses the keymap*
\f[B]zed-normal-keymap\f[R]*, 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\[aq]t notice.
This is not a concern for most users.
.RE
.PP
\f[B]zcp\f[R]* [ \f[I]\f[BI]-finqQvwW\f[I]\f[R] ] srcpat dest*
.PP
\f[B]zln\f[R]* [ \f[I]\f[BI]-finqQsvwW\f[I]\f[R] ] srcpat dest* Same as \f[B]zmv
-C\f[R]* and \f[I]\f[BI]zmv -L\f[I]\f[R], respectively.
These functions do not* appear in the zsh distribution, but can be created by
linking \f[B]zmv\f[R]* to* the names \f[B]zcp\f[R]* and \f[I]\f[BI]zln\f[I]\f[R]
in some directory in your \f[I]\f[BI]fpath\f[I]\f[R].*
.PP
\f[B]zkbd\f[R]
.PD 0
.P
.PD
See \[ga]Keyboard Definition\[aq] above.
.PP
\f[B]zmv\f[R]* [ \f[I]\f[BI]-finqQsvwW\f[I]\f[R] ] [ \f[I]\f[BI]-C\f[I]\f[R] |
\f[I]\f[BI]-L\f[I]\f[R] | \f[I]\f[BI]-M\f[I]\f[R] |
-{\f[I]\f[BI]p\f[I]\f[R]|\f[I]\f[BI]P\f[I]\f[R]} program ] [
\f[I]\f[BI]-o\f[I]\f[R] optstring ]*
.PP
** *\f[I]\f[R]srcpat dest * Move (usually, rename) files matching the pattern
\f[I]srcpat to\f[R] corresponding files having names of the form given by
\f[I]dest, where\f[R] \f[I]srcpat contains parentheses surrounding patterns
which will be\f[R] replaced in turn by \f[B]$1\f[R]\f[I],
\f[R]\f[B]$2\f[R]\f[I], ... in dest. For example,\f[R]
.RS
.RS
.IP
.nf
\f[C]
zmv \[aq](*).lis\[aq] \[aq]$1.txt\[aq]
\f[R]
.fi
.RE
.PP
renames \[ga]\f[B]foo.lis\f[R]*\[aq] to \[ga]\f[I]\f[BI]foo.txt\f[I]\f[R]\[aq],
\[ga]\f[I]\f[BI]my.old.stuff.lis\f[I]\f[R]\[aq] to*
\[ga]\f[B]my.old.stuff.txt\f[R]*\[aq], and so on.*
.PP
The pattern is always treated as an \f[B]EXTENDED_GLOB\f[R]* 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 \f[B]-f\f[R]
was not given) causes the entire function to abort without doing anything.
.PP
In addition to pattern replacement, the variable \f[B]$f\f[R]* can be referrred*
to in the second (replacement) argument.
This makes it possible to use variable substitution to alter the argument; see
examples below.
.PP
Options:
.PP
\f[B]-f\f[R]
.PD 0
.P
.PD
Force overwriting of destination files.
Not currently passed down to the
\f[B]mv\f[R]*/\f[I]\f[BI]cp\f[I]\f[R]/\f[I]\f[BI]ln\f[I]\f[R] command due to
vagaries of* implementations (but you can use \f[B]-o-f\f[R]* to do that).*
.PP
\f[B]-i\f[R]
.PD 0
.P
.PD
Interactive: show each line to be executed and ask the user whether to execute
it.
\[ga]\f[B]Y\f[R]*\[aq] or \[ga]\f[I]\f[BI]y\f[I]\f[R]\[aq] will execute it,
anything else will* skip it.
Note that you just need to type one character.
.PP
\f[B]-n\f[R]
.PD 0
.P
.PD
No execution: print what would happen, but don\[aq]t do it.
.PP
\f[B]-q\f[R]
.PD 0
.P
.PD
Turn bare glob qualifiers off: now assumed by default, so this has no effect.
.PP
\f[B]-Q\f[R]
.PD 0
.P
.PD
Force bare glob qualifiers on.
Don\[aq]t turn this on unless you are actually using glob qualifiers in a
pattern.
.PP
\f[B]-s\f[R]
.PD 0
.P
.PD
Symbolic, passed down to \f[B]ln\f[R]*; only works with
\f[I]\f[BI]-L\f[I]\f[R].*
.PP
\f[B]-v\f[R]
.PD 0
.P
.PD
Verbose: print each command as it\[aq]s being executed.
.PP
\f[B]-w\f[R]
.PD 0
.P
.PD
Pick out wildcard parts of the pattern, as described above, and implicitly add
parentheses for referring to them.
.PP
\f[B]-W\f[R]
.PD 0
.P
.PD
Just like \f[B]-w\f[R]*, with the addition of turning wildcards in* the
replacement pattern into sequential \f[B]${1}\f[R]* ..
\f[I]\f[BI]${N}\f[I]\f[R] references.*
.PP
\f[B]-C\f[R]
.PP
\f[B]-L\f[R]
.PP
\f[B]-M\f[R]
.PD 0
.P
.PD
Force \f[B]cp\f[R]*, \f[I]\f[BI]ln\f[I]\f[R] or \f[I]\f[BI]mv\f[I]\f[R],
respectively, regardless of* the name of the function.
.PP
\f[B]-p\f[R]* program*
.PD 0
.P
.PD
Call \f[I]program instead of \f[R]\f[B]cp\f[R]\f[I], \f[R]\f[B]ln\f[R]\f[I]
or\f[R] \f[B]mv\f[R]*.
Whatever it does, it should at least understand the form* \[ga]\f[I]program
\f[R]\f[B]--\f[R]\f[I] oldname newname\[aq]\f[R] where \f[I]oldname and newname
are filenames generated by \f[R]\f[B]zmv\f[R]\f[I].\f[R] \f[I]program will be
split into words, so might be e.g. the name\f[R] of an archive tool plus a copy
or rename subcommand.
.PP
\f[B]-P\f[R]* program*
.PD 0
.P
.PD
As \f[B]-p\f[R]* program, except that* \f[I]program does not accept a following
\f[R]\f[B]--\f[R]\f[I] to indicate the\f[R] end of options.
In this case filenames must already be in a sane form for the program in
question.
.PP
\f[B]-o\f[R]* optstring*
.PD 0
.P
.PD
The \f[I]optstring is split into words and\f[R] passed down verbatim to the
\f[B]cp\f[R]*, \f[I]\f[BI]ln\f[I]\f[R] or \f[I]\f[BI]mv\f[I]\f[R] command called
to* perform the work.
It should probably begin with a \[ga]\f[B]-\f[R]\f[I]\[aq].\f[R]
.PP
Further examples:
.RS
.IP
.nf
\f[C]
zmv -v \[aq](* *)\[aq] \[aq]${1// /_}\[aq]
\f[R]
.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.
.RS
.IP
.nf
\f[C]
zmv -v \[aq]* *\[aq] \[aq]${f// /_}\[aq]
\f[R]
.fi
.RE
.PP
This does exactly the same by referring to the file name stored in
\f[B]$f\f[R]*.*
.PP
For more complete examples and other implementation details, see the
\f[B]zmv\f[R]* source file, usually located in one of the directories named in*
your \f[B]fpath\f[R]*, or in \f[I]\f[BI]Functions/Misc/zmv\f[I]\f[R] in the zsh
distribution.*
.RE
.PP
\f[B]zrecompile\f[R]
.PD 0
.P
.PD
See \[ga]Recompiling Functions\[aq] above.
.PP
\f[B]zstyle+\f[R]* context style value [ \f[I]\f[BI]+\f[I]\f[R] subcontext style
value ...
]*
.PD 0
.P
.PD
This makes defining styles a bit simpler by using a single
\[ga]\f[B]+\f[R]\f[I]\[aq] as a\f[R] special token that allows you to append a
context name to the previously used context name.
Like this:
.RS
.IP
.nf
\f[C]
zstyle+ \[aq]:foo:bar\[aq] style1 value1 \[rs]
+\[aq]:baz\[aq] style2 value2 \[rs]
+\[aq]:frob\[aq] style3 value3
\f[R]
.fi
.RE
.PP
This defines \f[I]style1 with value1 for the context
\f[R]\f[B]:foo:bar\f[R]\f[I] as usual,\f[R] but it also defines \f[I]style2 with
value2 for the context\f[R] \f[B]:foo:bar:baz\f[R]* and style3 with value3 for
\f[I]\f[BI]:foo:bar:frob\f[I]\f[R].
Any* \f[I]subcontext may be the empty string to re-use the first context\f[R]
unchanged.
.SS Styles
.PP
\f[B]insert-tab\f[R] The \f[B]zed\f[R]* function sets this style in context
\[ga]\f[I]\f[BI]:completion:zed:*\f[I]\f[R]\[aq]* to turn off completion when
\f[B]TAB\f[R]* is typed at the beginning of a line.* You may override this by
setting your own value for this context and style.
.PP
\f[B]pager\f[R]
.PD 0
.P
.PD
The \f[B]nslookup\f[R]* function looks up this style in the context*
\[ga]\f[B]:nslookup\f[R]*\[aq] to determine the program used to display output
that does* not fit on a single screen.
.PP
\f[B]prompt\f[R]
.PP
\f[B]rprompt\f[R] The \f[B]nslookup\f[R]* function looks up this style in the
context* \[ga]\f[B]:nslookup\f[R]*\[aq] to set the prompt and the right-side
prompt, respectively.* The usual expansions for the \f[B]PS1\f[R]* and
\f[I]\f[BI]RPS1\f[I]\f[R] parameters may be used* (see EXPANSION OF PROMPT
SEQUENCES in \f[I]zshmisc(1)).\f[R]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment