
\input texinfo.tex
@c %**start of header
@iftex
@afourpaper
@setchapternewpage off
@end iftex
@setfilename zsh.info
@settitle zsh
@c %**end of header

@ifinfo
@set dsq '@:'
@set dsbq `@:`
@end ifinfo
@iftex
@set dsq '{}'
@set dsbq `{}`
@end iftex
@ifinfo
@dircategory Utilities
@direntry
     * ZSH: (zsh).                     The Z Shell Manual.
@end direntry
@end ifinfo

@noindent
@iftex
@finalout
@end iftex
@titlepage
@title The Z Shell Manual
@subtitle Version 4.0.7
@subtitle Updated June 18, 2003
@author Original documentation by Paul Falstad
@page
This is a texinfo version of the documentation for the Z Shell, originally by 
Paul Falstad.

@noindent
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.

@noindent
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided also that the
entire resulting derived work is distributed under the terms of a
permission notice identical to this one.

@noindent
Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions.
@end titlepage
@c Yodl file: Zsh/manual.yo
@ifinfo
@node Top, The Z Shell Manual, (dir), (dir)
@top The Z Shell Manual
This Info file documents Zsh, a freely available UNIX command interpreter
(shell), which of the standard shells most closely resembles the Korn shell
(ksh), although it is not completely compatible.

@noindent
Version 4.0.7, last updated June 18, 2003.
@end ifinfo

@noindent
@menu
* The Z Shell Manual::
* Introduction::
* Invocation::
* Files::
* Shell Grammar::
* Redirection::
* Command Execution::
* Functions::
* Jobs & Signals::
* Arithmetic Evaluation::
* Conditional Expressions::
* Prompt Expansion::
* Expansion::
* Parameters::
* Options::
* Shell Builtin Commands::
* Zsh Line Editor::
* Completion Widgets::
* Completion System::
* Completion Using compctl::
* Zsh Modules::
* Zftp Function System::
* User Contributions::

@noindent
--- Indices ---

@noindent
* Concept Index::
* Variables Index::
* Options Index::
* Functions Index::
* Editor Functions Index::
* Style and Tag Index::

@noindent
--- The Detailed Node Listing ---

@noindent
Introduction

@noindent
* Author::
* Availability::
* Mailing Lists::
* The Zsh FAQ::
* The Zsh Web Page::
* The Zsh Userguide::
* See Also::

@noindent
Invocation

@noindent
* Compatibility::
* Restricted Shell::

@noindent
Shell Grammar

@noindent
* Simple Commands & Pipelines::
* Precommand Modifiers::
* Complex Commands::
* Alternate Forms For Complex Commands::
* Reserved Words::
* Comments::
* Aliasing::
* Quoting::

@noindent
Expansion

@noindent
* History Expansion::
* Process Substitution::
* Parameter Expansion::
* Command Substitution::
* Arithmetic Expansion::
* Brace Expansion::
* Filename Expansion::
* Filename Generation::

@noindent
Parameters

@noindent
* Array Parameters::
* Positional Parameters::
* Local Parameters::
* Parameters Set By The Shell::
* Parameters Used By The Shell::

@noindent
Options

@noindent
* Specifying Options::
* Description of Options::
* Option Aliases::
* Single Letter Options::

@noindent
Zsh Line Editor

@noindent
* Movement::
* History Control::
* Modifying Text::
* Arguments::
* Completion::
* Miscellaneous::

@noindent
Completion Widgets

@noindent
* Special Parameters::
* Builtin Commands::
* Condition Codes::
* Matching Control::
* Completion Widget Example::

@noindent
Completion System

@noindent
* Initialization::
* Completion System Configuration::
* Control Functions::
* Bindable Commands::
* Completion Functions::
* Completion Directories::

@noindent
Completion Using compctl

@noindent
* Command Flags::
* Option Flags::
* Alternative Completion::
* Extended Completion::
* Example::

@noindent
Zsh Modules

@noindent
@c Yodl file: Zsh/manmodmenu.yo
* The zsh/cap Module::
* The zsh/clone Module::
* The zsh/compctl Module::
* The zsh/complete Module::
* The zsh/complist Module::
* The zsh/computil Module::
* The zsh/deltochar Module::
* The zsh/example Module::
* The zsh/files Module::
* The zsh/mapfile Module::
* The zsh/mathfunc Module::
* The zsh/parameter Module::
* The zsh/sched Module::
* The zsh/stat Module::
* The zsh/termcap Module::
* The zsh/terminfo Module::
* The zsh/zftp Module::
* The zsh/zle Module::
* The zsh/zleparameter Module::
* The zsh/zprof Module::
* The zsh/zpty Module::
* The zsh/zutil Module::
@c (avoiding a yodl bug)

@noindent
Zftp Function System

@noindent
* Installation::
* Zftp Functions::
* Miscellaneous Features::

@noindent
User Contributions

@noindent
* Utilities::
* Prompt Themes::
* ZLE Functions::
* Other Functions::

@noindent
@end menu
@node The Z Shell Manual, Introduction, Top, Top

@chapter The Z Shell Manual
@noindent
This document has been produced from the texinfo file @t{zsh.texi},
included in the @t{Doc} sub-directory of the Zsh distribution.

@section Producing documentation from zsh.texi
@noindent
The texinfo source may be converted into several formats:

@noindent
@table @asis
@item The Info manual
The Info format allows searching for topics, commands, functions, etc.
from the many Indices. The command `@t{makeinfo zsh.texi}' is used to
produce the Info documentation.

@item The printed manual
The command `@t{texi2dvi zsh.texi}' will output @t{zsh.dvi} which can
then be processed with @cite{dvips} and optionally @cite{gs} (Ghostscript) to
produce a nicely formatted printed manual.

@item The HTML manual
An HTML version of this manual is available at the Zsh web site via:

@noindent
@t{http://zsh.sunsite.dk/Doc/}.

@noindent
(The HTML version is produced with @cite{texi2html}, which may be obtained
from @t{http://www.mathematik.uni-kl.de/~obachman/Texi2html/}. The command is
`@t{texi2html -split chapter -expand info zsh.texi}'.  If necessary,
upgrade to version 1.64 of texi2html.)

@end table

@noindent
For those who do not have the necessary tools to process texinfo,
precompiled documentation (PostScript, dvi, info and HTML formats)
is available from the zsh archive site or its mirrors, in the file
@t{zsh-doc.tar.gz}. (See @ref{Availability} for a list of sites.)
@c (avoiding a yodl bug)
@c Yodl file: Zsh/intro.yo
@node Introduction, Invocation, The Z Shell Manual, Top

@chapter Introduction
@noindent
Zsh is a UNIX command interpreter (shell) usable as an interactive
login shell and as a shell script command processor.  Of the standard shells,
zsh most closely resembles @cite{ksh} but includes many enhancements.  Zsh
has command line editing, builtin spelling correction, programmable
command completion, shell functions (with autoloading), a history
mechanism, and a host of other features.
@c Yodl file: Zsh/metafaq.yo
@menu
* Author::
* Availability::
* Mailing Lists::
* The Zsh FAQ::
* The Zsh Web Page::
* The Zsh Userguide::
* See Also::
@end menu
@node Author, Availability, , Introduction

@section Author
@noindent
@cindex author
Zsh was originally written by Paul Falstad @t{<pf@@zsh.org>}.
Zsh is now maintained by the members of the zsh-workers mailing
list @t{<zsh-workers@@sunsite.dk>}.  The development is currently
coordinated by Peter Stephenson @t{<pws@@zsh.org>}.  The coordinator
can be contacted at @t{<coordinator@@zsh.org>}, but matters relating to
the code should generally go to the mailing list.
@node Availability, Mailing Lists, Author, Introduction

@section Availability
@noindent
Zsh is available from the following anonymous FTP sites.  These mirror
sites are kept frequently up to date.  The sites marked with @emph{(H)} may be
mirroring @t{ftp.cs.elte.hu} instead of the primary site.

@noindent
@cindex FTP sites for zsh
@cindex acquiring zsh by FTP
@cindex availability of zsh
@table @asis
@item Primary site
@t{ftp://ftp.zsh.org/pub/zsh/}@*
@t{http://www.zsh.org/pub/zsh/}

@item Australia
@t{ftp://ftp.zsh.org/pub/zsh/}@*
@t{http://www.zsh.org/pub/zsh/}@*
@t{ftp://ftp.ips.gov.au/pub/packages/zsh/}  @emph{(H)}

@item Denmark
@t{ftp://sunsite.dk/pub/unix/shells/zsh/}

@item Finland
@t{ftp://ftp.funet.fi/pub/unix/shells/zsh/}

@item France
@t{ftp://ftp.cenatls.cena.dgac.fr/shells/zsh/}

@item Germany
@t{ftp://ftp.fu-berlin.de/pub/unix/shells/zsh/}  @emph{(H)}@*
@t{ftp://ftp.gmd.de/packages/zsh/}@*
@t{ftp://ftp.uni-trier.de/pub/unix/shell/zsh/}

@item Hungary
@t{ftp://ftp.cs.elte.hu/pub/zsh/}@*
@t{http://www.cs.elte.hu/pub/zsh/}@*
@t{ftp://ftp.kfki.hu/pub/packages/zsh/}

@item Israel
@t{ftp://ftp.math.technion.ac.il/pub/zsh/}@*
@t{http://www.math.technion.ac.il/pub/zsh/}

@item Italy
@t{ftp://ftp.unina.it/pub/Unix/pkgs/shell/zsh/}

@item Japan
@t{ftp://ftp.nisiq.net/pub/shells/zsh/}  @emph{(H)}@*
@t{ftp://ftp.win.ne.jp/pub/shell/zsh/}

@item Norway
@t{ftp://ftp.uit.no/pub/unix/shells/zsh/}

@item Poland
@t{ftp://sunsite.icm.edu.pl/pub/unix/shells/zsh/}

@item Romania
@t{ftp://ftp.roedu.net/pub/mirrors/ftp.zsh.org/pub/zsh/}@*
@t{ftp://ftp.kappa.ro/pub/mirrors/ftp.zsh.org/pub/zsh/}

@item Slovenia
@t{ftp://ftp.siol.net/mirrors/zsh/}

@item Sweden
@t{ftp://ftp.lysator.liu.se/pub/unix/zsh/}

@item UK
@t{ftp://ftp.net.lut.ac.uk/zsh/}@*
@t{ftp://sunsite.org.uk/packages/zsh/}

@item USA
@t{ftp://uiarchive.uiuc.edu/pub/packages/shells/zsh/}@*
@t{ftp://ftp.rge.com/pub/shells/zsh/}@*
@t{ftp://foad.org/pub/zsh/}@*
@t{http://foad.org/zsh/}

@end table
@node Mailing Lists, The Zsh FAQ, Availability, Introduction

@section Mailing Lists
@noindent
@cindex mailing lists
Zsh has 3 mailing lists:

@noindent
@table @asis
@item @t{<zsh-announce@@sunsite.dk>}
Announcements about releases, major changes in the shell and the
monthly posting of the Zsh FAQ.  (moderated)

@item @t{<zsh-users@@sunsite.dk>}
User discussions.

@item @t{<zsh-workers@@sunsite.dk>}
Hacking, development, bug reports and patches.

@end table

@noindent
To subscribe or unsubscribe, send mail
to the associated administrative address for the mailing list.

@noindent
@table @asis
@item @t{<zsh-announce-subscribe@@sunsite.dk>}
@item @t{<zsh-users-subscribe@@sunsite.dk>}
@item @t{<zsh-workers-subscribe@@sunsite.dk>}

@noindent
@item @t{<zsh-announce-unsubscribe@@sunsite.dk>}
@item @t{<zsh-users-unsubscribe@@sunsite.dk>}
@item @t{<zsh-workers-unsubscribe@@sunsite.dk>}
@item
@end table

@noindent
YOU ONLY NEED TO JOIN ONE OF THE MAILING LISTS AS THEY ARE NESTED.
All submissions to @cite{zsh-announce} are automatically forwarded to
@cite{zsh-users}.  All submissions to @cite{zsh-users} are automatically
forwarded to @cite{zsh-workers}.

@noindent
If you have problems subscribing/unsubscribing to any of the mailing
lists, send mail to @t{<listmaster@@zsh.org>}.  The mailing lists are
maintained by Karsten Thygesen @t{<karthy@@kom.auc.dk>}.

@noindent
The mailing lists are archived; the archives can be accessed via the
administrative addresses listed above.  There is also a hypertext
archive, maintained by Geoff Wing @t{<gcw@@zsh.org>}, available at
@t{http://www.zsh.org/mla/}.
@node The Zsh FAQ, The Zsh Web Page, Mailing Lists, Introduction

@section The Zsh FAQ
@noindent
Zsh has a list of Frequently Asked Questions (FAQ), maintained by
Peter Stephenson @t{<pws@@zsh.org>}.  It is regularly posted to the
newsgroup @cite{comp.unix.shell} and the @cite{zsh-announce} mailing list.
The latest version can be found at any of the Zsh FTP sites, or at
@t{http://www.zsh.org/FAQ/}.  The contact address for FAQ-related matters
is @t{<faqmaster@@zsh.org>}.
@node The Zsh Web Page, The Zsh Userguide, The Zsh FAQ, Introduction

@section The Zsh Web Page
@noindent
Zsh has a web page which is located at @t{http://www.zsh.org/}.  This is
maintained by Karsten Thygesen @t{<karthy@@zsh.org>}, of SunSITE Denmark.
The contact address for web-related matters is @t{<webmaster@@zsh.org>}.
@node The Zsh Userguide, See Also, The Zsh Web Page, Introduction

@section The Zsh Userguide
@noindent
A userguide is currently in preparation.  It is intended to complement the
manual, with explanations and hints on issues where the manual can be
cabbalistic, hierographic, or downright mystifying (for example, the word
`hierographic' does not exist).  It can be viewed in its current state at
@t{http://zsh.sunsite.dk/Guide/}.  At the time of writing, chapters
dealing with startup files and their contents and the new completion system
were essentially complete.
@c (avoiding a yodl bug)
@c Yodl file: Zsh/seealso.yo
@node See Also, , The Zsh Userguide, Introduction

@section See Also
@noindent
man page sh(1),
man page csh(1),
man page tcsh(1),
man page rc(1),
man page bash(1),
man page ksh(1)

@noindent
@cite{IEEE Standard for information Technology -
Portable Operating System Interface (POSIX) -
Part 2: Shell and Utilities},
IEEE Inc, 1993, ISBN 1-55937-255-9.
@c (avoiding a yodl bug)
@c (avoiding a yodl bug)
@c Yodl file: Zsh/invoke.yo
@node Invocation, Files, Introduction, Top

@chapter Invocation
@noindent
@cindex invocation

@section Invocation Options
@noindent
@cindex flags, shell
@cindex shell flags
The following flags are interpreted by the shell when invoked to determine
where the shell will read commands from:

@noindent
@table @asis
@item @t{-c}
Take the first argument as a command to execute, rather than reading commands
from a script or standard input.  If any further arguments are given, the
first one is assigned to @t{$0}, rather than being used as a positional
parameter.

@item @t{-i}
Force shell to be interactive.

@item @t{-s}
Force shell to read commands from the standard input.
If the @t{-s} flag is not present and an argument is given,
the first argument is taken to be the pathname of a script to
execute.

@end table

@noindent
After the first one or two arguments have been appropriated as described above,
the remaining arguments are assigned to the positional parameters.

@noindent
For further options, which are common to invocation and the @t{set}
builtin, see
@ref{Options}.

@noindent
Options may be specified by name using the @t{-o} option.  @t{-o} acts like
a single-letter option, but takes a following string as the option name.
For example,

@noindent
@example
zsh -x -o shwordsplit scr
@end example

@noindent
runs the script @t{scr}, setting the @t{XTRACE} option by the corresponding
letter `@t{-x}' and the @t{SH_WORD_SPLIT} option by name.
Options may be turned @emph{off} by name by using @t{+o} instead of @t{-o}.
@t{-o} can be stacked up with preceding single-letter options, so for example
`@t{-xo shwordsplit}' or `@t{-xoshwordsplit}' is equivalent to
`@t{-x -o shwordsplit}'.

@noindent
Options may also be specified by name in GNU long option style,
`@t{--}@var{option-name}'.  When this is done, `@t{-}' characters in the
option name are permitted: they are translated into `@t{_}', and thus ignored.
So, for example, `@t{zsh --sh-word-split}' invokes zsh with the
@t{SH_WORD_SPLIT} option turned on.  Like other option syntaxes, options can
be turned off by replacing the initial `@t{-}' with a `@t{+}'; thus
`@t{+-sh-word-split}' is equivalent to `@t{--no-sh-word-split}'.
Unlike other option syntaxes, GNU-style long options cannot be stacked with
any other options, so for example `@t{-x-shwordsplit}' is an error,
rather than being treated like `@t{-x --shwordsplit}'.

@noindent
The special GNU-style option `@t{--version}' is handled; it sends to standard
output the shell's version information, then exits successfully.
`@t{--help}' is also handled; it sends to standard output a list of options
that can be used when invoking the shell, then exits successfully.

@noindent
Option processing may be finished, allowing following arguments that start with
`@t{-}' or `@t{+}' to be treated as normal arguments, in two ways.
Firstly, a lone `@t{-}' (or `@t{+}') as an argument by itself ends option
processing.  Secondly, a special option `@t{--}' (or `@t{+-}'), which may
be specified on its own (which is the standard POSIX usage) or may be stacked
with preceding options (so `@t{-x-}' is equivalent to `@t{-x --}').  Options
are not permitted to be stacked after `@t{--}' (so `@t{-x-f}' is an error),
but note the GNU-style option form discussed above, where `@t{--shwordsplit}'
is permitted and does not end option processing.

@noindent
Except when the @cite{sh}/@cite{ksh} emulation single-letter options are in effect,
the option `@t{-b}' (or `@t{+b}') ends option processing.
`@t{-b}' is like `@t{--}', except that further single-letter options can be
stacked after the `@t{-b}' and will take effect as normal.

@noindent
@menu
* Compatibility::
* Restricted Shell::
@end menu

@noindent
@c Yodl file: Zsh/compat.yo
@node Compatibility, Restricted Shell, , Invocation

@section Compatibility
@noindent
@cindex compatibility
@cindex sh, compatibility
@cindex ksh, compatibility
Zsh tries to emulate @cite{sh} or @cite{ksh} when it is invoked as
@t{sh} or @t{ksh} respectively; more precisely, it looks at the first
letter of the name by which it was invoked, excluding any initial `@t{r}'
(assumed to stand for `restricted'), and if that is `@t{s}' or `@t{k}' it
will emulate @cite{sh} or @cite{ksh}.  Furthermore, if invoked as @t{su} (which
happens on certain systems when the shell is executed by the @t{su}
command), the shell will try to find an alternative name from the @t{SHELL}
environment variable and perform emulation based on that.

@noindent
In @cite{sh} and @cite{ksh} compatibility modes the following
parameters are not special and not initialized by the shell:
@t{ARGC},
@t{argv},
@t{cdpath},
@t{fignore},
@t{fpath},
@t{HISTCHARS},
@t{mailpath},
@t{MANPATH},
@t{manpath},
@t{path},
@t{prompt},
@t{PROMPT},
@t{PROMPT2},
@t{PROMPT3},
@t{PROMPT4},
@t{psvar},
@t{status},
@t{watch}.

@noindent
The usual zsh startup/shutdown scripts are not executed.  Login shells
source @t{/etc/profile} followed by @t{$HOME/.profile}.  If the
@t{ENV} environment variable is set on invocation, @t{$ENV} is sourced
after the profile scripts.  The value of @t{ENV} is subjected to
parameter expansion, command substitution, and arithmetic expansion
before being interpreted as a pathname.  Note that the @t{PRIVILEGED}
option also affects the execution of startup files.

@noindent
The following options are set if the shell is invoked as @t{sh} or
@t{ksh}:
@t{NO_BAD_PATTERN},
@t{NO_BANG_HIST},
@t{NO_BG_NICE},
@t{NO_EQUALS},
@t{NO_FUNCTION_ARGZERO},
@t{GLOB_SUBST},
@t{NO_GLOBAL_EXPORT},
@t{NO_HUP},
@t{INTERACTIVE_COMMENTS},
@t{KSH_ARRAYS},
@t{NO_MULTIOS},
@t{NO_NOMATCH},
@t{NO_NOTIFY},
@t{POSIX_BUILTINS},
@t{NO_PROMPT_PERCENT},
@t{RM_STAR_SILENT},
@t{SH_FILE_EXPANSION},
@t{SH_GLOB},
@t{SH_OPTION_LETTERS},
@t{SH_WORD_SPLIT}.
Additionally the @t{BSD_ECHO} and @t{IGNORE_BRACES}
options are set if zsh is invoked as @t{sh}.
Also, the
@t{KSH_OPTION_PRINT},
@t{LOCAL_OPTIONS},
@t{PROMPT_BANG},
@t{PROMPT_SUBST}
and
@t{SINGLE_LINE_ZLE}
options are set if zsh is invoked as @t{ksh}.
@c (avoiding a yodl bug)
@c Yodl file: Zsh/restricted.yo
@node Restricted Shell, , Compatibility, Invocation

@section Restricted Shell
@noindent
@cindex restricted shell
@pindex RESTRICTED
When the basename of the command used to invoke zsh starts with the letter
`@t{r}' or the `@t{-r}' command line option is supplied at invocation, the
shell becomes restricted.  Emulation mode is determined after stripping the
letter `@t{r}' from the invocation name.  The following are disabled in
restricted mode:

@noindent
@itemize @bullet

@noindent
@item 
changing directories with the @t{cd} builtin
@item 
changing or unsetting the @t{PATH}, @t{path}, @t{MODULE_PATH},
@t{module_path}, @t{SHELL}, @t{HISTFILE}, @t{HISTSIZE}, @t{GID}, @t{EGID},
@t{UID}, @t{EUID}, @t{USERNAME}, @t{LD_LIBRARY_PATH},
@t{LD_AOUT_LIBRARY_PATH}, @t{LD_PRELOAD} and  @t{LD_AOUT_PRELOAD}
parameters
@item 
specifying command names containing @t{/}
@item 
specifying command pathnames using @t{hash}
@item 
redirecting output to files
@item 
using the @t{exec} builtin command to replace the shell with another
command
@item 
using @t{jobs -Z} to overwrite the shell process' argument and
environment space
@item 
using the @t{ARGV0} parameter to override @t{argv[0]} for external
commands
@item 
turning off restricted mode with @t{set +r} or @t{unsetopt
RESTRICTED}
@end itemize

@noindent
These restrictions are enforced after processing the startup files.  The
startup files should set up @t{PATH} to point to a directory of commands
which can be safely invoked in the restricted environment.  They may also
add further restrictions by disabling selected builtins.

@noindent
Restricted mode can also be activated any time by setting the
@t{RESTRICTED} option.  This immediately enables all the restrictions
described above even if the shell still has not processed all startup
files.
@c (avoiding a yodl bug)
@c (avoiding a yodl bug)
@c Yodl file: Zsh/files.yo
@node Files, Shell Grammar, Invocation, Top

@chapter Files
@noindent

@section Startup/Shutdown Files
@noindent
@cindex files, startup
@cindex startup files
@cindex files, shutdown
@cindex shutdown files
@pindex NO_RCS, use of
@pindex NO_GLOBAL_RCS, use of
Commands are first read from @t{/etc/zshenv}; this cannot be overridden.
Subsequent behaviour is modified by the @t{RCS} and
@t{GLOBAL_RCS} options; the former affects all startup files, while the
second only affects those in the @t{/etc} directory.  If one of the options
is unset at any point, any subsequent startup file(s) of the corresponding
type will not be read.  It is also possible for a file in @t{$ZDOTDIR} to
re-enable @t{GLOBAL_RCS}. Both @t{RCS} and @t{GLOBAL_RCS} are set by
default.

@noindent
Commands are then read from @t{$ZDOTDIR/.zshenv}.
@pindex LOGIN, use of
If the shell is a login shell, commands
are read from @t{/etc/zprofile} and then @t{$ZDOTDIR/.zprofile}.
Then, if the shell is interactive,
commands are read from @t{/etc/zshrc} and then @t{$ZDOTDIR/.zshrc}.
Finally, if the shell is a login shell, @t{/etc/zlogin} and
@t{$ZDOTDIR/.zlogin} are read.

@noindent
When a login shell exits, the files @t{$ZDOTDIR/.zlogout} and then
@t{/etc/zlogout} are read.  This happens with either an explicit exit
via the @t{exit} or @t{logout} commands, or an implicit exit by reading
end-of-file from the terminal.  However, if the shell terminates due
to @t{exec}'ing another process, the logout files are not read.
These are also affected by the @t{RCS} and @t{GLOBAL_RCS} options.
Note also that the @t{RCS} option affects the saving of history files,
i.e. if @t{RCS} is unset when the shell exits, no history file will be
saved.

@noindent
If @t{ZDOTDIR} is unset, @t{HOME} is used instead.
Those files listed above as being in @t{/etc} may be in another
directory, depending on the installation.

@noindent
As @t{/etc/zshenv} is run for all instances of zsh, it is important that
it be kept as small as possible.  In particular, it is a good idea to
put code that does not need to be run for every single shell behind
a test of the form `@t{if [[ -o rcs ]]; then ...}' so that it will not
be executed when zsh is invoked with the `@t{-f}' option.
@c Yodl file: Zsh/filelist.yo

@section Files
@noindent
@cindex files used
@table @asis
@item @t{$ZDOTDIR/.zshenv}
@item @t{$ZDOTDIR/.zprofile}
@item @t{$ZDOTDIR/.zshrc}
@item @t{$ZDOTDIR/.zlogin}
@item @t{$ZDOTDIR/.zlogout}
@item @t{$@{TMPPREFIX@}*}   (default is /tmp/zsh*)
@item @t{/etc/zshenv}
@item @t{/etc/zprofile}
@item @t{/etc/zshrc}
@item @t{/etc/zlogin}
@item @t{/etc/zlogout}    (installation-specific - @t{/etc} is the default)
@item
@end table
@c (avoiding a yodl bug)

@noindent
Any of these files may be pre-compiled with the @t{zcompile} builtin
command (@ref{Shell Builtin Commands}).  If a compiled file exists (named for the original file plus the
@t{.zwc} extension) and it is newer than the original file, the compiled
file will be used instead.
@c (avoiding a yodl bug)
@c Yodl file: Zsh/grammar.yo
@node Shell Grammar, Redirection, Files, Top

@chapter Shell Grammar
@noindent
@cindex shell grammar
@cindex grammar, shell
@menu
* Simple Commands & Pipelines::
* Precommand Modifiers::
* Complex Commands::
* Alternate Forms For Complex Commands::
* Reserved Words::
* Comments::
* Aliasing::
* Quoting::
@end menu
@node Simple Commands & Pipelines, Precommand Modifiers, , Shell Grammar

@section Simple Commands & Pipelines
@noindent
@cindex simple commands
@cindex commands, simple
A @emph{simple command} is a sequence of optional parameter
assignments followed by blank-separated words,
with optional redirections interspersed.
The first word is the command to be executed, and the remaining
words, if any, are arguments to the command.
If a command name is given, the parameter assignments modify
the environment of the command when it is executed.
The value of a simple command is its exit status,
or 128 plus the signal number if terminated by a signal.
For example,

@noindent
@example
echo foo
@end example

@noindent
is a simple command with arguments.

@noindent
@cindex pipeline
A @emph{pipeline} is either a simple command, or a sequence of two or more
simple commands where each command is separated from the next by `@t{|}'
or `@t{|&}'.  Where commands are separated by `@t{|}', the standard
output of the first command is connected to the
standard input of the next.  `@t{|&}' is shorthand for `@t{2>&1 |}', which
connects both the standard output and the standard error of the
command to the standard input of the next.  The value of a pipeline
is the value of the last command, unless the pipeline is preceded by
`@t{!}' in which case the value is the logical inverse of the value of the
last command.
For example,

@noindent
@example
echo foo | sed 's/foo/bar/'
@end example

@noindent
is a pipeline, where the output (`@t{foo}' plus a newline) of the first
command will be passed to the input of the second.

@noindent
@findex coproc
@cindex coprocess
If a pipeline is preceded by `@t{coproc}', it is executed as a coprocess;
a two-way pipe is established between it and the parent shell.  The
shell can read from or write to the coprocess by means of the `@t{>&p}'
and `@t{<&p}' redirection operators or with `@t{print -p}' and `@t{read -p}'.
A pipeline cannot be preceded by both `@t{coproc}' and `@t{!}'.
If job control is active, the coprocess can be treated in other than input
and output as an ordinary background job.

@noindent
@cindex sublist
A @emph{sublist} is either a single pipeline, or a sequence of two or more
pipelines separated by `@t{&&}' or `@t{||}'.  If two pipelines are separated
by `@t{&&}', the second pipeline is executed only if the first succeeds
(returns a zero value).  If two pipelines are separated by `@t{||}', the
second is executed only if the first fails (returns a nonzero value).
Both operators have equal precedence and are left associative.
The value of the sublist is the value of the last pipeline executed.
For example,

@noindent
@example
dmesg | grep panic && print yes
@end example

@noindent
is a sublist consisting of two pipelines, the second just a simple command
which will be executed if and only if the @t{grep} command returns a zero
value.  If it does not, the value of the sublist is that return value, else
it is the value returned by the @t{print} (almost certainly zero).

@noindent
@cindex list
A @emph{list} is a sequence of zero or more sublists, in which each sublist
is terminated by `@t{;}', `@t{&}', `@t{&|}', `@t{&!}', or a newline.
This terminator
may optionally be omitted from the last sublist in the list when the
list appears as a complex command inside `@t{(}...@t{)}'
or `@t{@{}...@t{@}}'.  When a
sublist is terminated by `@t{;}' or newline, the shell waits for it to
finish before executing the next sublist.  If a sublist is terminated
by a `@t{&}', `@t{&|}', or `@t{&!}',
the shell executes the last pipeline in it in the background, and
does not wait for it to finish (note the difference from other shells
which execute the whole sublist in the background).
A backgrounded pipeline returns a status of zero.

@noindent
More generally, a list can be seen as a set of any shell commands
whatsoever, including the complex commands below; this is implied wherever
the word `list' appears in later descriptions.  For example, the commands
in a shell function form a special sort of list.
@node Precommand Modifiers, Complex Commands, Simple Commands & Pipelines, Shell Grammar

@section Precommand Modifiers
@noindent
@cindex precommand modifiers
@cindex modifiers, precommand
A simple command may be preceded by a @emph{precommand modifier},
which will alter how the command is interpreted.  These modifiers are
shell builtin commands with the exception of @t{nocorrect} which is
a reserved word.

@noindent
@table @asis
@item @t{-}
The command is executed with a `@t{-}' prepended to its
@t{argv[0]} string.

@item @t{noglob}
Filename generation (globbing) is not performed on any of
the words.

@item @t{nocorrect}
Spelling correction is not done on any of the words.  This must appear
before any other precommand modifier, as it is interpreted immediately,
before any parsing is done.  It has no effect in non-interactive shells.

@item @t{exec}
The command is executed in the parent shell without forking.

@item @t{command}
The command word is taken to be the name of an external command,
rather than a shell function or builtin.

@item @t{builtin}
The command word is taken to be the name of a builtin command,
rather than a shell function or external command.

@end table
@node Complex Commands, Alternate Forms For Complex Commands, Precommand Modifiers, Shell Grammar

@section Complex Commands
@noindent
@cindex complex commands
@cindex commands, complex
A @emph{complex command} in zsh is one of the following:

@noindent
@table @asis
@findex if
@cindex if construct
@item @t{if} @var{list} @t{then} @var{list} [ @t{elif} @var{list} @t{then} @var{list} ] ... [ @t{else} @var{list} ] @t{fi}
The @t{if} @var{list} is executed, and if it returns a zero exit status,
the @t{then} @var{list} is executed.
Otherwise, the @t{elif} @var{list} is executed and if its value is zero,
the @t{then} @var{list} is executed.
If each @t{elif} @var{list} returns nonzero, the @t{else} @var{list} is executed.

@findex for
@cindex for loops
@cindex loops, for
@item @t{for} @var{name} [ @t{in} @var{word} ... @var{term} ] @t{do} @var{list} @t{done}
where @var{term} is at least one newline or @t{;}.
Expand the list of @var{word}s, and set the parameter
@var{name} to each of them in turn, executing
@var{list} each time.  If the @t{in} @var{word} is omitted,
use the positional parameters instead of the @var{word}s.

@item @t{for ((} [@var{expr1}] @t{;} [@var{expr2}] @t{;} [@var{expr3}] @t{)) do} @var{list} @t{done}
The arithmetic expression @var{expr1} is evaluated first (see
@ref{Arithmetic Evaluation}).  The arithmetic expression
@var{expr2} is repeatedly evaluated until it evaluates to zero and
when non-zero, @var{list} is executed and the arithmetic expression
@var{expr3} evaluated.  If any expression is omitted, then it behaves
as if it evaluated to 1.

@findex while
@cindex while loops
@cindex loops, while
@item @t{while} @var{list} @t{do} @var{list} @t{done}
Execute the @t{do} @var{list} as long as the @t{while} @var{list}
returns a zero exit status.

@findex until
@cindex until loops
@cindex loops, until
@item @t{until} @var{list} @t{do} @var{list} @t{done}
Execute the @t{do} @var{list} as long as @t{until} @var{list}
returns a nonzero exit status.

@findex repeat
@cindex repeat loops
@cindex loops, repeat
@item @t{repeat} @var{word} @t{do} @var{list} @t{done}
@var{word} is expanded and treated as an arithmetic expression,
which must evaluate to a number @var{n}.
@var{list} is then executed @var{n} times.

@findex case
@cindex case selection
@cindex selection, case
@item @t{case} @var{word} @t{in} [ [@t{(}] @var{pattern} [ @t{|} @var{pattern} ] ... @t{)} @var{list} (@t{;;}|@t{;&}) ] ... @t{esac}
Execute the @var{list} associated with the first @var{pattern}
that matches @var{word}, if any.  The form of the patterns
is the same as that used for filename generation.  See
@ref{Filename Generation}.
If the @var{list} that is executed is terminated with @t{;&} rather than
@t{;;}, the following list is also executed.  This continues until either
a list is terminated with @t{;;} or the @t{esac} is reached.

@findex select
@cindex user selection
@cindex selection, user
@item @t{select} @var{name} [ @t{in} @var{word} ... @var{term} ] @t{do} @var{list} @t{done}
where @var{term} is one or more newline or @t{;} to terminate the @var{word}s.
@vindex REPLY, use of
Print the set of @var{word}s, each preceded by a number.
If the @t{in} @var{word} is omitted, use the positional parameters.
The @t{PROMPT3} prompt is printed and a line is read from the line editor
if the shell is interactive and that is active, or else standard input.
If this line consists of the
number of one of the listed @var{word}s, then the parameter @var{name}
is set to the @var{word} corresponding to this number.
If this line is empty, the selection list is printed again.
Otherwise, the value of the parameter @var{name} is set to null.
The contents of the line read from standard input is saved
in the parameter @t{REPLY}.  @var{list} is executed
for each selection until a break or end-of-file is encountered.

@cindex subshells
@item @t{(} @var{list} @t{)}
Execute @var{list} in a subshell.  Traps set by the @t{trap} builtin
are reset to their default values while executing @var{list}.

@item @t{@{} @var{list} @t{@}}
Execute @var{list}.

@item @t{function} @var{word} ... [ @t{()} ] [ @var{term} ] @t{@{} @var{list} @t{@}}
@itemx @var{word} ... @t{()} [ @var{term} ] @t{@{} @var{list} @t{@}}
@itemx @var{word} ... @t{()} [ @var{term} ] @var{command}
where @var{term} is one or more newline or @t{;}.
Define a function which is referenced by any one of @var{word}.
Normally, only one @var{word} is provided; multiple @var{word}s
are usually only useful for setting traps.
The body of the function is the @var{list} between
the @t{@{} and @t{@}}.  See @ref{Functions}.

@noindent
If the option @t{SH_GLOB} is set for compatibility with other shells, then
whitespace may appear between between the left and right parentheses when
there is a single @var{word};  otherwise, the parentheses will be treated as
forming a globbing pattern in that case.

@cindex timing
@item @t{time} [ @var{pipeline} ]
The @var{pipeline} is executed, and timing statistics are
reported on the standard error in the form specified
by the @t{TIMEFMT} parameter.
If @var{pipeline} is omitted, print statistics about the
shell process and its children.

@cindex testing conditional expression
@item @t{[[} @var{exp} @t{]]}
Evaluates the conditional expression @var{exp}
and return a zero exit status if it is true.
See @ref{Conditional Expressions}
for a description of @var{exp}.

@end table
@node Alternate Forms For Complex Commands, Reserved Words, Complex Commands, Shell Grammar

@section Alternate Forms For Complex Commands
@noindent
@cindex alternate forms for complex commands
@cindex commands, alternate forms for complex
Many of zsh's complex commands have alternate forms.  These particular
versions of complex commands should be considered deprecated and may be
removed in the future.  The versions in the previous section should be
preferred instead.

@noindent
The short versions below only work if @var{sublist} is of the form `@t{@{}
@var{list} @t{@}}' or if the @t{SHORT_LOOPS} option is set.  For the @t{if},
@t{while} and @t{until} commands, in both these cases the test part of the
loop must also be suitably delimited, such as by `@t{[[ ... ]]}' or `@t{((
... ))}', else the end of the test will not be recognized.  For the
@t{for}, @t{repeat}, @t{case} and @t{select} commands no such special form
for the arguments is necessary, but the other condition (the special form
of @var{sublist} or use of the @t{SHORT_LOOPS} option) still applies.

@noindent
@table @asis
@item @t{if} @var{list} @t{@{} @var{list} @t{@}} [ @t{elif} @var{list} @t{@{} @var{list} @t{@}} ] ... [ @t{else @{} @var{list} @t{@}} ]
An alternate form of @t{if}.  The rules mean that

@noindent
@example
if [[ -o ignorebraces ]] @{
  print yes
@}
@end example

@noindent
works, but

@noindent
@example
if true @{  # Does not work!
  print yes
@}

@end example

@noindent
does @emph{not}, since the test is not suitably delimited.

@item @t{if} @var{list} @var{sublist}
A short form of the alternate `if'.  The same limitations on the form of
@var{list} apply as for the previous form.

@item @t{for} @var{name} @t{(} @var{word} ... @t{)} @var{sublist}
A short form of @t{for}.

@item @t{for} @var{name} [ @t{in} @var{word} ... @var{term} ] @var{sublist}
where @var{term} is at least one newline or @t{;}.
Another short form of @t{for}.

@item @t{for ((} [@var{expr1}] @t{;} [@var{expr2}] @t{;} [@var{expr3}] @t{))} @var{sublist}
A short form of the arithmetic @t{for} command.

@item @t{foreach} @var{name} @t{(} @var{word} ... @t{)} @var{list} @t{end}
Another form of @t{for}.

@item @t{while} @var{list} @t{@{} @var{list} @t{@}}
An alternative form of @t{while}.  Note the limitations on the form of
@var{list} mentioned above.

@item @t{until} @var{list} @t{@{} @var{list} @t{@}}
An alternative form of @t{until}.  Note the limitations on the form of
@var{list} mentioned above.

@item @t{repeat} @var{word} @var{sublist}
This is a short form of @t{repeat}.

@item @t{case} @var{word} @t{@{} [ [@t{(}] @var{pattern} [ @t{|} @var{pattern} ] ... @t{)} @var{list} (@t{;;}|@t{;&}) ] ... @t{@}}
An alternative form of @t{case}.

@item @t{select} @var{name} [ @t{in} @var{word} @var{term} ] @var{sublist}
where @var{term} is at least one newline or @t{;}.
A short form of @t{select}.

@end table
@node Reserved Words, Comments, Alternate Forms For Complex Commands, Shell Grammar

@section Reserved Words
@noindent
@cindex reserved words
@findex disable, use of
The following words are recognized as reserved words when used as the first
word of a command unless quoted or disabled using @t{disable -r}:

@noindent
@t{do done esac then elif else fi for case
if while function repeat time until
select coproc nocorrect foreach end ! [[ @{ @}}

@noindent
Additionally, `@t{@}}' is recognized in any position if the @t{IGNORE_BRACES} option
is not set.
@node Comments, Aliasing, Reserved Words, Shell Grammar

@section Comments
@noindent
@cindex comments
@pindex INTERACTIVE_COMMENTS, use of
@vindex histchars, use of
In noninteractive shells, or in interactive shells with the
@t{INTERACTIVE_COMMENTS} option set, a word beginning
with the third character of the @t{histchars} parameter
(`@t{#}' by default) causes that word and all the following
characters up to a newline to be ignored.
@node Aliasing, Quoting, Comments, Shell Grammar

@section Aliasing
@noindent
@cindex aliasing
Every token in the shell input is checked to see if there
is an alias defined for it.
If so, it is replaced by the text of the alias if it is in command
position (if it could be the first word of a simple command),
or if the alias is global.
If the text ends with a space, the next word in the shell input
is treated as though it were in command position for purposes of alias
expansion.
@findex alias, use of
@cindex aliases, global
An alias is defined using the @t{alias} builtin; global aliases
may be defined using the @t{-g} option to that builtin.

@noindent
Alias expansion is done on the shell input before any
other expansion except history expansion.  Therefore,
if an alias is defined for the word @t{foo}, alias expansion
may be avoided by quoting part of the word, e.g. @t{\foo}.
But there is nothing to prevent an alias being defined
for @t{\foo} as well.
@node Quoting, , Aliasing, Shell Grammar

@section Quoting
@noindent
@cindex quoting
A character may be @var{quoted} (that is, made
to stand for itself) by preceding it with a `@t{\}'.
`@t{\}' followed by a newline is ignored.

@noindent
A string enclosed between `@t{$'}' and `@t{'}' is
processed the same way as the string arguments of the
@t{print} builtin, and the resulting string is considered to be
entirely quoted.  A literal `@t{'}' character can be included in the
string by using the `@t{\'}' escape.

@noindent
All characters enclosed between a pair of single quotes (@t{@value{dsq}}) that
is not preceded by a `@t{$}' are quoted.  A single quote cannot appear
within single quotes unless the option @t{RC_QUOTES} is set, in which case
a pair of single quotes are turned into a single quote.  For example,

@noindent
@example
print @value{dsq}@value{dsq}
@end example

@noindent
outputs nothing apart from a newline if @t{RC_QUOTES} is not set, but one
single quote if it is set.

@noindent
Inside double quotes (@t{""}), parameter and
command substitution occur, and `@t{\}' quotes the characters
`@t{\}', `@t{`}', `@t{"}', and `@t{$}'.
@c (avoiding a yodl bug)
@c Yodl file: Zsh/redirect.yo
@node Redirection, Command Execution, Shell Grammar, Top

@chapter Redirection
@noindent
@cindex redirection
@cindex file descriptors
@cindex descriptors, file
If a command is followed by @t{&}
and job control is not active,
then the default standard input
for the command is the empty file @t{/dev/null}.
Otherwise, the environment for the execution of a command contains the
file descriptors of the invoking shell as modified by
input/output specifications.

@noindent
The following may appear anywhere in a simple command
or may precede or follow a complex command.
Expansion occurs before @var{word} or @var{digit}
is used except as noted below.
If the result of substitution on @var{word}
produces more than one filename,
redirection occurs for each
separate filename in turn.

@noindent
@table @asis
@item @t{<} @var{word}
Open file @var{word} for reading as standard input.

@item @t{<>} @var{word}
Open file @var{word} for reading and writing as standard input.
If the file does not exist then it is created.

@item @t{>} @var{word}
Open file @var{word} for writing as standard output.
If the file does not exist then it is created.
If the file exists, and the @t{CLOBBER} option is unset,
this causes an error;
otherwise, it is truncated to zero length.

@item @t{>|} @var{word}
@itemx @t{>!} @var{word}
Same as @t{>}, except that the file is truncated to zero length
if it exists, even if @t{CLOBBER} is unset.

@item @t{>>} @var{word}
Open file @var{word} for writing in append mode as standard output.
If the file does not exist, and the @t{CLOBBER}
option is unset, this causes an error;
otherwise, the file is created.

@item @t{>>|} @var{word}
@itemx @t{>>!} @var{word}
Same as @t{>>}, except that the file is created if it does not
exist, even if @t{CLOBBER} is unset.

@item @t{<<}[@t{-}] @var{word}
The shell input is read up to a line that is the same as
@var{word}, or to an end-of-file.
No parameter expansion, command substitution or
filename generation is performed on @var{word}.
The resulting document, called a
@emph{here-document}, becomes the standard input.

@noindent
If any character of @var{word} is quoted with
single or double quotes or a `@t{\}',
no interpretation is placed upon the characters of the document.
Otherwise, parameter and command substitution
occurs, `@t{\}' followed by a newline is removed,
and `@t{\}' must be used to quote the characters
`@t{\}', `@t{$}', `@t{`}' and the first character of @var{word}.

@noindent
If @t{<<-} is used, then all leading
tabs are stripped from @var{word} and from the document.

@item @t{<<<} @var{word}
Perform shell expansion on @var{word} and pass the result
to standard input.  This is known as a @emph{here-string}.

@item @t{<&} @var{number}
@itemx @t{>&} @var{number}
The standard input/output is duplicated from file descriptor
@var{number} (see man page dup2(2)).

@item @t{<& -}
@itemx @t{>& -}
Close the standard input/output.

@item @t{<& p}
@itemx @t{>& p}
The input/output from/to the coprocess is moved to the standard input/output.

@item @t{>&} @var{word}
@itemx @t{&>} @var{word}
(Except where `@t{>&} @var{word}' matches one of the above syntaxes;
`@t{&>}' can always be used to avoid this ambiguity.)
Redirects both standard output and standard error (file descriptor 2)
in the manner of `@t{>} @var{word}'.
Note that this does @emph{not} have the same effect as `@t{>} @var{word} @t{2>&1}'
in the presence of multios (see the section below).

@item @t{>&|} @var{word}
@itemx @t{>&!} @var{word}
@itemx @t{&>|} @var{word}
@itemx @t{&>!} @var{word}
Redirects both standard output and standard error (file descriptor 2)
in the manner of `@t{>|} @var{word}'.

@item @t{>>&} @var{word}
@itemx @t{&>>} @var{word}
Redirects both standard output and standard error (file descriptor 2)
in the manner of `@t{>>} @var{word}'.

@item @t{>>&|} @var{word}
@itemx @t{>>&!} @var{word}
@itemx @t{&>>|} @var{word}
@itemx @t{&>>!} @var{word}
Redirects both standard output and standard error (file descriptor 2)
in the manner of `@t{>>|} @var{word}'.

@end table

@noindent
If one of the above is preceded by a digit, then the file
descriptor referred to is that specified by the digit
instead of the default 0 or 1.
The order in which redirections are specified is significant.
The shell evaluates each redirection in terms of the
(@emph{file descriptor}, @emph{file})
association at the time of evaluation.
For example:

@noindent
@quotation
... @t{1>}@var{fname} @t{2>&1}
@end quotation

@noindent
first associates file descriptor 1 with file @var{fname}.
It then associates file descriptor 2 with the file associated with file
descriptor 1 (that is, @var{fname}).
If the order of redirections were reversed,
file descriptor 2 would be associated
with the terminal (assuming file descriptor 1 had been)
and then file descriptor 1 would be associated with file @var{fname}.

@section Multios
@noindent
@pindex MULTIOS, use of
If the user tries to open a file descriptor for writing more than once,
the shell opens the file descriptor as a pipe to a process that copies
its input to all the specified outputs, similar to @cite{tee},
provided the @t{MULTIOS} option is set, as it is by default.  Thus:

@noindent
@example
date >foo >bar
@end example

@noindent
writes the date to two files, named `@t{foo}' and `@t{bar}'.
Note that a pipe is an implicit redirection; thus

@noindent
@example
date >foo | cat
@end example

@noindent
writes the date to the file `@t{foo}', and also pipes it to cat.

@noindent
If the @t{MULTIOS}
option is set, the word after a redirection operator is also subjected
to filename generation (globbing).  Thus

@noindent
@example
: > *
@end example

@noindent
will truncate all files in the current directory,
assuming there's at least one.  (Without the @t{MULTIOS}
option, it would create an empty file called `@t{*}'.)
Similarly, you can do

@noindent
@example
echo exit 0 >> *.sh
@end example

@noindent
If the user tries to open a file descriptor for reading more than once,
the shell opens the file descriptor as a pipe to a process that copies
all the specified inputs to its output in the order
specified, similar to @cite{cat},
provided the @t{MULTIOS} option is set.  Thus

@noindent
@example
sort <foo <fubar
@end example

@noindent
or even

@noindent
@example
sort <f@{oo,ubar@}
@end example

@noindent
is equivalent to `@t{cat foo fubar | sort}'.

@noindent
Note that a pipe is an implicit redirection; thus

@noindent
@example
cat bar | sort <foo
@end example

@noindent
is equivalent to `@t{cat bar foo | sort}' (note the order of the inputs).

@noindent
If the @t{MULTIOS} option is @emph{un}set,
each redirection replaces the previous redirection for that file descriptor.
However, all files redirected to are actually opened, so

@noindent
@example
echo foo > bar > baz
@end example

@noindent
when @t{MULTIOS} is unset will truncate bar, and write `@t{foo}' into baz.

@noindent

@section Redirections with no command
@noindent
@vindex NULLCMD, use of
@vindex READNULLCMD, use of
@pindex CSH_NULLCMD, use of
@pindex SH_NULLCMD, use of
When a simple command consists of one or more redirection operators
and zero or more parameter assignments, but no command name, zsh can
behave in several ways.

@noindent
If the parameter @t{NULLCMD} is not set or the option @t{CSH_NULLCMD} is
set, an error is caused.  This is the @cite{csh} behavior and @t{CSH_NULLCMD}
is set by default when emulating @cite{csh}.

@noindent
If the option @t{SH_NULLCMD} is set, the builtin `@t{:}' is inserted as a
command with the given redirections.  This is the default when emulating
@cite{sh} or @cite{ksh}.

@noindent
Otherwise, if the parameter @t{NULLCMD} is set, its value will be used as a
command with the given redirections.  If both @t{NULLCMD} and
@t{READNULLCMD} are set, then the value of the latter will be used instead
of that of the former when the redirection is an input.  The default for
@t{NULLCMD} is `@t{cat}' and for @t{READNULLCMD} is `@t{more}'. Thus

@noindent
@example
< file
@end example

@noindent
shows the contents of @t{file} on standard output, with paging if that is a
terminal.  @t{NULLCMD} and @t{READNULLCMD} may refer to shell functions.

@noindent
@c (avoiding a yodl bug)
@c Yodl file: Zsh/exec.yo
@node Command Execution, Functions, Redirection, Top

@chapter Command Execution
@noindent
@cindex command execution
@cindex execution, of commands
If a command name contains no slashes, the shell attempts to locate
it.  If there exists a shell function by that name, the function
is invoked as described in @ref{Functions}.  If there exists
a shell builtin by that name, the builtin is invoked.

@noindent
@vindex path, use of
Otherwise, the shell searches each element of @t{$path} for a
directory containing an executable file by that name.  If the
search is unsuccessful, the shell prints an error message and returns
a nonzero exit status.

@noindent
If execution fails because the file is not in executable format,
and the file is not a directory, it is assumed to be a shell
script.  @t{/bin/sh} is spawned to execute it.  If the program
is a file beginning with `@t{#!}', the remainder of the first line
specifies an interpreter for the program.  The shell will
execute the specified interpreter on operating systems that do
not handle this executable format in the kernel.
@c (avoiding a yodl bug)
@c Yodl file: Zsh/func.yo
@node Functions, Jobs & Signals, Command Execution, Top

@chapter Functions
@noindent
@cindex functions
@findex function
Shell functions are defined with the @t{function} reserved word or the
special syntax `@var{funcname} @t{()}'.
Shell functions are read in and stored internally.
Alias names are resolved when the function is read.
Functions are executed like commands with the arguments
passed as positional parameters.
(See @ref{Command Execution}.)

@noindent
Functions execute in the same process as the caller and
share all files
and present working directory with the
caller.  A trap on @t{EXIT} set inside a function
is executed after the function completes in the environment
of the caller.

@noindent
@findex return, use of
The @t{return} builtin is used to return from function calls.

@noindent
@findex functions, use of
Function identifiers can be listed with the @t{functions} builtin.
@findex unfunction, use of
Functions can be undefined with the @t{unfunction} builtin.

@section Autoloading Functions
@noindent
@findex autoload, use of
@cindex autoloading functions
@cindex functions, autoloading

@noindent
A function can be marked as @emph{undefined} using the @t{autoload} builtin
(or `@t{functions -u}' or `@t{typeset -fu}').  Such a function has no
body.  When the function is first executed, the shell searches for its
definition using the elements of the @t{fpath} variable.  Thus to define
functions for autoloading, a typical sequence is:

@noindent
@example
fpath=(~/myfuncs $fpath)
autoload myfunc1 myfunc2 ...
@end example

@noindent
The usual alias expansion during reading will be suppressed if the
@t{autoload} builtin or its equivalent is given the option @t{-U}. This is
recommended for the use of functions supplied with the zsh distribution.
Note that for functions precompiled with the @t{zcompile} builtin command
the flag @t{-U} must be provided when the @t{.zwc} file is created, as the
corresponding information is compiled into the latter.

@noindent
For each @var{element} in @t{fpath}, the shell looks for three possible
files, the newest of which is used to load the definition for the function:

@noindent
@table @asis
@item @var{element}@t{.zwc}
A file created with the @t{zcompile} builtin command, which is expected to
contain the definitions for all functions in the directory named
@var{element}.  The file is treated in the same manner as a directory
containing files for functions and is searched for the definition of the
function.   If the definition is not found, the search for a definition
proceeds with the other two possibilities described below.

@noindent
If @var{element} already includes a @t{.zwc} extension (i.e. the extension
was explicitly given by the user), @var{element} is searched for the
definition of the function without comparing its age to that of other
files; in fact, there does not need to be any directory named @var{element}
without the suffix.  Thus including an element such as
`@t{/usr/local/funcs.zwc}' in @t{fpath} will speed up the search for
functions, with the disadvantage that functions included must be explicitly
recompiled by hand before the shell notices any changes.

@item @var{element}@t{/}@var{function}@t{.zwc}
A file created with @t{zcompile}, which is expected to contain the
definition for @var{function}.  It may include other function definitions
as well, but those are neither loaded nor executed; a file found in this
way is searched @emph{only} for the definition of @var{function}.

@item @var{element}@t{/}@var{function}
A file of zsh command text, taken to be the definition for @var{function}.

@end table

@noindent
In summary, the order of searching is, first, in the @emph{parents of}
directories in @t{fpath} for the newer of either a compiled directory or
a directory in @t{fpath}; second, if more than one of these contains a
definition for the function that is sought, the leftmost in the @t{fpath}
is chosen; and third, within a directory, the newer of either a compiled
function or an ordinary function definition is used.

@noindent
@pindex KSH_AUTOLOAD, use of
If the @t{KSH_AUTOLOAD} option is set, or the file contains only a
simple definition of the function, the file's contents will be executed.
This will normally define the function in question, but may also perform
initialization, which is executed in the context of the function execution,
and may therefore define local parameters.  It is an error if the function
is not defined by loading the file.

@noindent
Otherwise, the function body (with no surrounding `@var{funcname}@t{()
@{}@var{...}@t{@}}') is taken to be the complete contents of the file.  This
form allows the file to be used directly as an executable shell script.  If
processing of the file results in the function being re-defined, the
function itself is not re-executed.  To force the shell to perform
initialization and then call the function defined, the file should contain
initialization code (which will be executed then discarded) in addition to
a complete function definition (which will be retained for subsequent calls
to the function), and a call to the shell function, including any
arguments, at the end.

@noindent
For example, suppose the autoload file @t{func} contains

@noindent
@example
func() @{ print This is func; @}
print func is initialized

@end example

@noindent
then `@t{func; func}' with @t{KSH_AUTOLOAD} set will produce both messages
on the first call, but only the message `@t{This is func}' on the second
and subsequent calls.  Without @t{KSH_AUTOLOAD} set, it will produce
the initialization message on the first call, and the other message on the
second and subsequent calls.

@noindent
It is also possible to create a function that is not marked as autoloaded,
but which loads its own definition by searching @t{fpath}, by using
`@t{autoload -X}' within a shell function.  For example, the following are
equivalent:

@noindent
@example
myfunc() @{
  autoload -X
@}
myfunc args...
@end example

@noindent
and

@noindent
@example
unfunction myfunc   # if myfunc was defined
autoload myfunc
myfunc args...
@end example

@noindent
In fact, the @t{functions} command outputs `@t{builtin autoload -X}' as
the body of an autoloaded function.  A true autoloaded function can be
identified by the presence of the comment `@t{# undefined}' in the body,
because all comments are discarded from defined functions.  This is done
so that

@noindent
@example
eval "$(functions)"
@end example

@noindent
produces a reasonable result.

@noindent
To load the definition of an autoloaded function @t{myfunc} without
executing @t{myfunc}, use:

@noindent
@example
autoload +X myfunc
@end example

@noindent

@section Special Functions
@noindent
The following functions, if defined, have special meaning to
the shell:

@noindent
@table @asis
@findex chpwd
@item @t{chpwd}
Executed whenever the current working directory is changed.

@findex periodic
@item @t{periodic}
@vindex PERIOD
If the parameter @t{PERIOD}
is set, this function is executed every @t{$PERIOD}
seconds, just before a prompt.

@findex precmd
@item @t{precmd}
Executed before each prompt.

@findex preexec
@item @t{preexec}
Executed just after a command has been read and is about to be
executed.  If the history mechanism is active (and the line was not
discarded from the history buffer), the string that the user typed is
passed as the first argument, otherwise it is an empty string.  The
actual command that will be executed (including expanded aliases) is
passed in two different forms: the second argument is a single-line,
size-limited version of the command (with things like function bodies
elided); the third argument contains the full text what what is being
executed.

@item @t{TRAP}@var{NAL}
@cindex signals, trapping
@cindex trapping signals
If defined and non-null,
this function will be executed whenever the shell
catches a signal @t{SIG}@var{NAL}, where @var{NAL} is a signal
name as specified for the @t{kill} builtin.
The signal number will be passed as the first parameter to the function.

@noindent
If a function of this form is defined and null,
the shell and processes spawned by it will ignore @t{SIG}@var{NAL}.

@findex TRAPDEBUG
@item @t{TRAPDEBUG}
Executed after each command.

@findex TRAPEXIT
@item @t{TRAPEXIT}
Executed when the shell exits,
or when the current function exits if defined inside a function.

@findex TRAPZERR
@item @t{TRAPZERR}
Executed whenever a command has a non-zero exit status.  However, the
function is not executed if the command occurred in a sublist followed by
`@t{&&}' or `@t{||}'; only the final command in a sublist of this type
causes the trap to be executed.

@end table

@noindent
The functions beginning `@t{TRAP}' may alternatively be defined with the
@t{trap} builtin:  this may be preferable for some uses, as they are then
run in the environment of the calling process, rather than in their own
function environment.  Apart from the difference in calling procedure and
the fact that the function form appears in lists of functions, the forms

@noindent
@example
TRAPNAL() @{ 
 # code
@}
@end example

@noindent
and

@noindent
@example
trap '
 # code
' NAL
@end example

@noindent
are equivalent.
@c (avoiding a yodl bug)
@c Yodl file: Zsh/jobs.yo
@node Jobs & Signals, Arithmetic Evaluation, Functions, Top

@chapter Jobs & Signals
@noindent

@section Jobs
@noindent
@cindex jobs
If the @t{MONITOR} option is set,
an interactive shell associates a @emph{job} with each pipeline.
It keeps a table of current jobs, printed by the @t{jobs}
command, and assigns them small integer numbers.
When a job is started asynchronously with `@t{&}',
the shell prints a line which looks like:

@noindent
@example
[1] 1234
@end example

@noindent
indicating that the job which was started asynchronously was job number
1 and had one (top-level) process, whose process ID was 1234.

@noindent
If a job is started with `@t{&|}' or `@t{&!}',
then that job is immediately disowned.  After startup, it
does not have a place in the job table, and is not subject
to the job control features described here.

@noindent
If you are running a job and wish to do something else you may hit the key
^Z (control-Z) which sends a @t{TSTP} signal to the current job:  this key
may be redefined by the @t{susp} option of the external @t{stty} command.
@cindex jobs, suspending
@cindex suspending jobs
The shell will then normally indicate that the job has been `suspended',
and print another prompt.  You can then manipulate the state of this job,
@findex bg, use of
putting it in the background with the @t{bg} command, or run some other
commands and then eventually bring the job back into the foreground with
@findex fg, use of
the foreground command @t{fg}.  A ^Z takes effect immediately and
is like an interrupt in that pending output and unread input are discarded
when it is typed.

@noindent
A job being run in the background will suspend if it tries to read
from the terminal.
@cindex background jobs, I/O
@cindex jobs, background, I/O
Background jobs are normally allowed to produce output,
but this can be disabled by giving the command `@t{stty tostop}'.
If you set this
tty option, then background jobs will suspend when they try to produce
output like they do when they try to read input.

@noindent
When a command is suspended and continued later with the @t{fg} or
@t{wait} builtins, zsh restores tty modes that were in effect when it was
suspended.  This (intentionally) does not apply if the command is
continued via `@t{kill -CONT}', nor when it is continued with @t{bg}.

@noindent
@cindex jobs, referring to
@cindex referring to jobs
There are several ways to refer to jobs in the shell.
A job can be referred to by the process ID of any process of the job
or by one of the following:

@noindent
@table @asis
@item @t{%}@var{number}
The job with the given number.
@item @t{%}@var{string}
Any job whose command line begins with @var{string}.
@item @t{%?}@var{string}
Any job whose command line contains @var{string}.
@item @t{%%}
Current job.
@item @t{%+}
Equivalent to `@t{%%}'.
@item @t{%-}
Previous job.
@end table

@noindent
The shell learns immediately whenever a process changes state.
@pindex NOTIFY, use of
It normally informs you whenever a job becomes blocked so that
no further progress is possible.  If the @t{NOTIFY} option is not set,
it waits until just before it prints a prompt before it informs you.

@noindent
When the monitor mode is on, each background job that completes
triggers any trap set for @t{CHLD}.

@noindent
When you try to leave the shell while jobs are running or suspended, you will
be warned that `You have suspended (running) jobs'.
You may use the @t{jobs} command to see what they are.
If you do this or immediately try to
exit again, the shell will not warn you a second time; the suspended
jobs will be terminated, and the running jobs will be sent
a @t{SIGHUP} signal, if the @t{HUP} option is set.
@pindex HUP, use of

@noindent
@cindex jobs, disowning
@cindex disowning jobs
@findex disown, use of
To avoid having the shell terminate the running jobs, either
use the @cite{nohup} command (see man page nohup(1))
or the @t{disown} builtin.

@section Signals
@noindent
The @t{INT} and @t{QUIT} signals for an invoked
command are ignored if the command is followed by
`@t{&}' and the @t{MONITOR} option is not active.
Otherwise, signals have the values
inherited by the shell from its parent
(but see the @t{TRAP}@var{NAL} special functions in @ref{Functions}).
@c (avoiding a yodl bug)
@c Yodl file: Zsh/arith.yo
@node Arithmetic Evaluation, Conditional Expressions, Jobs & Signals, Top

@chapter Arithmetic Evaluation
@noindent
@cindex arithmetic evaluation
@cindex evaluation, arithmetic
@findex let, use of
The shell can perform integer and floating point arithmetic, either using
the builtin @t{let}, or via a substitution of the form @t{$((...))}.  For
integers, the shell is usually compiled to use 8-byte precision where this
is available, otherwise precision is 4 bytes.  This can be tested, for
example, by giving the command `@t{print - $(( 12345678901 ))}'; if the
number appears unchanged, the precision is at least 8 bytes.  Floating
point arithmetic is always double precision.

@noindent
The @t{let} builtin command takes arithmetic expressions as arguments; each
is evaluated separately.  Since many of the arithmetic operators, as well
as spaces, require quoting, an alternative form is provided: for any
command which begins with a `@t{((}', all the characters until a
matching `@t{))}' are treated as a quoted expression and
arithmetic expansion performed as for an argument of @t{let}.  More
precisely, `@t{((}@var{...}@t{))}' is equivalent to
`@t{let "}@var{...}@t{"}'.  For example, the following statement

@noindent
@example
(( val = 2 + 1 ))
@end example

@noindent
is equivalent to

@noindent
@example
let "val = 2 + 1"
@end example

@noindent
both assigning the value 3 to the shell variable @t{val} and returning a
zero status.

@noindent
@cindex bases, in arithmetic
Integers can be in bases other than 10.
A leading `@t{0x}' or `@t{0X}' denotes hexadecimal.
Integers may also be of the form `@var{base}@t{#}@var{n}',
where @var{base} is a decimal number between two and thirty-six
representing the arithmetic base and @var{n}
is a number in that base (for example, `@t{16#ff}' is 255 in hexadecimal).
The @var{base}@t{#} may also be omitted, in which case
base 10 is used.  For backwards compatibility the form
`@t{[}@var{base}@t{]}@var{n}' is also accepted.

@noindent
It is also possible to specify a base to be used for output in the form
`@t{[#}@var{base}@t{]}', for example `@t{[#16]}'.  This is used when
outputting arithmetical substitutions or when assigning to scalar
parameters, but an explicitly defined integer or floating point parameter
will not be affected.  If an integer variable is implicitly defined by an
arithmetic expression, any base specified in this way will be set as the
variable's output arithmetic base as if the option `@t{-i} @var{base}' to
the @t{typeset} builtin had been used.  The expression has no precedence
and if it occurs more than once in a mathematical expression, the last
encountered is used.  For clarity it is recommended that it appear at the
beginning of an expression.  As an example:

@noindent
@example
typeset -i 16 y
print $(( [#8] x = 32, y = 32 ))
print $x $y
@end example

@noindent
outputs first `@t{8#40}', the rightmost value in the given output base, and
then `@t{8#40 16#20}', because @t{y} has been explicitly declared to
have output base 16, while @t{x} (assuming it does not already exist) is
implicitly typed by the arithmetic evaluation, where it acquires the output
base 8.

@noindent
When an output base is specified using the `@t{[#}@var{base}@t{]}' syntax,
an appropriate base prefix will be output if necessary, so that the value
output is valid syntax for input.  If the @t{#} is doubled, for example
`@t{[##16]}', then no base prefix is output.

@noindent
Floating point constants are recognized by the presence of a decimal point
or an exponent.  The decimal point may be the first character of the
constant, but the exponent character @t{e} or @t{E} may not, as it will be
taken for a parameter name.

@noindent
@cindex arithmetic operators
@cindex operators, arithmetic
An arithmetic expression uses nearly the same syntax, precedence, and
associativity of expressions in C.
The following operators are supported (listed in decreasing order
of precedence):

@noindent
@table @asis
@item @t{+ - ! ~ ++ --}
unary plus/minus, logical NOT, complement, @{pre,post@}@{in,de@}crement
@item @t{<< >>}
bitwise shift left, right
@item @t{&}
bitwise AND
@item @t{^}
bitwise XOR
@item @t{|}
bitwise OR
@item @t{**}
exponentiation
@item @t{* / %}
multiplication, division, modulus (remainder)
@item @t{+ -}
addition, subtraction
@item @t{< > <= >=}
comparison
@item @t{== !=}
equality and inequality
@item @t{&&}
logical AND
@item @t{|| ^^}
logical OR, XOR
@item @t{? :}
ternary operator
@item @t{= += -= *= /= %= &= ^= |= <<= >>= &&= ||= ^^= **=}
assignment
@item @t{,}
comma operator
@end table

@noindent
The operators `@t{&&}', `@t{||}', `@t{&&=}', and `@t{||=}' are
short-circuiting, and only one of the latter two expressions in a ternary
operator is evaluated.  Note the precedence of the bitwise AND, OR,
and XOR operators.

@noindent
@cindex math functions
@cindex functions, math
Mathematical functions can be called with the syntax
`@var{func}@t{(}@var{args}@t{)}', where the function decides
if the @var{args} is used as a string or a comma-separated list of
arithmetic expressions. The shell currently defines no mathematical
functions by default, but the module @t{zsh/mathfunc} may be loaded with
the @t{zmodload} builtin to provide standard floating point mathematical
functions.

@noindent
An expression of the form `@t{##}@var{x}' where @var{x} is any character
sequence such as `@t{a}', `@t{^A}', or `@t{\M-\C-x}' gives the ASCII
value of this character and an expression of the form `@t{#}@var{foo}'
gives the ASCII value of the first character of the value of the
parameter @var{foo}.  Note that this is different from the expression
`@t{$#}@var{foo}', a standard parameter substitution which gives the
length of the parameter @var{foo}.  `@t{#\}' is accepted instead of
`@t{##}', but its use is deprecated.

@noindent
Named parameters and subscripted arrays can be referenced by name within an
arithmetic expression without using the parameter expansion syntax.  For
example,

@noindent
@example
((val2 = val1 * 2))
@end example

@noindent
assigns twice the value of @t{$val1} to the parameter named @t{val2}.

@noindent
An internal integer representation of a named parameter
can be specified with the @t{integer} builtin.
@cindex parameters, integer
@cindex integer parameters
@findex integer, use of
Arithmetic evaluation is performed on the value of each
assignment to a named parameter declared integer
in this manner.  Assigning a floating point number to an integer results in
rounding down to the next integer.

@noindent
@cindex parameters, floating point
@cindex floating point parameters
@findex float, use of
Likewise, floating point numbers can be declared with the @t{float}
builtin; there are two types, differing only in their output format, as
described for the @t{typeset} builtin.  The output format can be bypassed
by using arithmetic substitution instead of the parameter substitution,
i.e. `@t{$@{}@var{float}@t{@}}' uses the defined format, but
`@t{$((}@var{float}@t{))}' uses a generic floating point
format.

@noindent
Promotion of integer to floating point values is performed where
necessary.  In addition, if any operator which requires an integer
(`@t{~}', `@t{&}', `@t{|}', `@t{^}', `@t{%}', `@t{<<}', `@t{>>}' and their
equivalents with assignment) is given a floating point argument, it will be
silently rounded down to the next integer.

@noindent
Scalar variables can hold integer or floating point values at different
times; there is no memory of the numeric type in this case.

@noindent
If a variable is first assigned in a numeric context without previously
being declared, it will be implicitly typed as @t{integer} or @t{float} and
retain that type either until the type is explicitly changed or until the
end of the scope.  This can have unforeseen consequences.  For example, in
the loop

@noindent
@example
for (( f = 0; f < 1; f += 0.1 )); do
# use $f
done
@end example

@noindent
if @t{f} has not already been declared, the first assignment will cause it
to be created as an integer, and consequently the operation `@t{f += 0.1}'
will always cause the result to be truncated to zero, so that the loop will
fail.  A simple fix would be to turn the initialization into `@t{f = 0.0}'.
It is therefore best to declare numeric variables with explicit types.
@c (avoiding a yodl bug)
@c Yodl file: Zsh/cond.yo
@node Conditional Expressions, Prompt Expansion, Arithmetic Evaluation, Top

@chapter Conditional Expressions
@noindent
@cindex conditional expressions
@cindex expressions, conditional
A @emph{conditional expression} is used with the @t{[[}
compound command to test attributes of files and to compare strings.
Each expression can be constructed from one or more
of the following unary or binary expressions:

@noindent
@table @asis
@item @t{-a} @var{file}
true if @var{file} exists.

@item @t{-b} @var{file}
true if @var{file} exists and is a block special file.

@item @t{-c} @var{file}
true if @var{file} exists and is a character special file.

@item @t{-d} @var{file}
true if @var{file} exists and is a directory.

@item @t{-e} @var{file}
true if @var{file} exists.

@item @t{-f} @var{file}
true if @var{file} exists and is a regular file.

@item @t{-g} @var{file}
true if @var{file} exists and has its setgid bit set.

@item @t{-h} @var{file}
true if @var{file} exists and is a symbolic link.

@item @t{-k} @var{file}
true if @var{file} exists and has its sticky bit set.

@item @t{-n} @var{string}
true if length of @var{string} is non-zero.

@item @t{-o} @var{option}
true if option named @var{option} is on.  @var{option}
may be a single character, in which case it is a single letter option name.
(See @ref{Specifying Options}.)

@item @t{-p} @var{file}
true if @var{file} exists and is a FIFO special file (named pipe).

@item @t{-r} @var{file}
true if @var{file} exists and is readable by current process.

@item @t{-s} @var{file}
true if @var{file} exists and has size greater than zero.

@item @t{-t} @var{fd}
true if file descriptor number @var{fd}
is open and associated with a terminal device.
(note: @var{fd} is not optional)

@item @t{-u} @var{file}
true if @var{file} exists and has its setuid bit set.

@item @t{-w} @var{file}
true if @var{file} exists and is writable by current process.

@item @t{-x} @var{file}
true if @var{file} exists and is executable by current process.
If @var{file} exists and is a directory, then the current process
has permission to search in the directory.

@item @t{-z} @var{string}
true if length of @var{string} is zero.

@item @t{-L} @var{file}
true if @var{file} exists and is a symbolic link.

@item @t{-O} @var{file}
true if @var{file} exists and is owned by the effective user ID of this process.

@item @t{-G} @var{file}
true if @var{file} exists and its group matches
the effective group ID of this process.

@item @t{-S} @var{file}
true if @var{file} exists and is a socket.

@item @t{-N} @var{file}
true if @var{file} exists and its access time is
not newer than its modification time.

@item @var{file1} @t{-nt} @var{file2}
true if @var{file1} exists and is newer than @var{file2}.

@item @var{file1} @t{-ot} @var{file2}
true if @var{file1} exists and is older than @var{file2}.

@item @var{file1} @t{-ef} @var{file2}
true if @var{file1} and @var{file2} exist and refer to the same file.

@item @var{string} @t{=} @var{pattern}
@itemx @var{string} @t{==} @var{pattern}
true if @var{string} matches @var{pattern}.
The `@t{==}' form is the preferred one.  The `@t{=}' form is for
backward compatibility and should be considered obsolete.

@item @var{string} @t{!=} @var{pattern}
true if @var{string} does not match @var{pattern}.

@item @var{string1} @t{<} @var{string2}
true if @var{string1} comes before @var{string2}
based on ASCII value of their characters.

@item @var{string1} @t{>} @var{string2}
true if @var{string1} comes after @var{string2}
based on ASCII value of their characters.

@item @var{exp1} @t{-eq} @var{exp2}
true if @var{exp1} is numerically equal to @var{exp2}.

@item @var{exp1} @t{-ne} @var{exp2}
true if @var{exp1} is numerically not equal to @var{exp2}.

@item @var{exp1} @t{-lt} @var{exp2}
true if @var{exp1} is numerically less than @var{exp2}.

@item @var{exp1} @t{-gt} @var{exp2}
true if @var{exp1} is numerically greater than @var{exp2}.

@item @var{exp1} @t{-le} @var{exp2}
true if @var{exp1} is numerically less than or equal to @var{exp2}.

@item @var{exp1} @t{-ge} @var{exp2}
true if @var{exp1} is numerically greater than or equal to @var{exp2}.

@item @t{(} @var{exp} @t{)}
true if @var{exp} is true.

@item @t{!} @var{exp}
true if @var{exp} is false.

@item @var{exp1} @t{&&} @var{exp2}
true if @var{exp1} and @var{exp2} are both true.

@item @var{exp1} @t{||} @var{exp2}
true if either @var{exp1} or @var{exp2} is true.

@end table

@noindent
Normal shell expansion is performed on the @var{file}, @var{string} and
@var{pattern} arguments, but the result of each expansion is constrained to
be a single word, similar to the effect of double quotes.  However, pattern
metacharacters are active for the @var{pattern} arguments; the patterns
are the same as those used for filename generation, see
@ref{Filename Generation}, but there is no special behaviour
of `@t{/}' nor initial dots, and no glob qualifiers are allowed.

@noindent
In each of the above expressions, if
@var{file} is of the form `@t{/dev/fd/}@var{n}',
where @var{n} is an integer,
then the test applied to the open file whose
descriptor number is @var{n},
even if the underlying system does not support
the @t{/dev/fd} directory.

@noindent
In the forms which do numeric comparison, the expressions @var{exp}
undergo arithmetic expansion as if they were enclosed in @t{$((...))}.

@noindent
For example, the following:

@noindent
@example
[[ ( -f foo || -f bar ) && $report = y* ]] && print File exists.
@end example

@noindent
tests if either file @t{foo} or file @t{bar} exists, and if so, if the
value of the parameter @t{report} begins with `@t{y}'; if the complete
condition is true, the message `@t{File exists.}' is printed.
@c (avoiding a yodl bug)
@c Yodl file: Zsh/prompt.yo
@node Prompt Expansion, Expansion, Conditional Expressions, Top

@chapter Prompt Expansion
@noindent
Prompt sequences undergo a special form of expansion.  This type of expansion
is also available using the @t{-P} option to the @t{print} builtin.

@noindent
@pindex PROMPT_SUBST, use of
If the @t{PROMPT_SUBST} option is set, the prompt string is first subjected to
@emph{parameter expansion},
@emph{command substitution} and
@emph{arithmetic expansion}.
See
@ref{Expansion}.

@noindent
Certain escape sequences may be recognised in the prompt string.

@noindent
@pindex PROMPT_BANG, use of
If the @t{PROMPT_BANG} option is set, a `@t{!}' in the prompt is replaced
by the current history event number.  A literal `@t{!}' may then be
represented as `@t{!!}'.

@noindent
@pindex PROMPT_PERCENT, use of
If the @t{PROMPT_PERCENT} option is set, certain escape sequences that
start with `@t{%}' are expanded.
Some escapes take an optional integer argument, which
should appear between the `@t{%}' and the next character of the
sequence.  The following escape sequences are recognized:

@noindent
@table @asis
@item @t{%%}
A `@t{%}'.

@item @t{%)}
A `@t{)}'.

@item @t{%d}
@itemx @t{%/}
Present working directory (@t{$PWD}).  If an integer follows the `@t{%}',
it specifies a number of trailing components of @t{$PWD} to show; zero
means the whole path.  A negative integer specifies leading components,
i.e. @t{%-1d} specifies the first component.

@item @t{%~}
As @t{%d} and @t{%/}, but if @t{$PWD} has a named directory as its prefix,
that part is replaced by a `@t{~}' followed by the name of the directory.
If it starts with @t{$HOME}, that part is replaced by a `@t{~}'.

@item @t{%h}
@itemx @t{%!}
Current history event number.

@item @t{%L}
The current value of @t{$SHLVL}.

@item @t{%M}
The full machine hostname.

@item @t{%m}
The hostname up to the first `@t{.}'.
An integer may follow the `@t{%}' to specify
how many components of the hostname are desired.  With a negative integer,
trailing components of the hostname are shown.

@item @t{%S} (@t{%s})
Start (stop) standout mode.

@item @t{%U} (@t{%u})
Start (stop) underline mode.

@item @t{%B} (@t{%b})
Start (stop) boldface mode.

@item @t{%t}
@itemx @t{%@@}
Current time of day, in 12-hour, am/pm format.

@item @t{%T}
Current time of day, in 24-hour format.

@item @t{%*}
Current time of day in 24-hour format, with seconds.

@item @t{%n}
@t{$USERNAME}.

@item @t{%N}
The name of the script, sourced file, or shell function that zsh is
currently executing, whichever was started most recently.  If there is
none, this is equivalent to the parameter @t{$0}.  An integer may follow
the `@t{%}' to specify a number of trailing path components to show; zero
means the full path.  A negative integer specifies leading components.

@item @t{%i}
The line number currently being executed in the script, sourced file, or
shell function given by @t{%N}.  This is most useful for debugging as part
of @t{$PS4}.

@item @t{%w}
The date in @var{day}@t{-}@var{dd} format.

@item @t{%W}
The date in @var{mm}@t{/}@var{dd}@t{/}@var{yy} format.

@item @t{%D}
The date in @var{yy}@t{-}@var{mm}@t{-}@var{dd} format.

@item @t{%D@{}@var{string}@t{@}}
@var{string} is formatted using the @t{strftime} function.
See man page strftime(3) for more details.  Three additional codes are
available:  @t{%f} prints the day of the month, like @t{%e} but
without any preceding space if the day is a single digit, and
@t{%K}/@t{%L} correspond to @t{%k}/@t{%l} for the hour of the day
(24/12 hour clock) in the same way.

@item @t{%l}
The line (tty) the user is logged in on without @t{/dev/} prefix.
If name starts with @t{/dev/tty} this is stripped.

@item @t{%y}
The line (tty) the user is logged in on without @t{/dev/} prefix.
It does not treat @t{/dev/tty*} specially.

@item @t{%?}
The return code of the last command executed just before the prompt.

@item @t{%_}
The status of the parser, i.e. the shell constructs (like `@t{if}' and
`@t{for}') that have been started on the command line. If given an integer
number that many strings will be printed; zero or negative or no integer means
print as many as there are.  This is most useful in prompts @t{PS2} for
continuation lines and @t{PS4} for debugging with the @t{XTRACE} option; in
the latter case it will also work non-interactively.

@item @t{%E}
Clears to end of line.

@item @t{%#}
A `@t{#}' if the shell is running with privileges, a `@t{%}' if not.
Equivalent to `@t{%(!.#.%%)}'.
The definition of `privileged', for these purposes, is that either the
effective user ID is zero, or, if POSIX.1e capabilities are supported, that
at least one capability is raised in either the Effective or Inheritable
capability vectors.

@item @t{%v}
@vindex psvar, use of
The value of the first element of the @t{psvar} array parameter.  Following
the `@t{%}' with an integer gives that element of the array.  Negative
integers count from the end of the array.

@item @t{%@{}...@t{%@}}
Include a string as a literal escape sequence.
The string within the braces should not change the cursor
position.  Brace pairs can nest.

@item @t{%(}@var{x.true-text.false-text}@t{)}
Specifies a ternary expression.  The character following the @var{x} is
arbitrary; the same character is used to separate the text for the
`true' result from that for the `false' result.
This separator may not appear in the @var{true-text}, except as part of a
%-escape
sequence.  A `@t{)}' may appear in the @var{false-text} as `@t{%)}'.
@var{true-text}
and @var{false-text} may both contain arbitrarily-nested escape
sequences, including further ternary expressions.

@noindent
The left parenthesis may be preceded or followed by a positive integer @var{n},
which defaults to zero.  A negative integer will be multiplied by -1.
The test character @var{x} may be any of the following:

@noindent
@table @asis
@item @t{c}
@itemx @t{.}
@itemx @t{~}
True if the current path, with prefix replacement, has at least @var{n} elements.
@item @t{/}
@itemx @t{C}
True if the current absolute path has at least @var{n} elements.
@item @t{t}
True if the time in minutes is equal to @var{n}.
@item @t{T}
True if the time in hours is equal to @var{n}.
@item @t{d}
True if the day of the month is equal to @var{n}.
@item @t{D}
True if the month is equal to @var{n} (January = 0).
@item @t{w}
True if the day of the week is equal to @var{n} (Sunday = 0).
@item @t{?}
True if the exit status of the last command was @var{n}.
@item @t{#}
True if the effective uid of the current process is @var{n}.
@item @t{g}
True if the effective gid of the current process is @var{n}.
@item @t{l}
True if at least @var{n} characters have already been
printed on the current line.
@item @t{L}
True if the @t{SHLVL} parameter is at least @var{n}.
@item @t{S}
True if the @t{SECONDS} parameter is at least @var{n}.
@item @t{v}
True if the array @t{psvar} has at least @var{n} elements.
@item @t{_}
True if at least @var{n} shell constructs were started.
@item @t{!}
True if the shell is running with privileges.
@end table

@item @t{%<}@var{string}@t{<}
@itemx @t{%>}@var{string}@t{>}
@itemx @t{%[}@var{xstring}@t{]}
Specifies truncation behaviour for the remainder of the prompt string.
The third, deprecated, form is equivalent to `@t{%}@var{xstringx}',
i.e. @var{x} may be `@t{<}' or `@t{>}'.
The numeric argument, which in the third form may appear immediately
after the `@t{[}', specifies the maximum permitted length of
the various strings that can be displayed in the prompt.
The @var{string} will be displayed in
place of the truncated portion of any string; note this does not
undergo prompt expansion.

@noindent
The forms with `@t{<}' truncate at the left of the string,
and the forms with `@t{>}' truncate at the right of the string.
For example, if the current directory is `@t{/home/pike}',
the prompt `@t{%8<..<%/}' will expand to `@t{..e/pike}'.
In this string, the terminating character (`@t{<}', `@t{>}' or `@t{]}'),
or in fact any character, may be quoted by a preceding `@t{\}'; note
when using @t{print -P}, however, that this must be doubled as the
string is also subject to standard @t{print} processing, in addition
to any backslashes removed by a double quoted string:  the worst case
is therefore `@t{print -P "%<\\\\<<..."}'.

@noindent
If the @var{string} is longer than the specified truncation length,
it will appear in full, completely replacing the truncated string.

@noindent
The part of the prompt string to be truncated runs to the end of the
string, or to the end of the next enclosing group of the `@t{%(}'
construct, or to the next truncation encountered at the same grouping
level (i.e. truncations inside a `@t{%(}' are separate), which
ever comes first.  In particular, a truncation with argument zero
(e.g. `@t{%<<}') marks the end of the range of the string to be
truncated while turning off truncation from there on. For example, the
prompt '%10<...<%~%<<%# ' will print a truncated representation of the
current directory, followed by a `@t{%}' or `@t{#}', followed by a
space.  Without the `@t{%<<}', those two characters would be included
in the string to be truncated.

@item @t{%c}
@itemx @t{%.}
@itemx @t{%C}
Trailing component of @t{$PWD}.
An integer may follow the `@t{%}' to get more than one component.
Unless `@t{%C}' is used, tilde contraction is performed first.  These are
deprecated as @t{%c} and @t{%C} are equivalent to @t{%1~} and @t{%1/},
respectively, while explicit positive integers have the same effect as for
the latter two sequences.

@end table
@c (avoiding a yodl bug)
@c Yodl file: Zsh/expn.yo
@node Expansion, Parameters, Prompt Expansion, Top

@chapter Expansion
@noindent
@cindex expansion

The following types of expansions are performed in the indicated order in
five steps:

@noindent
@table @asis
@item @emph{History Expansion}
This is performed only in interactive shells.

@item @emph{Alias Expansion}
Aliases are expanded immediately before the command line is parsed as
explained
in @ref{Aliasing}.

@item @emph{Process Substitution}
@itemx @emph{Parameter Expansion}
@itemx @emph{Command Substitution}
@itemx @emph{Arithmetic Expansion}
@itemx @emph{Brace Expansion}
These five are performed in one step in left-to-right fashion.  After
these expansions, all unquoted occurrences of the characters `@t{\}',
`@t{'}' and `@t{"}' are removed.

@item @emph{Filename Expansion}
If the @t{SH_FILE_EXPANSION} option is set, the order of expansion is
modified for compatibility with @cite{sh} and @cite{ksh}.  In that case
@emph{filename expansion} is performed immediately after @emph{alias expansion},
preceding the set of five expansions mentioned above.

@cindex globbing
@item @emph{Filename Generation}
This expansion, commonly referred to as @cite{globbing}, is always done last.

@end table

@noindent
The following sections explain the types of expansion in detail.

@noindent
@menu
* History Expansion::
* Process Substitution::
* Parameter Expansion::
* Command Substitution::
* Arithmetic Expansion::
* Brace Expansion::
* Filename Expansion::
* Filename Generation::
@end menu
@node History Expansion, Process Substitution, , Expansion

@section History Expansion
@noindent
@cindex history
@cindex history expansion
@cindex expansion, history
History expansion allows you to use words from previous command
lines in the command line you are typing.  This simplifies spelling
corrections and the repetition of complicated commands or arguments.
@vindex HISTSIZE, use of
Immediately before execution, each command is saved in the history list,
the size of which is controlled by the @t{HISTSIZE} parameter.  The one
most recent command is always retained in any case.  Each saved command in
the history list is called a history @emph{event} and is assigned a number,
beginning with 1 (one) when the shell starts up.  The history number that
you may see in your prompt (see
@ref{Prompt Expansion}) is the number that is to be assigned to the @emph{next} command.

@noindent
@menu
* Overview::
* Event Designators::
* Word Designators::
* Modifiers::
@end menu
@node Overview, Event Designators, , History Expansion

@subsection Overview
@noindent
@vindex histchars, use of
A history expansion begins with the first character of the @t{histchars}
parameter, which is `@t{!}' by default, and may occur anywhere on the
command line; history expansions do not nest.  The `@t{!}' can be escaped
with `@t{\}' or can be enclosed between a pair of single quotes (@t{@value{dsq}})
to suppress its special meaning.  Double quotes will @emph{not} work for
this.  Following this history character is an optional event designator
(@ref{Event Designators}) and then an optional word
designator (@ref{Word Designators}); if neither of these designators is
present, no history expansion occurs.

@noindent
Input lines containing history expansions are echoed after being expanded,
but before any other expansions take place and before the command is
executed.  It is this expanded form that is recorded as the history event
for later references.

@noindent
By default, a history reference with no event designator refers to the
same event as any preceding history reference on that command line; if it
is the only history reference in a command, it refers to the previous
command.
@pindex CSH_JUNKIE_HISTORY, use of
However, if the option @t{CSH_JUNKIE_HISTORY} is set, then every history
reference with no event specification @emph{always} refers to the previous
command.

@noindent
For example, `@t{!}' is the event designator for the previous command, so
`@t{!!:1}' always refers to the first word of the previous command, and
`@t{!!$}' always refers to the last word of the previous command.  With
@t{CSH_JUNKIE_HISTORY} set, then `@t{!:1}' and `@t{!$}' function in the
same manner as `@t{!!:1}' and `@t{!!$}', respectively.  Conversely, if
@t{CSH_JUNKIE_HISTORY} is unset, then `@t{!:1}' and `@t{!$}' refer to the
first and last words, respectively, of the same event referenced by the
nearest other history reference preceding them on the current command
line, or to the previous command if there is no preceding reference.

@noindent
The character sequence `@t{^}@var{foo}@t{^}@var{bar}' (where `@t{^}' is
actually the second character of the @t{histchars} parameter)
repeats the last command, replacing the string @var{foo} with @var{bar}.
More precisely, the sequence `@t{^}@var{foo}@t{^}@var{bar}@t{^}' is
synonymous with `@t{!!:s}@t{^}@var{foo}@t{^}@var{bar}@t{^}', hence other
modifiers (see @ref{Modifiers}) may follow the final `@t{^}'.

@noindent
If the shell encounters the character sequence `@t{!"}'
in the input, the history mechanism is temporarily disabled until
the current list (see
@ref{Shell Grammar}) is fully parsed.  The `@t{!"}' is removed from the input, and any
subsequent `@t{!}' characters have no special significance.

@noindent
@findex fc, use of
A less convenient but more comprehensible form of command history support
is provided by the @t{fc} builtin.
@node Event Designators, Word Designators, Overview, History Expansion

@subsection Event Designators
@noindent
@cindex history event designators
@cindex event designators, history
An event designator is a reference to a command-line entry in the history
list.  In the list below, remember that the initial @t{`!'} in each item
may be changed to another character by setting the @t{histchars}
parameter.

@noindent
@table @asis
@item @t{!}
Start a history expansion, except when followed by a blank, newline,
`@t{=}' or `@t{(}'.  If followed immediately by a word designator
(@ref{Word Designators}), this forms a history reference
with no event designator (@ref{Overview}).

@item @t{!!}
Refer to the previous command.
By itself, this expansion
repeats the previous command.

@item @t{!}@var{n}
Refer to command-line @var{n}.

@item @t{!-}@var{n}
Refer to the current command-line minus @var{n}.

@item @t{!}@var{str}
Refer to the most recent command starting with @var{str}.

@item @t{!?}@var{str}[@t{?}]
Refer to the most recent command containing @var{str}.  The trailing
`@t{?}' is necessary if this reference is to be followed by a modifier or
followed by any text that is not to be considered part of @var{str}.

@item @t{!#}
Refer to the current command line typed in so far.  The line is
treated as if it were complete up to and including the word before the
one with the `@t{!#}' reference.

@item @t{!@{}...@t{@}}
Insulate a history reference from adjacent characters (if necessary).

@end table
@node Word Designators, Modifiers, Event Designators, History Expansion

@subsection Word Designators
@noindent
@cindex history word designators
@cindex word designators, history
A word designator indicates which word or words of a given command line are
to be included in a history reference.  A `@t{:}' usually
separates the event specification from the word designator.
It may be omitted only if the word designator begins with a
`@t{^}', `@t{$}', `@t{*}', `@t{-}' or `@t{%}'.
Word designators include:

@noindent
@table @asis
@item @t{0}
The first input word (command).
@item @var{n}
The @var{n}th argument.
@item @t{^}
The first argument.  That is, @t{1}.
@item @t{$}
The last argument.
@item @t{%}
The word matched by (the most recent) @t{?}@var{str} search.
@item @var{x}@t{-}@var{y}
A range of words; @var{x} defaults to @t{0}.
@item @t{*}
All the arguments, or a null value if there are none.
@item @var{x}@t{*}
Abbreviates `@var{x}@t{-$}'.
@item @var{x}@t{-}
Like `@var{x}@t{*}' but omitting word @t{$}.
@end table

@noindent
Note that a `@t{%}' word designator works only when used in one of
`@t{!%}', `@t{!:%}' or `@t{!?}@var{str}@t{?:%}', and only when used after a
@t{!?} expansion (possibly in an earlier command).  Anything else results
in an error, although the error may not be the most obvious one.
@node Modifiers, , Word Designators, History Expansion

@subsection Modifiers
@noindent
@cindex modifiers
@cindex colon modifiers
@cindex history modifiers
@cindex globbing modifiers
@cindex parameter modifiers
After the optional word designator, you can add
a sequence of one or more of the following modifiers,
each preceded by a `@t{:}'.  These modifiers also work on the result
of @emph{filename generation} and @emph{parameter expansion}, except where
noted.

@noindent
@table @asis
@item @t{h}
Remove a trailing pathname component, leaving the head.  This works
like `@t{dirname}'.

@item @t{r}
Remove a filename extension of the form `@t{.}@var{xxx}', leaving
the root name.

@item @t{e}
Remove all but the extension.

@item @t{t}
Remove all leading pathname components, leaving the tail.  This works
like `@t{basename}'.

@item @t{p}
Print the new command but do not execute it.  Only works with history
expansion.

@item @t{q}
Quote the substituted words, escaping further substitutions.  Works
with history expansion and parameter expansion, though for parameters
it is only useful if the resulting text is to be re-evaluated such as
by @t{eval}.

@item @t{Q}
Remove one level of quotes from the substituted words.

@item @t{x}
Like @t{q}, but break into words at whitespace.  Does not work with
parameter expansion.

@item @t{l}
Convert the words to all lowercase.

@item @t{u}
Convert the words to all uppercase.

@item @t{s/}@var{l}@t{/}@var{r}[@t{/}]
Substitute @var{r} for @var{l} as described below.
Unless preceded immediately by a @t{g}, with no colon between,
the substitution is done only for the
first string that matches @var{l}.  For arrays and for filename
generation, this applies to each word of the expanded text.

@item @t{&}
Repeat the previous @t{s} substitution.  Like @t{s}, may be preceded
immediately by a @t{g}.  In parameter expansion the @t{&} must appear
inside braces, and in filename generation it must be quoted with a
backslash.

@end table

@noindent
The @t{s/l/r/} substitution works as follows.  The left-hand side of
substitutions are not regular expressions, but character strings.  Any
character can be used as the delimiter in place of `@t{/}'.  A
backslash quotes the delimiter character.  The character `@t{&}', in
the right-hand-side @var{r}, is replaced by the text from the
left-hand-side @var{l}.  The `@t{&}' can be quoted with a backslash.  A
null @var{l} uses the previous string either from the previous @var{l}
or from the contextual scan string @var{s} from `@t{!?}@var{s}'.  You can
omit the rightmost delimiter if a newline immediately follows @var{r};
the rightmost `@t{?}' in a context scan can similarly be omitted.
Note the same record of the last @var{l} and @var{r} is maintained
across all forms of expansion.

@noindent
The following @t{f}, @t{F}, @t{w} and @t{W} modifiers work only with
parameter expansion and filename generation.  They are listed here to
provide a single point of reference for all modifiers.

@noindent
@table @asis
@item @t{f}
Repeats the immediately (without a colon) following modifier until the
resulting word doesn't change any more.

@item @t{F:}@var{expr}@t{:}
Like @t{f}, but repeats only @var{n} times if the expression
@var{expr} evaluates to @var{n}.  Any character can be used instead of
the `@t{:}'; if `@t{(}', `@t{[}', or `@t{@{}'
is used as the opening delimiter,
the closing delimiter should be '@t{)}', `@t{]}', or `@t{@}}',
respectively.

@item @t{w}
Makes the immediately following modifier work on each word in the
string.

@item @t{W:}@var{sep}@t{:}
Like @t{w} but words are considered to be the parts of the string
that are separated by @var{sep}. Any character can be used instead of
the `@t{:}'; opening parentheses are handled specially, see above.

@end table
@node Process Substitution, Parameter Expansion, History Expansion, Expansion

@section Process Substitution
@noindent
@cindex process substitution
@cindex substitution, process
Each command argument of the form
`@t{<(}@var{list}@t{)}',
`@t{>(}@var{list}@t{)}' or
`@t{=(}@var{list}@t{)}'
is subject to process substitution.
In the case of the @t{<} or @t{>} forms, the shell runs process
@var{list} asynchronously.  If the system supports the @t{/dev/fd}
mechanism, the command argument is the name of the device file
corresponding to a file descriptor; otherwise, if the system supports named
pipes (FIFOs), the command argument will be a named pipe.  If the form with
@t{>} is selected then writing on this special file will provide input for
@var{list}.  If @t{<} is used, then the file passed as an argument will
be connected to the output of the @var{list} process.  For example,

@noindent
@example
@t{paste <(cut -f1} @var{file1}@t{) <(cut -f3} @var{file2}@t{) |
tee >(}@var{process1}@t{) >(}@var{process2}@t{) >/dev/null}
@end example

@noindent
cuts fields 1 and 3 from the files @var{file1} and @var{file2} respectively,
pastes the results together, and sends it to the processes
@var{process1} and @var{process2}.

@noindent
Both the @t{/dev/fd} and the named pipe implementation have drawbacks.  In
the former case, some programmes may automatically close the file
descriptor in question before examining the file on the command line,
particularly if this is necessary for security reasons such as when the
programme is running setuid.  In the second case, if the
programme does not actually open the file, the subshell attempting to read
from or write to the pipe will (in a typical implementation, different
operating systems may have different behaviour) block for ever and have to
be killed explicitly.  In both cases, the shell actually supplies the
information using a pipe, so that programmes that expect to lseek
(see man page lseek(2)) on the file will not work.

@noindent
Also note that the previous example can be more compactly and
efficiently written (provided the @t{MULTIOS} option is set) as:

@noindent
@example
@t{paste <(cut -f1} @var{file1}@t{) <(cut -f3} @var{file2}@t{)} @t{> >(}@var{process1}@t{) > >(}@var{process2}@t{)}
@end example

@noindent
The shell uses pipes instead of FIFOs to implement the latter
two process substitutions in the above example.

@noindent
If @t{=} is used,
then the file passed as an argument will be the name
of a temporary file containing the output of the @var{list}
process.  This may be used instead of the @t{<}
form for a program that expects to lseek (see man page lseek(2))
on the input file.
@node Parameter Expansion, Command Substitution, Process Substitution, Expansion

@section Parameter Expansion
@noindent
@cindex parameter expansion
@cindex expansion, parameter
The character `@t{$}' is used to introduce parameter expansions.
See
@ref{Parameters}
for a description of parameters, including arrays, associative arrays,
and subscript notation to access individual array elements.

@noindent
In the expansions discussed below that require a pattern, the form of
the pattern is the same as that used for filename generation;
see @ref{Filename Generation}.  Note that these patterns, along with
the replacement text of any substitutions, are themselves subject to
parameter expansion, command substitution, and arithmetic expansion.
In addition to the following operations, the colon modifiers described in
@ref{Modifiers} in @ref{History Expansion} can be
applied:  for example, @t{$@{i:s/foo/bar/@}} performs string
substitution on the expansion of parameter @t{$i}.

@noindent
@table @asis
@item @t{$@{}@var{name}@t{@}}
The value, if any, of the parameter @var{name} is substituted.
The braces are required if the expansion is to be followed by
a letter, digit, or underscore that is not to be interpreted
as part of @var{name}.  In addition, more complicated forms of substitution
usually require the braces to be present; exceptions, which only apply if
the option @t{KSH_ARRAYS} is not set, are a single subscript or any colon
modifiers appearing after the name, or any of the characters `@t{^}',
`@t{=}', `@t{~}', `@t{#}' or `@t{+}' appearing before the name, all of
which work with or without braces.

@noindent
If @var{name} is an array parameter, and the @t{KSH_ARRAYS} option is not
set, then the value of each
element of @var{name} is substituted, one element per word.  Otherwise, the
expansion results in one word only; with @t{KSH_ARRAYS}, this is the first
element of an array.  No field splitting is done on the result unless the
@t{SH_WORD_SPLIT} option is set.

@item @t{$@{+}@var{name}@t{@}}
If @var{name} is the name of a set parameter `@t{1}' is substituted,
otherwise `@t{0}' is substituted.

@item @t{$@{}@var{name}@t{:-}@var{word}@t{@}}
If @var{name} is set and is non-null then substitute its
value; otherwise substitute @var{word}. If @var{name} is
missing, substitute @var{word}.

@item @t{$@{}@var{name}@t{:=}@var{word}@t{@}}
@itemx @t{$@{}@var{name}@t{::=}@var{word}@t{@}}
In the first form, if @var{name} is unset or is null then
set it to @var{word}; in the second form, unconditionally
set @var{name} to @var{word}.  In both forms, the value of
the parameter is then substituted.

@item @t{$@{}@var{name}@t{:?}@var{word}@t{@}}
If @var{name} is set and is non-null then substitute
its value; otherwise, print @var{word} and exit from the shell.
Interactive shells instead return to the prompt.
If @var{word} is omitted, then a standard message is printed.

@item @t{$@{}@var{name}@t{:+}@var{word}@t{@}}
If @var{name} is set and is non-null then substitute
@var{word}; otherwise substitute nothing.

@end table

@noindent
If the colon is omitted from one of the above expressions
containing a colon, then the shell only checks whether
@var{name} is set, not whether its value is null.

@noindent
In the following expressions, when @var{name} is an array and
the substitution is not quoted, or if the `@t{(@@)}' flag or the
@var{name}@t{[@@]} syntax is used, matching and replacement is
performed on each array element separately.

@noindent
@table @asis
@item @t{$@{}@var{name}@t{#}@var{pattern}@t{@}}
@itemx @t{$@{}@var{name}@t{##}@var{pattern}@t{@}}
If the @var{pattern} matches the beginning of the value of
@var{name}, then substitute the value of @var{name} with
the matched portion deleted; otherwise, just
substitute the value of @var{name}.  In the first
form, the smallest matching pattern is preferred;
in the second form, the largest matching pattern is
preferred.

@item @t{$@{}@var{name}@t{%}@var{pattern}@t{@}}
@itemx @t{$@{}@var{name}@t{%%}@var{pattern}@t{@}}
If the @var{pattern} matches the end of the value of
@var{name}, then substitute the value of @var{name} with
the matched portion deleted; otherwise, just
substitute the value of @var{name}.  In the first
form, the smallest matching pattern is preferred;
in the second form, the largest matching pattern is
preferred.

@item @t{$@{}@var{name}@t{:#}@var{pattern}@t{@}}
If the @var{pattern} matches the value of @var{name}, then substitute
the empty string; otherwise, just substitute the value of @var{name}.
If @var{name} is an array
the matching array elements are removed (use the `@t{(M)}' flag to
remove the non-matched elements).

@item @t{$@{}@var{name}@t{/}@var{pattern}@t{/}@var{repl}@t{@}}
@itemx @t{$@{}@var{name}@t{//}@var{pattern}@t{/}@var{repl}@t{@}}
Replace the longest possible match of @var{pattern} in the expansion of
parameter @var{name} by string @var{repl}.  The first form
replaces just the first occurrence, the second form all occurrences.
Both @var{pattern} and @var{repl} are subject to double-quoted substitution,
so that expressions like @t{$@{name/$opat/$npat@}} will work, but note the
usual rule that pattern characters in @t{$opat} are not treated specially
unless either the option @t{GLOB_SUBST} is set, or @t{$opat} is instead
substituted as @t{$@{~opat@}}.

@noindent
The @var{pattern} may begin with a `@t{#}', in which case the
@var{pattern} must match at the start of the string, or `@t{%}', in
which case it must match at the end of the string.  The @var{repl} may
be an empty string, in which case the final `@t{/}' may also be omitted.
To quote the final `@t{/}' in other cases it should be preceded by a
single backslash; this is not necessary if the
`@t{/}' occurs inside a substituted parameter.  Note also that the `@t{#}'
and `@t{%}' are not active if they occur inside a substituted parameter,
even at the start.

@noindent
The first `@t{/}' may be preceded by a `@t{:}', in which case the match
will only succeed if it matches the entire word.  Note also the
effect of the @t{I} and @t{S} parameter expansion flags below; however,
the flags @t{M}, @t{R}, @t{B}, @t{E} and @t{N} are not useful.

@noindent
For example,

@noindent
@example
foo="twinkle twinkle little star" sub="t*e" rep="spy"
print $@{foo//$@{~sub@}/$rep@}
print $@{(S)foo//$@{~sub@}/$rep@}
@end example

@noindent
Here, the `@t{~}' ensures that the text of @t{$sub} is treated as a
pattern rather than a plain string.  In the first case, the longest
match for @t{t*e} is substituted and the result is `@t{spy star}',
while in the second case, the shortest matches are taken and the
result is `@t{spy spy lispy star}'.

@item @t{$@{#}@var{spec}@t{@}}
If @var{spec} is one of the above substitutions, substitute
the length in characters of the result instead of
the result itself.  If @var{spec} is an array expression,
substitute the number of elements of the result.
Note that `@t{^}', `@t{=}', and `@t{~}', below, must appear
to the left of `@t{#}' when these forms are combined.

@item @t{$@{^}@var{spec}@t{@}}
@pindex RC_EXPAND_PARAM, toggle
@cindex array expansion style, rc
@cindex rc, array expansion style
Turn on the @t{RC_EXPAND_PARAM} option for the
evaluation of @var{spec}; if the `@t{^}' is doubled, turn it off.
When this option is set, array expansions of the form
@var{foo}@t{$@{}@var{xx}@t{@}}@var{bar},
where the parameter @var{xx}
is set to @t{(}@var{a b c}@t{)}, are substituted with
`@var{fooabar foobbar foocbar}' instead of the default
`@var{fooa b cbar}'.

@noindent
Internally, each such expansion is converted into the
equivalent list for brace expansion.  E.g., @t{$@{^var@}} becomes
@t{@{$var[1],$var[2],}...@t{@}}, and is processed as described in
@ref{Brace Expansion} below.
If word splitting is also in effect the
@t{$var[}@var{N}@t{]} may themselves be split into different list
elements.

@item @t{$@{=}@var{spec}@t{@}}
@pindex SH_WORD_SPLIT, toggle
@cindex field splitting, sh style, parameter
@cindex sh, field splitting style, parameter
Perform word splitting using the rules for @t{SH_WORD_SPLIT} during the
evaluation of @var{spec}, but regardless of whether the parameter appears in
double quotes; if the `@t{=}' is doubled, turn it off.
@vindex IFS, use of
This forces parameter expansions to be split into
separate words before substitution, using @t{IFS} as a delimiter.
This is done by default in most other shells.

@noindent
Note that splitting is applied to @var{word} in the assignment forms
of @var{spec} @emph{before} the assignment to @var{name} is performed.
This affects the result of array assignments with the @t{A} flag.

@item @t{$@{~}@var{spec}@t{@}}
@pindex GLOB_SUBST, toggle
Turn on the @t{GLOB_SUBST} option for the evaluation of
@var{spec}; if the `@t{~}' is doubled, turn it off.  When this option is
set, the string resulting from the expansion will be interpreted as a
pattern anywhere that is possible, such as in filename expansion and
filename generation and pattern-matching contexts like the right
hand side of the `@t{=}' and `@t{!=}' operators in conditions.

@end table

@noindent
If a @t{$@{}...@t{@}} type parameter expression or a
@t{$(}...@t{)} type command substitution is used in place of
@var{name} above, it is expanded first and the result is used as if
it were the value of @var{name}.  Thus it is
possible to perform nested operations:  @t{$@{$@{foo#head@}%tail@}}
substitutes the value of @t{$foo} with both `@t{head}' and `@t{tail}'
deleted.  The form with @t{$(}...@t{)} is often useful in
combination with the flags described next; see the examples below.
Each @var{name} or nested @t{$@{}...@t{@}} in a parameter expansion may
also be followed by a subscript expression as described in
@ref{Array Parameters}.

@noindent
Note that double quotes may appear around nested expressions, in which
case only the part inside is treated as quoted; for example,
@t{$@{(f)"$(foo)"@}} quotes the result of @t{$(foo)}, but the flag `@t{(f)}'
(see below) is applied using the rules for unquoted expansions.  Note
further that quotes are themselves nested in this context; for example, in
@t{"$@{(@@f)"$(foo)"@}"}, there are two sets of quotes, one surrounding the
whole expression, the other (redundant) surrounding the @t{$(foo)} as
before.

@noindent

@subsection Parameter Expansion Flags
@noindent
@cindex parameter expansion flags
@cindex flags, parameter expansion
@cindex substitution, parameter, flags
If the opening brace is directly followed by an opening parenthesis,
the string up to the matching closing parenthesis will be taken as a
list of flags.  In cases where repeating a flag is meaningful, the
repetitions need not be consecutive; for example, `(@t{q%q%q})'
means the same thing as the more readable `(@t{%%qqq})'.  The
following flags are supported:

@noindent
@table @asis
@item @t{%}
Expand all @t{%} escapes in the resulting words in the same way as in in
prompts (see @ref{Prompt Expansion}). If this flag is given twice,
full prompt expansion is done on the resulting words, depending on the
setting of the @t{PROMPT_PERCENT}, @t{PROMPT_SUBST} and @t{PROMPT_BANG}
options.

@item @t{@@}
In double quotes, array elements are put into separate words.
E.g., `@t{"$@{(@@)foo@}"}' is equivalent to `@t{"$@{foo[@@]@}"}' and
`@t{"$@{(@@)foo[1,2]@}"}' is the same as `@t{"$foo[1]" "$foo[2]"}'.
This is distinct from @emph{field splitting} by the the @t{f}, @t{s}
or @t{z} flags, which still applies within each array element.

@item @t{A}
Create an array parameter with `@t{$@{}...@t{=}...@t{@}}',
`@t{$@{}...@t{:=}...@t{@}}' or `@t{$@{}...@t{::=}...@t{@}}'.
If this flag is repeated (as in `@t{AA}'), create an associative
array parameter.  Assignment is made before sorting or padding.
The @var{name} part may be a subscripted range for ordinary
arrays; the @var{word} part @emph{must} be converted to an array, for
example by using `@t{$@{(AA)=}@var{name}@t{=}...@t{@}}' to activate
field splitting, when creating an associative array.

@item @t{c}
With @t{$@{#}@var{name}@t{@}}, count the total number of characters in an array,
as if the elements were concatenated with spaces between them.

@item @t{C}
Capitalize the resulting words.  `Words' in this case refers to sequences
of alphanumeric characters separated by non-alphanumerics, @emph{not} to words
that result from field splitting.

@item @t{e}
Perform @emph{parameter expansion}, @emph{command substitution} and
@emph{arithmetic expansion} on the result. Such expansions can be
nested but too deep recursion may have unpredictable effects.

@item @t{f}
Split the result of the expansion to lines. This is a shorthand
for `@t{ps:\n:}'.

@item @t{F}
Join the words of arrays together using newline as a separator.
This is a shorthand for `@t{pj:\n:}'.

@item @t{i}
With @t{o} or @t{O}, sort case-independently.

@item @t{k}
If @var{name} refers to an associative array, substitute the @emph{keys}
(element names) rather than the values of the elements.  Used with
subscripts (including ordinary arrays), force indices or keys to be
substituted even if the subscript form refers to values.  However,
this flag may not be combined with subscript ranges.

@item @t{L}
Convert all letters in the result to lower case.

@item @t{o}
Sort the resulting words in ascending order.

@item @t{O}
Sort the resulting words in descending order.

@item @t{P}
This forces the value of the parameter @var{name} to be interpreted as a
further parameter name, whose value will be used where appropriate. If
used with a nested parameter or command substitution, the result of that
will be taken as a parameter name in the same way.  For example, if you
have `@t{foo=bar}' and `@t{bar=baz}', the strings @t{$@{(P)foo@}},
@t{$@{(P)$@{foo@}@}}, and @t{$@{(P)$(echo bar)@}} will be expanded to `@t{baz}'.

@item @t{q}
Quote the resulting words with backslashes. If this flag is given
twice, the resulting words are quoted in single quotes and if it is
given three times, the words are quoted in double quotes. If it is
given four times, the words are quoted in single quotes preceded by a @t{$}.

@item @t{Q}
Remove one level of quotes from the resulting words.

@item @t{t}
Use a string describing the type of the parameter where the value
of the parameter would usually appear. This string consists of keywords
separated by hyphens (`@t{-}'). The first keyword in the string describes
the main type, it can be one of `@t{scalar}', `@t{array}', `@t{integer}',
`@t{float}' or `@t{association}'. The other keywords describe the type in
more detail:

@noindent
@table @asis
@item @t{local}
for local parameters

@item @t{left}
for left justified parameters

@item @t{right_blanks}
for right justified parameters with leading blanks

@item @t{right_zeros}
for right justified parameters with leading zeros

@item @t{lower}
for parameters whose value is converted to all lower case when it is
expanded

@item @t{upper}
for parameters whose value is converted to all upper case when it is
expanded

@item @t{readonly}
for readonly parameters

@item @t{tag}
for tagged parameters

@item @t{export}
for exported parameters

@item @t{unique}
for arrays which keep only the first occurrence of duplicated values

@item @t{hide}
for parameters with the `hide' flag

@item @t{special}
for special parameters defined by the shell

@end table

@item @t{U}
Convert all letters in the result to upper case.

@item @t{v}
Used with @t{k}, substitute (as two consecutive words) both the key
and the value of each associative array element.  Used with subscripts,
force values to be substituted even if the subscript form refers to
indices or keys.

@item @t{V}
Make any special characters in the resulting words visible.

@item @t{w}
With @t{$@{#}@var{name}@t{@}}, count words in arrays or strings; the @t{s}
flag may be used to set a word delimiter.

@item @t{W}
Similar to @t{w} with the difference that empty words between
repeated delimiters are also counted.

@item @t{X}
With this flag parsing errors occurring with the @t{Q} and @t{e} flags or the
pattern matching forms such as `@t{$@{}@var{name}@t{#}@var{pattern}@t{@}}' 
are reported. Without the flag they are silently ignored.

@item @t{z}
Split the result of the expansion into words using shell parsing to
find the words, i.e. taking into account any quoting in the value.

@noindent
Note that this is done very late, as for the `@t{(s)}' flag. So to
access single words in the result, one has to use nested expansions as 
in `@t{$@{$@{(z)foo@}[2]@}}'. Likewise, to remove the quotes in the
resulting words one would do: `@t{$@{(Q)$@{(z)foo@}@}}'.

@end table

@noindent
The following flags (except @t{p}) are followed by one or more arguments
as shown.  Any character, or the matching pairs `@t{(}...@t{)}',
`@t{@{}...@t{@}}', `@t{[}...@t{]}', or `@t{<}...@t{>}', may be used in place
of a colon as delimiters, but note that when a flag takes more than one
argument, a matched pair of delimiters must surround each argument.

@noindent
@table @asis
@item @t{p}
Recognize the same escape sequences as the @t{print} builtin
in string arguments to any of the flags described below.

@item @t{j:}@var{string}@t{:}
Join the words of arrays together using @var{string} as a separator.
@pindex SH_WORD_SPLIT, use of
Note that this occurs before field splitting by the @t{SH_WORD_SPLIT}
option.

@item @t{l:}@var{expr}@t{::}@var{string1}@t{::}@var{string2}@t{:}
Pad the resulting words on the left.  Each word will be truncated if
required and placed in a field @var{expr} characters wide.  The space
to the left will be filled with @var{string1} (concatenated as often
as needed) or spaces if @var{string1} is not given.  If both
@var{string1} and @var{string2} are given, this string is inserted
once directly to the left of each word, before padding.

@item @t{r:}@var{expr}@t{::}@var{string1}@t{::}@var{string2}@t{:}
As @t{l}, but pad the words on the right and insert @var{string2}
on the right.

@item @t{s:}@var{string}@t{:}
Force field splitting (see the option @t{SH_WORD_SPLIT}) at the
separator @var{string}.  Note that a @var{string} of two or more
characters means all must all match in sequence; this differs from
the treatment of two or more characters in the @t{IFS} parameter.

@end table

@noindent
The following flags are meaningful with the @t{$@{}...@t{#}...@t{@}} or
@t{$@{}...@t{%}...@t{@}} forms.  The @t{S} and @t{I} flags may also be
used with the @t{$@{}...@t{/}...@t{@}} forms.

@noindent
@table @asis
@item @t{S}
Search substrings as well as beginnings or ends; with @t{#} start
from the beginning and with @t{%} start from the end of the string.
With substitution via @t{$@{}...@t{/}...@t{@}} or
@t{$@{}...@t{//}...@t{@}}, specifies non-greedy matching, i.e. that the
shortest instead of the longest match should be replaced.

@item @t{I:}@var{expr}@t{:}
Search the @var{expr}th match (where @var{expr} evaluates to a number).
This only applies when searching for substrings, either with the @t{S}
flag, or with @t{$@{}...@t{/}...@t{@}} (only the @var{expr}th match is
substituted) or @t{$@{}...@t{//}...@t{@}} (all matches from the
@var{expr}th on are substituted).  The default is to take the first match.

@noindent
The @var{expr}th match is counted such that there is either one or zero
matches from each starting position in the string, although for global
substitution matches overlapping previous replacements are ignored.  With
the @t{$@{}...@t{%}...@t{@}} and @t{$@{}...@t{%%}...@t{@}} forms, the starting
position for the match moves backwards from the end as the index increases,
while with the other forms it moves forward from the start.

@noindent
Hence with the string
@example
which switch is the right switch for Ipswich?
@end example
substitutions of the form
@t{$@{}(@t{SI:}@var{N}@t{:})@t{string#w*ch@}} as @var{N} increases
from 1 will match and remove `@t{which}', `@t{witch}', `@t{witch}' and
`@t{wich}'; the form using `@t{##}' will match and remove `@t{which switch
is the right switch for Ipswich}', `@t{witch is the right switch for
Ipswich}', `@t{witch for Ipswich}' and `@t{wich}'. The form using `@t{%}'
will remove the same matches as for `@t{#}', but in reverse order, and the
form using `@t{%%}' will remove the same matches as for `@t{##}' in reverse
order.

@item @t{B}
Include the index of the beginning of the match in the result.

@item @t{E}
Include the index of the end of the match in the result.

@item @t{M}
Include the matched portion in the result.

@item @t{N}
Include the length of the match in the result.

@item @t{R}
Include the unmatched portion in the result (the @emph{R}est).

@end table

@noindent

@subsection Rules
@noindent

@noindent
Here is a summary of the rules for substitution; this assumes that braces
are present around the substitution, i.e. @t{$@{...@}}.  Some particular
examples are given below.  Note that the Zsh Development Group accepts
@emph{no responsibility} for any brain damage which may occur during the
reading of the following rules.

@noindent
@table @asis
@item @t{1.} @emph{Nested Substitution}
If multiple nested @t{$@{...@}} forms are present, substitution is
performed from the inside outwards.  At each level, the substitution takes
account of whether the current value is a scalar or an array, whether the
whole substitution is in double quotes, and what flags are supplied to the
current level of substitution, just as if the nested substitution were the
outermost.  The flags are not propagated up to enclosing
substitutions; the nested substitution will return either a scalar or an
array as determined by the flags, possibly adjusted for quoting.  All the
following steps take place where applicable at all levels of substitution.
Note that, unless the `@t{(P)}' flag is present, the flags and any subscripts
apply directly to the value of the nested substitution; for example, the
expansion @t{$@{$@{foo@}@}} behaves exactly the same as @t{$@{foo@}}.

@item @t{2.} @emph{Parameter Subscripting}
If the value is a raw parameter reference with a subscript, such as
@t{$@{}@var{var}@t{[3]@}}, the effect of subscripting is applied directly to
the parameter.  Subscripts are evaluated left to right; subsequent
subscripts apply to the scalar or array value yielded by the previous
subscript.  Thus if @t{var} is an array, @t{$@{var[1][2]@}} is the second
character of the first word, but @t{$@{var[2,4][2]@}} is the entire third
word (the second word of the range of words two through four of the
original array).  Any number of subscripts may appear.

@item @t{3.} @emph{Parameter Name Replacement}
The effect of any @t{(P)} flag, which treats the value so far as a
parameter name and replaces it with the corresponding value, is applied.

@item @t{4.} @emph{Double-Quoted Joining}
If the value after this process is an array, and the substitution
appears in double quotes, and no @t{(@@)} flag is present at the current
level, the words of the value are joined with the first character of the
parameter @t{$IFS}, by default a space, between each word (single word
arrays are not modified).  If the @t{(j)} flag is present, that is used for
joining instead of @t{$IFS}.

@item @t{5.} @emph{Nested Subscripting}
Any remaining subscripts (i.e. of a nested substitution) are evaluated at
this point, based on whether the value is an array or a scalar.  As with
@t{2.}, multiple subscripts can appear.  Note that @t{$@{foo[2,4][2]@}} is
thus equivalent to @t{$@{$@{foo[2,4]@}[2]@}} and also to
@t{"$@{$@{(@@)foo[2,4]@}[2]@}"} (the nested substitution returns an array in
both cases), but not to @t{"$@{$@{foo[2,4]@}[2]@}"} (the nested substitution
returns a scalar because of the quotes).

@item @t{6.} @emph{Modifiers}
Any modifiers, as specified by a trailing `@t{#}', `@t{%}', `@t{/}'
(possibly doubled) or by a set of modifiers of the form @t{:...} (see
@ref{Modifiers} in @ref{History Expansion}), are applied to the words
of the value at this level.

@item @t{7.} @emph{Forced Joining}
If the `@t{(j)}' flag is present, or no `@t{(j)}' flag is present but
the string is to be split as given by rules @t{8.} or @t{9.}, and joining
did not take place at step @t{4.}, any words in the value are joined
together using the given string or the first character of @t{$IFS} if none.
Note that the `@t{(F)}' flag implicitly supplies a string for joining in this
manner.

@item @t{8.} @emph{Forced Splitting}
If one of the `@t{(s)}', `@t{(f)}' or `@t{(z)}' flags are present, or the `@t{=}'
specifier was present (e.g. @t{$@{=}@var{var}@t{@}}), the word is split on
occurrences of the specified string, or (for @t{=} with neither of the two
flags present) any of the characters in @t{$IFS}.

@item @t{9.} @emph{Shell Word Splitting}
If no `@t{(s)}', `@t{(f)}' or `@t{=}' was given, but the word is not
quoted and the option @t{SH_WORD_SPLIT} is set, the word is split on
occurrences of any of the characters in @t{$IFS}.  Note this step, too,
takes place at all levels of a nested substitution.

@item @t{10.} @emph{Re-Evaluation}
Any `@t{(e)}' flag is applied to the value, forcing it to be re-examined
for new parameter substitutions, but also for command and arithmetic
substitutions.

@item @t{11.} @emph{Padding}
Any padding of the value by the `@t{(l.}@var{fill}@t{.)}' or
`@t{(r.}@var{fill}@t{.)}' flags is applied.

@item @t{12.} @emph{Semantic Joining}
In contexts where expansion semantics requires a single word to
result, all words are rejoined with the first character of @t{IFS}
between.  So in `@t{$@{(P}@t{)$@{(f}@t{)lines@}@}}'
the value of @t{$@{lines@}} is split at newlines, but then must be
joined again before the @t{P} flag can be applied.

@noindent
If a single word is not required, this rule is skipped.

@end table

@noindent

@subsection Examples
@noindent
The flag @t{f} is useful to split a double-quoted substitution line by
line.  For example, @t{$@{(f)"$(<}@var{file}@t{)"@}}
substitutes the contents of @var{file} divided so that each line is
an element of the resulting array.  Compare this with the effect of
@t{$}@t{(<}@var{file}@t{)} alone, which divides the file
up by words, or the same inside double quotes, which makes the entire
content of the file a single string.

@noindent
The following illustrates the rules for nested parameter expansions.
Suppose that @t{$foo} contains the array @t{(bar baz}@t{)}:

@noindent
@table @asis
@item @t{"$@{(@@)$@{foo@}[1]@}"}
This produces the result @t{b}.  First, the inner substitution
@t{"$@{foo@}"}, which has no array (@t{@@}) flag, produces a single word
result @t{"bar baz"}.  The outer substitution @t{"$@{(@@)...[1]@}"} detects
that this is a scalar, so that (despite the `@t{(@@)}' flag) the subscript
picks the first character. 

@item @t{"$@{$@{(@@)foo@}[1]@}"}
This produces the result `@t{bar}'.  In this case, the inner substitution
@t{"$@{(@@)foo@}"} produces the array `@t{(bar baz}@t{)}'.  The outer
substitution @t{"$@{...[1]@}"} detects that this is an array and picks the
first word.  This is similar to the simple case @t{"$@{foo[1]@}"}.

@end table

@noindent
As an example of the rules for word splitting and joining, suppose @t{$foo}
contains the array `@t{(ax1 bx1}@t{)}'.  Then

@noindent
@table @asis
@item @t{$@{(s/x/)foo@}}
produces the words `@t{a}', `@t{1 b}' and `@t{1}'.

@item @t{$@{(j/x/s/x/)foo@}}
produces `@t{a}', `@t{1}', `@t{b}' and `@t{1}'.

@item @t{$@{(s/x/)foo%%1*@}}
produces `@t{a}' and `@t{ b}' (note the extra space).  As substitution
occurs before either joining or splitting, the operation  first generates
the modified array @t{(ax bx}@t{)}, which is joined to give
@t{"ax bx"}, and then split to give `@t{a}', `@t{ b}' and `'.  The final
empty string will then be elided, as it is not in double quotes.

@end table

@noindent
@node Command Substitution, Arithmetic Expansion, Parameter Expansion, Expansion

@section Command Substitution
@noindent
@cindex command substitution
@cindex substitution, command
A command enclosed in parentheses preceded by a dollar sign, like
`@t{$(}...@t{)}', or quoted with grave 
accents, like `@t{`}...@t{`}', is replaced with its standard output, with
any trailing newlines deleted.
If the substitution is not enclosed in double quotes, the
output is broken into words using the @t{IFS} parameter.
@vindex IFS, use of
The substitution `@t{$(cat} @var{foo}@t{)}' may be replaced
by the equivalent but faster `@t{$(<}@var{foo}@t{)}'.
In either case, if the option @t{GLOB_SUBST} is set,
the output is eligible for filename generation.
@node Arithmetic Expansion, Brace Expansion, Command Substitution, Expansion

@section Arithmetic Expansion
@noindent
@cindex arithmetic expansion
@cindex expansion, arithmetic
A string of the form `@t{$[}@var{exp}@t{]}' or
`@t{$((}@var{exp}@t{))}' is substituted
with the value of the arithmetic expression @var{exp}.  @var{exp} is
subjected to @emph{parameter expansion}, @emph{command substitution}
and @emph{arithmetic expansion} before it is evaluated.
See @ref{Arithmetic Evaluation}.
@node Brace Expansion, Filename Expansion, Arithmetic Expansion, Expansion

@section Brace Expansion
@noindent
@cindex brace expansion
@cindex expansion, brace
A string of the form
`@var{foo}@t{@{}@var{xx}@t{,}@var{yy}@t{,}@var{zz}@t{@}}@var{bar}'
is expanded to the individual words
`@var{fooxxbar}', `@var{fooyybar}' and `@var{foozzbar}'.
Left-to-right order is preserved.  This construct
may be nested.  Commas may be quoted in order to
include them literally in a word.

@noindent
An expression of the form `@t{@{}@var{n1}@t{..}@var{n2}@t{@}}',
where @var{n1} and @var{n2} are integers,
is expanded to every number between
@var{n1} and @var{n2} inclusive.  If either number begins with a
zero, all the resulting numbers will be padded with leading zeroes to
that minimum width.  If the numbers are in decreasing order the
resulting sequence will also be in decreasing order.

@noindent
If a brace expression matches none of the above forms, it is left
unchanged, unless the @t{BRACE_CCL} option is set.
@pindex BRACE_CCL, use of
In that case, it is expanded to a sorted list of the individual
characters between the braces, in the manner of a search set.
`@t{-}' is treated specially as in a search set, but `@t{^}' or `@t{!}' as
the first character is treated normally.

@noindent
Note that brace expansion is not part of filename generation (globbing); an
expression such as @t{*/@{foo,bar@}} is split into two separate words
@t{*/foo} and @t{*/bar} before filename generation takes place.  In
particular, note that this is liable to produce a `no match' error if
@emph{either} of the two expressions does not match; this is to be contrasted
with @t{*/(foo|bar)}, which is treated as a single pattern but otherwise
has similar effects.
@node Filename Expansion, Filename Generation, Brace Expansion, Expansion

@section Filename Expansion
@noindent
@cindex filename expansion
@cindex expansion, filename
Each word is checked to see if it begins with an unquoted `@t{~}'.
If it does, then the word up to a `@t{/}',
or the end of the word if there is no `@t{/}',
is checked to see if it can be substituted in one of the ways
described here.  If so, then the `@t{~}' and the checked portion are
replaced with the appropriate substitute value.

@noindent
A `@t{~}' by itself is replaced by the value of @t{$HOME}.
A `@t{~}' followed by a `@t{+}' or a `@t{-}' is replaced by the value of
@t{$PWD} or @t{$OLDPWD}, respectively.

@noindent
A `@t{~}' followed by a number is replaced by the directory at that
position in the directory stack.
`@t{~0}' is equivalent to `@t{~+}',
and `@t{~1}' is the top of the stack.
`@t{~+}' followed by a number is replaced by the directory at that
position in the directory stack.
`@t{~+0}' is equivalent to `@t{~+}',
and `@t{~+1}' is the top of the stack.
`@t{~-}' followed by a number is replaced by the directory that
many positions from the bottom of the stack.
`@t{~-0}' is the bottom of the stack.
@pindex PUSHD_MINUS, use of
The @t{PUSHD_MINUS}
option exchanges the effects of `@t{~+}' and `@t{~-}' where they are
followed by a number.

@noindent
@cindex directories, named
@cindex named directories
A `@t{~}' followed by anything not already covered is looked up as a
named directory, and replaced by the value of that named directory if found.
Named directories are typically home directories for users on the system.
They may also be defined if the text after the `@t{~}' is the name
of a string shell parameter whose value begins with a `@t{/}'.
It is also possible to define directory names using the @t{-d} option to the
@t{hash} builtin.

@noindent
In certain circumstances (in prompts, for instance), when the shell
prints a path, the path is checked to see if it has a named
directory as its prefix.  If so, then the prefix portion
is replaced with a `@t{~}' followed by the name of the directory.
The shortest way of referring to the directory is used,
with ties broken in favour of using a named directory,
except when the directory is @t{/} itself.  The parameters @t{$PWD} and
@t{$OLDPWD} are never abbreviated in this fashion.

@noindent
If a word begins with an unquoted `@t{=}'
and the @t{EQUALS} option is set,
the remainder of the word is taken as the
name of a command or alias.  If a command
exists by that name, the word is replaced
by the full pathname of the command.
If an alias exists by that name, the word
is replaced with the text of the alias.

@noindent
Filename expansion is performed on the right hand side of a parameter
assignment, including those appearing after commands of the
@t{typeset} family.  In this case, the right hand side will be treated
as a colon-separated list in the manner of the @t{PATH} parameter,
so that a `@t{~}' or an `@t{=}' following a `@t{:}' is eligible for expansion.
All such behaviour can be
disabled by quoting the `@t{~}', the `@t{=}', or the whole expression (but not
simply the colon); the @t{EQUALS} option is also respected.

@noindent
If the option @t{MAGIC_EQUAL_SUBST} is set, any unquoted shell
argument in the form `@var{identifier}@t{=}@var{expression}' becomes eligible
for file expansion as described in the previous paragraph.  Quoting the
first `@t{=}' also inhibits this.
@node Filename Generation, , Filename Expansion, Expansion

@section Filename Generation
@noindent
@cindex filename generation
If a word contains an unquoted instance of one of the characters
`@t{*}', `@t{(}', `@t{|}', `@t{<}', `@t{[}', or `@t{?}', it is regarded
as a pattern for filename generation, unless the @t{GLOB} option is unset.
@pindex GLOB, use of
If the @t{EXTENDED_GLOB} option is set,
@pindex EXTENDED_GLOB, use of
the `@t{^}' and `@t{#}' characters also denote a pattern; otherwise
they are not treated specially by the shell.

@noindent
The word is replaced with a list of sorted filenames that match
the pattern.  If no matching pattern is found, the shell gives
an error message, unless the @t{NULL_GLOB} option is set,
@pindex NULL_GLOB, use of
in which case the word is deleted; or unless the @t{NOMATCH}
option is unset, in which case the word is left unchanged.
@pindex NOMATCH, use of

@noindent
In filename generation,
the character `@t{/}' must be matched explicitly;
also, a `@t{.}' must be matched
explicitly at the beginning of a pattern or after a `@t{/}', unless the
@t{GLOB_DOTS} option is set.
@pindex GLOB_DOTS, use of
No filename generation pattern
matches the files `@t{.}' or `@t{..}'.  In other instances of pattern
matching, the `@t{/}' and `@t{.}' are not treated specially.

@subsection Glob Operators
@noindent
@table @asis
@item @t{*}
Matches any string, including the null string.

@item @t{?}
Matches any character.

@item @t{[}...@t{]}
Matches any of the enclosed characters.  Ranges of characters
can be specified by separating two characters by a `@t{-}'.
A `@t{-}' or `@t{]}' may be matched by including it as the
first character in the list.
@cindex character classes
There are also several named classes of characters, in the form
`@t{[:}@var{name}@t{:]}' with the following meanings:  `@t{[:alnum:]}'
alphanumeric, `@t{[:alpha:]}' alphabetic,
`@t{[:blank:]}' space or tab,
`@t{[:cntrl:]}' control character, `@t{[:digit:]}' decimal
digit, `@t{[:graph:]}' printable character except whitespace,
`@t{[:lower:]}' lowercase letter, `@t{[:print:]}' printable character,
`@t{[:punct:]}' printable character neither alphanumeric nor whitespace,
`@t{[:space:]}' whitespace character, `@t{[:upper:]}' uppercase letter, 
`@t{[:xdigit:]}' hexadecimal digit.  These use the macros provided by
the operating system to test for the given character combinations,
including any modifications due to local language settings:  see
man page ctype(3).  Note that the square brackets are additional
to those enclosing the whole set of characters, so to test for a
single alphanumeric character you need `@t{[[:alnum:]]}'.  Named
character sets can be used alongside other types,
e.g. `@t{[[:alpha:]0-9]}'.

@item @t{[^}...@t{]}
@itemx @t{[!}...@t{]}
Like @t{[}...@t{]}, except that it matches any character which is
not in the given set.

@item @t{<}[@var{x}]@t{-}[@var{y}]@t{>}
Matches any number in the range @var{x} to @var{y}, inclusive.
Either of the numbers may be omitted to make the range open-ended;
hence `@t{<->}' matches any number.  To match individual digits, the
@t{[}...@t{]} form is more efficient.

@noindent
Be careful when using other wildcards adjacent to patterns of this form;
for example, @t{<0-9>*} will actually match any number whatsoever at the
start of the string, since the `@t{<0-9>}' will match the first digit, and
the `@t{*}' will match any others.  This is a trap for the unwary, but is
in fact an inevitable consequence of the rule that the longest possible
match always succeeds.  Expressions such as `@t{<0-9>[^[:digit:]]*}' can be
used instead.

@item @t{(}...@t{)}
Matches the enclosed pattern.  This is used for grouping.
If the @t{KSH_GLOB} option is set, then a
`@t{@@}', `@t{*}', `@t{+}', `@t{?}' or `@t{!}' immediately preceding
the `@t{(}' is treated specially, as detailed below. The option
@t{SH_GLOB} prevents bare parentheses from being used in this way, though
the @t{KSH_GLOB} option is still available.

@noindent
Note that grouping cannot extend over multiple directories: it is an error
to have a `@t{/}' within a group (this only applies for patterns used in
filename generation).  There is one exception:  a group of the form
@t{(}@var{pat}@t{/)#} appearing as a complete path segment can
match a sequence of directories.  For example, @t{foo/(a*/)#bar} matches
@t{foo/bar}, @t{foo/any/bar}, @t{foo/any/anyother/bar}, and so on.

@item @var{x}@t{|}@var{y}
Matches either @var{x} or @var{y}.
This operator has lower precedence than any other.
The `@t{|}' character
must be within parentheses, to avoid interpretation as a pipeline.

@item @t{^}@var{x}
(Requires @t{EXTENDED_GLOB} to be set.)
Matches anything except the pattern @var{x}.
This has a higher precedence than `@t{/}', so `@t{^foo/bar}'
will search directories in `@t{.}' except `@t{./foo}'
for a file named `@t{bar}'.

@item @var{x}@t{~}@var{y}
(Requires @t{EXTENDED_GLOB} to be set.)
Match anything that matches the pattern @var{x} but does not match @var{y}.
This has lower precedence than any operator except `@t{|}', so
`@t{*/*~foo/bar}' will search for all files in all directories in `@t{.}'
and then exclude `@t{foo/bar}' if there was such a match.
Multiple patterns can be excluded by
`@var{foo}@t{~}@var{bar}@t{~}@var{baz}'.
In the exclusion pattern (@var{y}), `@t{/}' and `@t{.}' are not treated
specially the way they usually are in globbing.

@item @var{x}@t{#}
(Requires @t{EXTENDED_GLOB} to be set.)
Matches zero or more occurrences of the pattern @var{x}.
This operator has high precedence; `@t{12#}' is equivalent to `@t{1(2#)}',
rather than `@t{(12)#}'.  It is an error for an unquoted `@t{#}' to follow
something which cannot be repeated; this includes an empty string, a
pattern already followed by `@t{##}', or parentheses when part of a
@t{KSH_GLOB} pattern (for example, `@t{!(}@var{foo}@t{)#}' is
invalid and must be replaced by
`@t{*(!(}@var{foo}@t{))}').

@item @var{x}@t{##}
(Requires @t{EXTENDED_GLOB} to be set.)
Matches one or more occurrences of the pattern @var{x}.
This operator has high precedence; `@t{12##}' is equivalent to `@t{1(2##)}',
rather than `@t{(12)##}'.  No more than two active `@t{#}' characters may
appear together.

@end table

@subsection ksh-like Glob Operators
@noindent
@pindex KSH_GLOB, use of
If the @t{KSH_GLOB} option is set, the effects of parentheses can be
modified by a preceding `@t{@@}', `@t{*}', `@t{+}', `@t{?}' or `@t{!}'.
This character need not be unquoted to have special effects,
but the `@t{(}' must be.

@noindent
@table @asis
@item @t{@@(}...@t{)}
Match the pattern in the parentheses.  (Like `@t{(}...@t{)}'.)

@item @t{*(}...@t{)}
Match any number of occurrences.  (Like `@t{(}...@t{)#}'.)

@item @t{+(}...@t{)}
Match at least one occurrence.  (Like `@t{(}...@t{)##}'.)

@item @t{?(}...@t{)}
Match zero or one occurrence.  (Like `@t{(|}...@t{)}'.)

@item @t{!(}...@t{)}
Match anything but the expression in parentheses.
(Like `@t{(^(}...@t{))}'.)

@end table

@subsection Precedence
@noindent
@cindex precedence of glob operators
The precedence of the operators given above is (highest) `@t{^}', `@t{/}',
`@t{~}', `@t{|}' (lowest); the
remaining operators are simply treated from left to right as part of a
string, with `@t{#}' and `@t{##}' applying to the shortest possible
preceding unit (i.e. a character, `@t{?}', `@t{[}...@t{]}',
`@t{<}...@t{>}', or a parenthesised expression).  As mentioned
above, a `@t{/}' used as a directory separator may not appear inside
parentheses, while a `@t{|}' must do so; in patterns used in other contexts
than filename generation (for example, in @t{case} statements and tests
within `@t{[[}...@t{]]}'), a `@t{/}' is not special; and `@t{/}' is also
not special after a `@t{~}' appearing outside parentheses in a filename
pattern.

@subsection Globbing Flags
@noindent
There are various flags which affect any text to their right up to the
end of the enclosing group or to the end of the pattern; they require
the @t{EXTENDED_GLOB} option. All take the form
@t{(#}@var{X}@t{)} where @var{X} may have one of the following
forms:

@noindent
@table @asis
@item i
Case insensitive:  upper or lower case characters in the pattern match
upper or lower case characters.

@item l
Lower case characters in the pattern match upper or lower case
characters; upper case characters in the pattern still only match
upper case characters.

@item I
Case sensitive:  locally negates the effect of @t{i} or @t{l} from
that point on.

@item b
Activate backreferences for parenthesised groups in the pattern;
this does not work in filename generation.  When a pattern with a set of
active parentheses is matched, the strings matched by the groups are
stored in the array @t{$match}, the indices of the beginning of the matched
parentheses in the array @t{$mbegin}, and the indices of the end in the array
@t{$mend}, with the first element of each array corresponding to the first
parenthesised group, and so on.  These arrays are not otherwise special to
the shell.  The indices use the same convention as does parameter
substitution, so that elements of @t{$mend} and @t{$mbegin} may be used in
subscripts; the @t{KSH_ARRAYS} option is respected.  Sets of globbing flags
are not considered parenthesised groups; only the first nine active
parentheses can be referenced.

@noindent
For example,

@noindent
@example
foo="a string with a message"
if [[ $foo = (a|an)' '(#b)(*)' '* ]]; then
  print $@{foo[$mbegin[1],$mend[1]]@}
fi
@end example

@noindent
prints `@t{string with a}'.  Note that the first parenthesis is before the
@t{(#b)} and does not create a backreference.

@noindent
Backreferences work with all forms of pattern matching other than filename
generation, but note that when performing matches on an entire array, such
as @t{$@{}@var{array}@t{#}@var{pattern}@t{@}}, or a global substitution, such
as @t{$@{}@var{param}@t{//}@var{pat}@t{/}@var{repl}@t{@}}, only the data for the
last match remains available.  In the case of global replacements this may
still be useful.  See the example for the @t{m} flag below.

@noindent
The numbering of backreferences strictly follows the order of the opening
parentheses from left to right in the pattern string, although sets of
parentheses may be nested.  There are special rules for parentheses followed
by `@t{#}' or `@t{##}'.  Only the last match of the parenthesis is
remembered: for example, in `@t{[[ abab = (#b)([ab])# ]]}', only the final
`@t{b}' is stored in @t{match[1]}.  Thus extra parentheses may be necessary
to match the complete segment: for example, use `@t{X((ab|cd)#)Y}' to match
a whole string of either `@t{ab}' or `@t{cd}' between `@t{X}' and `@t{Y}',
using the value of @t{$match[1]} rather than @t{$match[2]}.

@noindent
If the match fails none of the parameters is altered, so in some cases it
may be necessary to initialise them beforehand.  If some of the
backreferences fail to match --- which happens if they are in an alternate
branch which fails to match, or if they are followed by @t{#} and matched
zero times --- then the matched string is set to the empty string, and the
start and end indices are set to -1.

@noindent
Pattern matching with backreferences is slightly slower than without.

@item B
Deactivate backreferences, negating the effect of the @t{b} flag from that
point on.

@item m
Set references to the match data for the entire string matched; this is
similar to backreferencing and does not work in filename generation.  The
flag must be in effect at the end of the pattern, i.e. not local to a
group. The parameters @t{$MATCH},  @t{$MBEGIN} and @t{$MEND} will be set to
the string matched and to the indices of the beginning and end of the
string, respectively.  This is most useful in parameter substitutions, as
otherwise the string matched is obvious.

@noindent
For example,

@noindent
@example
arr=(veldt jynx grimps waqf zho buck)
print $@{arr//(#m)[aeiou]/$@{(U)MATCH@}@}
@end example

@noindent
forces all the matches (i.e. all vowels) into uppercase, printing
`@t{vEldt jynx grImps wAqf zhO bUck}'.

@noindent
Unlike backreferences, there is no speed penalty for using match
references, other than the extra substitutions required for the
replacement strings in cases such as the example shown.

@item M
Deactivate the @t{m} flag, hence no references to match data will be
created.

@item @t{a}@var{num}
Approximate matching: @var{num} errors are allowed in the string matched by
the pattern.  The rules for this are described in the next subsection.

@item @t{s}, @t{e}
Unlike the other flags, these have only a local effect, and each must
appear on its own:  `@t{(#s)}' and `@t{(#e)}' are the only valid forms.
The `@t{(#s)}' flag succeeds only at the start of the test string, and the
`@t{(#e)}' flag succeeds only at the end of the test string; they
correspond to `@t{^}' and `@t{$}' in standard regular expressions.  They
are useful for matching path segments in patterns other than those in
filename generation (where path segments are in any case treated
separately).  For example, `@t{*((#s)|/)test((#e)|/)*}' matches a path
segment `@t{test}' in any of the following strings: @t{test},
@t{test/at/start}, @t{at/end/test}, @t{in/test/middle}.

@noindent
Another use is in parameter substitution; for example
`@t{$@{array/(#s)A*Z(#e)@}}' will remove only elements of an array which
match the complete pattern `@t{A*Z}'.  There are other ways of performing
many operations of this type, however the combination of the substitution
operations `@t{/}' and `@t{//}' with the `@t{(#s)}' and `@t{(#e)}' flags
provides a single simple and memorable method.

@noindent
Note that assertions of the form `@t{(^(#s))}' also work, i.e. match
anywhere except at the start of the string, although this actually means
`anything except a zero-length portion at the start of the string'; you
need to use `@t{(""~(#s))}' to match a zero-length portion of the string
not at the start.

@end table

@noindent
For example, the test string @t{fooxx} can be matched by the pattern
@t{(#i}@t{)FOOXX}, but not by @t{(#l}@t{)FOOXX},
@t{(#i}@t{)FOO}@t{(#I}@t{)XX} or
@t{((#i}@t{)FOOX}@t{)X}.  The string
@t{(#ia2}@t{)readme} specifies case-insensitive matching of
@t{readme} with up to two errors.

@noindent
When using the ksh syntax for grouping both @t{KSH_GLOB} and
@t{EXTENDED_GLOB} must be set and the left parenthesis should be
preceded by @t{@@}.  Note also that the flags do not affect letters
inside @t{[...]} groups, in other words @t{(#i}@t{)[a-z]}
still matches only lowercase letters.  Finally, note that when
examining whole paths case-insensitively every directory must be
searched for all files which match, so that a pattern of the form
@t{(#i}@t{)/foo/bar/...} is potentially slow.

@noindent

@subsection Approximate Matching
@noindent
When matching approximately, the shell keeps a count of the errors found,
which cannot exceed the number specified in the
@t{(#a}@var{num}@t{)} flags.  Four types of error are recognised:

@noindent
@table @asis
@item 1.
Different characters, as in @t{fooxbar} and @t{fooybar}.

@item 2.
Transposition of characters, as in @t{banana} and @t{abnana}.

@item 3.
A character missing in the target string, as with the pattern @t{road} and
target string @t{rod}.

@item 4.
An extra character appearing in the target string, as with @t{stove}
and @t{strove}.

@end table

@noindent
Thus, the pattern @t{(#a3}@t{)abcd} matches @t{dcba}, with the
errors occurring by using the first rule twice and the second once,
grouping the string as @t{[d][cb][a]} and @t{[a][bc][d]}.

@noindent
Non-literal parts of the pattern must match exactly, including characters
in character ranges: hence @t{(#a1}@t{)???}  matches strings of
length four, by applying rule 4 to an empty part of the pattern, but not
strings of length two, since all the @t{?} must match.  Other characters
which must match exactly are initial dots in filenames (unless the
@t{GLOB_DOTS} option is set), and all slashes in filenames, so that
@t{a/bc} is two errors from @t{ab/c} (the slash cannot be transposed with
another character).  Similarly, errors are counted separately for
non-contiguous strings in the pattern, so that @t{(ab|cd}@t{)ef}
is two errors from @t{aebf}.

@noindent
When using exclusion via the @t{~} operator, approximate matching is
treated entirely separately for the excluded part and must be activated
separately.  Thus, @t{(#a1}@t{)README~READ_ME} matches
@t{READ.ME} but not @t{READ_ME}, as the trailing @t{READ_ME} is matched
without approximation.  However,
@t{(#a1}@t{)README~(#a1}@t{)READ_ME}
does not match any pattern of the form @t{READ}@var{?}@t{ME} as all
such forms are now excluded.

@noindent
Apart from exclusions, there is only one overall error count; however, the
maximum errors allowed may be altered locally, and this can be delimited by
grouping.  For example,
@t{(#a1}@t{)cat}@t{((#a0}@t{)dog}@t{)fox}
allows one error in total, which may not occur in the @t{dog} section, and
the pattern
@t{(#a1}@t{)cat}@t{(#a0}@t{)dog}@t{(#a1}@t{)fox}
is equivalent.  Note that the point at which an error is first found is the
crucial one for establishing whether to use approximation; for example,
@t{(#a1)abc(#a0)xyz} will not match @t{abcdxyz}, because the error occurs
at the `@t{x}', where approximation is turned off.

@noindent
Entire path segments may be matched approximately, so that
`@t{(#a1)/foo/d/is/available/at/the/bar}' allows one error in any path
segment.  This is much less efficient than without the @t{(#a1)}, however,
since every directory in the path must be scanned for a possible
approximate match.  It is best to place the @t{(#a1)} after any path
segments which are known to be correct.

@noindent

@subsection Recursive Globbing
@noindent
A pathname component of the form `@t{(}@var{foo}@t{/)#}'
matches a path consisting of zero or more directories
matching the pattern @var{foo}.

@noindent
As a shorthand, `@t{**/}' is equivalent to `@t{(*/)#}'; note that this
therefore matches files in the current directory as well as
subdirectories.
Thus:

@noindent
@example
ls (*/)#bar
@end example

@noindent
or

@noindent
@example
ls **/bar
@end example

@noindent
does a recursive directory search for files named `@t{bar}' (potentially
including the file `@t{bar}' in the current directory).  This form does not
follow symbolic links; the alternative form `@t{***/}' does, but is
otherwise identical.  Neither of these can be combined with other forms of
globbing within the same path segment; in that case, the `@t{*}'
operators revert to their usual effect.

@subsection Glob Qualifiers
@noindent
@cindex globbing, qualifiers
@cindex qualifiers, globbing
Patterns used for filename generation may end in a
list of qualifiers enclosed in parentheses.
The qualifiers specify which filenames that otherwise match the given pattern
will be inserted in the argument list.

@noindent
@pindex BARE_GLOB_QUAL, use of
If the option @t{BARE_GLOB_QUAL} is set, then a trailing set of parentheses
containing no `@t{|}' or `@t{(}' characters (or `@t{~}' if it is special)
is taken as a set of
glob qualifiers.  A glob subexpression that would normally be taken as glob
qualifiers, for example `@t{(^x)}', can be forced to be treated as part of
the glob pattern by doubling the parentheses, in this case producing
`@t{((^x))}'.

@noindent
A qualifier may be any one of the following:

@noindent
@table @asis
@item @t{/}
directories

@item @t{.}
plain files

@item @t{@@}
symbolic links

@item @t{=}
sockets

@item @t{p}
named pipes (FIFOs)

@item @t{*}
executable plain files (0100)

@item @t{%}
device files (character or block special)

@item @t{%b}
block special files

@item @t{%c}
character special files

@item @t{r}
owner-readable files (0400)

@item @t{w}
owner-writable files (0200)

@item @t{x}
owner-executable files (0100)

@item @t{A}
group-readable files (0040)

@item @t{I}
group-writable files (0020)

@item @t{E}
group-executable files (0010)

@item @t{R}
world-readable files (0004)

@item @t{W}
world-writable files (0002)

@item @t{X}
world-executable files (0001)

@item @t{s}
setuid files (04000)

@item @t{S}
setgid files (02000)

@item @t{t}
files with the sticky bit (01000)

@item @t{f}@var{spec}
files with access rights matching @var{spec}. This @var{spec} may be a
octal number optionally preceded by a `@t{=}', a `@t{+}', or a
`@t{-}'. If none of these characters is given, the behavior is the
same as for `@t{=}'. The octal number describes the mode bits to be
expected, if combined with a `@t{=}', the value given must match the
file-modes exactly, with a `@t{+}', at least the bits in the
given number must be set in the file-modes, and with a `@t{-}', the
bits in the number must not be set. Giving a `@t{?}' instead of a
octal digit anywhere in the number ensures that the corresponding bits 
in the file-modes are not checked, this is only useful in combination
with `@t{=}'.

@noindent
If the qualifier `@t{f}' is followed by any other character anything
up to the next matching character (`@t{[}', `@t{@{}', and `@t{<}' match 
`@t{]}', `@t{@}}', and `@t{>}' respectively, any other character
matches itself) is taken as a list of comma-separated
@var{sub-spec}s. Each @var{sub-spec} may be either an octal number as
described above or a list of any of the characters `@t{u}', `@t{g}',
`@t{o}', and `@t{a}', followed by a `@t{=}', a `@t{+}', or a
`@t{-}', followed by a list of any of the characters `@t{r}', `@t{w}', 
`@t{x}', `@t{s}', and `@t{t}', or an octal digit. The first list of
characters specify which access rights are to be checked. If a `@t{u}'
is given, those for the owner of the file are used, if a `@t{g}' is
given, those of the group are checked, a `@t{o}' means to test those
of other users, and the `@t{a}' says to test all three groups. The
`@t{=}', `@t{+}', and `@t{-}' again says how the modes are to be
checked and have the same meaning as described for the first form
above. The second list of characters finally says which access rights
are to be expected: `@t{r}' for read access, `@t{w}' for write access, 
`@t{x}' for the right to execute the file (or to search a directory),
`@t{s}' for the setuid and setgid bits, and `@t{t}' for the sticky
bit.

@noindent
Thus, `@t{*(f70?)}' gives the files for which the owner has read,
write, and execute permission, and for which other group members have
no rights, independent of the permissions for other users. The pattern
`@t{*(f-100)}' gives all files for which the owner does not have
execute permission, and `@t{*(f:gu+w,o-rx:)}' gives the files for which 
the owner and the other members of the group have at least write
permission, and for which other users don't have read or execute
permission.

@item @t{e}@var{string}
The @var{string} will be executed as shell code.  The filename will be
included in the list if and only if the code returns a zero status (usually
the status of the last command).  The first character after the `@t{e}'
will be used as a separator and anything up to the next matching separator
will be taken  as the @var{string}; `@t{[}', `@t{@{}', and `@t{<}' match
`@t{]}', `@t{@}}', and `@t{>}', respectively, while any other character
matches itself. Note that expansions must be quoted in the @var{string}
to prevent them from being expanded before globbing is done.

@noindent
@vindex REPLY, use of
@vindex reply, use of
During the execution of @var{string} the filename currently being tested is
available in the parameter @t{REPLY}; the parameter may be altered to
a string to be inserted into the list instead of the original
filename.  In addition, the parameter @t{reply} may be set to an array or a
string, which overrides the value of @t{REPLY}.  If set to an array, the
latter is inserted into the command line word by word.

@noindent
For example, suppose a directory contains a single file `@t{lonely}'.  Then
the expression `@t{*(e:'reply=($@{REPLY@}@{1,2@})':)}' will cause the words
`@t{lonely1 lonely2}' to be inserted into the command line.  Note the
quotation marks.

@item @t{d}@var{dev}
files on the device @var{dev}

@item @t{l}[@t{-}|@t{+}]@var{ct}
files having a link count less than @var{ct} (@t{-}), greater than
@var{ct} (@t{+}), or equal to @var{ct}

@item @t{U}
files owned by the effective user ID

@item @t{G}
files owned by the effective group ID

@item @t{u}@var{id}
files owned by user ID @var{id} if it is a number, if not, than the
character after the `@t{u}' will be used as a separator and the string
between it and the next matching separator
(`@t{[}', `@t{@{}', and `@t{<}'
match `@t{]}', `@t{@}}', and `@t{>}' respectively,
any other character matches
itself) will be taken as a user name, and the user ID of this user will
be taken (e.g. `@t{u:foo:}' or `@t{u[foo]}' for user `@t{foo}')

@item @t{g}@var{id}
like @t{u}@var{id} but with group IDs or names

@item @t{a}[@t{Mwhms}][@t{-}|@t{+}]@var{n}
files accessed exactly @var{n} days ago.  Files accessed within the last
@var{n} days are selected using a negative value for @var{n} (@t{-}@var{n}).
Files accessed more than @var{n} days ago are selected by a positive @var{n}
value (@t{+}@var{n}).  Optional unit specifiers `@t{M}', `@t{w}',
`@t{h}', `@t{m}' or `@t{s}' (e.g. `@t{ah5}') cause the check to be
performed with months (of 30 days), weeks, hours, minutes or seconds
instead of days, respectively.  For instance, `@t{echo *(ah-5)}' would
echo files accessed within the last five hours.

@item @t{m}[@t{Mwhms}][@t{-}|@t{+}]@var{n}
like the file access qualifier, except that it uses the file modification
time.

@item @t{c}[@t{Mwhms}][@t{-}|@t{+}]@var{n}
like the file access qualifier, except that it uses the file inode change
time.

@item @t{L}[@t{+}|@t{-}]@var{n}
files less than @var{n} bytes (@t{-}), more than @var{n} bytes (@t{+}), or
exactly @var{n} bytes in length. If this flag is directly followed by a `@t{k}'
(`@t{K}'), `@t{m}' (`@t{M}'), or `@t{p}' (`@t{P}') (e.g. `@t{Lk-50}')
the check is performed with kilobytes, megabytes, or blocks (of 512 bytes)
instead.

@item @t{^}
negates all qualifiers following it

@item @t{-}
toggles between making the qualifiers work on symbolic links (the
default) and the files they point to

@item @t{M}
sets the @t{MARK_DIRS} option for the current pattern
@pindex MARK_DIRS, setting in pattern

@item @t{T}
appends a trailing qualifier mark to the filenames, analogous to the
@t{LIST_TYPES} option, for the current pattern (overrides @t{M})

@item @t{N}
sets the @t{NULL_GLOB} option for the current pattern
@pindex NULL_GLOB, setting in pattern

@item @t{D}
sets the @t{GLOB_DOTS} option for the current pattern
@pindex GLOB_DOTS, setting in pattern

@item @t{n}
sets the @t{NUMERIC_GLOB_SORT} option for the current pattern
@pindex NUMERIC_GLOB_SORT, setting in pattern

@item @t{o}@var{c}
specifies how the names of the files should be sorted. If @var{c} is
@t{n} they are sorted by name (the default); if it is @t{L} they
are sorted depending on the size (length) of the files; if @t{l} 
they are sorted by the number of links; if @t{a}, @t{m}, or @t{c}
they are sorted by the time of the last access, modification, or
inode change respectively; if @t{d}, files in subdirectories appear before
those in the current directory at each level of the search --- this is best
combined with other criteria, for example `@t{odon}' to sort on names for
files within the same directory.  Note that @t{a}, @t{m}, and @t{c} compare
the age against the current time, hence the first name in the list is the
youngest file. Also note that the modifiers @t{^} and @t{-} are used,
so `@t{*(^-oL)}' gives a list of all files sorted by file size in descending
order, following any symbolic links.

@item @t{O}@var{c}
like `@t{o}', but sorts in descending order; i.e. `@t{*(^oc)}' is the
same as `@t{*(Oc)}' and `@t{*(^Oc)}' is the same as `@t{*(oc)}'; `@t{Od}'
puts files in the current directory before those in subdirectories at each
level of the search.

@item @t{[}@var{beg}[@t{,}@var{end}]@t{]}
specifies which of the matched filenames should be included in the
returned list. The syntax is the same as for array
subscripts. @var{beg} and the optional @var{end} may be mathematical
expressions. As in parameter subscripting they may be negative to make 
them count from the last match backward. E.g.: `@t{*(-OL[1,3])}'
gives a list of the names of the three largest files.

@end table

@noindent
More than one of these lists can be combined, separated by commas. The
whole list matches if at least one of the sublists matches (they are
`or'ed, the qualifiers in the sublists are `and'ed).  Some qualifiers,
however, affect all matches generated, independent of the sublist in
which they are given.  These are the qualifiers `@t{M}', `@t{T}',
`@t{N}', `@t{D}', `@t{n}', `@t{o}', `@t{O}' and the subscripts given
in brackets (`@t{[...]}').

@noindent
If a `@t{:}' appears in a qualifier list, the remainder of the expression in
parenthesis is interpreted as a modifier (see @ref{Modifiers}
in @ref{History Expansion}).  Note that
each modifier must be introduced by a separate `@t{:}'.  Note also that the
result after modification does not have to be an existing file.  The
name of any existing file can be followed by a modifier of the form
`@t{(:..)}' even if no actual filename generation is performed.
Thus:

@noindent
@example
ls *(-/)
@end example

@noindent
lists all directories and symbolic links that point to directories,
and

@noindent
@example
ls *(%W)
@end example

@noindent
lists all world-writable device files in the current directory, and

@noindent
@example
ls *(W,X)
@end example

@noindent
lists all files in the current directory that are
world-writable or world-executable, and

@noindent
@example
echo /tmp/foo*(u0^@@:t)
@end example

@noindent
outputs the basename of all root-owned files beginning with the string
`@t{foo}' in @t{/tmp}, ignoring symlinks, and

@noindent
@example
ls *.*~(lex|parse).[ch](^D^l1)
@end example

@noindent
lists all files having a link count of one whose names contain a dot
(but not those starting with a dot, since @t{GLOB_DOTS} is explicitly
switched off) except for @t{lex.c}, @t{lex.h}, @t{parse.c} and @t{parse.h}.
@c (avoiding a yodl bug)
@c Yodl file: Zsh/params.yo
@node Parameters, Options, Expansion, Top

@chapter Parameters
@noindent
@cindex parameters

@section Description
@noindent
A parameter has a name, a value, and a number of attributes.
A name may be any sequence of alphanumeric
characters and underscores, or the single characters
`@t{*}', `@t{@@}', `@t{#}', `@t{?}', `@t{-}', `@t{$}', or `@t{!}'.
The value may be a @emph{scalar} (a string),
an integer, an array (indexed numerically), or an @emph{associative}
array (an unordered set of name-value pairs, indexed by name).  To declare
the type of a parameter, or to assign a scalar or integer value to a
parameter, use the @t{typeset} builtin.
@findex typeset, use of

@noindent
The value of a scalar or integer parameter may also be assigned by
writing:
@cindex assignment

@noindent
@quotation
@var{name}@t{=}@var{value}
@end quotation

@noindent
If the integer attribute, @t{-i}, is set for @var{name}, the @var{value}
is subject to arithmetic evaluation.  See @ref{Array Parameters}
for additional forms of assignment.

@noindent
To refer to the value of a parameter, write `@t{$}@var{name}' or
`@t{$@{}@var{name}@t{@}}'.  See
@ref{Parameter Expansion}
for complete details.

@noindent
In the parameter lists that follow, the mark `<S>' indicates that the
parameter is special.
Special parameters cannot have their type changed, and they stay special even
if unset.  `<Z>' indicates that the parameter does not exist when the shell
initializes in @t{sh} or @t{ksh} emulation mode.
@menu
* Array Parameters::
* Positional Parameters::
* Local Parameters::
* Parameters Set By The Shell::
* Parameters Used By The Shell::
@end menu
@node Array Parameters, Positional Parameters, , Parameters

@section Array Parameters
@noindent
To assign an array value, write one of:
@findex set, use of
@cindex array assignment

@noindent
@quotation
@t{set -A} @var{name} @var{value} ...
@end quotation
@quotation
@var{name}@t{=(}@var{value} ...@t{)}
@end quotation

@noindent
If no parameter @var{name} exists, an ordinary array parameter is created.
If the parameter @var{name} exists and is a scalar, it is replaced by a new
array.  Ordinary array parameters may also be explicitly declared with:
@findex typeset, use of

@noindent
@quotation
@t{typeset -a} @var{name}
@end quotation

@noindent
Associative arrays @emph{must} be declared before assignment, by using:

@noindent
@quotation
@t{typeset -A} @var{name}
@end quotation

@noindent
When @var{name} refers to an associative array, the list in an assignment
is interpreted as alternating keys and values:

@noindent
@quotation
set -A @var{name} @var{key} @var{value} ...
@end quotation
@quotation
@var{name}@t{=(}@var{key} @var{value} ...@t{)}
@end quotation

@noindent
Every @var{key} must have a @var{value} in this case.  Note that this
assigns to the entire array, deleting any elements that do not appear
in the list.

@noindent
To create an empty array (including associative arrays), use one of:

@noindent
@quotation
@t{set -A} @var{name}
@end quotation
@quotation
@var{name}@t{=()}
@end quotation

@noindent

@subsection Array Subscripts
@noindent
@cindex subscripts

@noindent
Individual elements of an array may be selected using a subscript.  A
subscript of the form `@t{[}@var{exp}@t{]}' selects the single element
@var{exp}, where @var{exp} is an arithmetic expression which will be subject
to arithmetic expansion as if it were surrounded by
`@t{$((}...@t{))}'.  The elements are numbered
beginning with 1, unless the @t{KSH_ARRAYS} option is set in which case
they are numbered from zero.
@pindex KSH_ARRAYS, use of

@noindent
Subscripts may be used inside braces used to delimit a parameter name, thus
`@t{$@{foo[2]@}}' is equivalent to `@t{$foo[2]}'.  If the @t{KSH_ARRAYS}
option is set, the braced form is the only one that works, as bracketed
expressions otherwise are not treated as subscripts.

@noindent
The same subscripting syntax is used for associative arrays, except that
no arithmetic expansion is applied to @var{exp}.  However, the parsing
rules for arithmetic expressions still apply, which affects the way that
certain special characters must be protected from interpretation.  See
@emph{Subscript Parsing} below for details.

@noindent
A subscript of the form `@t{[*]}' or `@t{[@@]}' evaluates to all elements
of an array; there is no difference between the two except when they
appear within double quotes.
`@t{"$foo[*]"}' evaluates to `@t{"$foo[1] $foo[2] }...@t{"}', whereas
`@t{"$foo[@@]"}' evaluates to `@t{"$foo[1]" "$foo[2]" }...'.  For
associative arrays, `@t{[*]}' or `@t{[@@]}' evaluate to all the values (not
the keys, but see @emph{Subscript Flags} below), in no particular order.
When an array parameter is referenced as `@t{$}@var{name}' (with no
subscript) it evaluates to `@t{$}@var{name}@t{[*]}', unless the @t{KSH_ARRAYS}
option is set in which case it evaluates to `@t{$@{}@var{name}@t{[0]@}}' (for
an associative array, this means the value of the key `@t{0}', which may
not exist even if there are values for other keys).

@noindent
A subscript of the form `@t{[}@var{exp1}@t{,}@var{exp2}@t{]}'
selects all elements in the range @var{exp1} to @var{exp2},
inclusive. (Associative arrays are unordered, and so do not support
ranges.) If one of the subscripts evaluates to a negative number,
say @t{-}@var{n}, then the @var{n}th element from the end
of the array is used.  Thus `@t{$foo[-3]}' is the third element
from the end of the array @t{foo}, and
`@t{$foo[1,-1]}' is the same as `@t{$foo[*]}'.

@noindent
Subscripting may also be performed on non-array values, in which
case the subscripts specify a substring to be extracted.
For example, if @t{FOO} is set to `@t{foobar}', then
`@t{echo $FOO[2,5]}' prints `@t{ooba}'.

@noindent

@subsection Array Element Assignment
@noindent

@noindent
A subscript may be used on the left side of an assignment like so:

@noindent
@quotation
@var{name}@t{[}@var{exp}@t{]=}@var{value}
@end quotation

@noindent
In this form of assignment the element or range specified by @var{exp}
is replaced by the expression on the right side.  An array (but not an
associative array) may be created by assignment to a range or element.
Arrays do not nest, so assigning a parenthesized list of values to an
element or range changes the number of elements in the array, shifting the
other elements to accommodate the new values.  (This is not supported for
associative arrays.)

@noindent
This syntax also works as an argument to the @t{typeset} command:

@noindent
@quotation
@t{typeset} @t{"}@var{name}@t{[}@var{exp}@t{]"=}@var{value}
@end quotation

@noindent
The @var{value} may @emph{not} be a parenthesized list in this case; only
single-element assignments may be made with @t{typeset}.  Note that quotes
are necessary in this case to prevent the brackets from being interpreted
as filename generation operators.  The @t{noglob} precommand modifier
could be used instead.

@noindent
To delete an element of an ordinary array, assign `@t{()}' to
that element.  To delete an element of an associative array, use the
@t{unset} command:

@noindent
@quotation
@t{unset} @t{"}@var{name}@t{[}@var{exp}@t{]"}
@end quotation

@noindent

@subsection Subscript Flags
@noindent
@cindex subscript flags

@noindent
If the opening bracket, or the comma in a range, in any subscript
expression is directly followed by an opening parenthesis, the string up
to the matching closing one is considered to be a list of flags, as in
`@var{name}@t{[(}@var{flags}@t{)}@var{exp}@t{]}'.  The flags
currently understood are:

@noindent
@table @asis
@item @t{w}
If the parameter subscripted is a scalar than this flag makes
subscripting work on words instead of characters.  The default word
separator is whitespace.

@item @t{s:}@var{string}@t{:}
This gives the @var{string} that separates words (for use with the
@t{w} flag).

@item @t{p}
Recognize the same escape sequences as the @t{print} builtin in
the string argument of a subsequent `@t{s}' flag.

@item @t{f}
If the parameter subscripted is a scalar than this flag makes
subscripting work on lines instead of characters, i.e. with elements
separated by newlines.  This is a shorthand for `@t{pws:\n:}'.

@item @t{r}
Reverse subscripting: if this flag is given, the @var{exp} is taken as a
pattern and the result is the first matching array element, substring or
word (if the parameter is an array, if it is a scalar, or if it is a
scalar and the `@t{w}' flag is given, respectively).  The subscript used
is the number of the matching element, so that pairs of subscripts such as
`@t{$foo[(r)}@var{??}@t{,3]}' and `@t{$foo[(r)}@var{??}@t{,(r)f*]}' are
possible.  If the parameter is an associative array, only the value part
of each pair is compared to the pattern, and the result is that value.
Reverse subscripts may be used for assigning to ordinary array elements,
but not for assigning to associative arrays.

@item @t{R}
Like `@t{r}', but gives the last match.  For associative arrays, gives
all possible matches.

@item @t{i}
Like `@t{r}', but gives the index of the match instead; this may not be
combined with a second argument.  On the left side of an assignment,
behaves like `@t{r}'.  For associative arrays, the key part of each pair
is compared to the pattern, and the first matching key found is the
result.

@item @t{I}
Like `@t{i}', but gives the index of the last match, or all possible
matching keys in an associative array.

@item @t{k}
If used in a subscript on an associative array, this flag causes the keys
to be interpreted as patterns, and returns the value for the first key
found where @var{exp} is matched by the key.  This flag does not work on
the left side of an assignment to an associative array element.  If used
on another type of parameter, this behaves like `@t{r}'.

@item @t{K}
On an associative array this is like `@t{k}' but returns all values where
@var{exp} is matched by the keys.  On other types of parameters this has
the same effect as `@t{R}'.

@item @t{n:}@var{expr}@t{:}
If combined with `@t{r}', `@t{R}', `@t{i}' or `@t{I}', makes them give
the @var{n}th or @var{n}th last match (if @var{expr} evaluates to
@var{n}).  This flag is ignored when the array is associative.

@item @t{b:}@var{expr}@t{:}
If combined with `@t{r}', `@t{R}', `@t{i}' or `@t{I}', makes them begin
at the @var{n}th or @var{n}th last element, word, or character (if @var{expr}
evaluates to @var{n}).  This flag is ignored when the array is associative.

@item @t{e}
This flag has no effect and for ordinary arrays is retained for backward
compatibility only.  For associative arrays, this flag can be used to
force @t{*} or @t{@@} to be interpreted as a single key rather than as a
reference to all values.  This flag may be used on the left side of an
assignment.

@end table

@noindent
See @emph{Parameter Expansion Flags} (@ref{Parameter Expansion}) for additional ways to manipulate the results of array subscripting.

@noindent

@subsection Subscript Parsing
@noindent

@noindent
This discussion applies mainly to associative array key strings and to
patterns used for reverse subscripting (the `@t{r}', `@t{R}', `@t{i}',
etc. flags), but it may also affect parameter substitutions that appear
as part of an arithmetic expression in an ordinary subscript.

@noindent
The basic rule to remember when writing a subscript expression is that all
text between the opening `@t{[}' and the closing `@t{]}' is interpreted
@emph{as if} it were in double quotes (@ref{Quoting}).  However, unlike double quotes which normally cannot nest, subscript
expressions may appear inside double-quoted strings or inside other
subscript expressions (or both!), so the rules have two important
differences.

@noindent
The first difference is that brackets (`@t{[}' and `@t{]}') must appear as
balanced pairs in a subscript expression unless they are preceded by a
backslash (`@t{\}').  Therefore, within a subscript expression (and unlike
true double-quoting) the sequence `@t{\[}' becomes `@t{[}', and similarly
`@t{\]}' becomes `@t{]}'.  This applies even in cases where a backslash is
not normally required; for example, the pattern `@t{[^[]}' (to match any
character other than an open bracket) should be written `@t{[^\[]}' in a
reverse-subscript pattern.  However, note that `@t{\[^\[\]}' and even
`@t{\[^[]}' mean the @emph{same} thing, because backslashes are always
stripped when they appear before brackets!

@noindent
The same rule applies to parentheses (`@t{(}' and `@t{)}') and
braces (`@t{@{}' and `@t{@}}'): they must appear either in balanced pairs or
preceded by a backslash, and backslashes that protect parentheses or
braces are removed during parsing.  This is because parameter expansions
may be surrounded balanced braces, and subscript flags are introduced by
balanced parenthesis.

@noindent
The second difference is that a double-quote (`@t{"}') may appear as part
of a subscript expression without being preceded by a backslash, and
therefore that the two characters `@t{\"}' remain as two characters in the
subscript (in true double-quoting, `@t{\"}' becomes `@t{"}').  However,
because of the standard shell quoting rules, any double-quotes that appear
must occur in balanced pairs unless preceded by a backslash.  This makes
it more difficult to write a subscript expression that contains an odd
number of double-quote characters, but the reason for this difference is
so that when a subscript expression appears inside true double-quotes, one
can still write `@t{\"}' (rather than `@t{\\\"}') for `@t{"}'.

@noindent
To use an odd number of double quotes as a key in an assignment, use the
@t{typeset} builtin and an enclosing pair of double quotes; to refer to
the value of that key, again use double quotes:

@noindent
@example
typeset -A aa
typeset "aa[one\"two\"three\"quotes]"=QQQ
print "$aa[one\"two\"three\"quotes]"
@end example

@noindent
It is important to note that the quoting rules do not change when a
parameter expansion with a subscript is nested inside another subscript
expression.  That is, it is not necessary to use additional backslashes
within the inner subscript expression; they are removed only once, from
the innermost subscript outwards.  Parameters are also expanded from the
innermost subscript first, as each expansion is encountered left to right
in the outer expression.

@noindent
A further complication arises from a way in which subscript parsing is
@emph{not} different from double quote parsing.  As in true double-quoting,
the sequences `@t{\*}', and `@t{\@@}' remain as two characters when they
appear in a subscript expression.  To use a literal `@t{*}' or `@t{@@}' as
an associative array key, the `@t{e}' flag must be used:

@noindent
@example
typeset -A aa
aa[(e)*]=star
print $aa[(e)*]
@end example

@noindent
A last detail must be considered when reverse subscripting is performed.
Parameters appearing in the subscript expression are first expanded and
then the complete expression is interpreted as a pattern.  This has two
effects: first, parameters behave as if @t{GLOB_SUBST} were on (and it
cannot be turned off); second, backslashes are interpreted twice, once
when parsing the array subscript and again when parsing the pattern.  In a
reverse subscript, it's necessary to use @emph{four} backslashes to cause a
single backslash to match literally in the pattern.  For complex patterns,
it is often easiest to assign the desired pattern to a parameter and then
refer to that parameter in the subscript, because then the backslashes,
brackets, parentheses, etc., are seen only when the complete expression is
converted to a pattern.  To match the value of a parameter literally in a
reverse subscript, rather than as a pattern,
use `@t{$@{(q}@t{)}@var{name}@t{@}}' (@ref{Parameter Expansion}) to quote the expanded value.

@noindent
Note that the `@t{k}' and `@t{K}' flags are reverse subscripting for an
ordinary array, but are @emph{not} reverse subscripting for an associative
array!  (For an associative array, the keys in the array itself are
interpreted as patterns by those flags; the subscript is a plain string
in that case.)

@noindent
One final note, not directly related to subscripting: the numeric names
of positional parameters (@ref{Positional Parameters}) are parsed specially, so for example `@t{$2foo}' is equivalent to
`@t{$@{2@}foo}'.  Therefore, to use subscript syntax to extract a substring
from a positional parameter, the expansion must be surrounded by braces;
for example, `@t{$@{2[3,5]@}}' evaluates to the third through fifth
characters of the second positional parameter, but `@t{$2[3,5]}' is the
entire second parameter concatenated with the filename generation pattern
`@t{[3,5]}'.

@noindent
@node Positional Parameters, Local Parameters, Array Parameters, Parameters

@section Positional Parameters
@noindent
The positional parameters provide access to the command-line arguments
of a shell function, shell script, or the shell itself; see
@ref{Invocation}, and also @ref{Functions}.
The parameter @var{n}, where @var{n} is a number,
is the @var{n}th positional parameter.
The parameters @t{*}, @t{@@} and @t{argv} are
arrays containing all the positional parameters;
thus `@t{$argv[}@var{n}@t{]}', etc., is equivalent to simply `@t{$}@var{n}'.

@noindent
Positional parameters may be changed after the shell or function starts by
using the @t{set} builtin, by assigning to the @t{argv} array, or by direct
assignment of the form `@var{n}@t{=}@var{value}' where @var{n} is the number of
the positional parameter to be changed.  This also creates (with empty
values) any of the positions from 1 to @var{n} that do not already have
values.  Note that, because the positional parameters form an array, an
array assignment of the form `@var{n}@t{=(}@var{value} ...@t{)}' is
allowed, and has the effect of shifting all the values at positions greater
than @var{n} by as many positions as necessary to accommodate the new values.

@noindent
@node Local Parameters, Parameters Set By The Shell, Positional Parameters, Parameters

@section Local Parameters
@noindent
Shell function executions delimit scopes for shell parameters.
(Parameters are dynamically scoped.)  The @t{typeset} builtin, and its
alternative forms @t{declare}, @t{integer}, @t{local} and @t{readonly}
(but not @t{export}), can be used to declare a parameter as being local
to the innermost scope.

@noindent
When a parameter is read or assigned to, the
innermost existing parameter of that name is used.  (That is, the
local parameter hides any less-local parameter.)  However, assigning
to a non-existent parameter, or declaring a new parameter with @t{export},
causes it to be created in the @emph{outer}most scope.

@noindent
Local parameters disappear when their scope ends.
@t{unset} can be used to delete a parameter while it is still in scope;
any outer parameter of the same name remains hidden.

@noindent
Special parameters may also be made local; they retain their special
attributes unless either the existing or the newly-created parameter
has the @t{-h} (hide) attribute.  This may have unexpected effects:
there is no default value, so if there is no assignment at the
point the variable is made local, it will be set to an empty value (or zero
in the case of integers).  
The following:

@noindent
@example
typeset PATH=/new/directory:$PATH
@end example

@noindent
is valid for temporarily allowing the shell or programmes called from it to
find the programs in @t{/new/directory} inside a function.

@noindent
Note that the restriction in older versions of zsh that local parameters
were never exported has been removed.

@noindent
@node Parameters Set By The Shell, Parameters Used By The Shell, Local Parameters, Parameters

@section Parameters Set By The Shell
@noindent
The following parameters are automatically set by the shell:

@noindent
@table @asis
@vindex !
@item @t{!} <S>
The process ID of the last background command invoked.

@vindex #
@item @t{#} <S>
The number of positional parameters in decimal.  Note that some confusion
may occur with the syntax @t{$#}@var{param} which substitutes the length of
@var{param}.  Use @t{$@{#@}} to resolve ambiguities.  In particular, the
sequence `@t{$#-}@var{...}' in an arithmetic expression is interpreted as
the length of the parameter @t{-}, q.v.

@vindex ARGC
@item @t{ARGC} <S> <Z>
Same as @t{#}.

@vindex $
@item @t{$} <S>
The process ID of this shell.

@vindex -
@item @t{-} <S>
Flags supplied to the shell on invocation or by the @t{set}
or @t{setopt} commands.

@vindex *
@item @t{*} <S>
An array containing the positional parameters.

@vindex argv
@item @t{argv} <S> <Z>
Same as @t{*}.  Assigning to @t{argv} changes the local positional
parameters, but @t{argv} is @emph{not} itself a local parameter.
Deleting @t{argv} with @t{unset} in any function deletes it everywhere,
although only the innermost positional parameter array is deleted (so
@t{*} and @t{@@} in other scopes are not affected).

@vindex @@
@item @t{@@} <S>
Same as @t{argv[@@]}, even when @t{argv} is not set.

@vindex ?
@item @t{?} <S>
The exit value returned by the last command.

@vindex 0
@item @t{0} <S>
The name used to invoke the current shell.  If the @t{FUNCTION_ARGZERO} option
is set, this is set temporarily within a shell function to the name of the
function, and within a sourced script to the name of the script.

@vindex status
@item @t{status} <S> <Z>
Same as @t{?}.

@vindex pipestatus
@item @t{pipestatus} <S> <Z>
An array containing the exit values returned by all commands in the
last pipeline.

@vindex _
@item @t{_} <S>
The last argument of the previous command.
Also, this parameter is set in the environment of every command
executed to the full pathname of the command.

@vindex CPUTYPE
@item @t{CPUTYPE}
The machine type (microprocessor class or machine model),
as determined at run time.

@vindex EGID
@item @t{EGID} <S>
The effective group ID of the shell process.  If you have sufficient
privileges, you may change the effective group ID of the shell
process by assigning to this parameter.  Also (assuming sufficient
privileges), you may start a single command with a different
effective group ID by `@t{(EGID=}@var{gid}@t{; command)}'

@vindex EUID
@item @t{EUID} <S>
The effective user ID of the shell process.  If you have sufficient
privileges, you may change the effective user ID of the shell process
by assigning to this parameter.  Also (assuming sufficient privileges),
you may start a single command with a different
effective user ID by `@t{(EUID=}@var{uid}@t{; command)}'

@vindex ERRNO
@item @t{ERRNO} <S>
The value of errno (see man page errno(3))
as set by the most recently failed system call.
This value is system dependent and is intended for debugging
purposes.

@vindex GID
@item @t{GID} <S>
The real group ID of the shell process.  If you have sufficient privileges,
you may change the group ID of the shell process by assigning to this
parameter.  Also (assuming sufficient privileges), you may start a single
command under a different
group ID by `@t{(GID=}@var{gid}@t{; command)}'

@vindex HOST
@item @t{HOST}
The current hostname.

@vindex LINENO
@item @t{LINENO} <S>
The line number of the current line within the current script, sourced
file, or shell function being executed, whichever was started most
recently.  Note that in the case of shell functions the line
number refers to the function as it appeared in the original definition,
not necessarily as displayed by the @t{functions} builtin.

@vindex LOGNAME
@item @t{LOGNAME}
If the corresponding variable is not set in the environment of the
shell, it is initialized to the login name corresponding to the
current login session. This parameter is exported by default but
this can be disabled using the @t{typeset} builtin.

@vindex MACHTYPE
@item @t{MACHTYPE}
The machine type (microprocessor class or machine model),
as determined at compile time.

@vindex OLDPWD
@item @t{OLDPWD}
The previous working directory.  This is set when the shell initializes
and whenever the directory changes.

@vindex OPTARG
@item @t{OPTARG} <S>
The value of the last option argument processed by the @t{getopts}
command.

@vindex OPTIND
@item @t{OPTIND} <S>
The index of the last option argument processed by the @t{getopts}
command.

@vindex OSTYPE
@item @t{OSTYPE}
The operating system, as determined at compile time.

@vindex PPID
@item @t{PPID} <S>
The process ID of the parent of the shell.

@vindex PWD
@item @t{PWD}
The present working directory.  This is set when the shell initializes
and whenever the directory changes.

@vindex RANDOM
@item @t{RANDOM} <S>
A random integer from 0 to 32767, newly generated each time
this parameter is referenced.  The random number generator
can be seeded by assigning a numeric value to @t{RANDOM}.

@vindex SECONDS
@item @t{SECONDS} <S>
The number of seconds since shell invocation.  If this parameter
is assigned a value, then the value returned upon reference
will be the value that was assigned plus the number of seconds
since the assignment.

@vindex SHLVL
@item @t{SHLVL} <S>
Incremented by one each time a new shell is started.

@vindex signals
@item @t{signals}
An array containing the names of the signals.

@vindex TTY
@item @t{TTY}
The name of the tty associated with the shell, if any.

@vindex TTYIDLE
@item @t{TTYIDLE} <S>
The idle time of the tty associated with the shell in seconds or -1 if there
is no such tty.

@vindex UID
@item @t{UID} <S>
The real user ID of the shell process.  If you have sufficient privileges,
you may change the user ID of the shell by assigning to this parameter.
Also (assuming sufficient privileges), you may start a single command
under a different
user ID by `@t{(UID=}@var{uid}@t{; command)}'

@vindex USERNAME
@item @t{USERNAME} <S>
The username corresponding to the real user ID of the shell process.  If you
have sufficient privileges, you may change the username (and also the
user ID and group ID) of the shell by assigning to this parameter.
Also (assuming sufficient privileges), you may start a single command
under a different username (and user ID and group ID)
by `@t{(USERNAME=}@var{username}@t{; command)}'

@vindex VENDOR
@item @t{VENDOR}
The vendor, as determined at compile time.

@vindex ZSH_NAME
@item @t{ZSH_NAME}
Expands to the basename of the command used to invoke this instance
of zsh.

@vindex ZSH_VERSION
@item @t{ZSH_VERSION}
The version number of this zsh.

@end table
@node Parameters Used By The Shell, , Parameters Set By The Shell, Parameters

@section Parameters Used By The Shell
@noindent
The following parameters are used by the shell.

@noindent
In cases where there are two parameters with an upper- and lowercase
form of the same name, such as @t{path} and @t{PATH}, the lowercase form
is an array and the uppercase form is a scalar with the elements of the
array joined together by colons.  These are similar to tied parameters
created via `@t{typeset -T}'.  The normal use for the colon-separated
form is for exporting to the environment, while the array form is easier
to manipulate within the shell.  Note that unsetting either of the pair
will unset the other; they retain their special properties when
recreated, and recreating one of the pair will recreate the other.

@noindent
@table @asis
@vindex ARGV0
@item @t{ARGV0}
If exported, its value is used as the @t{argv[0]} of external commands.
Usually used in constructs like `@t{ARGV0=emacs nethack}'.

@vindex BAUD
@item @t{BAUD}
The baud rate of the current connection.  Used by the line editor
update mechanism to compensate for a slow terminal by delaying
updates until necessary.  This may be profitably set to a lower value
in some circumstances, e.g.
for slow modems dialing into a communications server which is connected
to a host via a fast link; in this case, this variable
would be set by default to the speed of the fast link, and not
the modem.
This parameter should be set to the baud
rate of the slowest part of the link for best performance. The compensation
mechanism can be turned off by setting the variable to zero.

@vindex cdpath
@vindex CDPATH
@item @t{cdpath} <S> <Z> (@t{CDPATH} <S>)
An array (colon-separated list)
of directories specifying the search path for the @t{cd} command.

@vindex COLUMNS
@item @t{COLUMNS} <S>
The number of columns for this terminal session.
Used for printing select lists and for the line editor.

@vindex DIRSTACKSIZE
@item @t{DIRSTACKSIZE}
The maximum size of the directory stack.  If the
stack gets larger than this, it will be truncated automatically.
This is useful with the @t{AUTO_PUSHD} option.
@pindex AUTO_PUSHD, use of

@vindex FCEDIT
@item @t{FCEDIT}
The default editor for the @t{fc} builtin.

@vindex fignore
@vindex FIGNORE
@item @t{fignore} <S> <Z> (@t{FIGNORE} <S>)
An array (colon separated list)
containing the suffixes of files to be ignored
during filename completion.  However, if completion only generates files
with suffixes in this list, then these files are completed anyway.

@vindex fpath
@vindex FPATH
@item @t{fpath} <S> <Z> (@t{FPATH} <S>)
An array (colon separated list)
of directories specifying the search path for
function definitions.  This path is searched when a function
with the @t{-u} attribute is referenced.  If an executable
file is found, then it is read and executed in the current environment.

@vindex histchars
@item @t{histchars} <S>
Three characters used by the shell's history and lexical analysis
mechanism.  The first character signals the start of a history
expansion (default `@t{!}').  The second character signals the
start of a quick history substitution (default `@t{^}').  The third
character is the comment character (default `@t{#}').

@vindex HISTCHARS
@item @t{HISTCHARS} <S> <Z>
Same as @t{histchars}.  (Deprecated.)

@vindex HISTFILE
@item @t{HISTFILE}
The file to save the history in when an interactive shell exits.
If unset, the history is not saved.

@vindex HISTSIZE
@item @t{HISTSIZE} <S>
The maximum number of events stored in the internal history list.
If you use the @t{HIST_EXPIRE_DUPS_FIRST} option, setting this value
larger than the @t{SAVEHIST} size will give you the difference as a
cushion for saving duplicated history events.

@vindex HOME
@item @t{HOME} <S>
The default argument for the @t{cd} command.

@vindex IFS
@item @t{IFS} <S>
Internal field separators (by default space, tab, newline and NUL), that
are used to separate words which result from
command or parameter expansion and words read by
the @t{read} builtin.  Any characters from the set space, tab and
newline that appear in the IFS are called @emph{IFS white space}.
One or more IFS white space characters or one non-IFS white space
character together with any adjacent IFS white space character delimit
a field.  If an IFS white space character appears twice consecutively
in the IFS, this character is treated as if it were not an IFS white
space character.

@vindex KEYTIMEOUT
@item @t{KEYTIMEOUT}
The time the shell waits, in hundredths of seconds, for another key to
be pressed when reading bound multi-character sequences.

@vindex LANG
@item @t{LANG} <S>
This variable determines the locale category for any category not
specifically selected via a variable starting with `@t{LC_}'.

@vindex LC_ALL
@item @t{LC_ALL} <S>
This variable overrides the value of the `@t{LANG}' variable and the value
of any of the other variables starting with `@t{LC_}'.

@vindex LC_COLLATE
@item @t{LC_COLLATE} <S>
This variable determines the locale category for character collation
information within ranges in glob brackets and for sorting.

@vindex LC_CTYPE
@item @t{LC_CTYPE} <S>
This variable determines the locale category for character handling
functions.

@vindex LC_MESSAGES
@item @t{LC_MESSAGES} <S>
This variable determines the language in which messages should be
written.  Note that zsh does not use message catalogs.

@vindex LC_NUMERIC
@item @t{LC_NUMERIC} <S>
This variable affects the decimal point character and thousands
separator character for the formatted input/output functions
and string conversion functions.  Note that zsh ignores this
setting when parsing floating point mathematical expressions.

@vindex LC_TIME
@item @t{LC_TIME} <S>
This variable determines the locale category for date and time
formatting in prompt escape sequences.

@vindex LINES
@item @t{LINES} <S>
The number of lines for this terminal session.
Used for printing select lists and for the line editor.

@vindex LISTMAX
@item @t{LISTMAX}
In the line editor, the number of matches to list without asking
first. If the value is negative, the list will be shown if it spans at 
most as many lines as given by the absolute value.
If set to zero, the shell asks only if the top of the listing would scroll
off the screen.

@vindex LOGCHECK
@item @t{LOGCHECK}
The interval in seconds between checks for login/logout activity
using the @t{watch} parameter.

@vindex MAIL
@item @t{MAIL}
If this parameter is set and @t{mailpath} is not set,
the shell looks for mail in the specified file.

@vindex MAILCHECK
@item @t{MAILCHECK}
The interval in seconds between checks for new mail.

@vindex mailpath
@vindex MAILPATH
@item @t{mailpath} <S> <Z> (@t{MAILPATH} <S>)
An array (colon-separated list) of filenames to check for
new mail.  Each filename can be followed by a `@t{?}' and a
message that will be printed.  The message will undergo
parameter expansion, command substitution and arithmetic
expansion with the variable @t{$_} defined as the name
of the file that has changed.  The default message is
`@t{You have new mail}'.  If an element is a directory
instead of a file the shell will recursively check every
file in every subdirectory of the element.

@vindex manpath
@vindex MANPATH
@item @t{manpath} <S> <Z> (@t{MANPATH} <S> <Z>)
An array (colon-separated list)
whose value is not used by the shell.  The @t{manpath}
array can be useful, however, since setting it also sets
@t{MANPATH}, and vice versa.

@vindex module_path
@vindex MODULE_PATH
@item @t{module_path} <S> <Z> (@t{MODULE_PATH} <S>)
An array (colon-separated list)
of directories that @t{zmodload}
searches for dynamically loadable modules.
This is initialized to a standard pathname,
usually `@t{/usr/local/lib/zsh/$ZSH_VERSION}'.
(The `@t{/usr/local/lib}' part varies from installation to installation.)
For security reasons, any value set in the environment when the shell
is started will be ignored.

@noindent
These parameters only exist if the installation supports dynamic
module loading.

@vindex NULLCMD
@cindex null command style
@cindex csh, null command style
@cindex ksh, null command style
@item @t{NULLCMD} <S>
The command name to assume if a redirection is specified
with no command.  Defaults to @t{cat}.  For @cite{sh}/@cite{ksh}
behavior, change this to @t{:}.  For @cite{csh}-like
behavior, unset this parameter; the shell will print an
error message if null commands are entered.

@vindex path
@vindex PATH
@item @t{path} <S> <Z> (@t{PATH} <S>)
An array (colon-separated list)
of directories to search for commands.
When this parameter is set, each directory is scanned
and all files found are put in a hash table.

@vindex POSTEDIT
@item @t{POSTEDIT} <S>
This string is output whenever the line editor exits.
It usually contains termcap strings to reset the terminal.

@vindex PROMPT
@item @t{PROMPT} <S> <Z>
@vindex PROMPT2
@itemx @t{PROMPT2} <S> <Z>
@vindex PROMPT3
@itemx @t{PROMPT3} <S> <Z>
@vindex PROMPT4
@itemx @t{PROMPT4} <S> <Z>
Same as @t{PS1}, @t{PS2}, @t{PS3} and @t{PS4},
respectively.

@vindex prompt
@item @t{prompt} <S> <Z>
Same as @t{PS1}.

@vindex PS1
@item @t{PS1} <S>
The primary prompt string, printed before a command is read.
the default is `@t{%m%# }'.  It undergoes a special form of expansion
before being displayed; see @ref{Prompt Expansion}.

@vindex PS2
@item @t{PS2} <S>
The secondary prompt, printed when the shell needs more information
to complete a command.
It is expanded in the same way as @t{PS1}.
The default is `@t{%_> }', which displays any shell constructs or quotation
marks which are currently being processed.

@vindex PS3
@item @t{PS3} <S>
Selection prompt used within a @t{select} loop.
It is expanded in the same way as @t{PS1}.
The default is `@t{?# }'.

@vindex PS4
@item @t{PS4} <S>
The execution trace prompt.  Default is `@t{+%N:%i> }', which displays
the name of the current shell structure and the line number within it.
In sh or ksh emulation, the default is `@t{+ }'.

@vindex psvar
@vindex PSVAR
@item @t{psvar} <S> <Z> (@t{PSVAR} <S>)
An array (colon-separated list) whose first nine values can be used in
@t{PROMPT} strings.  Setting @t{psvar} also sets @t{PSVAR}, and
vice versa.

@vindex READNULLCMD
@item @t{READNULLCMD} <S>
The command name to assume if a single input redirection
is specified with no command.  Defaults to @t{more}.

@vindex REPORTTIME
@item @t{REPORTTIME}
If nonnegative, commands whose combined user and system execution times
(measured in seconds) are greater than this value have timing
statistics printed for them.

@vindex REPLY
@item @t{REPLY}
This parameter is reserved by convention to pass string values between
shell scripts and shell builtins in situations where a function call or
redirection are impossible or undesirable.  The @t{read} builtin and the
@t{select} complex command may set @t{REPLY}, and filename generation both
sets and examines its value when evaluating certain expressions.  Some
modules also employ @t{REPLY} for similar purposes.

@vindex reply
@item @t{reply}
As @t{REPLY}, but for array values rather than strings.

@vindex RPROMPT
@item @t{RPROMPT} <S>
@vindex RPS1
@itemx @t{RPS1} <S>
This prompt is displayed on the right-hand side of the screen
when the primary prompt is being displayed on the left.
This does not work if the @t{SINGLELINEZLE} option is set.
It is expanded in the same way as @t{PS1}.

@vindex SAVEHIST
@item @t{SAVEHIST}
The maximum number of history events to save in the history file.

@vindex SPROMPT
@item @t{SPROMPT} <S>
The prompt used for spelling correction.  The sequence
`@t{%R}' expands to the string which presumably needs spelling
correction, and `@t{%r}' expands to the proposed correction.
All other prompt escapes are also allowed.

@vindex STTY
@item @t{STTY}
If this parameter is set in a command's environment, the shell runs the
@t{stty} command with the value of this parameter as arguments in order to
set up the terminal before executing the command. The modes apply only to the
command, and are reset when it finishes or is suspended. If the command is
suspended and continued later with the @t{fg} or @t{wait} builtins it will
see the modes specified by @t{STTY}, as if it were not suspended.  This
(intentionally) does not apply if the command is continued via `@t{kill
-CONT}'.  @t{STTY} is ignored if the command is run in the background, or
if it is in the environment of the shell but not explicitly assigned to in
the input line. This avoids running stty at every external command by
accidentally exporting it. Also note that @t{STTY} should not be used for
window size specifications; these will not be local to the command.

@vindex TERM
@item @t{TERM} <S>
The type of terminal in use.  This is used when looking up termcap
sequences.  An assignment to @t{TERM} causes zsh to re-initialize the
terminal, even if the value does not change (e.g., `@t{TERM=$TERM}').  It
is necessary to make such an assignment upon any change to the terminal
definition database or terminal type in order for the new settings to
take effect.

@vindex TIMEFMT
@item @t{TIMEFMT}
The format of process time reports with the @t{time} keyword.
The default is `@t{%E real  %U user  %S system  %P %J}'.
Recognizes the following escape sequences:

@noindent
@table @asis
@item @t{%%}
A `@t{%}'.
@item @t{%U}
CPU seconds spent in user mode.
@item @t{%S}
CPU seconds spent in kernel mode.
@item @t{%E}
Elapsed time in seconds.
@item @t{%P}
The CPU percentage, computed as (@t{%U}+@t{%S})/@t{%E}.
@item @t{%J}
The name of this job.
@end table

@noindent
A star may be inserted between the percent sign and flags printing time.
This cause the time to be printed in
`@var{hh}@t{:}@var{mm}@t{:}@var{ss}@t{.}@var{ttt}'
format (hours and minutes are only printed if they are not zero).

@vindex TMOUT
@item @t{TMOUT}
If this parameter is nonzero, the shell will receive an @t{ALRM}
signal if a command is not entered within the specified number of
seconds after issuing a prompt. If there is a trap on @t{SIGALRM}, it
will be executed and a new alarm is scheduled using the value of the
@t{TMOUT} parameter after executing the trap.  If no trap is set, and
the idle time of the terminal is not less than the value of the
@t{TMOUT} parameter, zsh terminates.  Otherwise a new alarm is
scheduled to @t{TMOUT} seconds after the last keypress.

@vindex TMPPREFIX
@item @t{TMPPREFIX}
A pathname prefix which the shell will use for all temporary files.
Note that this should include an initial part for the file name as
well as any directory names.  The default is `@t{/tmp/zsh}'.

@vindex watch
@vindex WATCH
@item @t{watch} <S> <Z> (@t{WATCH} <S>)
An array (colon-separated list) of login/logout events to report.
If it contains the single word `@t{all}', then all login/logout events
are reported.  If it contains the single word `@t{notme}', then all
events are reported as with `@t{all}' except @t{$USERNAME}.
An entry in this list may consist of a username,
an `@t{@@}' followed by a remote hostname,
and a `@t{%}' followed by a line (tty).
Any or all of these components may be present in an entry;
if a login/logout event matches all of them,
it is reported.

@vindex WATCHFMT
@item @t{WATCHFMT}
The format of login/logout reports if the @t{watch} parameter is set.
Default is `@t{%n has %a %l from %m}'.
Recognizes the following escape sequences:

@noindent
@table @asis
@item @t{%n}
The name of the user that logged in/out.

@item @t{%a}
The observed action, i.e. "logged on" or "logged off".

@item @t{%l}
The line (tty) the user is logged in on.

@item @t{%M}
The full hostname of the remote host.

@item @t{%m}
The hostname up to the first `@t{.}'.  If only the
IP address is available or the utmp field contains
the name of an X-windows display, the whole name is printed.

@noindent
@emph{NOTE:}
The `@t{%m}' and `@t{%M}' escapes will work only if there is a host name
field in the utmp on your machine.  Otherwise they are
treated as ordinary strings.

@item @t{%S} (@t{%s})
Start (stop) standout mode.

@item @t{%U} (@t{%u})
Start (stop) underline mode.

@item @t{%B} (@t{%b})
Start (stop) boldface mode.

@item @t{%t}
@itemx @t{%@@}
The time, in 12-hour, am/pm format.

@item @t{%T}
The time, in 24-hour format.

@item @t{%w}
The date in `@var{day}@t{-}@var{dd}' format.

@item @t{%W}
The date in `@var{mm}@t{/}@var{dd}@t{/}@var{yy}' format.

@item @t{%D}
The date in `@var{yy}@t{-}@var{mm}@t{-}@var{dd}' format.

@item @t{%(}@var{x}@t{:}@var{true-text}@t{:}@var{false-text}@t{)}
Specifies a ternary expression.
The character following the @var{x} is
arbitrary; the same character is used to separate the text
for the "true" result from that for the "false" result.
Both the separator and the right parenthesis may be escaped
with a backslash.
Ternary expressions may be nested.

@noindent
The test character @var{x} may be any one of `@t{l}', `@t{n}', `@t{m}'
or `@t{M}', which indicate a `true' result if the corresponding
escape sequence would return a non-empty value; or it may be `@t{a}',
which indicates a `true' result if the watched user has logged in,
or `false' if he has logged out.
Other characters evaluate to neither true nor false; the entire
expression is omitted in this case.

@noindent
If the result is `true', then the @var{true-text}
is formatted according to the rules above and printed,
and the @var{false-text} is skipped.
If `false', the @var{true-text} is skipped and the @var{false-text}
is formatted and printed.
Either or both of the branches may be empty, but
both separators must be present in any case.

@end table

@vindex WORDCHARS
@item @t{WORDCHARS} <S>
A list of non-alphanumeric characters considered part of a word
by the line editor.

@vindex ZBEEP
@item @t{ZBEEP}
If set, this gives a string of characters, which can use all the same codes
as the @t{bindkey} command as described in
@ref{The zsh/zle Module}, that will be output to the terminal
instead of beeping.  This may have a visible instead of an audible effect;
for example, the string `@t{\e[?5h\e[?5l}' on a vt100 or xterm will have
the effect of flashing reverse video on and off (if you usually use reverse
video, you should use the string `@t{\e[?5l\e[?5h}' instead).  This takes
precedence over the @t{NOBEEP} option.

@vindex ZDOTDIR
@item @t{ZDOTDIR}
The directory to search for shell startup files (.zshrc, etc),
if not @t{$HOME}.

@end table
@c (avoiding a yodl bug)
@c Yodl file: Zsh/options.yo
@node Options, Shell Builtin Commands, Parameters, Top

@chapter Options
@noindent
@cindex options
@menu
* Specifying Options::
* Description of Options::
* Option Aliases::
* Single Letter Options::
@end menu
@node Specifying Options, Description of Options, , Options

@section Specifying Options
@noindent
@cindex options, specifying
Options are primarily referred to by name.
These names are case insensitive and underscores are ignored.
For example, `@t{allexport}' is equivalent to `@t{A__lleXP_ort}'.

@noindent
The sense of an option name may be inverted by preceding it with
`@t{no}', so `@t{setopt No_Beep}' is equivalent to `@t{unsetopt beep}'.
This inversion can only be done once, so `@t{nonobeep}' is @emph{not}
a synonym for `@t{beep}'.  Similarly, `@t{tify}' is not a synonym for
`@t{nonotify}' (the inversion of `@t{notify}').

@noindent
Some options also have one or more single letter names.
There are two sets of single letter options: one used by default,
and another used to emulate @cite{sh}/@cite{ksh} (used when the
@t{SH_OPTION_LETTERS} option is set).
The single letter options can be used on the shell command line,
or with the @t{set}, @t{setopt} and @t{unsetopt}
builtins, as normal Unix options preceded by `@t{-}'.

@noindent
The sense of the single letter options may be inverted by using
`@t{+}' instead of `@t{-}'.
Some of the single letter option names refer to an option being off,
in which case the inversion of that name refers to the option being on.
For example, `@t{+n}' is the short name of `@t{exec}', and
`@t{-n}' is the short name of its inversion, `@t{noexec}'.

@noindent
In strings of single letter options supplied to the shell at startup,
trailing whitespace will be ignored; for example the string `@t{-f    }'
will be treated just as `@t{-f}', but the string `@t{-f i}' is an error.
This is because many systems which implement the `@t{#!}' mechanism for
calling scripts do not strip trailing whitespace.

@noindent
@node Description of Options, Option Aliases, Specifying Options, Options

@section Description of Options
@noindent
@cindex options, description
In the following list, options set by default in all emulations are marked
<D>; those set by default only in csh, ksh, sh, or zsh emulations are marked
<C>, <K>, <S>, <Z> as appropriate.  When listing options (by `@t{setopt}',
`@t{unsetopt}', `@t{set -o}' or `@t{set +o}'), those turned on by default
appear in the list prefixed with `@t{no}'.  Hence (unless
@t{KSH_OPTION_PRINT} is set), `@t{setopt}' shows all options whose settings
are changed from the default.

@noindent
@table @asis
@pindex ALIASES
@cindex aliases, expansion
@item @t{ALIASES} <D>
Expand aliases.

@pindex ALL_EXPORT
@cindex export, automatic
@item @t{ALL_EXPORT} (@t{-a}, ksh: @t{-a})
All parameters subsequently defined are automatically exported.

@pindex ALWAYS_LAST_PROMPT
@item @t{ALWAYS_LAST_PROMPT} <D>
If unset, key functions that list completions try to return to the last
prompt if given a numeric argument. If set these functions try to
return to the last prompt if given @emph{no} numeric argument.

@pindex ALWAYS_TO_END
@item @t{ALWAYS_TO_END}
If a completion is performed with the cursor within a word, and a
full completion is inserted, the cursor is moved to the end of the
word.  That is, the cursor is moved to the end of the word if either
a single match is inserted or menu completion is performed.

@pindex APPEND_HISTORY
@cindex history, appending to a file
@item @t{APPEND_HISTORY} <D>
If this is set, zsh sessions will append their history list to
the history file, rather than overwrite it. Thus, multiple parallel
zsh sessions will all have their history lists added to the
history file, in the order they are killed.

@pindex AUTO_CD
@cindex cd, automatic
@item @t{AUTO_CD} (@t{-J})
If a command is issued that can't be executed as a normal command,
and the command is the name of a directory, perform the @t{cd}
command to that directory.

@pindex AUTO_LIST
@cindex completion, listing choices
@item @t{AUTO_LIST} (@t{-9}) <D>
Automatically list choices on an ambiguous completion.

@pindex AUTO_MENU
@cindex completion, menu
@item @t{AUTO_MENU} <D>
Automatically use menu completion after the second consecutive request for
completion, for example by pressing the tab key repeatedly. This option
is overridden by @t{MENU_COMPLETE}.

@pindex AUTO_NAME_DIRS
@cindex directories, named
@item @t{AUTO_NAME_DIRS}
Any parameter that is set to the absolute name of a directory
immediately becomes a name for that directory, that will be used
by the `@t{%~}'
and related prompt sequences, and will be available when completion
is performed on a word starting with `@t{~}'.
(Otherwise, the parameter must be used in the form `@t{~}@var{param}' first.)

@pindex AUTO_PARAM_KEYS
@item @t{AUTO_PARAM_KEYS} <D>
If a parameter name was completed and a following character
(normally a space) automatically
inserted, and the next character typed is one
of those that have to come directly after the name (like `@t{@}}', `@t{:}',
etc.), the automatically added character is deleted, so that the character
typed comes immediately after the parameter name.
Completion in a brace expansion is affected similarly: the added character
is a `@t{,}', which will be removed if `@t{@}}' is typed next.

@pindex AUTO_PARAM_SLASH
@item @t{AUTO_PARAM_SLASH} <D>
If a parameter is completed whose content is the name of a directory,
then add a trailing slash instead of a space.

@pindex AUTO_PUSHD
@cindex cd, behaving like pushd
@cindex pushd, making cd behave like
@item @t{AUTO_PUSHD} (@t{-N})
Make @t{cd} push the old directory onto the directory stack.

@pindex AUTO_REMOVE_SLASH
@cindex slash, removing trailing
@item @t{AUTO_REMOVE_SLASH} <D>
When the last character resulting from a completion is a slash and the next
character typed is a word delimiter, a slash, or a character that ends 
a command (such as a semicolon or an ampersand), remove the slash.

@pindex AUTO_RESUME
@cindex jobs, resuming automatically
@cindex resuming jobs automatically
@item @t{AUTO_RESUME} (@t{-W})
Treat single word simple commands without redirection
as candidates for resumption of an existing job.

@pindex BAD_PATTERN
@cindex globbing, bad pattern
@cindex filename generation, bad pattern
@item @t{BAD_PATTERN} (@t{+2}) <C> <Z>
If a pattern for filename generation is badly formed, print an error message.
(If this option is unset, the pattern will be left unchanged.)

@pindex BANG_HIST
@cindex history, enable substitution
@cindex enable history substitution
@item @t{BANG_HIST} (@t{+K}) <C> <Z>
Perform textual history expansion, @cite{csh}-style,
treating the character `@t{!}' specially.

@pindex BARE_GLOB_QUAL
@cindex globbing qualifiers, enable
@cindex enable globbing qualifiers
@item @t{BARE_GLOB_QUAL} <Z>
In a glob pattern, treat a trailing set of parentheses as a qualifier
list, if it contains no `@t{|}', `@t{(}' or (if special) `@t{~}'
characters.  See @ref{Filename Generation}.

@pindex BASH_AUTO_LIST
@cindex completion, listing choices, bash style
@item @t{BASH_AUTO_LIST}
On an ambiguous completion, automatically list choices when the
completion function is called twice in succession.  This takes
precedence over @t{AUTO_LIST}.  The setting of @t{LIST_AMBIGUOUS} is
respected.  If @t{AUTO_MENU} is set, the menu behaviour will then start
with the third press.  Note that this will not work with
@t{MENU_COMPLETE}, since repeated completion calls immediately cycle
through the list in that case.

@pindex BEEP
@cindex beep, enabling
@cindex enabling the beep
@item @t{BEEP} (@t{+B}) <D>
Beep on error in ZLE.

@pindex BG_NICE
@cindex jobs, background priority
@cindex background jobs, priority of
@cindex priority of background jobs
@item @t{BG_NICE} (@t{-6}) <C> <Z>
Run all background jobs at a lower priority.  This option
is set by default.

@pindex BRACE_CCL
@cindex brace expansion, extending
@cindex expansion, brace, extending
@item @t{BRACE_CCL}
Expand expressions in braces which would not otherwise undergo brace
expansion to a lexically ordered list of all the characters.  See
@ref{Brace Expansion}.

@pindex BSD_ECHO
@cindex echo, BSD compatible
@item @t{BSD_ECHO} <S>
Make the @t{echo} builtin compatible with the BSD man page echo(1) command.
This disables backslashed escape sequences in echo strings unless the
@t{-e} option is specified.

@pindex C_BASES
@cindex bases, output in C format
@cindex hexadecimal, output in C format
@cindex octal, output in C format
@item @t{C_BASES}
Output hexadecimal numbers in the standard C format, for example `@t{0xFF}'
instead of the usual `@t{16#FF}'.  If the option @t{OCTAL_ZEROES} is also
set (it is not by default), octal numbers will be treated similarly and
hence appear as `@t{077}' instead of `@t{8#77}'.  This option has no effect
on the choice of the output base, nor on the output of bases other than
hexadecimal and octal.  Note that these formats will be understood on input
irrespective of the setting of @t{C_BASES}.

@pindex CDABLE_VARS
@cindex cd, to parameter
@item @t{CDABLE_VARS} (@t{-T})
If the argument to a @t{cd} command (or an implied @t{cd} with the
@t{AUTO_CD} option set) is not a directory, and does not begin with a
slash, try to expand the expression as if it were preceded by a `@t{~}' (see
@ref{Filename Expansion}).

@pindex CHASE_DOTS
@cindex cd, with .. in argument
@item @t{CHASE_DOTS}
When changing to a directory containing a path segment `@t{..}' which would
otherwise be treated as canceling the previous segment in the path (in
other words, `@t{foo/..}' would be removed from the path, or if `@t{..}' is
the first part of the path, the last part of @t{$PWD} would be deleted),
instead resolve the path to the physical directory.  This option is
overridden by @t{CHASE_LINKS}.

@noindent
For example, suppose @t{/foo/bar} is a link to the directory @t{/alt/rod}.
Without this option set, `@t{cd /foo/bar/..}' changes to @t{/foo}; with it
set, it changes to @t{/alt}.  The same applies if the current directory
is @t{/foo/bar} and `@t{cd ..}' is used.  Note that all other symbolic
links in the path will also be resolved.

@pindex CHASE_LINKS
@cindex links, symbolic
@cindex symbolic links
@item @t{CHASE_LINKS} (@t{-w})
Resolve symbolic links to their true values when changing directory.
This also has the effect of @t{CHASE_DOTS}, i.e. a `@t{..}' path segment
will be treated as referring to the physical parent, even if the preceding
path segment is a symbolic link.

@pindex CHECK_JOBS
@cindex exiting, checking jobs when
@cindex logging out, checking jobs when
@item @t{CHECK_JOBS} <Z>
Report the status of background and suspended jobs before exiting a shell
with job control; a second attempt to exit the shell will succeed.
@t{NO_CHECK_JOBS} is best used only in combination with @t{NO_HUP}, else
such jobs will be killed automatically.

@noindent
The check is omitted if the commands run from the previous command line
included a `@t{jobs}' command, since it is assumed the user is aware that
there are background or suspended jobs.  A `@t{jobs}' command run from the
@t{precmd} function is not counted for this purpose.

@pindex CLOBBER
@cindex clobbering, of files
@cindex file clobbering, allowing
@item @t{CLOBBER} (@t{+C}, ksh: @t{+C}) <D>
Allows `@t{>}' redirection to truncate existing files,
and `@t{>>}' to create files.
Otherwise `@t{>!}' or `@t{>|}' must be used to truncate a file,
and `@t{>>!}' or `@t{>>|}' to create a file.

@pindex COMPLETE_ALIASES
@cindex aliases, completion of
@item @t{COMPLETE_ALIASES}
Prevents aliases on the command line from being internally substituted
before completion is attempted.  The effect is to make the alias a
distinct command for completion purposes.

@pindex COMPLETE_IN_WORD
@item @t{COMPLETE_IN_WORD}
If unset, the cursor is set to the end of the word if completion is
started. Otherwise it stays there and completion is done from both ends.

@pindex CORRECT
@cindex correction, spelling
@cindex spelling correction
@item @t{CORRECT} (@t{-0})
Try to correct the spelling of commands.

@pindex CORRECT_ALL
@item @t{CORRECT_ALL} (@t{-O})
Try to correct the spelling of all arguments in a line.

@pindex CSH_JUNKIE_HISTORY
@cindex csh, history style
@cindex history style, csh
@item @t{CSH_JUNKIE_HISTORY} <C>
A history reference without an event specifier will always refer to the
previous command.  Without this option, such a history reference refers
to the same event as the previous history reference, defaulting to the
previous command.

@pindex CSH_JUNKIE_LOOPS
@cindex csh, loop style
@cindex loop style, csh
@item @t{CSH_JUNKIE_LOOPS} <C>
Allow loop bodies to take the form `@var{list}; @t{end}' instead of
`@t{do} @var{list}; @t{done}'.

@pindex CSH_JUNKIE_QUOTES
@cindex csh, quoting style
@cindex quoting style, csh
@item @t{CSH_JUNKIE_QUOTES} <C>
Changes the rules for single- and double-quoted text to match that of
@cite{csh}.  These require that embedded newlines be preceded by a backslash;
unescaped newlines will cause an error message.
In double-quoted strings, it is made impossible to escape `@t{$}', `@t{`}'
or `@t{"}' (and `@t{\}' itself no longer needs escaping).
Command substitutions are only expanded once, and cannot be nested.

@pindex CSH_NULLCMD
@vindex NULLCMD, ignoring
@vindex READNULLCMD, ignoring
@cindex redirections with no command, csh
@cindex csh, redirections with no command
@item @t{CSH_NULLCMD} <C>
Do not use the values of @t{NULLCMD} and @t{READNULLCMD} 
when running redirections with no command.  This make 
such redirections fail (see @ref{Redirection}).

@pindex CSH_NULL_GLOB
@cindex csh, null globbing style
@cindex null globbing style, csh
@cindex globbing, null, style, csh
@item @t{CSH_NULL_GLOB} <C>
If a pattern for filename generation has no matches,
delete the pattern from the argument list;
do not report an error unless all the patterns
in a command have no matches.
Overrides @t{NOMATCH}.

@pindex DVORAK
@item @t{DVORAK}
Use the Dvorak keyboard instead of the standard qwerty keyboard as a basis
for examining spelling mistakes for the @t{CORRECT} and @t{CORRECT_ALL}
options and the @t{spell-word} editor command.

@pindex EQUALS
@cindex filename expansion, =
@item @t{EQUALS} <Z>
Perform @t{=} filename expansion.
(See @ref{Filename Expansion}.)

@pindex ERR_EXIT
@cindex exit status, trapping
@item @t{ERR_EXIT} (@t{-e}, ksh: @t{-e})
If a command has a non-zero exit status, execute the @t{ZERR}
trap, if set, and exit.  This is disabled while running initialization
scripts.

@pindex EXEC
@cindex command execution, enabling
@item @t{EXEC} (@t{+n}, ksh: @t{+n}) <D>
Do execute commands.  Without this option, commands are
read and checked for syntax errors, but not executed.
This option cannot be turned off in an interactive shell,
except when `@t{-n}' is supplied to the shell at startup.

@pindex EXTENDED_GLOB
@cindex globbing, extended
@item @t{EXTENDED_GLOB}
Treat the `@t{#}', `@t{~}' and `@t{^}' characters as part of patterns
for filename generation, etc.  (An initial unquoted `@t{~}'
always produces named directory expansion.)

@pindex EXTENDED_HISTORY
@cindex history, timestamping
@item @t{EXTENDED_HISTORY} <C>
Save each command's beginning timestamp (in seconds since the epoch)
and the duration (in seconds) to the history file.  The format of
this prefixed data is:

@noindent
`@t{:}@var{<beginning time>}@t{:}@var{<elapsed seconds>}@t{:}@var{<command>}'.

@pindex FLOW_CONTROL
@cindex flow control
@item @t{FLOW_CONTROL} <D>
If this option is unset,
output flow control via start/stop characters (usually assigned to
^S/^Q) is disabled in the shell's editor.

@pindex FUNCTION_ARGZERO
@cindex $0, setting
@item @t{FUNCTION_ARGZERO} <C> <Z>
When executing a shell function or sourcing a script, set @t{$0}
temporarily to the name of the function/script.

@pindex GLOB
@cindex globbing, enabling
@cindex enabling globbing
@item @t{GLOB} (@t{+F}, ksh: @t{+f}) <D>
Perform filename generation (globbing).
(See @ref{Filename Generation}.)

@pindex GLOBAL_EXPORT
@cindex environment, and local parameters
@item @t{GLOBAL_EXPORT} (@t{<Z>})
If this option is set, passing the @t{-x} flag to the builtins @t{declare},
@t{float}, @t{integer}, @t{readonly} and @t{typeset} (but not @t{local})
will also set the @t{-g} flag;  hence parameters exported to
the environment will not be made local to the enclosing function, unless
they were already or the flag @t{+g} is given explicitly.  If the option is
unset, exported parameters will be made local in just the same way as any
other parameter.

@noindent
This option is set by default for backward compatibility; it is not
recommended that its behaviour be relied upon.  Note that the builtin
@t{export} always sets both the @t{-x} and @t{-g} flags, and hence its
effect extends beyond the scope of the enclosing function; this is the
most portable way to achieve this behaviour.

@cindex exporting, and local parameters
@pindex GLOBAL_RCS
@cindex startup files, global, inhibiting
@cindex files, global startup, inhibiting
@item @t{GLOBAL_RCS} (@t{-d}) <D>
If this option is unset, the startup files @t{/etc/zprofile},
@t{/etc/zshrc}, @t{/etc/zlogin} and @t{/etc/zlogout} will not be run.  It
can be disabled and re-enabled at any time, including inside local startup
files (@t{.zshrc}, etc.).

@pindex GLOB_ASSIGN
@item @t{GLOB_ASSIGN} <C>
If this option is set, filename generation (globbing) is
performed on the right hand side of scalar parameter assignments of
the form `@var{name}@t{=}@var{pattern} (e.g. `@t{foo=*}').
If the result has more than one word the parameter will become an array
with those words as arguments. This option is provided for backwards
compatibility only: globbing is always performed on the right hand side
of array assignments of the form `@var{name}@t{=(}@var{value}@t{)}'
(e.g. `@t{foo=(*)}') and this form is recommended for clarity;
with this option set, it is not possible to predict whether the result
will be an array or a scalar.

@pindex GLOB_COMPLETE
@item @t{GLOB_COMPLETE}
When the current word has a glob pattern, do not insert all the words
resulting from the expansion but generate matches as for completion and
cycle through them like @t{MENU_COMPLETE}. The matches are generated as if
a `@t{*}' was added to the end of the word, or inserted at the cursor when
@t{COMPLETE_IN_WORD} is set.  This actually uses pattern matching, not
globbing, so it works not only for files but for any completion, such as
options, user names, etc.

@pindex GLOB_DOTS
@cindex globbing, of . files
@item @t{GLOB_DOTS} (@t{-4})
Do not require a leading `@t{.}' in a filename to be matched explicitly.

@pindex GLOB_SUBST
@item @t{GLOB_SUBST} <C> <K> <S>
Treat any characters resulting from parameter expansion as being
eligible for file expansion and filename generation, and any
characters resulting from command substitution as being eligible for
filename generation.  Braces (and commas in between) do not become eligible
for expansion.

@pindex HASH_CMDS
@cindex hashing, of commands
@cindex command hashing
@item @t{HASH_CMDS} <D>
Note the location of each command the first time it is executed.
Subsequent invocations of the same command will use the
saved location, avoiding a path search.
If this option is unset, no path hashing is done at all.
However, when @t{CORRECT} is set, commands whose names do not appear in
the functions or aliases hash tables are hashed in order to avoid
reporting them as spelling errors.

@pindex HASH_DIRS
@cindex hashing, of directories
@cindex directories, hashing
@item @t{HASH_DIRS} <D>
Whenever a command name is hashed, hash the directory containing it,
as well as all directories that occur earlier in the path.
Has no effect if neither @t{HASH_CMDS} nor @t{CORRECT} is set.

@pindex HASH_LIST_ALL
@item @t{HASH_LIST_ALL} <D>
Whenever a command completion is attempted, make sure the entire
command path is hashed first.  This makes the first completion slower.

@pindex HIST_ALLOW_CLOBBER
@item @t{HIST_ALLOW_CLOBBER}
Add `@t{|}' to output redirections in the history.  This allows history
references to clobber files even when @t{CLOBBER} is unset.

@pindex HIST_BEEP
@cindex history beeping
@cindex beep, history
@item @t{HIST_BEEP} <D>
Beep when an attempt is made to access a history entry which
isn't there.

@pindex HIST_EXPIRE_DUPS_FIRST
@cindex history, expiring duplicates
@item @t{HIST_EXPIRE_DUPS_FIRST}
If the internal history needs to be trimmed to add the current command line,
setting this option will cause the oldest history event that has a duplicate
to be lost before losing a unique event from the list.
You should be sure to set the value of @t{HISTSIZE} to a larger number
than @t{SAVEHIST} in order to give you some room for the duplicated
events, otherwise this option will behave just like
@t{HIST_IGNORE_ALL_DUPS} once the history fills up with unique events.

@pindex HIST_FIND_NO_DUPS
@cindex history, ignoring duplicates in search
@item @t{HIST_FIND_NO_DUPS}
When searching for history entries in the line editor, do not display
duplicates of a line previously found, even if the duplicates are not
contiguous.

@pindex HIST_IGNORE_ALL_DUPS
@cindex history, ignoring all duplicates
@item @t{HIST_IGNORE_ALL_DUPS}
If a new command line being added to the history list duplicates an
older one, the older command is removed from the list (even if it is
not the previous event).

@pindex HIST_IGNORE_DUPS
@cindex history, ignoring duplicates
@item @t{HIST_IGNORE_DUPS} (@t{-h})
Do not enter command lines into the history list
if they are duplicates of the previous event.

@pindex HIST_IGNORE_SPACE
@cindex history, ignoring spaces
@item @t{HIST_IGNORE_SPACE} (@t{-g})
Remove command lines from the history list when the first character on
the line is a space, or when one of the expanded aliases contains a
leading space.
Note that the command lingers in the internal history until the next
command is entered before it vanishes, allowing you to briefly reuse
or edit the line.  If you want to make it vanish right away without
entering another command, type a space and press return.

@pindex HIST_NO_FUNCTIONS
@item @t{HIST_NO_FUNCTIONS}
Remove function definitions from the history list.
Note that the function lingers in the internal history until the next
command is entered before it vanishes, allowing you to briefly reuse
or edit the definition.

@pindex HIST_NO_STORE
@item @t{HIST_NO_STORE}
Remove the @t{history} (@t{fc -l}) command from the history list
when invoked.
Note that the command lingers in the internal history until the next
command is entered before it vanishes, allowing you to briefly reuse
or edit the line.

@pindex HIST_REDUCE_BLANKS
@item @t{HIST_REDUCE_BLANKS}
Remove superfluous blanks from each command line
being added to the history list.

@pindex HIST_SAVE_NO_DUPS
@item @t{HIST_SAVE_NO_DUPS}
When writing out the history file, older commands that duplicate
newer ones are omitted.

@pindex HIST_VERIFY
@cindex history, verifying substitution
@item @t{HIST_VERIFY}
Whenever the user enters a line with history expansion,
don't execute the line directly; instead, perform
history expansion and reload the line into the editing buffer.

@pindex HUP
@cindex jobs, HUP
@item @t{HUP} <Z>
Send the @t{HUP} signal to running jobs when the
shell exits.

@pindex IGNORE_BRACES
@cindex disabling brace expansion
@cindex brace expansion, disabling
@cindex expansion, brace, disabling
@item @t{IGNORE_BRACES} (@t{-I}) <S>
Do not perform brace expansion.

@pindex IGNORE_EOF
@cindex EOF, ignoring
@item @t{IGNORE_EOF} (@t{-7})
Do not exit on end-of-file.  Require the use
of @t{exit} or @t{logout} instead.
However, ten consecutive EOFs will cause the shell to exit anyway,
to avoid the shell hanging if its tty goes away.

@noindent
Also, if this option is set and the Zsh Line Editor is used, widgets
implemented by shell functions can be bound to EOF (normally
Control-D) without printing the normal warning message.  This works
only for normal widgets, not for completion widgets.

@pindex INC_APPEND_HISTORY
@cindex history, incremental appending to a file
@item @t{INC_APPEND_HISTORY}
This options works like @t{APPEND_HISTORY} except that new history lines
are added to the @t{$HISTFILE} incrementally (as soon as they are
entered), rather than waiting until the shell is killed.
The file is periodically trimmed to the number of lines specified by
@t{$SAVEHIST}, but can exceed this value between trimmings.

@pindex INTERACTIVE
@item @t{INTERACTIVE} (@t{-i}, ksh: @t{-i})
This is an interactive shell.  This option is set upon initialisation if
the standard input is a tty and commands are being read from standard input.
(See the discussion of @t{SHIN_STDIN}.)
This heuristic may be overridden by specifying a state for this option
on the command line.
The value of this option cannot be changed anywhere other than the command line.

@pindex INTERACTIVE_COMMENTS
@cindex comments, in interactive shells
@item @t{INTERACTIVE_COMMENTS} (@t{-k}) <K> <S>
Allow comments even in interactive shells.

@pindex KSH_ARRAYS
@cindex arrays, ksh style
@cindex array style, ksh
@cindex ksh, array style
@item @t{KSH_ARRAYS} <K> <S>
Emulate @cite{ksh} array handling as closely as possible.  If this option
is set, array elements are numbered from zero, an array parameter
without subscript refers to the first element instead of the whole array,
and braces are required to delimit a subscript (`@t{$@{path[2]@}}' rather
than just `@t{$path[2]}').

@pindex KSH_AUTOLOAD
@item @t{KSH_AUTOLOAD} <K> <S>
Emulate @cite{ksh} function autoloading.  This means that when a function is
autoloaded, the corresponding file is merely executed, and must define
the function itself.  (By default, the function is defined to the contents
of the file.  However, the most common @cite{ksh}-style case - of the file
containing only a simple definition of the function - is always handled
in the @cite{ksh}-compatible manner.)

@pindex KSH_GLOB
@item @t{KSH_GLOB} <K>
In pattern matching, the interpretation of parentheses is affected by
a preceding `@t{@@}', `@t{*}', `@t{+}', `@t{?}' or `@t{!}'.
See @ref{Filename Generation}.

@pindex KSH_OPTION_PRINT
@cindex option printing, ksh style
@cindex option printing style, ksh
@cindex ksh, option printing style
@item @t{KSH_OPTION_PRINT} <K>
Alters the way options settings are printed: instead of separate lists of
set and unset options, all options are shown, marked `on' if
they are in the non-default state, `off' otherwise.

@pindex KSH_TYPESET
@cindex argument splitting, in typeset etc.
@cindex ksh, argument splitting in typeset
@item @t{KSH_TYPESET} <K>
Alters the way arguments to the @t{typeset} family of commands, including
@t{declare}, @t{export}, @t{float}, @t{integer}, @t{local} and
@t{readonly}, are processed.  Without this option, zsh will perform normal
word splitting after command and parameter expansion in arguments of an
assignment; with it, word splitting does not take place in those cases.

@pindex LIST_AMBIGUOUS
@cindex ambiguous completion
@cindex completion, ambiguous
@item @t{LIST_AMBIGUOUS} <D>
This option works when @t{AUTO_LIST} or @t{BASH_AUTO_LIST} is also
set.  If there is an unambiguous prefix to insert on the command line,
that is done without a completion list being displayed; in other
words, auto-listing behaviour only takes place when nothing would be
inserted.  In the case of @t{BASH_AUTO_LIST}, this means that the list
will be delayed to the third call of the function.

@pindex LIST_BEEP
@cindex beep, ambiguous completion
@cindex completion, beep on ambiguous
@item @t{LIST_BEEP} <D>
Beep on an ambiguous completion.  More accurately, this forces the
completion widgets to return status 1 on an ambiguous completion, which
causes the shell to beep if the option @t{BEEP} is also set; this may
be modified if completion is called from a user-defined widget.

@pindex LIST_PACKED
@cindex completion, listing
@item @t{LIST_PACKED}
Try to make the completion list smaller (occupying less lines) by
printing the matches in columns with different widths.

@pindex LIST_ROWS_FIRST
@cindex completion, listing order
@item @t{LIST_ROWS_FIRST}
Lay out the matches in completion lists sorted horizontally, that is,
the second match is to the right of the first one, not under it as
usual.

@pindex LIST_TYPES
@cindex marking file types
@cindex files, marking type of
@item @t{LIST_TYPES} (@t{-X}) <D>
When listing files that are possible completions, show the
type of each file with a trailing identifying mark.

@pindex LOCAL_OPTIONS
@item @t{LOCAL_OPTIONS} <K>
If this option is set at the point of return from a shell function,
all the options (including this one) which were in force upon entry to
the function are restored.  Otherwise, only this option and the
@t{XTRACE} and @t{PRINT_EXIT_VALUE} options are restored.  Hence
if this is explicitly unset by a shell function the other options in
force at the point of return will remain so.
A shell function can also guarantee itself a known shell configuration
with a formulation like `@t{emulate -L zsh}'; the @t{-L} activates
@t{LOCAL_OPTIONS}.

@pindex LOCAL_TRAPS
@item @t{LOCAL_TRAPS} <K>
If this option is set when a signal trap is set inside a function, then the
previous status of the trap for that signal will be restored when the
function exits.  Note that this option must be set @emph{prior} to altering the
trap behaviour in a function; unlike @t{LOCAL_OPTIONS}, the value on exit
from the function is irrelevant.  However, it does not need to be set
before any global trap for that to be correctly restored by a function.
For example,

@noindent
@example
unsetopt localtraps
trap - INT
fn() @{ setopt localtraps; trap @value{dsq} INT; sleep 3; @}
@end example

@noindent
will restore normally handling of @t{SIGINT} after the function exits.

@pindex LOGIN
@item @t{LOGIN} (@t{-l}, ksh: @t{-l})
This is a login shell.
If this option is not explicitly set, the shell is a login shell if
the first character of the @t{argv[0]} passed to the shell is a `@t{-}'.

@pindex LONG_LIST_JOBS
@cindex jobs, list format
@item @t{LONG_LIST_JOBS} (@t{-R})
List jobs in the long format by default.

@pindex MAGIC_EQUAL_SUBST
@item @t{MAGIC_EQUAL_SUBST}
All unquoted arguments of the form `@var{anything}@t{=}@var{expression}'
appearing after the command name have filename expansion (that is,
where @var{expression} has a leading `@t{~}' or `@t{=}') performed on
@var{expression} as if it were a parameter assignment.  The argument is
not otherwise treated specially; it is passed to the command as a single
argument, and not used as an actual parameter assignment.  For example, in
@t{echo foo=~/bar:~/rod}, both occurrences of @t{~} would be replaced.
Note that this happens anyway with @t{typeset} and similar statements.

@noindent
This option respects the setting of the @t{KSH_TYPESET} option.  In other
words, if both options are in effect, arguments looking like
assignments will not undergo wordsplitting.

@pindex MAIL_WARNING
@cindex mail, warning of reading
@item @t{MAIL_WARNING} (@t{-U})
Print a warning message if a mail file has been
accessed since the shell last checked.

@pindex MARK_DIRS
@cindex directories, marking
@cindex marking directories
@item @t{MARK_DIRS} (@t{-8}, ksh: @t{-X})
Append a trailing `@t{/}' to all directory
names resulting from filename generation (globbing).

@pindex MENU_COMPLETE
@cindex completion, menu
@item @t{MENU_COMPLETE} (@t{-Y})
On an ambiguous completion, instead of listing possibilities or beeping,
insert the first match immediately.  Then when completion is requested
again, remove the first match and insert the second match, etc.
When there are no more matches, go back to the first one again.
@t{reverse-menu-complete} may be used to loop through the list
in the other direction. This option overrides @t{AUTO_MENU}.

@pindex MONITOR
@cindex job control, allowing
@item @t{MONITOR} (@t{-m}, ksh: @t{-m})
Allow job control.  Set by default in interactive shells.

@pindex MULTIOS
@item @t{MULTIOS} <Z>
Perform implicit @cite{tee}s or @cite{cat}s when multiple
redirections are attempted (see @ref{Redirection}).

@pindex NOMATCH
@cindex globbing, no matches
@item @t{NOMATCH} (@t{+3}) <C> <Z>
If a pattern for filename generation has no matches,
print an error, instead of
leaving it unchanged in the argument list.
This also applies to file expansion
of an initial `@t{~}' or `@t{=}'.

@pindex NOTIFY
@cindex background jobs, notification
@cindex notification of background jobs
@item @t{NOTIFY} (@t{-5}, ksh: @t{-b}) <Z>
Report the status of background jobs immediately, rather than
waiting until just before printing a prompt.

@pindex NULL_GLOB
@cindex globbing, no matches
@item @t{NULL_GLOB} (@t{-G})
If a pattern for filename generation has no matches,
delete the pattern from the argument list instead
of reporting an error.  Overrides @t{NOMATCH}.

@pindex NUMERIC_GLOB_SORT
@cindex globbing, sorting numerically
@item @t{NUMERIC_GLOB_SORT}
If numeric filenames are matched by a filename generation pattern,
sort the filenames numerically rather than lexicographically.

@pindex OCTAL_ZEROES
@cindex octal, arithmetic expressions
@item @t{OCTAL_ZEROES} <S>
Interpret any integer constant beginning with a 0 as octal, per IEEE Std
1003.2-1992 (ISO 9945-2:1993).  This is not enabled by default as it
causes problems with parsing of, for example, date and time strings with
leading zeroes.

@pindex OVERSTRIKE
@cindex editor, overstrike mode
@cindex overstrike mode, of editor
@item @t{OVERSTRIKE}
Start up the line editor in overstrike mode.

@pindex PATH_DIRS
@cindex path search, extended
@item @t{PATH_DIRS} (@t{-Q})
Perform a path search even on command names with slashes in them.
Thus if `@t{/usr/local/bin}' is in the user's path, and he or she types
`@t{X11/xinit}', the command `@t{/usr/local/bin/X11/xinit}' will be executed
(assuming it exists).
Commands explicitly beginning with `@t{/}', `@t{./}' or `@t{../}'
are not subject to the path search.
This also applies to the @t{.} builtin.

@noindent
Note that subdirectories of the current directory are always searched for
executables specified in this form.  This takes place before any search
indicated by this option, and regardless of whether `@t{.}' or the current
directory appear in the command search path.

@pindex POSIX_BUILTINS
@item @t{POSIX_BUILTINS} <K> <S>
When this option is set the @t{command} builtin can be used to execute
shell builtin commands.  Parameter assignments specified before shell
functions and special builtins are kept after the command completes unless
the special builtin is prefixed with the @t{command} builtin.  Special
builtins are
@t{.},
@t{:},
@t{break},
@t{continue},
@t{declare},
@t{eval},
@t{exit},
@t{export},
@t{integer},
@t{local},
@t{readonly},
@t{return},
@t{set},
@t{shift},
@t{source},
@t{times},
@t{trap} and
@t{unset}.

@pindex PRINT_EIGHT_BIT
@cindex eight bit characters, printing
@item @t{PRINT_EIGHT_BIT}
Print eight bit characters literally in completion lists, etc.
This option is not necessary if your system correctly returns the
printability of eight bit characters (see man page ctype(3)).

@pindex PRINT_EXIT_VALUE
@cindex exit status, printing
@item @t{PRINT_EXIT_VALUE} (@t{-1})
Print the exit value of programs with non-zero exit status.

@pindex PRIVILEGED
@cindex privileged mode
@cindex mode, privileged
@item @t{PRIVILEGED} (@t{-p}, ksh: @t{-p})
Turn on privileged mode. This is enabled automatically on startup if the
effective user (group) ID is not equal to the real user (group) ID.  Turning
this option off causes the effective user and group IDs to be set to the
real user and group IDs. This option disables sourcing user startup files.
If zsh is invoked as `@t{sh}' or `@t{ksh}' with this option set,
@t{/etc/suid_profile} is sourced (after @t{/etc/profile} on interactive
shells). Sourcing @t{~/.profile} is disabled and the contents of the
@t{ENV} variable is ignored. This option cannot be changed using the
@t{-m} option of @t{setopt} and @t{unsetopt}, and changing it inside a
function always changes it globally regardless of the @t{LOCAL_OPTIONS}
option.

@pindex PROMPT_BANG
@cindex prompt, ! expansion
@item @t{PROMPT_BANG} <K>
If set, `@t{!}' is treated specially in prompt expansion.
See @ref{Prompt Expansion}.

@pindex PROMPT_CR
@cindex prompt, with CR
@item @t{PROMPT_CR} (@t{+V}) <D>
Print a carriage return just before printing
a prompt in the line editor.  This is on by default as multi-line editing
is only possible if the editor knows where the start of the line appears.

@pindex PROMPT_PERCENT
@cindex prompt, % expansion
@item @t{PROMPT_PERCENT} <C> <Z>
If set, `@t{%}' is treated specially in prompt expansion.
See @ref{Prompt Expansion}.

@pindex PROMPT_SUBST
@cindex prompt, parameter expansion
@item @t{PROMPT_SUBST} <K>
If set, @emph{parameter expansion}, @emph{command substitution} and
@emph{arithmetic expansion} are performed in prompts.

@pindex PUSHD_IGNORE_DUPS
@cindex directory stack, ignoring duplicates
@item @t{PUSHD_IGNORE_DUPS}
Don't push multiple copies of the same directory onto the directory stack.

@pindex PUSHD_MINUS
@cindex directory stack, controlling syntax
@item @t{PUSHD_MINUS}
Exchanges the meanings of `@t{+}' and `@t{-}'
when used with a number to specify a directory in the stack.

@pindex PUSHD_SILENT
@cindex directory stack, silencing
@item @t{PUSHD_SILENT} (@t{-E})
Do not print the directory stack after @t{pushd} or @t{popd}.

@pindex PUSHD_TO_HOME
@cindex pushd, to home
@item @t{PUSHD_TO_HOME} (@t{-D})
Have @t{pushd} with no arguments act like `@t{pushd $HOME}'.

@pindex RC_EXPAND_PARAM
@cindex rc, parameter expansion style
@cindex parameter expansion style, rc
@item @t{RC_EXPAND_PARAM} (@t{-P})
Array expansions of the form
`@var{foo}@t{$@{}@var{xx}@t{@}}@var{bar}', where the parameter
@var{xx} is set to @t{(}@var{a b c}@t{)}, are substituted with
`@var{fooabar foobbar foocbar}' instead of the default
`@var{fooa b cbar}'.

@pindex RC_QUOTES
@cindex rc, quoting style
@cindex quoting style, rc
@item @t{RC_QUOTES}
Allow the character sequence `@t{@value{dsq}}' to signify a single quote
within singly quoted strings.  Note this does not apply in quoted strings
using the format @t{$'}@var{...}@t{'}, where a backslashed single quote can
be used.

@pindex RCS
@cindex startup files, sourcing
@item @t{RCS} (@t{+f}) <D>
After @t{/etc/zshenv} is sourced on startup, source the
@t{.zshenv}, @t{/etc/zprofile}, @t{.zprofile},
@t{/etc/zshrc}, @t{.zshrc}, @t{/etc/zlogin}, @t{.zlogin}, and @t{.zlogout}
files, as described in @ref{Files}.
If this option is unset, the @t{/etc/zshenv} file is still sourced, but any
of the others will not be; it can be set at any time to prevent the
remaining startup files after the currently executing one from
being sourced.

@pindex REC_EXACT
@cindex completion, exact matches
@item @t{REC_EXACT} (@t{-S})
In completion, recognize exact matches even
if they are ambiguous.

@pindex RESTRICTED
@cindex restricted shell
@item @t{RESTRICTED} (@t{-r})
Enables restricted mode.  This option cannot be changed using
@t{unsetopt}, and setting it inside a function always changes it
globally regardless of the @t{LOCAL_OPTIONS} option.  See
@ref{Restricted Shell}.

@pindex RM_STAR_SILENT
@cindex rm *, querying before
@cindex querying before rm *
@item @t{RM_STAR_SILENT} (@t{-H}) <K> <S>
Do not query the user before executing `@t{rm *}' or `@t{rm path/*}'.

@pindex RM_STAR_WAIT
@cindex rm *, waiting before
@cindex waiting before rm *
@item @t{RM_STAR_WAIT}
If querying the user before executing `@t{rm *}' or `@t{rm path/*}',
first wait ten seconds and ignore anything typed in that time.
This avoids the problem of reflexively answering `yes' to the query
when one didn't really mean it.  The wait and query can always be
avoided by expanding the `@t{*}' in ZLE (with tab).

@pindex SHARE_HISTORY
@cindex share history
@cindex history, sharing
@item @t{SHARE_HISTORY} <K>

@noindent
This option both imports new commands from the history file, and also
causes your typed commands to be appended to the history file (the
latter is like specifying @t{INC_APPEND_HISTORY}).
The history lines are also output with timestamps ala
@t{EXTENDED_HISTORY} (which makes it easier to find the spot where
we left off reading the file after it gets re-written).

@noindent
By default, history movement commands visit the imported lines as
well as the local lines, but you can toggle this on and off with the
set-local-history zle binding.  It is also possible to create a zle
widget that will make some commands ignore imported commands, and
some include them.

@noindent
If you find that you want more control over when commands
get imported, you may wish to turn @t{SHARE_HISTORY} off,
@t{INC_APPEND_HISTORY} on, and then manually import
commands whenever you need them using `@t{fc -RI}'.

@pindex SH_FILE_EXPANSION
@cindex sh, expansion style
@cindex expansion style, sh
@item @t{SH_FILE_EXPANSION} <K> <S>
Perform filename expansion (e.g., ~ expansion) @emph{before}
parameter expansion, command substitution, arithmetic expansion
and brace expansion.
If this option is unset, it is performed @emph{after}
brace expansion, so things like `@t{~$USERNAME}' and
`@t{~@{pfalstad,rc@}}' will work.

@pindex SH_GLOB
@cindex sh, globbing style
@cindex globbing style, sh
@item @t{SH_GLOB} <K> <S>
Disables the special meaning of `@t{(}', `@t{|}', `@t{)}'
and '@t{<}' for globbing the result of parameter and command substitutions,
and in some other places where
the shell accepts patterns.  This option is set by default if zsh is
invoked as @t{sh} or @t{ksh}.

@pindex SHIN_STDIN
@item @t{SHIN_STDIN} (@t{-s}, ksh: @t{-s})
Commands are being read from the standard input.
Commands are read from standard input if no command is specified with
@t{-c} and no file of commands is specified.  If @t{SHIN_STDIN}
is set explicitly on the command line,
any argument that would otherwise have been
taken as a file to run will instead be treated as a normal positional
parameter.
Note that setting or unsetting this option on the command line does not
necessarily affect the state the option will have while the shell is
running - that is purely an indicator of whether on not commands are
@emph{actually} being read from standard input.
The value of this option cannot be changed anywhere other 
than the command line.

@pindex SH_NULLCMD
@vindex NULLCMD, ignoring
@vindex READNULLCMD, ignoring
@cindex sh, redirections with no command
@cindex ksh, redirections with no command
@cindex redirections with no command, sh
@cindex redirections with no command, ksh
@item @t{SH_NULLCMD} <K> <S>
Do not use the values of @t{NULLCMD} and @t{READNULLCMD} 
when doing redirections, use `@t{:}' instead (see @ref{Redirection}).

@pindex SH_OPTION_LETTERS
@cindex sh, single letter options style
@cindex ksh, single letter options style
@cindex single letter options, ksh style
@cindex options, single letter, ksh style
@item @t{SH_OPTION_LETTERS} <K> <S>
If this option is set the shell tries to interpret single letter options
(which are used with @t{set} and @t{setopt}) like @cite{ksh} does.
This also affects the value of the @t{-} special parameter.

@pindex SHORT_LOOPS
@item @t{SHORT_LOOPS} <C> <Z>
Allow the short forms of @t{for}, @t{select},
@t{if}, and @t{function} constructs.

@pindex SH_WORD_SPLIT
@cindex field splitting, sh style
@cindex sh, field splitting style
@item @t{SH_WORD_SPLIT} (@t{-y}) <K> <S>
Causes field splitting to be performed on unquoted parameter expansions.
Note that this option has nothing to do with word splitting.
(See @ref{Parameter Expansion}.)

@pindex SINGLE_COMMAND
@cindex single command
@pindex INTERACTIVE, use of
@item @t{SINGLE_COMMAND} (@t{-t}, ksh: @t{-t})
If the shell is reading from standard input, it exits after a single command
has been executed.  This also makes the shell non-interactive, unless the
@t{INTERACTIVE} option is explicitly set on the command line.
The value of this option cannot be changed anywhere other than the command line.

@pindex SINGLE_LINE_ZLE
@cindex editor, single line mode
@item @t{SINGLE_LINE_ZLE} (@t{-M}) <K>
Use single-line command line editing instead of multi-line.

@pindex SUN_KEYBOARD_HACK
@cindex sun keyboard, annoying
@cindex annoying keyboard, sun
@item @t{SUN_KEYBOARD_HACK} (@t{-L})
If a line ends with a backquote, and there are an odd number
of backquotes on the line, ignore the trailing backquote.
This is useful on some keyboards where the return key is
too small, and the backquote key lies annoyingly close to it.

@pindex UNSET
@cindex parameters, substituting unset
@cindex unset parameters, substituting
@item @t{UNSET} (@t{+u}, ksh: @t{+u}) <K> <S> <Z>
Treat unset parameters as if they were empty when substituting.
Otherwise they are treated as an error.

@pindex VERBOSE
@cindex tracing, of input lines
@cindex input, tracing
@item @t{VERBOSE} (@t{-v}, ksh: @t{-v})
Print shell input lines as they are read.

@pindex XTRACE
@cindex tracing, of commands
@cindex commands, tracing
@item @t{XTRACE} (@t{-x}, ksh: @t{-x})
Print commands and their arguments as they are executed.

@pindex ZLE
@cindex editor, enabling
@cindex enabling the editor
@item @t{ZLE} (@t{-Z})
Use the zsh line editor.  Set by default in interactive shells connected to
a terminal.

@end table
@node Option Aliases, Single Letter Options, Description of Options, Options

@section Option Aliases
@noindent
@cindex options, aliases
Some options have alternative names.  These aliases are never used for
output, but can be used just like normal option names when specifying
options to the shell.

@noindent
@table @asis
@pindex BRACE_EXPAND
@item @t{BRACE_EXPAND}
@emph{NO_}@t{IGNORE_BRACES}
(ksh and bash compatibility)

@pindex DOT_GLOB
@item @t{DOT_GLOB}
@t{GLOB_DOTS}
(bash compatibility)

@pindex HASH_ALL
@item @t{HASH_ALL}
@t{HASH_CMDS}
(bash compatibility)

@pindex HIST_APPEND
@item @t{HIST_APPEND}
@t{APPEND_HISTORY}
(bash compatibility)

@pindex HIST_EXPAND
@item @t{HIST_EXPAND}
@t{BANG_HIST}
(bash compatibility)

@pindex LOG
@item @t{LOG}
@emph{NO_}@t{HIST_NO_FUNCTIONS}
(ksh compatibility)

@pindex MAIL_WARN
@item @t{MAIL_WARN}
@t{MAIL_WARNING}
(bash compatibility)

@pindex ONE_CMD
@item @t{ONE_CMD}
@t{SINGLE_COMMAND}
(bash compatibility)

@pindex PHYSICAL
@item @t{PHYSICAL}
@t{CHASE_LINKS}
(ksh and bash compatibility)

@pindex PROMPT_VARS
@item @t{PROMPT_VARS}
@t{PROMPT_SUBST}
(bash compatibility)

@pindex STDIN
@item @t{STDIN}
@t{SHIN_STDIN}
(ksh compatibility)

@pindex TRACK_ALL
@item @t{TRACK_ALL}
@t{HASH_CMDS}
(ksh compatibility)

@end table
@node Single Letter Options, , Option Aliases, Options

@section Single Letter Options
@noindent
@cindex options, single letter
@cindex single letter options

@subsection Default set
@noindent
@table @asis
@item @t{-0}
CORRECT
@item @t{-1}
PRINT_EXIT_VALUE
@item @t{-2}
@emph{NO_}BAD_PATTERN
@item @t{-3}
@emph{NO_}NOMATCH
@item @t{-4}
GLOB_DOTS
@item @t{-5}
NOTIFY
@item @t{-6}
BG_NICE
@item @t{-7}
IGNORE_EOF
@item @t{-8}
MARK_DIRS
@item @t{-9}
AUTO_LIST
@item @t{-B}
@emph{NO_}BEEP
@item @t{-C}
@emph{NO_}CLOBBER
@item @t{-D}
PUSHD_TO_HOME
@item @t{-E}
PUSHD_SILENT
@item @t{-F}
@emph{NO_}GLOB
@item @t{-G}
NULL_GLOB
@item @t{-H}
RM_STAR_SILENT
@item @t{-I}
IGNORE_BRACES
@item @t{-J}
AUTO_CD
@item @t{-K}
@emph{NO_}BANG_HIST
@item @t{-L}
SUN_KEYBOARD_HACK
@item @t{-M}
SINGLE_LINE_ZLE
@item @t{-N}
AUTO_PUSHD
@item @t{-O}
CORRECT_ALL
@item @t{-P}
RC_EXPAND_PARAM
@item @t{-Q}
PATH_DIRS
@item @t{-R}
LONG_LIST_JOBS
@item @t{-S}
REC_EXACT
@item @t{-T}
CDABLE_VARS
@item @t{-U}
MAIL_WARNING
@item @t{-V}
@emph{NO_}PROMPT_CR
@item @t{-W}
AUTO_RESUME
@item @t{-X}
LIST_TYPES
@item @t{-Y}
MENU_COMPLETE
@item @t{-Z}
ZLE
@item @t{-a}
ALL_EXPORT
@item @t{-e}
ERR_EXIT
@item @t{-f}
@emph{NO_}RCS
@item @t{-g}
HIST_IGNORE_SPACE
@item @t{-h}
HIST_IGNORE_DUPS
@item @t{-i}
INTERACTIVE
@item @t{-k}
INTERACTIVE_COMMENTS
@item @t{-l}
LOGIN
@item @t{-m}
MONITOR
@item @t{-n}
@emph{NO_}EXEC
@item @t{-p}
PRIVILEGED
@item @t{-r}
RESTRICTED
@item @t{-s}
SHIN_STDIN
@item @t{-t}
SINGLE_COMMAND
@item @t{-u}
@emph{NO_}UNSET
@item @t{-v}
VERBOSE
@item @t{-w}
CHASE_LINKS
@item @t{-x}
XTRACE
@item @t{-y}
SH_WORD_SPLIT
@end table

@subsection sh/ksh emulation set
@noindent
@table @asis
@item @t{-C}
@emph{NO_}CLOBBER
@item @t{-X}
MARK_DIRS
@item @t{-a}
ALL_EXPORT
@item @t{-b}
NOTIFY
@item @t{-e}
ERR_EXIT
@item @t{-f}
@emph{NO_}GLOB
@item @t{-i}
INTERACTIVE
@item @t{-l}
LOGIN
@item @t{-m}
MONITOR
@item @t{-n}
@emph{NO_}EXEC
@item @t{-p}
PRIVILEGED
@item @t{-r}
RESTRICTED
@item @t{-s}
SHIN_STDIN
@item @t{-t}
SINGLE_COMMAND
@item @t{-u}
@emph{NO_}UNSET
@item @t{-v}
VERBOSE
@item @t{-x}
XTRACE
@end table

@subsection Also note
@noindent
@table @asis
@item @t{-A}
Used by @t{set} for setting arrays
@item @t{-b}
Used on the command line to specify end of option processing
@item @t{-c}
Used on the command line to specify a single command
@item @t{-m}
Used by @t{setopt} for pattern-matching option setting
@item @t{-o}
Used in all places to allow use of long option names
@item @t{-s}
Used by @t{set} to sort positional parameters
@end table
@c (avoiding a yodl bug)
@c Yodl file: Zsh/builtins.yo
@node Shell Builtin Commands, Zsh Line Editor, Options, Top

@chapter Shell Builtin Commands
@noindent
@cindex builtin commands
@cindex commands, builtin
@table @asis
@findex -
@item @t{-} @var{simple command}
See @ref{Precommand Modifiers}.

@findex .
@item @t{.} @var{file} [ @var{arg} ... ]
Read commands from @var{file} and execute them in the current shell
environment.

@noindent
If @var{file} does not contain a slash, or if @t{PATH_DIRS} is set,
the shell looks in the components of @t{$path} to find the directory
containing @var{file}.  Files in the current directory are not read
unless `@t{.}' appears somewhere in @t{$path}.  If a file named
`@var{file}@t{.zwc}' is found, is newer than @var{file}, and is the
compiled form (created with the @t{zcompile} builtin) of @var{file},
then commands are read from that file instead of @var{file}.

@noindent
If any arguments @var{arg} are given,
they become the positional parameters; the old positional
parameters are restored when the @var{file} is done executing.
The exit status is the exit status of the last command executed.

@findex :
@cindex expanding parameters
@cindex parameters, expanding
@cindex doing nothing
@item @t{:} [ @var{arg} ... ]
This command does nothing, although normal argument expansions is performed
which may have effects on shell parameters.  A zero exit code is returned.

@findex alias
@cindex aliases, defining
@cindex aliases, listing
@item @t{alias} [ @{@t{+|@t{-}}@}@t{gmrL} ] [ @var{name}[@t{=}@var{value}] ... ]
For each @var{name} with a corresponding @var{value}, define an alias
with that value.  A trailing space in @var{value} causes the next word
to be checked for alias expansion.  If the @t{-g} flag is present,
define a global alias; global aliases are expanded even if they do not
occur in command position.

@noindent
For each @var{name} with no @var{value},
print the value of @var{name}, if any.  With no arguments, print all
currently defined aliases.  If the @t{-m} flag is given the arguments
are taken as patterns (they should be quoted to preserve them from being
interpreted as glob patterns), and the aliases matching these patterns
are printed.  When printing aliases and the @t{-g} or @t{-r} flags
are present, then restrict the printing to global or regular
aliases, respectively.  Using `@t{+}' instead of `@t{-}', or ending
the option list with a single `@t{+}', prevents the values of the
aliases from being printed.

@noindent
If the @t{-L} flag is present, then print each
alias in a manner suitable for putting in a startup script.  The exit
status is nonzero if a @var{name} (with no @var{value}) is given for
which no alias has been defined.

@findex autoload
@cindex functions, autoloading
@cindex autoloading functions
@item @t{autoload} [ @{@t{+}|@t{-}@}@t{UXmt} ] [ @t{-wkz} ] [ @var{name} ... ]
Equivalent to @t{functions -u}, with the exception of @t{-X}/@t{+X},
@t{-w}, @t{-k} and @t{-z}.

@noindent
The flag @t{-X} may be used only inside a shell function, and may not be
followed by a @var{name}.  It causes the calling function to be marked for
autoloading and then immediately loaded and executed, with the current
array of positional parameters as arguments.  This replaces the previous
definition of the function.  If no function definition is found, an error
is printed and the function remains undefined and marked for autoloading.

@noindent
The flag @t{+X} attempts to load each @var{name} as an autoloaded function,
but does @emph{not} execute it.  The exit status is zero (success) if the
function was not previously defined @emph{and} a definition for it was found.
This does @emph{not} replace any existing definition of the function.  The
exit status is nonzero (failure) if the function was already defined or
when no definition was found.  In the latter case the function remains
undefined and marked for autoloading.

@noindent
The flag @t{+X} may be combined with either @t{-k} or @t{-z} to make
the function be loaded using ksh-style or zsh-style autoloading,
respectively. If neither is given, the current setting of the
@t{KSH_AUTOLOAD} options determines how the function is loaded. With
ksh-style autoloading, the contents of the file will not be executed
immediately. Instead, the function created will contain the contents of 
the file plus a call to the function itself appended to it, thus given 
normal ksh autoloading behaviour on the first call to the function.

@noindent
With the @t{-w} flag, the @var{name}s are taken as names of files compiled
with the @t{zcompile} builtin, and all functions defined in them are
marked for autoloading.

@findex bg
@cindex jobs, backgrounding
@item @t{bg} [ @var{job} ... ]
@itemx @var{job} ... @t{&}
Put each specified @var{job} in the background,
or the current job if none is specified.

@item @t{bindkey}
See @ref{Zle Builtins}.

@findex break
@cindex exiting loops
@cindex loops, exiting
@item @t{break} [ @var{n} ]
Exit from an enclosing @t{for}, @t{while},
@t{until}, @t{select} or @t{repeat} loop.  If @var{n}
is specified, then break @var{n} levels instead of just one.

@findex builtin
@item @t{builtin} @var{name} [ @var{args} ... ]
Executes the builtin @var{name}, with the given @var{args}.

@findex bye
@item @t{bye}
Same as @t{exit}.

@item @t{cap}
See @ref{The zsh/cap Module}.

@findex cd
@cindex directories, changing
@item @t{cd} [ @t{-sLP} ] [ @var{arg} ]
@itemx @t{cd} [ @t{-sLP} ] @var{old} @var{new}
@itemx @t{cd} [ @t{-sLP} ] @{@t{+}|@t{-}@}@var{n}
Change the current directory.  In the first form, change the
current directory to @var{arg}, or to the value of @t{$HOME} if
@var{arg} is not specified.  If @var{arg} is `@t{-}', change to the
value of @t{$OLDPWD}, the previous directory.
Otherwise, if a directory named @var{arg} is not found in the current
directory and @var{arg} does not begin with a slash, search each
component of the shell parameter @t{cdpath}.  If no directory is found
and the option @t{CDABLE_VARS} is set, and a parameter named @var{arg}
exists whose value begins with a slash, treat its value as the
directory.  In that case, the parameter is added to the named
directory hash table.

@noindent
The second form of @t{cd} substitutes the string @var{new}
for the string @var{old} in the name of the current directory,
and tries to change to this new directory.

@noindent
The third form of @t{cd} extracts an entry from the directory
stack, and changes to that directory.  An argument of the form
`@t{+}@var{n}' identifies a stack entry by counting from the left
of the list shown by the @t{dirs} command, starting with zero.
An argument of the form `@t{-}@var{n}' counts from the right.
If the @t{PUSHD_MINUS} option is set, the meanings of `@t{+}'
and `@t{-}' in this context are swapped.

@noindent
If the @t{-s} option is specified, @t{cd} refuses to change the current
directory if the given pathname contains symlinks.  If the @t{-P} option
is given or the @t{CHASE_LINKS} option is set, symbolic links are resolved
to their true values.  If the @t{-L} option is given symbolic links are
followed regardless of the state of the @t{CHASE_LINKS} option.

@findex chdir
@item @t{chdir}
Same as @t{cd}.

@item @t{clone}
See @ref{The zsh/clone Module}.

@findex command
@item @t{command} @var{simple command}
See @ref{Precommand Modifiers}.

@item @t{comparguments}
See @ref{The zsh/computil Module}.

@item @t{compcall}
See @ref{The zsh/compctl Module}.

@item @t{compctl}
See @ref{The zsh/compctl Module}.

@item @t{compdescribe}
See @ref{The zsh/computil Module}.

@item @t{compfiles}
See @ref{The zsh/computil Module}.

@item @t{compgroups}
See @ref{The zsh/computil Module}.

@item @t{compquote}
See @ref{The zsh/computil Module}.

@item @t{comptags}
See @ref{The zsh/computil Module}.

@item @t{comptry}
See @ref{The zsh/computil Module}.

@item @t{compvalues}
See @ref{The zsh/computil Module}.

@findex continue
@cindex loops, continuing
@cindex continuing loops
@item @t{continue} [ @var{n} ]
Resume the next iteration of the enclosing
@t{for}, @t{while}, @t{until}, @t{select} or
@t{repeat} loop.  If @var{n} is specified, break out of
@var{n}-1 loops and resume at the @var{n}th enclosing loop.

@findex declare
@item @t{declare}
Same as @t{typeset}.

@findex dirs
@cindex directory stack, printing
@item @t{dirs} [ @t{-v} ] [ @var{arg} ... ]
With no arguments, print the contents of the directory stack.
If the @t{-v} option is given, number the directories
in the stack when printing.
Directories are added to this stack with the @t{pushd} command,
and removed with the @t{cd} or @t{popd} commands.
If arguments are specified, load them onto the directory stack,
replacing anything that was there, and push the current directory
onto the stack.

@findex disable
@cindex disabling commands
@cindex commands, disabling
@item @t{disable} [ @t{-afmr} ] @var{name} ...
Temporarily disable the @var{name}d hash table elements.  The default
is to disable builtin commands.  This allows you to use an external
command with the same name as a builtin command.  The @t{-a} option
causes @t{disable} to act on aliases.  The @t{-f} option causes
@t{disable} to act on shell functions.  The @t{-r} options causes
@t{disable} to act on reserved words.  Without arguments all disabled
hash table elements from the corresponding hash table are printed.
With the @t{-m} flag the arguments are taken as patterns (which should be
quoted to prevent them from undergoing filename expansion), and all hash
table elements from the corresponding hash table matching these patterns
are disabled.  Disabled objects can be enabled with the @t{enable}
command.

@findex disown
@cindex jobs, disowning
@item @t{disown} [ @var{job} ... ]
@itemx @var{job} ... @t{&|}
@itemx @var{job} ... @t{&!}
Remove the specified @var{job}s from the job table; the shell will
no longer report their status, and will not complain if you
try to exit an interactive shell with them running or stopped.
If no @var{job} is specified, disown the current job.

@findex echo
@item @t{echo} [ @t{-neE} ] [ @var{arg} ... ]
Write each @var{arg} on the standard output, with a space separating
each one.
If the @t{-n} flag is not present, print a newline at the end.
@t{echo} recognizes the following escape sequences:

@noindent
@table @asis
@item @t{\a}
bell character
@item @t{\b}
backspace
@item @t{\c}
suppress final newline
@item @t{\e}
escape
@item @t{\f}
form feed
@item @t{\n}
linefeed (newline)
@item @t{\r}
carriage return
@item @t{\t}
horizontal tab
@item @t{\v}
vertical tab
@item @t{\\}
backslash
@item @t{\0}@var{NNN}
character code in octal
@item @t{\x}@var{NN}
character code in hexadecimal
@end table

@noindent
@pindex BSD_ECHO, use of
The @t{-E} flag, or the @t{BSD_ECHO} option, can be used to disable
these escape sequences.  In the latter case, @t{-e} flag can be used to
enable them.

@item @t{echotc}
See @ref{The zsh/termcap Module}.

@item @t{echoti}
See @ref{The zsh/terminfo Module}.

@findex emulate
@cindex compatibility, sh
@cindex compatibility, ksh
@cindex compatibility, csh
@cindex sh, compatibility
@cindex ksh, compatibility
@cindex csh, compatibility
@item @t{emulate} [ @t{-LR} ] @{@t{zsh}|@t{sh}|@t{ksh}|@t{csh}@}
Set up zsh options to emulate the specified shell as much as possible.
@cite{csh} will never be fully emulated.
If the argument is not one of the shells listed above, @t{zsh}
will be used as a default; more precisely, the tests performed on the
argument are the same as those used to determine the emulation at startup
based on the shell name, see
@ref{Compatibility}
.  If the @t{-R} option is given, all options
are reset to their default value corresponding to the specified emulation
mode, except for certain options describing the interactive
environment; otherwise, only those options likely to cause portability
problems in scripts and functions are altered.  If the @t{-L} option
is given, the options @t{LOCAL_OPTIONS} and @t{LOCAL_TRAPS} will be set as
well, causing the effects of the @t{emulate} command and any @t{setopt} and
@t{trap} commands to be local to the immediately surrounding shell
function, if any; normally these options are turned off in all emulation
modes except @t{ksh}.

@findex enable
@cindex enabling commands
@cindex commands, enabling
@item @t{enable} [ @t{-afmr} ] @var{name} ...
Enable the @var{name}d hash table elements, presumably disabled
earlier with @t{disable}.  The default is to enable builtin commands.
The @t{-a} option causes @t{enable} to act on aliases.  The @t{-f}
option causes @t{enable} to act on shell functions.  The @t{-r}
option causes @t{enable} to act on reserved words.  Without arguments
all enabled hash table elements from the corresponding hash table are
printed.  With the @t{-m} flag the arguments are taken as patterns
(should be quoted) and all hash table elements from the corresponding
hash table matching these patterns are enabled.  Enabled objects can be
disabled with the @t{disable} builtin command.

@findex eval
@cindex evaluating arguments as commands
@item @t{eval} [ @var{arg} ... ]
Read the arguments as input to the shell and execute the resulting
command in the current shell process.

@findex exec
@item @t{exec} @var{simple command}
See @ref{Precommand Modifiers}.

@findex exit
@item @t{exit} [ @var{n} ]
Exit the shell with the exit code specified by @var{n}; if none
is specified, use the exit code from the last command executed.
@pindex IGNORE_EOF, use of
An EOF condition will also cause the shell to exit, unless
the @t{IGNORE_EOF} option is set.

@findex export
@item @t{export} [ @var{name}[@t{=}@var{value}] ... ]
The specified @var{name}s are marked for automatic export
to the environment of subsequently executed commands.
Equivalent to @t{typeset -gx}.
If a parameter specified does not
already exist, it is created in the global scope.

@findex false
@cindex doing nothing, unsuccessfully
@item @t{false} [ @var{arg} ... ]
Do nothing and return an exit code of 1.

@findex fc
@cindex history, editing
@cindex editing history
@item @t{fc} [ @t{-e} @var{ename} ] [ @t{-nlrdDfEim} ] [ @var{old}@t{=}@var{new} ... ] [ @var{first} [ @var{last} ] ]
@itemx @t{fc} @t{-ARWI} [ @var{filename} ]
Select a range of commands from @var{first} to @var{last} from the
history list.
The arguments @var{first} and @var{last} may be specified as a
number or as a string.  A negative number is used as an offset
to the current history event number.
A string specifies the most recent event beginning with the given string.
All substitutions @var{old}@t{=}@var{new}, if any, are then performed
on the commands.

@noindent
If the @t{-l} flag is given, the resulting commands are listed on
standard output.
If the @t{-m} flag is also given the first argument is taken as a
pattern (should be quoted) and only the history events matching this
pattern will be shown.
Otherwise the editor program @var{ename} is invoked on a file containing
these history events.  If @var{ename} is not given, the value
of the parameter @t{FCEDIT} is used.  If @var{ename} is `@t{-}',
no editor is invoked.  When editing is complete, the edited
command is executed.

@noindent
If @var{first} is not specified, it will be set to -1 (the most recent
event), or to -16 if the @t{-l} flag is given.
If @var{last} is not specified, it will be set to @var{first},
or to -1 if the @t{-l} flag is given.

@noindent
The flag @t{-r} reverses the order of the commands and the
flag @t{-n} suppresses command numbers when listing.
Also when listing, @t{-d} prints timestamps for each command, and
@t{-f} prints full time-date stamps.  Adding the @t{-E} flag
causes the dates to be printed as `@var{dd}@t{.}@var{mm}@t{.}@var{yyyy}',
instead of the default `@var{mm}@t{/}@var{dd}@t{/}@var{yyyy}'.
Adding the @t{-i} flag causes the dates to be printed in ISO8601
`@var{yyyy}@t{-}@var{mm}@t{-}@var{dd}' format.
With the @t{-D} flag, @t{fc} prints elapsed times.

@noindent
@cindex history, file
@cindex file, history
`@t{fc -R}' reads the history from the given file,
`@t{fc -W}' writes the history out to the given file,
and `@t{fc -A}' appends the history out to the given file.
If no filename is specified, the @t{$HISTFILE} is assumed.
If the @t{-I} option is added to @t{-R}, only those events that are
not already contained within the internal history list are added.
If the @t{-I} option is added to @t{-A} or @t{-W}, only those
events that are new since last incremental append/write to
the history file are appended/written.
In any case, the created file will have no more than @t{$SAVEHIST}
entries.

@findex fg
@cindex jobs, foregrounding
@cindex jobs, resuming
@item @t{fg} [ @var{job} ... ]
@itemx @var{job} ...
Bring each specified @var{job} in turn to the foreground.
If no @var{job} is specified, resume the current job.

@findex float
@item @t{float} [ @{@t{+}|@t{-}@}@t{EFHghlrtux} ] [ @var{name}[@t{=}@var{value}] ... ]
Equivalent to @t{typeset -E}, except that options irrelevant to floating
point numbers are not permitted.

@findex functions
@item @t{functions} [ @{@t{+}|@t{-}@}@t{UXmtu} ] [ @var{name} ... ]
Equivalent to @t{typeset -f}.

@item @t{getcap}
See @ref{The zsh/cap Module}.

@findex getln
@cindex line, reading
@cindex reading a line
@item @t{getln} [ @t{-AclneE} ] @var{name} ...
Read the top value from the buffer stack and put it in
the shell parameter @t{name}.  Equivalent to
@t{read -zr}.

@findex getopts
@cindex options, processing
@item @t{getopts} @var{optstring} @var{name} [ @var{arg} ... ]
Checks the @var{arg}s for legal options.  If the @var{arg}s are omitted,
use the positional parameters.  A valid option argument
begins with a `@t{+}' or a `@t{-}'.  An argument not beginning with
a `@t{+}' or a `@t{-}', or the argument `@t{--}', ends the options.
@var{optstring} contains the letters that @t{getopts}
recognizes.  If a letter is followed by a `@t{:}', that option
is expected to have an argument.  The options can be
separated from the argument by blanks.

@noindent
Each time it is invoked, @t{getopts} places the option letter it finds
in the shell parameter @var{name}, prepended with a `@t{+}' when
@var{arg} begins with a `@t{+}'.  The index of the next @var{arg}
is stored in @t{OPTIND}.  The option argument, if any,
is stored in @t{OPTARG}.
@vindex OPTIND, use of
@vindex OPTARG, use of

@noindent
The first option to be examined may be changed by explicitly assigning
to @t{OPTIND}.  @t{OPTIND} has an initial value of @t{1}, and is
normally reset to @t{1} upon exit from a shell function.  @t{OPTARG}
is not reset and retains its value from the most recent call to
@t{getopts}.  If either of @t{OPTIND} or @t{OPTARG} is explicitly
unset, it remains unset, and the index or option argument is not
stored.  The option itself is still stored in @var{name} in this case.

@noindent
A leading `@t{:}' in @var{optstring} causes @t{getopts} to store the
letter of any invalid option in @t{OPTARG}, and to set @var{name} to
`@t{?}' for an unknown option and to `@t{:}' when a required option is
missing.  Otherwise, @t{getopts} sets @var{name} to `@t{?}' and prints
an error message when an option is invalid.  The exit status is
nonzero when there are no more options.

@findex hash
@item @t{hash} [ @t{-Ldfmrv} ] [ @var{name}[@t{=}@var{value}] ] ...
@t{hash} can be used to directly modify the contents of the command
hash table, and the named directory hash table.  Normally one would
modify these tables by modifying one's @t{PATH}
(for the command hash table) or by creating appropriate shell parameters
(for the named directory hash table).
The choice of hash table to work on is determined by the @t{-d} option;
without the option the command hash table is used, and with the option the
named directory hash table is used.

@noindent
Given no arguments, and neither the @t{-r} or @t{-f} options,
the selected hash table will be listed in full.

@noindent
The @t{-r} option causes the selected hash table to be emptied.
It will be subsequently rebuilt in the normal fashion.
The @t{-f} option causes the selected hash table to be fully
rebuilt immediately.  For the command hash table this hashes
all the absolute directories in the @t{PATH},
and for the named directory hash table this adds all users' home directories.
These two options cannot be used with any arguments.

@noindent
The @t{-m} option causes the arguments to be taken as patterns
(which should be quoted) and the elements of the hash table
matching those patterns are printed.  This is the only way to display
a limited selection of hash table elements.

@noindent
For each @var{name} with a corresponding @var{value}, put `@var{name}' in
the selected hash table, associating it with the pathname `@var{value}'.
In the command hash table, this means that
whenever `@var{name}' is used as a command argument, the shell will try
to execute the file given by `@var{value}'.
In the named directory hash table, this means
that `@var{value}' may be referred to as `@t{~}@var{name}'.

@noindent
For each @var{name} with no
corresponding @var{value}, attempt to add @var{name} to the hash table,
checking what the appropriate @t{value} is in the normal manner for
that hash table.  If an appropriate @t{value} can't be found, then
the hash table will be unchanged.

@noindent
The @t{-v} option causes hash table entries to be listed as they are
added by explicit specification.  If has no effect if used with @t{-f}.

@noindent
If the @t{-L} flag is present, then each hash table entry is printed in
the form of a call to hash.

@findex history
@item @t{history}
Same as @t{fc -l}.

@findex integer
@item @t{integer} [ @{@t{+}|@t{-}@}@t{Hghilrtux} ] [ @var{name}[@t{=}@var{value}] ... ]
Equivalent to @t{typeset -i}, except that options irrelevant to
integers are not permitted.

@findex jobs
@item @t{jobs} [ @t{-dlprs} ] [ @var{job} ... ]
@itemx @t{jobs -Z} @var{string}
Lists information about each given job, or all jobs
if @var{job} is omitted.  The @t{-l} flag lists process
IDs, and the @t{-p} flag lists process groups.
If the @t{-r} flag is specified only running jobs will be listed
and if the @t{-s} flag is given only stopped jobs are shown.
If the @t{-d} flag is given, the directory from which the job was
started (which may not be the current directory of the job) will also
be shown.

@noindent
The @t{-Z} option replaces the shell's argument and environment space with
the given string, truncated if necessary to fit.  This will normally be
visible in @t{ps} (man page ps(1)) listings.  This feature is typically
used by daemons, to indicate their state.

@findex kill
@cindex killing jobs
@cindex jobs, killing
@item @t{kill} [ @t{-s} @var{signal_name} ] @var{job} ...
@itemx @t{kill} [ @t{-}@var{sig} ] @var{job} ...
@itemx @t{kill} @t{-l} [ @var{sig} ... ]
Sends either @t{SIGTERM} or the specified signal to the given
jobs or processes.
Signals are given by number or by names, without the `@t{SIG}' prefix.
If the signal being sent is not `@t{KILL}' or `@t{CONT}', then the job
will be sent a `@t{CONT}' signal if it is stopped.
The argument @var{job} can be the process ID of a job
not in the job list.
In the third form, @t{kill -l}, if @var{sig} is not
specified the signal names are listed.  Otherwise, for each
@var{sig} that is a name, the corresponding signal number is
listed.  For each @var{sig} that is a signal number or a number
representing the exit status of a process which was terminated or
stopped by a signal the name of the signal is printed.

@findex let
@item @t{let} @var{arg} ...
Evaluate each @var{arg} as an arithmetic expression.
See @ref{Arithmetic Evaluation} for a description
of arithmetic expressions.  The exit status is 0 if the
value of the last expression is nonzero, and 1 otherwise.

@findex limit
@cindex resource limits
@cindex limits, resource
@item @t{limit} [ @t{-hs} ] [ @var{resource} [ @var{limit} ] ] ...
Set or display resource limits.  Unless the @t{-s} flag is given,
the limit applies only the children of the shell.  If @t{-s} is
given without other arguments, the resource limits of the current
shell is set to the previously set resource limits of the children.

@noindent
If @var{limit} is not specified, print the current limit placed
on @var{resource}, otherwise
set the limit to the specified value.  If the @t{-h} flag
is given, use hard limits instead of soft limits.
If no @var{resource} is given, print all limits.

@noindent
@var{resource} can be one of:

@noindent
@table @asis
@item @t{addressspace}
Maximum amount of address space used.
@item @t{aiomemorylocked}
Maximum amount of memory locked in RAM for AIO operations.
@item @t{aiooperations}
Maximum number of AIO operations.
@item @t{cachedthreads}
Maximum number of cached threads.
@item @t{coredumpsize}
Maximum size of a core dump.
@item @t{cputime}
Maximum CPU seconds per process.
@item @t{datasize}
Maximum data size (including stack) for each process.
@item @t{descriptors}
Maximum value for a file descriptor.
@item @t{filesize}
Largest single file allowed.
@item @t{maxproc}
Maximum number of processes.
@item @t{maxpthreads}
Maximum number of threads per process.
@item @t{memorylocked}
Maximum amount of memory locked in RAM.
@item @t{memoryuse}
Maximum resident set size.
@item @t{resident}
Maximum resident set size.
@item @t{sockbufsize}
Maximum size of all socket buffers.
@item @t{stacksize}
Maximum stack size for each process.
@item @t{vmemorysize}
Maximum amount of virtual memory.
@end table

@noindent
Which of these resource limits are available depends on the system.
@var{resource} can be abbreviated to any unambiguous prefix.

@noindent
@var{limit} is a number, with an optional scaling factor, as follows:

@noindent
@table @asis
@item @var{n}@t{h}
hours
@item @var{n}@t{k}
kilobytes (default)
@item @var{n}@t{m}
megabytes or minutes
@item [@var{mm}@t{:}]@var{ss}
minutes and seconds
@end table

@findex local
@item @t{local} [ @{@t{+}|@t{-}@}@t{AEFHLRUZahilrtux} [@var{n}]] [ @var{name}[@t{=}@var{value}] ] ...
Same as @t{typeset}, except that the options @t{-g}, and
@t{-f} are not permitted.  In this case the @t{-x} option does not force
the use of @t{-g}, i.e. exported variables will be local to functions.

@findex log
@vindex watch, use of
@cindex watching users
@cindex users, watching
@item @t{log}
List all users currently logged in who are affected by
the current setting of the @t{watch} parameter.

@findex logout
@item @t{logout} [ @var{n} ]
Same as @t{exit}, except that it only works in a login shell.

@findex noglob
@item @t{noglob} @var{simple command}
See @ref{Precommand Modifiers}.

@findex popd
@item @t{popd} [ @{@t{+}|@t{-}@}@var{n} ]
Remove an entry from the directory stack, and perform a @t{cd} to
the new top directory.  With no argument, the current top entry is
removed.  An argument of the form `@t{+}@var{n}' identifies a stack
entry by counting from the left of the list shown by the @t{dirs} command,
starting with zero.  An argument of the form @t{-n} counts from the right.
@pindex PUSHD_MINUS, use of
If the @t{PUSHD_MINUS} option is set, the meanings of `@t{+}' and
`@t{-}' in this context are swapped.

@findex print
@item @t{print} [ @t{-bnrslzpNDPoOicm} ] [ @t{-u}@var{n} ] [ @t{-R} [ @t{-en} ]] [ @var{arg} ... ]
With no flags or with the flag `@t{-}', the arguments are printed on
the standard output as described by @t{echo}, with the following differences:
the escape sequence `@t{\M-}@var{x}' metafies the character
@var{x} (sets the highest bit),
`@t{\C-}@var{x}' produces a control character (`@t{\C-@@}' and `@t{\C-?}' give the
characters NUL and delete), and `@t{\E}' is a synonym for `@t{\e}'.
Finally, if not in an escape
sequence, `@t{\}' escapes the following character and is not printed.

@noindent
@table @asis
@item @t{-r}
Ignore the escape conventions of @t{echo}.

@item @t{-R}
Emulate the BSD @t{echo} command, which does not process escape sequences
unless the @t{-e} flag is given.  The @t{-n} flag suppresses the trailing
newline.  Only the @t{-e} and @t{-n} flags are recognized after
@t{-R}; all other arguments and options are printed.

@item @t{-b}
Recognize all the escape sequences defined for the @t{bindkey} command,
see 
@ref{Zle Builtins}.

@item @t{-m}
Take the first argument as a pattern (should be quoted), and remove
it from the argument list together with subsequent arguments that
do not match this pattern.

@item @t{-s}
Place the results in the history list instead of on the standard output.

@item @t{-n}
Do not add a newline to the output.

@item @t{-l}
Print the arguments separated by newlines instead of spaces.

@item @t{-N}
Print the arguments separated and terminated by nulls.

@item @t{-o}
Print the arguments sorted in ascending order.

@item @t{-O}
Print the arguments sorted in descending order.

@item @t{-i}
If given together with @t{-o} or @t{-O}, sorting is performed
case-independently.

@item @t{-c}
Print the arguments in columns.

@item @t{-u}@var{n}
Print the arguments to file descriptor @var{n}.

@item @t{-p}
Print the arguments to the input of the coprocess.

@item @t{-z}
Push the arguments onto the editing buffer stack, separated by spaces.

@item @t{-D}
Treat the arguments as directory names, replacing prefixes with @t{~}
expressions, as appropriate.

@item @t{-P}
Perform prompt expansion (see
@ref{Prompt Expansion}).

@end table

@findex pushd
@pindex PUSHD_TO_HOME, use of
@pindex PUSHD_MINUS, use of
@pindex CDABLE_VARS, use of
@pindex PUSHD_SILENT, use of
@item @t{pushd} [ @var{arg} ]
@itemx @t{pushd} @var{old} @var{new}
@itemx @t{pushd} @{@t{+}|@t{-}@}@var{n}
Change the current directory, and push the old current directory
onto the directory stack.  In the first form, change the
current directory to @var{arg}.
If @var{arg} is not specified, change to the second directory
on the stack (that is, exchange the top two entries), or
change to @t{$HOME} if the @t{PUSHD_TO_HOME}
option is set or if there is only one entry on the stack.
Otherwise, @var{arg} is interpreted as it would be by @t{cd}.
The meaning of @var{old} and @var{new} in the second form is also
the same as for @t{cd}.

@noindent
The third form of @t{pushd} changes directory by rotating the
directory list.  An argument of the form `@t{+}@var{n}' identifies a stack
entry by counting from the left of the list shown by the @t{dirs}
command, starting with zero.  An argument of the form `@t{-}@var{n}' counts
from the right.  If the @t{PUSHD_MINUS} option is set, the meanings
of `@t{+}' and `@t{-}' in this context are swapped.

@noindent
If the option @t{PUSHD_SILENT} is not set, the directory
stack will be printed after a @t{pushd} is performed.

@findex pushln
@item @t{pushln} [ @var{arg} ... ]
Equivalent to @t{print -nz}.

@findex pwd
@pindex CHASE_LINKS, use of
@item @t{pwd} [ @t{-rLP} ]
Print the absolute pathname of the current working directory.
If the @t{-r} or the @t{-P} flag is specified, or the @t{CHASE_LINKS}
option is set and the @t{-L} flag is not given, the printed path will not
contain symbolic links.

@findex r
@item @t{r}
Same as @t{fc -e -}.

@findex read
@vindex IFS, use of

@item @t{read} [ @t{-rzpqAclneEt} ] [ @t{-k} [ @var{num} ] ] [ @t{-u}@var{n} ] [ @var{name}[@t{?}@var{prompt}] ] [ @var{name} ...  ]
@vindex REPLY, use of
@vindex reply, use of
Read one line and break it into fields using the characters
in @t{$IFS} as separators, except as noted below.
The first field is assigned to the first @var{name}, the second field
to the second @var{name}, etc., with leftover
fields assigned to the last @var{name}.
If @var{name} is omitted then
@t{REPLY} is used for scalars and @t{reply} for arrays.

@noindent
@table @asis
@item @t{-r}
Raw mode: a `@t{\}' at the end of a line does not signify line
continuation and backslashes in the line don't quote the following
character and are not removed.

@item @t{-q}
Read only one character from the terminal and set @var{name} to
`@t{y}' if this character was `@t{y}' or `@t{Y}' and to `@t{n}' otherwise.
With this flag set the return value is zero only if the character was
`@t{y}' or `@t{Y}'.  Note that this always reads from the terminal, even
if used with the @t{-p} or @t{-u} or @t{-z} flags or with redirected input.
This option may also be used within zle widgets.

@item @t{-k} [ @var{num} ]
Read only one (or @var{num}) characters.  All are assigned to the first
@var{name}, without word splitting.  This flag is ignored when @t{-q} is
present.  Input is read from the terminal unless one of @t{-u} or @t{-p}
is present.  This option may also be used within zle widgets.

@noindent
Note that @var{num} must be in the argument word that follows @t{-k}, not
in the same word.  See @t{-u}.

@item @t{-z}
Read one entry from the editor buffer stack and assign it to the first
@var{name}, without word splitting.  Text is pushed onto the stack with
`@t{print -z}' or with @t{push-line} from the line editor (see
@ref{Zsh Line Editor}).  This flag is ignored when the @t{-k} or @t{-q} flags are present.

@item @t{-e}
@itemx @t{-E}
The input read is printed (echoed) to the standard output.  If the @t{-e}
flag is used, no input is assigned to the parameters.

@item @t{-A}
The first @var{name} is taken as the name of an array and all words are
assigned to it.

@item @t{-c}
@itemx @t{-l}
These flags are allowed only if called inside a
function used for completion (specified with the @t{-K} flag to
@t{compctl}).  If the @t{-c} flag is given, the words of the
current command are read. If the @t{-l} flag is given, the whole
line is assigned as a scalar.  If both flags are present, @t{-l}
is used and @t{-c} is ignored.

@item @t{-n}
Together with @t{-c}, the number of the word the cursor is on is
read.  With @t{-l}, the index of the character the cursor is on is
read.  Note that the command name is word number 1, not word 0,
and that when the cursor is at the end of the line, its character
index is the length of the line plus one.

@item @t{-u}@var{n}
Input is read from file descriptor @var{n}, where @var{n} is a single
digit and must @emph{not} be separated from @t{-u} by any whitespace.

@item @t{-p}
Input is read from the coprocess.

@item @t{-t}
Test if input is available before attempting to read; if none is, return
status 1 and do not set any variables.  This is not available when reading
from the editor buffer with @t{-z}, when called from within completion
with @t{-c} or @t{-l}, with @t{-q} which clears the input queue before
reading, or within zle where other mechanisms should be used to test for
input.

Note that read does not attempt to alter the input processing mode.  The
default mode is canonical input, in which an entire line is read at a time,
so usually `@t{read -t}' will not read anything until an entire line has
been typed.  However, when reading from the terminal with @t{-k}
this is automatically handled; note that only availability of the first
character is tested, so that e.g. `@t{read -t -k 2}' can still block on the
second character.

@end table
If the first argument contains a `@t{?}', the remainder of this
word is used as a @var{prompt} on standard error when the shell
is interactive.

@noindent
The value (exit status) of @t{read} is 1 when an end-of-file is
encountered, or when @t{-c} or @t{-l} is present and the command is
not called from a @t{compctl} function, or as described for @t{-q}.
Otherwise the value is 0.

@noindent
The behavior of some combinations of the @t{-k}, @t{-p}, @t{-q}, @t{-u}
and @t{-z} flags is undefined.  Presently @t{-q} cancels all the others,
@t{-p} cancels @t{-u}, @t{-k} cancels @t{-z}, and otherwise @t{-z}
cancels both @t{-p} and @t{-u}.

@noindent
The @t{-c} or @t{-l} flags cancel any and all of @t{-kpquz}.

@cindex parameters, marking readonly
@findex readonly
@item @t{readonly}
Same as @t{typeset -r}.

@findex rehash
@item @t{rehash}
Same as @t{hash -r}.

@findex return
@cindex functions, returning from
@item @t{return} [ @var{n} ]
Causes a shell function or @t{.} script to return to
the invoking script with the return status specified by @var{n}.  If @var{n}
is omitted, the return status is that of the last command
executed.

@noindent
If @t{return} was executed from a trap in a @t{TRAP}@var{NAL} function,
the effect is different for zero and non-zero return status.  With zero
status (or after an implicit return at the end of the trap), the shell
will return to whatever it was previously processing; with a non-zero
status, the shell will behave as interrupted except that the return
status of the trap is retained.  Note that the numeric value of the signal
which caused the trap is passed as the first argument, so the statement
`@t{return $((128+$1))}' will return the same status as if the signal
had not been trapped.

@item @t{sched}
See @ref{The zsh/sched Module}.

@findex set
@cindex parameters, listing
@cindex parameters, positional
@cindex parameters, setting array
@cindex array parameters, setting
@item @t{set} [ @{@t{+}|@t{-}@}@var{options} | @{@t{+}|@t{-}@}@t{o} @var{option_name} ] ... [ @{@t{+}|@t{-}@}@t{A} [ @var{name} ] ] [ @var{arg} ... ]
Set the options for the shell and/or set the positional parameters, or
declare and set an array.  If the @t{-s} option is given, it causes the
specified arguments to be sorted before assigning them to the positional
parameters (or to the array @var{name} if @t{-A} is used).  With @t{+s}
sort arguments in descending order.  For the meaning of the other flags, see
@ref{Options}.  Flags may be specified by name using the @t{-o} option.

@noindent
If the @t{-A} flag is specified, @var{name} is
set to an array containing the given @var{arg}s. if @t{+A} is used and
@var{name} is an array, the given arguments will replace the initial
elements of that array; if no @var{name} is specified, all arrays are
printed.  Otherwise the positional parameters are set.  If no arguments are
given, then the names and values of all parameters are printed on the
standard output.  If the only argument is `@t{+}',
the names of all parameters are printed.

@item @t{setcap}
See @ref{The zsh/cap Module}.

@findex setopt
@cindex options, setting
@item @t{setopt} [ @{@t{+}|@t{-}@}@var{options} | @{@t{+}|@t{-}@}@t{o} @var{option_name} ] [ @var{name} ... ]
Set the options for the shell.  All options specified either
with flags or by name are set.  If no arguments are supplied,
the names of all options currently set are printed.
If the @t{-m} flag is given the arguments are taken as patterns
(which should be quoted to protect them from filename expansion), and all
options with names matching these patterns are set.

@findex shift
@cindex parameters, positional
@item @t{shift} [ @var{n} ] [ @var{name} ... ]
The positional parameters @t{$@{}@var{n}+1@t{@}} ... are renamed
to @t{$1} ..., where @var{n} is an arithmetic expression that
defaults to 1.
If any @var{name}s are given then the arrays with these names are
shifted instead of the positional parameters.

@findex source
@item @t{source} @var{file} [ @var{arg} ... ]
Same as @t{.}, except that the current directory is always searched and
is always searched first, before directories in @t{$path}.

@item @t{stat}
See @ref{The zsh/stat Module}.

@findex suspend
@cindex shell, suspending
@cindex suspending the shell
@item @t{suspend} [ @t{-f} ]
Suspend the execution of the shell (send it a @t{SIGTSTP})
until it receives a @t{SIGCONT}.
Unless the @t{-f} option is given, this will refuse to suspend a login shell.

@findex test
@item @t{test} [ @var{arg} ... ]
@itemx @t{[} [ @var{arg} ... ] @t{]}
Like the system version of @t{test}.  Added for compatibility;
use conditional expressions instead (see @ref{Conditional Expressions}).

@findex times
@cindex shell, timing
@cindex timing the shell
@item @t{times}
Print the accumulated user and system times for the shell
and for processes run from the shell.

@findex trap
@cindex signals, trapping
@cindex trapping signals
@item @t{trap} [ @var{arg} [ @var{sig} ... ] ]
@var{arg} is a series of commands (usually quoted to protect it from
immediate evaluation by the shell) to be read and executed when the shell
receives @var{sig}.  Each @var{sig} can be given as a number
or as the name of a signal.
If @var{arg} is `@t{-}', then all traps @var{sig} are reset to their
default values.  If @var{arg} is the empty string, then this signal
is ignored by the shell and by the commands it invokes.

@noindent
If @var{sig} is @t{ZERR} then @var{arg} will be executed
after each command with a nonzero exit status.
If @var{sig} is @t{DEBUG} then @var{arg} will be executed
after each command.
If @var{sig} is @t{0} or @t{EXIT}
and the @t{trap} statement is executed inside the body of a function,
then the command @var{arg} is executed after the function completes.
If @var{sig} is @t{0} or @t{EXIT}
and the @t{trap} statement is not executed inside the body of a function,
then the command @var{arg} is executed when the shell terminates.

@noindent
The @t{trap} command with no arguments prints a list of commands
associated with each signal.

@noindent
Note that traps defined with the @t{trap} builtin are slightly different
from those defined as `@t{TRAP}@var{NAL} () @{ ... @}', as the latter have
their own function environment (line numbers, local variables, etc.) while
the former use the environment of the command in which they were called.
For example,

@noindent
@example
trap 'print $LINENO' DEBUG
@end example

@noindent
will print the line number of a command executed after it has run, while

@noindent
@example
TRAPDEBUG() @{ print $LINENO; @}
@end example

@noindent
will always print the number zero.

@findex true
@cindex doing nothing, successfully
@item @t{true} [ @var{arg} ... ]
Do nothing and return an exit code of 0.

@findex ttyctl
@cindex tty, freezing
@item @t{ttyctl} @t{-fu}
The @t{-f} option freezes the tty, and @t{-u} unfreezes it.
When the tty is frozen, no changes made to the tty settings by
external programs will be honored by the shell, except for changes in the
size of the screen; the shell will
simply reset the settings to their previous values as soon as each
command exits or is suspended.  Thus, @t{stty} and similar programs have
no effect when the tty is frozen.  Without options it reports whether the
terminal is frozen or not.

@findex type
@item @t{type} [ @t{-wfpams} ] @var{name} ...
Equivalent to @t{whence -v}.

@findex typeset
@cindex parameters, setting
@cindex parameters, declaring
@item @t{typeset} [ @{@t{+}|@t{-}@}@t{AEFHLRUZafghilrtuxm} [@var{n}]] [ @var{name}[@t{=}@var{value}] ... ]
@itemx @t{typeset} -T [ @{@t{+|@t{-}}@}@t{LRUZrux} ] @var{SCALAR}[@t{=}@var{value}] @var{array}
Set or display attributes and values for shell parameters.

@noindent
A parameter is created for each @var{name} that does not already refer
to one.  When inside a function, a new parameter is created for every
@var{name} (even those that already exist), and is unset again when the
function completes.  See
@ref{Local Parameters}.  The same rules apply to special shell parameters, which
retain their special attributes when made local.

@noindent
For each @var{name}@t{=}@var{value} assignment, the parameter
@var{name} is set to @var{value}.  Note that arrays currently cannot be
assigned in @t{typeset} expressions, only scalars and integers.

@noindent
For each remaining @var{name} that refers to a parameter that is set, the
name and value of the parameter are printed in the form of an assignment.
Nothing is printed for newly-created parameters, or when any attribute
flags listed below are given along with the @var{name}.  Using `@t{+}'
instead of minus to introduce an attribute turns it off.

@noindent
If the @t{-T} option is given, exactly two (or zero) @var{name}
arguments must be present.  They represent a scalar and an array (in
that order) that will be tied together in the manner of @t{$PATH} and
@t{$path}.  In other words, an array present in the latter variable
appears as a scalar with the elements of the array joined by colons in
the former.  Only the scalar may have an initial value.  Both the
scalar and the array may otherwise be manipulated as normal.  If one
is unset, the other will automatically be unset too.  There is no way
of untying the variables without unsetting them, or converting the
type of one of them with another @t{typeset} command; @t{+T} does not
work, assigning an array to @var{SCALAR} is an error, and assigning a
scalar to @var{array} sets it to be a single-element array.  Note that
both `@t{typeset -xT ...}' and `@t{export -T ...}' work, but only the
scalar will be marked for export.

@noindent
The @t{-g} (global) flag is treated specially: it means that any
resulting parameter will not be restricted to local scope.  Note that this
does not necessarily mean that the parameter will be global, as the flag
will apply to any existing parameter (even if unset) from an enclosing
function.  This flag does not affect the parameter after creation, hence it
has no effect when listing existing parameters, nor does the flag @t{+g}
have any effect except in combination with @t{-m} (see below).

@noindent
If no @var{name} is present, the names and values of all parameters are
printed.  In this case the attribute flags restrict the display to only
those parameters that have the specified attributes, and using `@t{+}'
rather than `@t{-}' to introduce the flag suppresses printing of the values
of parameters when there is no parameter name.  Also, if the last option
is the word `@t{+}', then names are printed but values are not.

@noindent
If the @t{-m} flag is given the @var{name} arguments are taken as patterns
(which should be quoted).  With no attribute flags, all parameters (or
functions with the @t{-f} flag) with matching names are printed.  Note that
@t{-m} is ignored if no patterns are given.  If the @t{+g} flag is combined
with @t{-m}, a new local parameter is created for every matching parameter
that is not already local.  Otherwise @t{-m} applies all other flags or
assignments to the existing parameters.  Except when assignments are made
with @var{name}@t{=}@var{value}, using @t{+m} forces the matching parameters
to be printed, even inside a function.

@noindent
If no attribute flags are given and either no @t{-m} flag is present or
the @t{+m} form was used, each parameter name printed is preceded by a
list of the attributes of that parameter (@t{array}, @t{association},
@t{exported}, @t{integer}, @t{readonly}).  If @t{+m} is used with attribute
flags, and all those flags are introduced with @t{+}, the matching
parameter names are printed but their values are not.

@noindent
The following attribute flags may be specified:

@noindent
@table @asis
@item @t{-A}
The names refer to associative array parameters; see
@ref{Array Parameters}.

@item @t{-L}
Left justify and remove leading blanks from @var{value}.
If @var{n} is nonzero, it defines the width of the field;
otherwise it is determined by the width of the value of the first
assignment.
When the parameter is expanded, it is filled on the right with
blanks or truncated if necessary to fit the field.
Leading zeros are removed if the @t{-Z} flag is also set.

@item @t{-R}
Right justify and fill with leading blanks.  If @var{n} is nonzero
if defines the width of the field;
otherwise it is determined by the width of the value of the first
assignment.
When the parameter is expanded, the field is left filled with
blanks or truncated from the end.

@item @t{-U}
For arrays (but not for associative arrays), keep only the first
occurrence of each duplicated value.  This may also be set for
colon-separated special parameters like @t{PATH} or @t{FIGNORE}, etc.
This flag has a different meaning when used with @t{-f}; see below.

@item @t{-Z}
Right justify and fill with leading zeros if the first non-blank
character is a digit and the @t{-L} flag has not been set.
If @var{n} is nonzero it defines the width of the field;
otherwise it is determined by the width of the value of the
first assignment.

@item @t{-a}
The names refer to array parameters.  An array parameter may be
created this way, but it may not be assigned to in the @t{typeset}
statement.  When displaying, both normal and associative arrays are
shown.

@item @t{-f}
The names refer to functions rather than parameters.  No assignments
can be made, and the only other valid flags are @t{-t}, @t{-u} and
@t{-U}.  The flag @t{-t} turns on execution tracing for this
function.  The @t{-u} and @t{-U} flags cause the function to be
marked for autoloading; @t{-U} also causes alias expansion to be
suppressed when the function is loaded.  The @t{fpath} parameter
will be searched to find the function definition when the function
is first referenced; see @ref{Functions}.

@item @t{-h}
Hide: only useful for special parameters (those marked `<S>' in the table in
@ref{Parameters Set By The Shell}), and for local parameters with the same name as a special parameter,
though harmless for others.  A special parameter with this attribute will
not retain its special effect when made local.  Thus after `@t{typeset -h
PATH}', a function containing `@t{typeset PATH}' will create an ordinary
local parameter without the usual behaviour of @t{PATH}.  Alternatively,
the local parameter may itself be given this attribute; hence inside a
function `@t{typeset -h PATH}' creates an ordinary local parameter and the
special @t{PATH} parameter is not altered in any way.  It is also possible
to create a local parameter using `@t{typeset +h }@var{special}', where the
local copy of @var{special} will retain its special properties regardless of
having the @t{-h} attribute.  Global special parameters loaded from shell
modules (currently those in @t{zsh/mapfile} and @t{zsh/parameter}) are
automatically given the @t{-h} attribute to avoid name clashes.

@item @t{-H}
Hide value: specifies that @t{typeset} will not display the value of the
parameter when listing parameters; the display for such parameters is
always as if the `@t{+}' flag had been given.  Use of the parameter is
in other respects normal, and the option does not apply if the parameter is
specified by name, or by pattern with the @t{-m} option.  This is on by
default for the parameters in the @t{zsh/parameter} and @t{zsh/mapfile}
modules.  Note, however, that unlike the @t{-h} flag this is also useful
for non-special parameters.

@item @t{-i}
Use an internal integer representation.  If @var{n} is nonzero it
defines the output arithmetic base, otherwise it is determined by the
first assignment.

@item @t{-E}
Use an internal double-precision floating point representation.  On output
the variable will be converted to scientific notation.  If @var{n} is
nonzero it defines the number of significant figures to display; the
default is ten.

@item @t{-F}
Use an internal double-precision floating point representation.  On output
the variable will be converted to fixed-point decimal notation.  If @var{n}
is nonzero it defines the number of digits to display after the decimal
point; the default is ten.

@item @t{-l}
Convert the result to lower case whenever the parameter is expanded.
The value is @emph{not} converted when assigned.

@item @t{-r}
The given @var{name}s are marked readonly.

@item @t{-t}
Tags the named parameters.  Tags have no special meaning to the shell.
This flag has a different meaning when used with @t{-f}; see above.

@item @t{-u}
Convert the result to upper case whenever the parameter is expanded.
The value is @emph{not} converted when assigned.
This flag has a different meaning when used with @t{-f}; see above.

@item @t{-x}
Mark for automatic export to the environment of subsequently
executed commands.  If the option @t{GLOBAL_EXPORT} is set, this implies
the option @t{-g}, unless @t{+g} is also explicitly given; in other words
the parameter is not made local to the enclosing function.  This is for
compatibility with previous versions of zsh.

@end table

@findex ulimit
@cindex resource limits
@cindex limits, resource
@item @t{ulimit} [ @t{-SHacdflmnpstv} [ @var{limit} ] ... ]
Set or display resource limits of the shell and the processes started by
the shell.  The value of @var{limit} can be a number in the unit specified
below or the value `@t{unlimited}'.  By default, only soft limits are
manipulated. If the @t{-H} flag is given use
hard limits instead of soft limits.  If the @t{-S} flag is given
together with the @t{-H} flag set both hard and soft limits.  If no
options are used, the file size limit (@t{-f}) is assumed.  If
@var{limit} is omitted the current value of the specified resources are
printed.  When more than one resource values are printed the limit name and
unit is printed before each value.

@noindent
@table @asis
@item @t{-a}
Lists all of the current resource limits.
@item @t{-c}
512-byte blocks on the size of core dumps.
@item @t{-d}
K-bytes on the size of the data segment.
@item @t{-f}
512-byte blocks on the size of files written.
@item @t{-l}
K-bytes on the size of locked-in memory.
@item @t{-m}
K-bytes on the size of physical memory.
@item @t{-n}
open file descriptors.
@item @t{-s}
K-bytes on the size of the stack.
@item @t{-t}
CPU seconds to be used.
@item @t{-u}
processes available to the user.
@item @t{-v}
K-bytes on the size of virtual memory.
@end table

@findex umask
@cindex umask
@item @t{umask} [ @t{-S} ] [ @var{mask} ]
The umask is set to @var{mask}.  @var{mask} can be either
an octal number or a symbolic value as described in man page chmod(1).
If @var{mask} is omitted, the current value is printed.  The @t{-S}
option causes the mask to be printed as a symbolic value.  Otherwise,
the mask is printed as an octal number.  Note that in
the symbolic form the permissions you specify are those which are to be
allowed (not denied) to the users specified.

@cindex aliases, removing
@findex unalias
@item @t{unalias}
Same as @t{unhash -a}.

@cindex functions, removing
@findex unfunction
@item @t{unfunction}
Same as @t{unhash -f}.

@findex unhash
@item @t{unhash} [ @t{-adfm} ] @var{name} ...
Remove the element named @var{name} from an internal hash table.  The
default is remove elements from the command hash table.  The @t{-a}
option causes @t{unhash} to remove aliases.  The @t{-f} option causes
@t{unhash} to remove shell functions.  The @t{-d} options causes
@t{unhash} to remove named directories.  If the @t{-m} flag is given
the arguments are taken as patterns (should be quoted) and all elements
of the corresponding hash table with matching names will be removed.

@findex unlimit
@cindex resource limits
@cindex limits, resource
@item @t{unlimit} [ @t{-hs} ] @var{resource} ...
The resource limit for each @var{resource} is set to the hard limit.
If the @t{-h} flag is given and the shell has appropriate privileges,
the hard resource limit for each @var{resource} is removed.
The resources of the shell process are only changed if the @t{-s}
flag is given.

@findex unset
@cindex parameters, unsetting
@item @t{unset} [ @t{-fmv} ] @var{name} ...
Each named parameter is unset.
Local parameters remain local even if unset; they appear unset within scope,
but the previous value will still reappear when the scope ends.

@noindent
Individual elements of associative array parameters may be unset by using
subscript syntax on @var{name}, which should be quoted (or the entire command
prefixed with @t{noglob}) to protect the subscript from filename generation.

@noindent
If the @t{-m} flag is specified the arguments are taken as patterns (should
be quoted) and all parameters with matching names are unset.  Note that this
cannot be used when unsetting associative array elements, as the subscript
will be treated as part of the pattern.

@noindent
The @t{-v} flag specifies that @var{name} refers to parameters. This is the
default behaviour.

@noindent
@t{unset -f} is equivalent to @t{unfunction}.

@findex unsetopt
@cindex options, unsetting
@item @t{unsetopt} [ @{@t{+}|@t{-}@}@var{options} | @{@t{+}|@t{-}@}@t{o} @var{option_name} ] [ @var{name} ... ]
Unset the options for the shell.  All options specified either
with flags or by name are unset.  If no arguments are supplied,
the names of all options currently unset are printed.
If the @t{-m} flag is given the arguments are taken as patterns
(which should be quoted to preserve them from being interpreted as glob
patterns), and all options with names matching these patterns are unset.

@item @t{vared}
See @ref{Zle Builtins}.

@findex wait
@cindex waiting for jobs
@cindex jobs, waiting for
@item @t{wait} [ @var{job} ... ]
Wait for the specified jobs or processes.  If @var{job} is not given
then all currently active child processes are waited for.
Each @var{job} can be either a job specification or the process ID
of a job in the job table.
The exit status from this command is that of the job waited for.

@findex whence
@item @t{whence} [ @t{-vcwfpams} ] @var{name} ...
For each name, indicate how it would be interpreted if used as a
command name.

@noindent
@table @asis
@item @t{-v}
Produce a more verbose report.

@item @t{-c}
Print the results in a @cite{csh}-like format.
This takes precedence over @t{-v}.

@item @t{-w}
For each @var{name}, print `@var{name}@t{:} @var{word}' where @var{word}
is one of @t{alias}, @t{builtin}, @t{command}, @t{function},
@t{hashed}, @t{reserved} or @t{none}, according as @var{name}
corresponds to an alias, a built-in command, an external command, a
shell function, a command defined with the @t{hash} builtin, a
reserved word, or is not recognised.  This takes precedence over
@t{-v} and @t{-c}.

@item @t{-f}
Causes the contents of a shell function to be
displayed, which would otherwise not happen unless the @t{-c}
flag were used.

@item @t{-p}
Do a path search for @var{name}
even if it is an alias, reserved word, shell function or builtin.

@item @t{-a}
Do a search for all occurrences of @var{name}
throughout the command path.
Normally only the first occurrence is printed.

@item @t{-m}
The arguments are taken as patterns (should be
quoted), and the information is displayed for each command matching one
of these patterns.

@item @t{-s}
If a pathname contains symlinks, print the symlink-free pathname as well.

@end table

@findex where
@item @t{where} [ @t{-wpms} ] @var{name} ...
Equivalent to @t{whence -ca}.

@findex which
@item @t{which} [ @t{-wpams} ] @var{name} ...
Equivalent to @t{whence -c}.

@findex zcompile
@cindex .zwc files, creation
@cindex compilation
@item @t{zcompile} [ @t{-U} ] [ @t{-z} | @t{-k} ] [ @t{-R} | @t{-M} ] @var{file} [ @var{name} ... ]
@itemx @t{zcompile} @t{-ca} [ @t{-m} ] [ @t{-R} | @t{-M} ] @var{file} [ @var{name} ... ]
@itemx @t{zcompile -t} @var{file} [ @var{name} ... ]
This builtin command can be used to compile functions or scripts,
storing the compiled form in a file, and to examine files containing
the compiled form.  This allows faster autoloading of functions and
execution of scripts by avoiding parsing of the text when the files
are read.

@noindent
The first form (without the @t{-c}, @t{-a} or @t{-t} options) creates a
compiled file.  If only the @var{file} argument is given, the
output file has the name `@var{file}@t{.zwc}' and will be placed in
the same directory as the @var{file}.  The shell will load the compiled
file instead of the normal function file when the function
is autoloaded; see
@ref{Functions}
for a description of how autoloaded functions are searched.  The
extension @t{.zwc} stands for `zsh word code'.

@noindent
If there is at least one @var{name} argument, all the named files
are compiled into the output @var{file} given as the first argument.  If
@var{file} does not end in @t{.zwc}, this extension is automatically
appended.  Files containing multiple compiled functions are called `digest'
files, and are intended to be used as elements of the @t{FPATH}/@t{fpath}
special array.

@noindent
The second form, with the @t{-c} or @t{-a} options, writes the compiled
definitions for all the named functions into @var{file}.  For @t{-c}, the
names must be functions currently defined in the shell, not those marked
for autoloading.  Undefined functions that are marked for autoloading
may be written by using the @t{-a} option, in which case the @t{fpath}
is searched and the contents of the definition files for those
functions, if found, are compiled into @var{file}.  If both @t{-c} and
@t{-a} are given, names of both defined functions and functions marked
for autoloading may be given.  In either case, the functions in files
written with the @t{-c} or @t{-a} option will be autoloaded as if the
@t{KSH_AUTOLOAD} option were unset.

@noindent
The reason for handling loaded and not-yet-loaded functions with
different options is that some definition files for autoloading define
multiple functions, including the function with the same name as the
file, and, at the end, call that function.  In such cases the output of
`@t{zcompile -c}' does not include the additional functions defined in
the file, and any other initialization code in the file is lost.  Using
`@t{zcompile -a}' captures all this extra information.

@noindent
If the @t{-m} option is combined with @t{-c} or @t{-a},
the @var{name}s are used as patterns and all functions whose names
match one of these patterns will be written. If no @var{name} is given,
the definitions of all functions currently defined or marked as
autoloaded will be written.

@noindent
The third form, with the @t{-t} option, examines an existing
compiled file.  Without further arguments, the names of the original
files compiled into it are listed.  The first line of output shows
the version of the shell which compiled the file and how the file
will be used (i.e. by reading it directly or by mapping it into memory).
With arguments, nothing is output and the return value is set to zero if
definitions for @emph{all} @var{name}s were found in the compiled
file, and non-zero if the definition for at least one @var{name} was not
found.

@noindent
Other options:

@noindent
@table @asis
@item @t{-U}
Aliases are not expanded when compiling the @var{name}d files.

@item @t{-R}
When the compiled file is read, its contents are copied into the
shell's memory, rather than memory-mapped (see @t{-M}).  This
happens automatically on systems that do not support memory mapping.

@noindent
When compiling scripts instead of autoloadable functions, it is
often desirable to use this option; otherwise the whole file, including the
code to define functions which have already been defined, will
remain mapped, consequently wasting memory.

@item @t{-M}
The compiled file is mapped into the shell's memory when read. This
is done in such a way that multiple instances of the shell running
on the same host will share this mapped file.  If neither @t{-R} nor
@t{-M} is given, the @t{zcompile} builtin decides what to do based
on the size of the compiled file.

@item @t{-k}
@itemx @t{-z}
These options are used when the compiled file contains functions which
are to be autoloaded. If @t{-z} is given, the
function will be autoloaded as if the @t{KSH_AUTOLOAD} option is
@emph{not} set, even if it is set at the time the compiled file is
read, while if the @t{-k} is given, the function will be loaded as if
@t{KSH_AUTOLOAD} @emph{is} set.  If neither of these options is given, the
function will be loaded as determined by the setting of the
@t{KSH_AUTOLOAD} option at the time the compiled file is read.

These options may also appear as many times as necessary between the listed
@var{name}s to specify the loading style of all following functions, up to
the next @t{-k} or @t{-z}.

@end table

@noindent
The created file always contains two versions of the compiled
format, one for big-endian machines and one for small-endian
machines.  The upshot of this is that the compiled file is machine
independent and if it is read or mapped, only one half of the file
is actually used (and mapped).


@item @t{zformat}
See @ref{The zsh/zutil Module}.

@item @t{zftp}
See @ref{The zsh/zftp Module}.

@item @t{zle}
See @ref{Zle Builtins}.

@findex zmodload
@cindex modules, loading
@cindex loading modules
@item @t{zmodload} [ @t{-dL} ] [ ... ]
@itemx @t{zmodload -e} [ @t{-A} ] [ ... ]
@itemx @t{zmodload} [ @t{-a} [ @t{-bcpf} [ @t{-I} ] ] ] [ @t{-iL} ] ...
@itemx @t{zmodload} @t{-u} [ @t{-abcdpf} [ @t{-I} ] ] [ @t{-iL} ] ...
@itemx @t{zmodload} @t{-A} [ @t{-L} ] [ @var{modalias}[@t{=}@var{module}] ... ]
@itemx @t{zmodload} @t{-R} @var{modalias} ... 
Performs operations relating to zsh's loadable modules.
Loading of modules while the shell is running (`dynamical loading') is not
available on all operating systems, or on all installations on a particular
operating system, although the @t{zmodload} command itself is always
available and can be used to manipulate modules built into versions of the
shell executable without dynamical loading.

@noindent
Without arguments the names of all currently loaded binary modules are
printed.  The @t{-L} option causes this list to be in the form of a
series of @t{zmodload} commands.  Forms with arguments are:

@noindent
@table @asis
@item @t{zmodload} [ @t{-i} ] @var{name} ... 
@itemx @t{zmodload} @t{-u} [ @t{-i} ] @var{name} ...
In the simplest case, @t{zmodload} loads a binary module.  The module must
be in a file with a name consisting of the specified @var{name} followed by
a standard suffix, usually `@t{.so}' (`@t{.sl}' on HPUX).
If the module to be loaded is
already loaded and the @t{-i} option is given, the duplicate module is
ignored.  Otherwise @t{zmodload} prints an error message.

@noindent
The @var{name}d module is searched for in the same way a command is, using
@t{$module_path} instead of @t{$path}.  However, the path search is
performed even when the module name contains a `@t{/}', which it usually does.
There is no way to prevent the path search.

@noindent
With @t{-u}, @t{zmodload} unloads modules.  The same @var{name}
must be given that was given when the module was loaded, but it is not
necessary for the module to exist in the filesystem.
The @t{-i} option suppresses the error if the module is already
unloaded (or was never loaded).

@noindent
Each module has a boot and a cleanup function.  The module
will not be loaded if its boot function fails.  Similarly a module
can only be unloaded if its cleanup function runs successfully.

@item @t{zmodload} @t{-d} [ @t{-L} ] [ @var{name} ]
@itemx @t{zmodload} @t{-d} @var{name} @var{dep} ...
@itemx @t{zmodload} @t{-ud} @var{name} [ @var{dep} ... ]
The @t{-d} option can be used to specify module dependencies.  The modules
named in the second and subsequent arguments will be loaded before the
module named in the first argument.

@noindent
With @t{-d} and one argument, all dependencies for that module are listed.
With @t{-d} and no arguments, all module dependencies are listed.  This
listing is by default in a Makefile-like format.  The @t{-L} option
changes this format to a list of @t{zmodload -d} commands.

@noindent
If @t{-d} and @t{-u} are both used, dependencies are removed.  If only one
argument is given, all dependencies for that module are removed.

@item @t{zmodload} @t{-ab} [ @t{-L} ]
@itemx @t{zmodload} @t{-ab} [ @t{-i} ] @var{name} [ @var{builtin} ... ]
@itemx @t{zmodload} @t{-ub} [ @t{-i} ] @var{builtin} ...
The @t{-ab} option defines autoloaded builtins.  It defines the specified
@var{builtin}s.  When any of those builtins is called, the module specified
in the first argument is loaded.  If only the @var{name} is given, one
builtin is defined, with the same name as the module.  @t{-i} suppresses
the error if the builtin is already defined or autoloaded, regardless of
which module it came from.

@noindent
With @t{-ab} and no arguments, all autoloaded builtins are listed, with the
module name (if different) shown in parentheses after the builtin name.
The @t{-L} option changes this format to a list of @t{zmodload -a}
commands.

@noindent
If @t{-b} is used together with the @t{-u} option, it removes builtins
previously defined with @t{-ab}.  This is only possible if the builtin is
not yet loaded.  @t{-i} suppresses the error if the builtin is already
removed (or never existed).

@item @t{zmodload} @t{-ac} [ @t{-IL} ]
@itemx @t{zmodload} @t{-ac} [ @t{-iI} ] @var{name} [ @var{cond} ... ]
@itemx @t{zmodload} @t{-uc} [ @t{-iI} ] @var{cond} ...
The @t{-ac} option is used to define autoloaded condition codes. The
@var{cond} strings give the names of the conditions defined by the
module. The optional @t{-I} option is used to define infix condition
names. Without this option prefix condition names are defined.

@noindent
If given no condition names, all defined names are listed (as a series of
@t{zmodload} commands if the @t{-L} option is given).

@noindent
The @t{-uc} option removes definitions for autoloaded conditions.

@item @t{zmodload} @t{-ap} [ @t{-L} ]
@itemx @t{zmodload} @t{-ap} [ @t{-i} ] @var{name} [ @var{parameter} ... ]
@itemx @t{zmodload} @t{-up} [ @t{-i} ] @var{parameter} ...
The @t{-p} option is like the @t{-b} and @t{-c} options, but makes
@t{zmodload} work on autoloaded parameters instead.

@item @t{zmodload} @t{-af} [ @t{-L} ]
@itemx @t{zmodload} @t{-af} [ @t{-i} ] @var{name} [ @var{function} ... ]
@itemx @t{zmodload} @t{-uf} [ @t{-i} ] @var{function} ...
The @t{-f} option is like the @t{-b}, @t{-p}, and @t{-c} options, but
makes @t{zmodload} work on autoloaded math functions instead. 

@item @t{zmodload} @t{-a} [ @t{-L} ]
@itemx @t{zmodload} @t{-a} [ @t{-i} ] @var{name} [ @var{builtin} ... ]
@itemx @t{zmodload} @t{-ua} [ @t{-i} ] @var{builtin} ...
Equivalent to @t{-ab} and @t{-ub}.

@item @t{zmodload -e} [ @t{-A} ] [ @var{string} ... ]
The @t{-e} option without arguments lists all loaded modules; if the @t{-A}
option is also given, module aliases corresponding to loaded modules are
also shown.  With arguments only the return status is set to zero
if all @var{string}s given as arguments are names of loaded modules
and to one if at least on @var{string} is not the name of a
loaded module.  This can be used to test for the availability 
of things implemented by modules.  In this case, any aliases are
automatically resolved and the @t{-A} flag is not used.

@item @t{zmodload} @t{-A} [ @t{-L} ] [ @var{modalias}[@t{=}@var{module}] ... ]
For each argument, if both @var{modalias} and @var{module} are given,
define @var{modalias} to be an alias for the module @var{module}.
If the module @var{modalias} is ever subsequently requested, either via a
call to @t{zmodload} or implicitly, the shell will attempt to load
@var{module} instead.  If @var{module} is not given, show the definition of
@var{modalias}.  If no arguments are given, list all defined module aliases.
When listing, if the @t{-L} flag was also given, list the definition as a
@t{zmodload} command to recreate the alias.

@noindent
The existence of aliases for modules is completely independent of whether
the name resolved is actually loaded as a module: while the alias exists,
loading and unloading the module under any alias has exactly the same
effect as using the resolved name, and does not affect the connection
between the alias and the resolved name which can be removed either by
@t{zmodload -R} or by redefining the alias.  Chains of aliases (i.e. where
the first resolved name is itself an alias) are valid so long as these are
not circular.  As the aliases take the same format as module names, they
may include path separators:  in this case, there is no requirement for any
part of the path named to exist as the alias will be resolved first.  For
example, `@t{any/old/alias}' is always a valid alias.

@noindent
Dependencies added to aliased modules are actually added to the resolved
module; these remain if the alias is removed.  It is valid to create an
alias whose name is one of the standard shell modules and which resolves to
a different module.  However, if a module has dependencies, it
will not be possible to use the module name as an alias as the module will
already be marked as a loadable module in its own right.

@noindent
Apart from the above, aliases can be used in the @t{zmodload} command
anywhere module names are required.  However, aliases will not be
shown in lists of loaded modules with a bare `@t{zmodload}'.

@item @t{zmodload} @t{-R} @var{modalias} ... 
For each @var{modalias} argument that was previously defined as a module
alias via @t{zmodload -A}, delete the alias.  If any was not defined, an
error is caused and the remainder of the line is ignored.

@end table

@noindent
Note that @t{zsh} makes no distinction between modules that were linked 
into the shell and modules that are loaded dynamically. In both cases
this builtin command has to be used to make available the builtins and
other things defined by modules (unless the module is autoloaded on
these definitions). This is true even for systems that don't support
dynamic loading of modules.

@item @t{zparseopts}
See @ref{The zsh/zutil Module}.

@item @t{zprof}
See @ref{The zsh/zprof Module}.

@item @t{zpty}
See @ref{The zsh/zpty Module}.

@item @t{zregexparse}
See @ref{The zsh/zutil Module}.

@item @t{zstyle}
See @ref{The zsh/zutil Module}.

@end table
@c (avoiding a yodl bug)
@c Yodl file: Zsh/zle.yo
@node Zsh Line Editor, Completion Widgets, Shell Builtin Commands, Top

@chapter Zsh Line Editor
@noindent
@cindex line editor
@cindex editor, line
@cindex ZLE

@section Description
@noindent
@pindex ZLE, use of
If the @t{ZLE} option is set (which it is by default in interactive shells)
and the shell input is attached to the terminal, the user
is able to edit command lines.

@noindent
There are two display modes.  The first, multiline mode, is the
default.  It only works if the @t{TERM} parameter is set to a valid
terminal type that can move the cursor up.  The second, single line
mode, is used if @t{TERM} is invalid or incapable of moving the
cursor up, or if the @t{SINGLE_LINE_ZLE} option is set.
@pindex SINGLE_LINE_ZLE, use of
@cindex ksh, editor mode
@cindex editor ksh style
This mode
is similar to @cite{ksh}, and uses no termcap sequences.  If @t{TERM} is
"emacs", the @t{ZLE} option will be unset by default.

@noindent
@vindex BAUD, use of
@vindex COLUMNS, use of
@vindex LINES, use of
The parameters @t{BAUD}, @t{COLUMNS}, and @t{LINES} are also used by the
line editor.
@ref{Parameters Used By The Shell}.

@noindent
@menu
* Keymaps::
* Zle Builtins::
* Zle Widgets::
@end menu

@noindent
@node Keymaps, Zle Builtins, , Zsh Line Editor

@section Keymaps
@noindent
@cindex keymaps
@cindex key bindings
@cindex bindings, key
A keymap in ZLE contains a set of bindings between key sequences
and ZLE commands.  The empty key sequence cannot be bound.

@noindent
There can be any number of keymaps at any time, and each keymap has one
or more names.  If all of a keymap's names are deleted, it disappears.
@findex bindkey, use of
@t{bindkey} can be used to manipulate keymap names.

@noindent
Initially, there are four keymaps:

@noindent
@table @asis
@item @t{emacs}
EMACS emulation
@item @t{viins}
vi emulation - insert mode
@item @t{vicmd}
vi emulation - command mode
@item @t{.safe}
fallback keymap
@end table

@noindent
The `@t{.safe}' keymap is special.  It can never be altered, and the name
can never be removed.  However, it can be linked to other names, which can
be removed.  In the future other special keymaps may be added; users should
avoid using names beginning with `@t{.}' for their own keymaps.

@noindent
@vindex VISUAL
@vindex EDITOR
In addition to these four names, either `@t{emacs}' or `@t{viins}' is
also linked to the name `@t{main}'.  If one of the @t{VISUAL} or
@t{EDITOR} environment variables contain the string `@t{vi}' when the shell
starts up then it will be `@t{viins}', otherwise it will be `@t{emacs}'.
@t{bindkey}'s @t{-e} and @t{-v}
options provide a convenient way to override this default choice.

@noindent
When the editor starts up, it will select the `@t{main}' keymap.
If that keymap doesn't exist, it will use `@t{.safe}' instead.

@noindent
In the `@t{.safe}' keymap, each single key is bound to @t{self-insert},
except for ^J (line feed) and ^M (return) which are bound to @t{accept-line}.
This is deliberately not pleasant to use; if you are using it, it
means you deleted the main keymap, and you should put it back.

@subsection Reading Commands
@noindent
When ZLE is reading a command from the terminal, it may read a sequence
that is bound to some command and is also a prefix of a longer bound string.
In this case ZLE will wait a certain time to see if more characters
are typed, and if not (or they don't match any longer string) it will
execute the binding.  This timeout is defined by the @t{KEYTIMEOUT} parameter;
its default is 0.4 sec.  There is no timeout if the prefix string is not
itself bound to a command.

@noindent
As well as ZLE commands, key sequences can be bound to other strings, by using
`@t{bindkey -s}'.
When such a sequence is read, the replacement string is pushed back as input,
and the command reading process starts again using these fake keystrokes.
This input can itself invoke further replacement strings, but in order to
detect loops the process will be stopped if there are twenty such replacements
without a real command being read.

@noindent
@node Zle Builtins, Zle Widgets, Keymaps, Zsh Line Editor

@section Zle Builtins
@noindent
@cindex zle, builtin commands
The ZLE module contains three related builtin commands. The @t{bindkey}
command manipulates keymaps and key bindings; the @t{vared} command invokes
ZLE on the value of a shell parameter; and the @t{zle} command manipulates
editing widgets and allows command line access to ZLE commands from within
shell functions.

@noindent
@table @asis
@findex bindkey
@cindex keys, rebinding
@cindex rebinding keys
@cindex keys, binding
@cindex binding keys
@cindex keymaps
@item @t{bindkey} [ @var{options} ] @t{-l}
@itemx @t{bindkey} [ @var{options} ] @t{-d}
@itemx @t{bindkey} [ @var{options} ] @t{-D} @var{keymap} ...
@itemx @t{bindkey} [ @var{options} ] @t{-A} @var{old-keymap new-keymap}
@itemx @t{bindkey} [ @var{options} ] @t{-N} @var{new-keymap} [ @var{old-keymap} ]
@itemx @t{bindkey} [ @var{options} ] @t{-m}
@itemx @t{bindkey} [ @var{options} ] @t{-r} @var{in-string} ...
@itemx @t{bindkey} [ @var{options} ] @t{-s} @var{in-string out-string} ...
@itemx @t{bindkey} [ @var{options} ] @var{in-string command} ...
@itemx @t{bindkey} [ @var{options} ] [ @var{in-string} ]
@t{bindkey}'s options can be divided into three categories: keymap selection,
operation selection, and others.  The keymap selection options are:

@noindent
@table @asis
@item @t{-e}
Selects keymap `@t{emacs}', and also links it to `@t{main}'.

@item @t{-v}
Selects keymap `@t{viins}', and also links it to `@t{main}'.

@item @t{-a}
Selects keymap `@t{vicmd}'.

@item @t{-M}
The first non-option argument is used as a keymap name,
and does not otherwise count as an argument.

@end table

@noindent
If a keymap selection is required and none of the options above are used, the
`@t{main}' keymap is used.  Some operations do not permit a keymap to be
selected, namely:

@noindent
@table @asis
@item @t{-l}
List all existing keymap names.  If the @t{-L}
option is also used, list in the form of @t{bindkey}
commands to create the keymaps.

@item @t{-d}
Delete all existing keymaps and reset to the default state.

@item @t{-D} @var{keymap} ...
Delete the named @var{keymap}s.

@item @t{-A} @var{old-keymap new-keymap}
Make the @var{new-keymap} name an alias for @var{old-keymap}, so that
both names refer to the same keymap.  The names have equal standing;
if either is deleted, the other remains.  If there is already a keymap
with the @var{new-keymap} name, it is deleted.

@item @t{-N} @var{new-keymap} [ @var{old-keymap} ]
Create a new keymap, named @var{new-keymap}.  If a keymap already has that
name, it is deleted.  If an @var{old-keymap} name is given, the new keymap
is initialized to be a duplicate of it, otherwise the new keymap will
be empty.

@end table

@noindent
To use a newly created keymap, it should be linked to @t{main}.  Hence
the sequence of commands to create and use a new keymap `@t{mymap}'
initialized from the @t{emacs} keymap (which remains unchanged) is:

@noindent
@example
bindkey -N mymap emacs
bindkey -A mymap main
@end example

@noindent
Note that while `@t{bindkey -A} @var{newmap} @t{main}' will work when
@var{newmap} is @t{emacs} or @t{viins}, it will not work for @t{vicmd}, as
switching from vi insert to command mode becomes impossible.

@noindent
The following operations act on the `@t{main}' keymap if no keymap
selection option was given:

@noindent
@table @asis
@item @t{-m}
Add the built-in set of meta-key bindings to the selected keymap.
Only keys that are unbound or bound to @t{self-insert} are affected.

@item @t{-r} @var{in-string} ...
Unbind the specified @var{in-string}s in the selected keymap.
This is exactly equivalent to binding the strings to @t{undefined-key}.

@noindent
When @t{-R} is also used, interpret the @var{in-string}s as ranges.

@noindent
When @t{-p} is also used, the @var{in-string}s specify prefixes.  Any
binding that has the given @var{in-string} as a prefix, not including the
binding for the @var{in-string} itself, if any, will be removed.  For
example,

@noindent
@example
bindkey -rpM viins '^['
@end example

@noindent
will remove all bindings in the vi-insert keymap beginning with an escape
character (probably cursor keys), but leave the binding for the escape
character itself (probably @t{vi-cmd-mode}).  This is incompatible with the
option @t{-R}.

@item @t{-s} @var{in-string out-string} ...
Bind each @var{in-string} to each @var{out-string}.
When @var{in-string} is typed, @var{out-string} will be
pushed back and treated as input to the line editor.
When @t{-R} is also used, interpret the @var{in-string}s as ranges.

@item @var{in-string command} ...
Bind each @var{in-string} to each @var{command}.
When @t{-R} is used, interpret the @var{in-string}s as ranges.

@item [ @var{in-string} ]
List key bindings.  If an @var{in-string} is specified, the binding of
that string in the selected keymap is displayed.  Otherwise, all key
bindings in the selected keymap are displayed.  (As a special case,
if the @t{-e} or @t{-v} option is used alone, the keymap is @emph{not}
displayed - the implicit linking of keymaps is the only thing that
happens.)

@noindent
When the option @t{-p} is used, the @var{in-string} must be present.
The listing shows all bindings which have the given key sequence as a
prefix, not including any bindings for the key sequence itself.

@noindent
When the @t{-L} option is used, the list is in the form of @t{bindkey}
commands to create the key bindings.

@end table

@noindent
When the @t{-R} option is used as noted above, a valid range consists of
two characters, with an optional `@t{-}' between them.  All characters
between the two specified, inclusive, are bound as specified.

@noindent
For either @var{in-string} or @var{out-string}, the following
escape sequences are recognised:

@noindent
@table @asis
@item @t{\a}
bell character
@item @t{\b}
backspace
@item @t{\e}, @t{\E}
escape
@item @t{\f}
form feed
@item @t{\n}
linefeed (newline)
@item @t{\r}
carriage return
@item @t{\t}
horizontal tab
@item @t{\v}
vertical tab
@item @t{\}@var{NNN}
character code in octal
@item @t{\x}@var{NN}
character code in hexadecimal
@item @t{\M}[@t{-}]@var{X}
character with meta bit set
@item @t{\C}[@t{-}]@var{X}
control character
@item @t{^}@var{X}
control character
@end table

@noindent
In all other cases, `@t{\}' escapes the following character.  Delete is
written as `@t{^?}'.  Note that `@t{\M^?}' and `@t{^\M?}' are not the same,
and that (unlike emacs), the bindings `@t{\M-}@var{X}' and `@t{\e}@var{X}'
are entirely distinct, although they are initialized to the same bindings
by `@t{bindkey -m}'.

@findex vared
@cindex parameters, editing
@cindex editing parameters
@item @t{vared} [ @t{-Aache} ] [ @t{-p} @var{prompt} ] [ @t{-r} @var{rprompt} ] @var{name}
The value of the parameter @var{name} is loaded into the edit
buffer, and the line editor is invoked.  When the editor exits,
@var{name} is set to the string value returned by the editor.
When the @t{-c} flag is given, the parameter is created if it doesn't
already exist.  The @t{-a} flag may be given with @t{-c} to create
an array parameter, or the @t{-A} flag to create an associative array.
If the type of an existing parameter does not match the type to be
created, the parameter is unset and recreated.

@noindent
If an array or array slice is being edited, separator characters as defined
in @t{$IFS} will be shown quoted with a backslash, as will backslashes
themselves.  Conversely, when the edited text is split into an array, a
backslash quotes an immediately following separator character or backslash;
no other special handling of backslashes, or any handling of quotes, is
performed.

@noindent
Individual elements of existing array or associative array parameters
may be edited by using subscript syntax on @var{name}.  New elements are
created automatically, even without @t{-c}.

@noindent
If the @t{-p} flag is given, the following string will be taken as
the prompt to display at the left.  If the @t{-r} flag is given,
the following string gives the prompt to display at the right.  If the
@t{-h} flag is specified, the history can be accessed from ZLE. If the 
@t{-e} flag is given, typing @t{^D} (Control-D) on an empty line
causes @t{vared} to exit immediately with a non-zero return value.

@findex zle
@cindex widgets, rebinding
@cindex rebinding widgets
@cindex widgets, binding
@cindex binding widgets
@cindex widgets, invoking
@cindex invoking widgets
@cindex widgets, calling
@cindex calling widgets
@cindex widgets, defining
@cindex defining widgets
@item @t{zle} @t{-l} [ @t{-L} | @t{-a} ] [ @var{string} ... ]
@itemx @t{zle} @t{-D} @var{widget} ...
@itemx @t{zle} @t{-A} @var{old-widget} @var{new-widget}
@itemx @t{zle} @t{-N} @var{widget} [ @var{function} ]
@itemx @t{zle} @t{-C} @var{widget} @var{completion-widget} @var{function}
@itemx @t{zle} @t{-R} [ @t{-c} ] [ @var{display-string} ] [ @var{string} ... ]
@itemx @t{zle} @t{-M} @var{string}
@itemx @t{zle} @t{-U} @var{string}
@itemx @t{zle} @t{-I}
@itemx @t{zle} @var{widget} @t{[ -n} @var{num} @t{]} @t{[ -N ]} @var{args} ...
@itemx @t{zle}
The @t{zle} builtin performs a number of different actions concerning
ZLE.  Which operation it performs depends on its options:

@noindent
@table @asis
@item @t{-l} [ @t{-L} | @t{-a} ]
List all existing user-defined widgets.  If the @t{-L}
option is used, list in the form of @t{zle}
commands to create the widgets.

@noindent
When combined with the @t{-a} option, all widget names are listed,
including the builtin ones. In this case the @t{-L} option is ignored.

@noindent
If at least one @var{string} is given, nothing will be printed but the
return status will be zero if all @var{string}s are names of existing
widgets (or of user-defined widgets if the @t{-a} flag is not given)
and non-zero if at least one @var{string} is not a name of an defined
widget.

@item @t{-D} @var{widget} ...
Delete the named @var{widget}s.

@item @t{-A} @var{old-widget} @var{new-widget}
Make the @var{new-widget} name an alias for @var{old-widget}, so that
both names refer to the same widget.  The names have equal standing;
if either is deleted, the other remains.  If there is already a widget
with the @var{new-widget} name, it is deleted.

@item @t{-N} @var{widget} [ @var{function} ]
Create a user-defined widget.  If there is already a widget with the
specified name, it is overwritten.  When the new
widget is invoked from within the editor, the specified shell @var{function}
is called.  If no function name is specified, it defaults to
the same name as the widget.  For further information, see the section
@emph{Widgets} in
@ref{Zsh Line Editor}.

@cindex completion widgets, creating
@item @t{-C} @var{widget} @var{completion-widget} @var{function}
Create a user-defined completion widget named @var{widget}. The 
completion widget will behave like the built-in completion-widget
whose name is given as @var{completion-widget}. To generate the
completions, the shell function @var{function} will be called.
For further information, see
@ref{Completion Widgets}.

@item @t{-R} [ @t{-c} ] [ @var{display-string} ] [ @var{string} ... ]
Redisplay the command line; this is to be called from within a user-defined
widget to allow changes to become visible.  If a @var{display-string} is
given and not empty, this is shown in the status line (immediately
below the line being edited).

@noindent
If the optional @var{string}s are given they are listed below the
prompt in the same way as completion lists are printed. If no
@var{string}s are given but the @t{-c} option is used such a list is
cleared.

@noindent
Note that this option is only useful for widgets that do not exit
immediately after using it because the strings displayed will be erased 
immediately after return from the widget.

@noindent
This command can safely be called outside user defined widgets; if zle is
active, the display will be refreshed, while if zle is not active, the
command has no effect.  In this case there will usually be no other
arguments.  The status is zero if zle was active, else one.

@item @t{-M} @var{string}
As with the @t{-R} option, the @var{string} will be displayed below the 
command line; unlike the @t{-R} option, the string will not be put into
the status line but will instead be printed normally below the
prompt.  This means that the @var{string} will still be displayed after
the widget returns (until it is overwritten by subsequent commands).

@item @t{-U} @var{string}
This pushes the characters in the @var{string} onto the input stack of
ZLE.  After the widget currently executed finishes ZLE will behave as
if the characters in the @var{string} were typed by the user.

@noindent
As ZLE uses a stack, if this option is used repeatedly
the last string pushed onto the stack will be processed first.  However,
the characters in each @var{string} will be processed in the order in which
they appear in the string.

@item @t{-I}
Unusually, this option is only useful @emph{outside} ordinary widget functions.
It invalidates the current zle display in preparation for output; usually
this will be from a trap function.  It has no effect if zle is not
active.  When a trap exits, the shell checks to see if the display needs
restoring, hence the following will print output in such a way as not to
disturb the line being edited:

@noindent
@example
TRAPUSR1() @{
    # Invalidate zle display
  zle -I
    # Show output
  print Hello
@}
@end example

@noindent
Note that there are better ways of manipulating the display from within zle
widgets.  In general, the trap function may need to test whether zle is
loaded before using this method; if it is not, there is no point in loading
it specially since the line editor will not be active.

@noindent
The status is zero if zle was active, else one.

@item @var{widget} @t{[ -n} @var{num} @t{]} @t{[ -N ]} @var{args} ...
Invoke the specified widget.  This can only be done when ZLE is
active; normally this will be within a user-defined widget.

@noindent
With the options @t{-n} and @t{-N}, the current numerical argument will be
saved and then restored after the call to @t{widget}; `@t{-n} @var{num}'
sets the numerical argument temporarily to @var{num}, while `@t{-N}' sets it
to the default, i.e. as if there were none.

@noindent
Any further arguments will be passed to the widget.  If it is a shell
function, these are passed down as positional parameters; for builtin
widgets it is up to the widget in question what it does with them.
Currently arguments are only handled by the incremental-search commands,
the @t{history-search-forward} and @t{-backward} and the corresponding
functions prefixed by @t{vi-}, and by @t{universal-argument}.  No error is
flagged if the command does not use the arguments, or only uses some of
them.

@noindent
The return status reflects the success or failure of the operation carried
out by the widget, or if it is a user-defined widget the return status of
the shell function.  

@noindent
A non-zero return status causes the shell to beep when the widget exits,
unless the @t{BEEP} options was unset or the widget was called via the
@t{zle} command.  Thus if a user defined widget requires an immediate beep,
it should call the @t{beep} widget directly.

@end table

@noindent
With no options and no arguments, only the return status will be
set. It is zero if ZLE is currently active and widgets could be
invoked using this builtin command and non-zero if ZLE is not active.

@end table

@noindent
@node Zle Widgets, , Zle Builtins, Zsh Line Editor

@section Widgets
@noindent
@cindex widgets
All actions in the editor are performed by `widgets'.  A widget's job is
simply to perform some small action.  The ZLE commands that key sequences
in keymaps are bound to are in fact widgets.  Widgets can be user-defined
or built in.

@noindent
The standard widgets built in to ZLE are listed in Standard Widgets below.
Other built-in widgets can be defined by other modules (see
@ref{Zsh Modules}).  Each built-in widget has two names: its normal canonical name, and the
same name preceded by a `@t{.}'.  The `@t{.}' name is special: it can't be
rebound to a different widget.  This makes the widget available even when
its usual name has been redefined.

@noindent
User-defined widgets are defined using `@t{zle -N}', and implemented
as shell functions.  When the widget is executed, the corresponding
shell function is executed, and can perform editing (or other) actions.
It is recommended that user-defined widgets should not have names
starting with `@t{.}'.

@section User-Defined Widgets
@noindent
@cindex widgets, user-defined
User-defined widgets, being implemented as shell functions,
can execute any normal shell command.  They can also run other widgets
(whether built-in or user-defined) using the @t{zle} builtin command.
The standard input of the function is closed to prevent external commands
from unintentionally blocking ZLE by reading from the terminal, but
@t{read -k} or @t{read -q} can be used to read characters.  Finally,
they can examine and edit the ZLE buffer being edited by
reading and setting the special parameters described below.

@noindent
@cindex parameters, editor
@cindex parameters, zle
These special parameters are always available in widget functions, but
are not in any way special outside ZLE.  If they have some normal value
outside ZLE, that value is temporarily inaccessible, but will return
when the widget function exits.  These special parameters in fact have
local scope, like parameters created in a function using @t{local}.

@noindent
Inside completion widgets and traps called while ZLE is active, these
parameters are available read-only.

@noindent
@table @asis
@vindex BUFFER
@item @t{BUFFER} (scalar)
The entire contents of the edit buffer.  If it is written to, the
cursor remains at the same offset, unless that would put it outside the
buffer.

@vindex BUFFERLINES
@item @t{BUFFERLINES}
The number of screen lines needed for the edit buffer currently
displayed on screen (i.e. without any changes to the preceding
parameters done after the last redisplay).

@vindex CURSOR
@item @t{CURSOR} (integer)
The offset of the cursor, within the edit buffer.  This is in the range
0 to @t{$#BUFFER}, and is by definition equal to @t{$#LBUFFER}.
Attempts to move the cursor outside the buffer will result in the
cursor being moved to the appropriate end of the buffer.

@vindex HISTNO
@item @t{HISTNO} (integer)
The current history number.

@vindex KEYS
@item @t{KEYS} (scalar)
The keys typed to invoke this widget, as a literal string.

@vindex LASTWIDGET
@item @t{LASTWIDGET} (scalar)
The name of the last widget that was executed.

@vindex LBUFFER
@item @t{LBUFFER} (scalar)
The part of the buffer that lies to the left of the cursor position.
If it is assigned to, only that part of the buffer is replaced, and the
cursor remains between the new @t{$LBUFFER} and the old @t{$RBUFFER}.

@vindex MARK
@item @t{MARK} (integer)
Like @t{CURSOR}, but for the mark.

@vindex NUMERIC
@item @t{NUMERIC} (integer)
The numeric argument. If no numeric argument was given, this parameter
is unset. When this is set inside a widget function, builtin widgets
called with the @t{zle} builtin command will use the value
assigned. If it is unset inside a widget function, builtin widgets
called behave as if no numeric argument was given.

@vindex PENDING
@item @t{PENDING} (integer)
The number of bytes pending for input, i.e. the number of bytes which have
already been typed and can immediately be read. On systems where the shell
is not able to get this information, this parameter will always have a
value of zero.

@vindex PREBUFFER
@item @t{PREBUFFER} (scalar)
In a multi-line input at the secondary prompt, this read-only parameter
contains the contents of the lines before the one the cursor is
currently in.

@vindex RBUFFER
@item @t{RBUFFER} (scalar)
The part of the buffer that lies to the right of the cursor position.
If it is assigned to, only that part of the buffer is replaced, and the
cursor remains between the old @t{$LBUFFER} and the new @t{$RBUFFER}.

@vindex WIDGET
@item @t{WIDGET} (scalar)
The name of the widget currently being executed.

@end table

@section Standard Widgets
@noindent
@cindex widgets, standard
The following is a list of all the standard widgets,
and their default bindings in emacs mode,
vi command mode and vi insert mode
(the `@t{emacs}', `@t{vicmd}' and `@t{viins}' keymaps, respectively).

@noindent
Note that cursor keys are bound to movement keys in all three keymaps;
the shell assumes that the cursor keys send the key sequences reported
by the terminal-handling library (termcap or terminfo).  The key sequences
shown in the list are those based on the VT100, common on many modern
terminals, but in fact these are not necessarily bound.  In the case of the
@t{viins} keymap, the initial escape character of the sequences serves also
to return to the @t{vicmd} keymap: whether this happens is determined by
the @t{KEYTIMEOUT} parameter, see @ref{Parameters}.
@menu
* Movement::
* History Control::
* Modifying Text::
* Arguments::
* Completion::
* Miscellaneous::
@end menu
@node Movement, History Control, , Zle Widgets

@subsection Movement
@noindent
@table @asis
@tindex vi-backward-blank-word
@item @t{vi-backward-blank-word} (unbound) (B) (unbound)
Move backward one word, where a word is defined as a series of
non-blank characters.

@tindex backward-char
@item @t{backward-char} (^B ESC-[D) (unbound) (unbound)
Move backward one character.

@tindex vi-backward-char
@item @t{vi-backward-char} (unbound) (^H h ^?) (ESC-[D)
Move backward one character, without changing lines.

@tindex backward-word
@item @t{backward-word} (ESC-B ESC-b) (unbound) (unbound)
Move to the beginning of the previous word.

@tindex emacs-backward-word
@item @t{emacs-backward-word}
Move to the beginning of the previous word.

@tindex vi-backward-word
@item @t{vi-backward-word} (unbound) (b) (unbound)
Move to the beginning of the previous word, vi-style.

@tindex beginning-of-line
@item @t{beginning-of-line} (^A) (unbound) (unbound)
Move to the beginning of the line.  If already at the beginning
of the line, move to the beginning of the previous line, if any.

@tindex vi-beginning-of-line
@item @t{vi-beginning-of-line}
Move to the beginning of the line, without changing lines.

@tindex end-of-line
@item @t{end-of-line} (^E) (unbound) (unbound)
Move to the end of the line.  If already at the end
of the line, move to the end of the next line, if any.

@tindex vi-end-of-line
@item @t{vi-end-of-line} (unbound) ($) (unbound)
Move to the end of the line.
If an argument is given to this command, the cursor will be moved to
the end of the line (argument - 1) lines down.

@tindex vi-forward-blank-word
@item @t{vi-forward-blank-word} (unbound) (W) (unbound)
Move forward one word, where a word is defined as a series of
non-blank characters.

@tindex vi-forward-blank-word-end
@item @t{vi-forward-blank-word-end} (unbound) (E) (unbound)
Move to the end of the current word, or, if at the end of the current word,
to the end of the next word,
where a word is defined as a series of non-blank characters.

@tindex forward-char
@item @t{forward-char} (^F ESC-[C) (unbound) (unbound)
Move forward one character.

@tindex vi-forward-char
@item @t{vi-forward-char} (unbound) (space l) (ESC-[C)
Move forward one character.

@tindex vi-find-next-char
@item @t{vi-find-next-char} (^X^F) (f) (unbound)
Read a character from the keyboard, and move to
the next occurrence of it in the line.

@tindex vi-find-next-char-skip
@item @t{vi-find-next-char-skip} (unbound) (t) (unbound)
Read a character from the keyboard, and move to
the position just before the next occurrence of it in the line.

@tindex vi-find-prev-char
@item @t{vi-find-prev-char} (unbound) (F) (unbound)
Read a character from the keyboard, and move to
the previous occurrence of it in the line.

@tindex vi-find-prev-char-skip
@item @t{vi-find-prev-char-skip} (unbound) (T) (unbound)
Read a character from the keyboard, and move to
the position just after the previous occurrence of it in the line.

@tindex vi-first-non-blank
@item @t{vi-first-non-blank} (unbound) (^) (unbound)
Move to the first non-blank character in the line.

@tindex vi-forward-word
@item @t{vi-forward-word} (unbound) (w) (unbound)
Move forward one word, vi-style.

@tindex forward-word
@item @t{forward-word} (ESC-F ESC-f) (unbound) (unbound)
Move to the beginning of the next word.
The editor's idea of a word is specified with the @t{WORDCHARS}
parameter.

@tindex emacs-forward-word
@item @t{emacs-forward-word}
Move to the end of the next word.

@tindex vi-forward-word-end
@item @t{vi-forward-word-end} (unbound) (e) (unbound)
Move to the end of the next word.

@tindex vi-goto-column
@item @t{vi-goto-column} (ESC-|) (|) (unbound)
Move to the column specified by the numeric argument.

@tindex vi-goto-mark
@item @t{vi-goto-mark} (unbound) (`) (unbound)
Move to the specified mark.

@tindex vi-goto-mark-line
@item @t{vi-goto-mark-line} (unbound) (') (unbound)
Move to beginning of the line containing the specified mark.

@tindex vi-repeat-find
@item @t{vi-repeat-find} (unbound) (;) (unbound)
Repeat the last @t{vi-find} command.

@tindex vi-rev-repeat-find
@item @t{vi-rev-repeat-find} (unbound) (,) (unbound)
Repeat the last @t{vi-find} command in the opposite direction.

@end table
@node History Control, Modifying Text, Movement, Zle Widgets

@subsection History Control
@noindent
@table @asis
@tindex beginning-of-buffer-or-history
@item @t{beginning-of-buffer-or-history} (ESC-<) (unbound) (unbound)
Move to the beginning of the buffer, or if already there,
move to the first event in the history list.

@tindex beginning-of-line-hist
@item @t{beginning-of-line-hist}
Move to the beginning of the line.  If already at the
beginning of the buffer, move to the previous history line.

@tindex beginning-of-history
@item @t{beginning-of-history}
Move to the first event in the history list.

@tindex down-line-or-history
@item @t{down-line-or-history} (^N ESC-[B) (j) (ESC-[B)
Move down a line in the buffer, or if already at the bottom line,
move to the next event in the history list.

@tindex vi-down-line-or-history
@item @t{vi-down-line-or-history} (unbound) (+) (unbound)
Move down a line in the buffer, or if already at the bottom line,
move to the next event in the history list.
Then move to the first non-blank character on the line.

@tindex down-line-or-search
@item @t{down-line-or-search}
Move down a line in the buffer, or if already at the bottom line,
search forward in the history for a line beginning with the first
word in the buffer.

@noindent
If called from a function by the @t{zle} command with arguments, the first
argument is taken as the string for which to search, rather than the
first word in the buffer.

@tindex down-history
@item @t{down-history} (unbound) (^N) (unbound)
Move to the next event in the history list.

@tindex history-beginning-search-backward
@item @t{history-beginning-search-backward}
Search backward in the history for a line beginning with the current
line up to the cursor.
This leaves the cursor in its original position.

@tindex end-of-buffer-or-history
@item @t{end-of-buffer-or-history} (ESC->) (unbound) (unbound)
Move to the end of the buffer, or if already there,
move to the last event in the history list.

@tindex end-of-line-hist
@item @t{end-of-line-hist}
Move to the end of the line.  If already at the end of
the buffer, move to the next history line.

@tindex end-of-history
@item @t{end-of-history}
Move to the last event in the history list.

@tindex vi-fetch-history
@item @t{vi-fetch-history} (unbound) (G) (unbound)
Fetch the history line specified by the numeric argument.
This defaults to the current history line
(i.e. the one that isn't history yet).

@tindex history-incremental-search-backward
@item @t{history-incremental-search-backward} (^R ^Xr) (unbound) (unbound)
Search backward incrementally for a specified string.  The search is
case-insensitive if the search string does not have uppercase letters and no
numeric argument was given.  The string may begin with `@t{^}' to anchor the
search to the beginning of the line.

@noindent
A restricted set of editing functions
is available in the mini-buffer.  An interrupt signal, as defined by the stty
setting, will stop the search and go back to the original line.  An undefined
key will have the same effect. The supported functions are:
@t{backward-delete-char},
@t{vi-backward-delete-char},
@t{clear-screen},
@t{redisplay},
@t{quoted-insert},
@t{vi-quoted-insert},
@t{accept-and-hold},
@t{accept-and-infer-next-history},
@t{accept-line} and
@t{accept-line-and-down-history}.

@noindent
@t{magic-space} just inserts a space.
@t{vi-cmd-mode} toggles between the `@t{main}' and `@t{vicmd}' keymaps;
the `@t{main}' keymap (insert mode) will be selected initially.
@t{history-incremental-search-backward} will get the
next occurrence of the contents of the mini-buffer.
@t{history-incremental-search-forward} inverts the sense of the search.
@t{vi-repeat-search} and @t{vi-rev-repeat-search} are similarly supported.
The direction of the search is indicated in the mini-buffer.

@noindent
Any multi-character string
that is not bound to one of the above functions will beep and interrupt the
search, leaving the last found line in the buffer. Any single character that
is not bound to one of the above functions, or @t{self-insert} or
@t{self-insert-unmeta}, will have the same effect but the function will be
executed.

@noindent
When called from a widget function by the @t{zle} command, the incremental
search commands can take a string argument.  This will be treated as a
string of keys, as for arguments to the @t{bindkey} command, and used as
initial input for the command.  Any characters in the string which are
unused by the incremental search will be silently ignored.  For example,

@noindent
@example
zle history-incremental-search-backward forceps
@end example

@noindent
will search backwards for @t{forceps}, leaving the minibuffer containing
the string `@t{forceps}'.

@tindex history-incremental-search-forward
@item @t{history-incremental-search-forward} (^S ^Xs) (unbound) (unbound)
Search forward incrementally for a specified string.  The search is
case-insensitive if the search string does not have uppercase letters and no
numeric argument was given.  The string may begin with `@t{^}' to anchor the
search to the beginning of the line.  The functions available in the
mini-buffer are the same as for @t{history-incremental-search-backward}.

@tindex history-search-backward
@item @t{history-search-backward} (ESC-P ESC-p) (unbound) (unbound)
Search backward in the history for a line beginning with the first
word in the buffer.

@noindent
If called from a function by the @t{zle} command with arguments, the first
argument is taken as the string for which to search, rather than the
first word in the buffer.

@tindex vi-history-search-backward
@item @t{vi-history-search-backward} (unbound) (/) (unbound)
Search backward in the history for a specified string.
The string may begin with `@t{^}' to anchor the search to the
beginning of the line.

@noindent
A restricted set of editing functions is available in
the mini-buffer.  An interrupt signal, as defined by the stty setting,  will
stop the search.
The functions available in the mini-buffer are:
@t{accept-line},
@t{backward-delete-char},
@t{vi-backward-delete-char},
@t{backward-kill-word},
@t{vi-backward-kill-word},
@t{clear-screen},
@t{redisplay},
@t{quoted-insert}
and
@t{vi-quoted-insert}.

@noindent
@t{vi-cmd-mode} is treated the same as accept-line, and
@t{magic-space} is treated as a space.
Any other character that is not bound to self-insert or
self-insert-unmeta will beep and be ignored. If the function is called from vi
command mode, the bindings of the current insert mode will be used.

@noindent
If called from a function by the @t{zle} command with arguments, the first
argument is taken as the string for which to search, rather than the
first word in the buffer.

@tindex history-search-forward
@item @t{history-search-forward} (ESC-N ESC-n) (unbound) (unbound)
Search forward in the history for a line beginning with the first
word in the buffer.

@noindent
If called from a function by the @t{zle} command with arguments, the first
argument is taken as the string for which to search, rather than the
first word in the buffer.

@tindex vi-history-search-forward
@item @t{vi-history-search-forward} (unbound) (?) (unbound)
Search forward in the history for a specified string.
The string may begin with `@t{^}' to anchor the search to the
beginning of the line. The functions available in the mini-buffer are the same
as for @t{vi-history-search-backward}.  Argument handling is also the same
as for that command.

@tindex infer-next-history
@item @t{infer-next-history} (^X^N) (unbound) (unbound)
Search in the history list for a line matching the current one and
fetch the event following it.

@tindex insert-last-word
@item @t{insert-last-word} (ESC-_ ESC-.) (unbound) (unbound)
Insert the last word from the previous history event at the
cursor position.  If a positive numeric argument is given,
insert that word from the end of the previous history event.
If the argument is zero or negative insert that word from the
left (zero inserts the previous command word).  Repeating this command
replaces the word just inserted with the last word from the
history event prior to the one just used; numeric arguments can be used in
the same way to pick a word from that event.

@tindex vi-repeat-search
@item @t{vi-repeat-search} (unbound) (n) (unbound)
Repeat the last vi history search.

@tindex vi-rev-repeat-search
@item @t{vi-rev-repeat-search} (unbound) (N) (unbound)
Repeat the last vi history search, but in reverse.

@tindex up-line-or-history
@item @t{up-line-or-history} (^P ESC-[A) (k) (ESC-[A)
Move up a line in the buffer, or if already at the top line,
move to the previous event in the history list.

@tindex vi-up-line-or-history
@item @t{vi-up-line-or-history} (unbound) (-) (unbound)
Move up a line in the buffer, or if already at the top line,
move to the previous event in the history list.
Then move to the first non-blank character on the line.

@tindex up-line-or-search
@item @t{up-line-or-search}
Move up a line in the buffer, or if already at the top line,
search backward in the history for a line beginning with the
first word in the buffer.

@noindent
If called from a function by the @t{zle} command with arguments, the first
argument is taken as the string for which to search, rather than the
first word in the buffer.

@tindex up-history
@item @t{up-history} (unbound) (^P) (unbound)
Move to the previous event in the history list.

@tindex history-beginning-search-forward
@item @t{history-beginning-search-forward}
Search forward in the history for a line beginning with the current
line up to the cursor.
This leaves the cursor in its original position.

@end table
@node Modifying Text, Arguments, History Control, Zle Widgets

@subsection Modifying Text
@noindent
@table @asis
@tindex vi-add-eol
@item @t{vi-add-eol} (unbound) (A) (unbound)
Move to the end of the line and enter insert mode.

@tindex vi-add-next
@item @t{vi-add-next} (unbound) (a) (unbound)
Enter insert mode after the current cursor position, without changing lines.

@tindex backward-delete-char
@item @t{backward-delete-char} (^H ^?) (unbound) (unbound)
Delete the character behind the cursor.

@tindex vi-backward-delete-char
@item @t{vi-backward-delete-char} (unbound) (X) (^H)
Delete the character behind the cursor, without changing lines.
If in insert mode, this won't delete past the point where insert mode was
last entered.

@tindex backward-delete-word
@item @t{backward-delete-word}
Delete the word behind the cursor.

@tindex backward-kill-line
@item @t{backward-kill-line}
Kill from the beginning of the line to the cursor position.

@tindex backward-kill-word
@item @t{backward-kill-word} (^W ESC-^H ESC-^?) (unbound) (unbound)
Kill the word behind the cursor.

@tindex vi-backward-kill-word
@item @t{vi-backward-kill-word} (unbound) (unbound) (^W)
Kill the word behind the cursor, without going past the point where insert
mode was last entered.

@tindex capitalize-word
@item @t{capitalize-word} (ESC-C ESC-c) (unbound) (unbound)
Capitalize the current word and move past it.

@tindex vi-change
@item @t{vi-change} (unbound) (c) (unbound)
Read a movement command from the keyboard, and kill
from the cursor position to the endpoint of the movement.
Then enter insert mode.
If the command is @t{vi-change}, change the current line.

@tindex vi-change-eol
@item @t{vi-change-eol} (unbound) (C) (unbound)
Kill to the end of the line and enter insert mode.

@tindex vi-change-whole-line
@item @t{vi-change-whole-line} (unbound) (S) (unbound)
Kill the current line and enter insert mode.

@tindex copy-region-as-kill
@item @t{copy-region-as-kill} (ESC-W ESC-w) (unbound) (unbound)
Copy the area from the cursor to the mark to the kill buffer.

@tindex copy-prev-word
@item @t{copy-prev-word} (ESC-^_) (unbound) (unbound)
Duplicate the word to the left of the cursor.

@tindex copy-prev-shell-word
@item @t{copy-prev-shell-word} (ESC-^_) (unbound) (unbound)
Like @t{copy-prev-word}, but the word is found by using shell parsing, 
whereas @t{copy-prev-word} looks for blanks. This makes a difference
when the word is quoted and contains spaces.

@tindex vi-delete
@item @t{vi-delete} (unbound) (d) (unbound)
Read a movement command from the keyboard, and kill
from the cursor position to the endpoint of the movement.
If the command is @t{vi-delete}, kill the current line.

@tindex delete-char
@item @t{delete-char}
Delete the character under the cursor.

@tindex vi-delete-char
@item @t{vi-delete-char} (unbound) (x) (unbound)
Delete the character under the cursor,
without going past the end of the line.

@tindex delete-word
@item @t{delete-word}
Delete the current word.

@tindex down-case-word
@item @t{down-case-word} (ESC-L ESC-l) (unbound) (unbound)
Convert the current word to all lowercase and move past it.

@tindex kill-word
@item @t{kill-word} (ESC-D ESC-d) (unbound) (unbound)
Kill the current word.

@tindex gosmacs-transpose-chars
@item @t{gosmacs-transpose-chars}
Exchange the two characters behind the cursor.

@tindex vi-indent
@item @t{vi-indent} (unbound) (>) (unbound)
Indent a number of lines.

@tindex vi-insert
@item @t{vi-insert} (unbound) (i) (unbound)
Enter insert mode.

@tindex vi-insert-bol
@item @t{vi-insert-bol} (unbound) (I) (unbound)
Move to the first non-blank character on the line and enter insert mode.

@tindex vi-join
@item @t{vi-join} (^X^J) (J) (unbound)
Join the current line with the next one.

@tindex kill-line
@item @t{kill-line} (^K) (unbound) (unbound)
Kill from the cursor to the end of the line.
If already on the end of the line, kill the newline character.

@tindex vi-kill-line
@item @t{vi-kill-line} (unbound) (unbound) (^U)
Kill from the cursor back to wherever insert mode was last entered.

@tindex vi-kill-eol
@item @t{vi-kill-eol} (unbound) (D) (unbound)
Kill from the cursor to the end of the line.

@tindex kill-region
@item @t{kill-region}
Kill from the cursor to the mark.

@tindex kill-buffer
@item @t{kill-buffer} (^X^K) (unbound) (unbound)
Kill the entire buffer.

@tindex kill-whole-line
@item @t{kill-whole-line} (^U) (unbound) (unbound)
Kill the current line.

@tindex vi-match-bracket
@item @t{vi-match-bracket} (^X^B) (%) (unbound)
Move to the bracket character (one of @t{@{@}}, @t{()} or @t{[]}) that
matches the one under the cursor.
If the cursor is not on a bracket character, move forward without going
past the end of the line to find one, and then go to the matching bracket.

@tindex vi-open-line-above
@item @t{vi-open-line-above} (unbound) (O) (unbound)
Open a line above the cursor and enter insert mode.

@tindex vi-open-line-below
@item @t{vi-open-line-below} (unbound) (o) (unbound)
Open a line below the cursor and enter insert mode.

@tindex vi-oper-swap-case
@item @t{vi-oper-swap-case}
Read a movement command from the keyboard, and swap
the case of all characters
from the cursor position to the endpoint of the movement.
If the movement command is @t{vi-oper-swap-case},
swap the case of all characters on the current line.

@tindex overwrite-mode
@item @t{overwrite-mode} (^X^O) (unbound) (unbound)
Toggle between overwrite mode and insert mode.

@tindex vi-put-before
@item @t{vi-put-before} (unbound) (P) (unbound)
Insert the contents of the kill buffer before the cursor.
If the kill buffer contains a sequence of lines (as opposed to characters),
paste it above the current line.

@tindex vi-put-after
@item @t{vi-put-after} (unbound) (p) (unbound)
Insert the contents of the kill buffer after the cursor.
If the kill buffer contains a sequence of lines (as opposed to characters),
paste it below the current line.

@tindex quoted-insert
@item @t{quoted-insert} (^V) (unbound) (unbound)
Insert the next character typed into the buffer literally.
An interrupt character will not be inserted.

@tindex vi-quoted-insert
@item @t{vi-quoted-insert} (unbound) (unbound) (^Q ^V)
Display a `@t{^}' at the cursor position, and
insert the next character typed into the buffer literally.
An interrupt character will not be inserted.

@tindex quote-line
@item @t{quote-line} (ESC-') (unbound) (unbound)
Quote the current line; that is, put a `@t{'}' character at the
beginning and the end, and convert all `@t{'}' characters
to `@t{'\@value{dsq}}'.

@tindex quote-region
@item @t{quote-region} (ESC-") (unbound) (unbound)
Quote the region from the cursor to the mark.

@tindex vi-replace
@item @t{vi-replace} (unbound) (R) (unbound)
Enter overwrite mode.

@tindex vi-repeat-change
@item @t{vi-repeat-change} (unbound) (.) (unbound)
Repeat the last vi mode text modification.
If a count was used with the modification, it is remembered.
If a count is given to this command, it overrides the remembered count,
and is remembered for future uses of this command.
The cut buffer specification is similarly remembered.

@tindex vi-replace-chars
@item @t{vi-replace-chars} (unbound) (r) (unbound)
Replace the character under the cursor with a character
read from the keyboard.

@tindex self-insert
@item @t{self-insert} (printable characters) (unbound) (printable characters and some control characters)
Insert a character into the buffer at the cursor position.

@tindex self-insert-unmeta
@item @t{self-insert-unmeta} (ESC-^I ESC-^J ESC-^M) (unbound) (unbound)
Insert a character into the buffer after stripping the meta bit
and converting ^M to ^J.

@tindex vi-substitute
@item @t{vi-substitute} (unbound) (s) (unbound)
Substitute the next character(s).

@tindex vi-swap-case
@item @t{vi-swap-case} (unbound) (~) (unbound)
Swap the case of the character under the cursor and move past it.

@tindex transpose-chars
@item @t{transpose-chars} (^T) (unbound) (unbound)
Exchange the two characters to the left of the
cursor if at end of line, else exchange the
character under the cursor with the character
to the left.

@tindex transpose-words
@item @t{transpose-words} (ESC-T ESC-t) (unbound) (unbound)
Exchange the current word with the one before it.

@tindex vi-unindent
@item @t{vi-unindent} (unbound) (<) (unbound)
Unindent a number of lines.

@tindex up-case-word
@item @t{up-case-word} (ESC-U ESC-u) (unbound) (unbound)
Convert the current word to all caps and move past it.

@tindex yank
@item @t{yank} (^Y) (unbound) (unbound)
Insert the contents of the kill buffer at the cursor position.

@tindex yank-pop
@item @t{yank-pop} (ESC-y) (unbound) (unbound)
Remove the text just yanked, rotate the kill-ring,
and yank the new top.  Only works following
@t{yank} or @t{yank-pop}.

@tindex vi-yank
@item @t{vi-yank} (unbound) (y) (unbound)
Read a movement command from the keyboard, and copy the region
from the cursor position to the endpoint of the movement
into the kill buffer.
If the command is @t{vi-yank}, copy the current line.

@tindex vi-yank-whole-line
@item @t{vi-yank-whole-line} (unbound) (Y) (unbound)
Copy the current line into the kill buffer.

@tindex vi-yank-eol
@item @t{vi-yank-eol}
Copy the region from the cursor position to the end of the line
into the kill buffer.
Arguably, this is what Y should do in vi, but it isn't what it actually does.

@end table
@node Arguments, Completion, Modifying Text, Zle Widgets

@subsection Arguments
@noindent
@table @asis
@tindex digit-argument
@item @t{digit-argument} (ESC-0..ESC-9) (1-9) (unbound)
Start a new numeric argument, or add to the current one.
See also @t{vi-digit-or-beginning-of-line}.  This only works if bound to a
key sequence ending in a decimal digit.

@noindent
Inside a widget function, a call to this function treats the last key of
the key sequence which called the widget as the digit.

@tindex neg-argument
@item @t{neg-argument} (ESC--) (unbound) (unbound)
Changes the sign of the following argument.

@tindex universal-argument
@item @t{universal-argument}
Multiply the argument of the next command by 4.  Alternatively, if
this command is followed by an integer (positive or negative), use
that as the argument for the next command.  Thus digits cannot be
repeated using this command.  For example, if this command occurs
twice, followed immediately by @t{forward-char}, move forward sixteen
spaces; if instead it is followed by @t{-2}, then @t{forward-char},
move backward two spaces.

@noindent
Inside a widget function, if passed an argument, i.e. `@t{zle
universal-argument} @var{num}', the numerical argument will be set to
@var{num}; this is equivalent to `@t{NUMERIC=}@var{num}'.

@end table
@node Completion, Miscellaneous, Arguments, Zle Widgets

@subsection Completion
@noindent
@table @asis
@tindex accept-and-menu-complete
@item @t{accept-and-menu-complete}
In a menu completion, insert the current completion into the buffer,
and advance to the next possible completion.

@tindex complete-word
@item @t{complete-word}
Attempt completion on the current word.

@tindex delete-char-or-list
@item @t{delete-char-or-list} (^D) (unbound) (unbound)
Delete the character under the cursor.  If the cursor
is at the end of the line, list possible completions for the
current word.

@tindex expand-cmd-path
@item @t{expand-cmd-path}
Expand the current command to its full pathname.

@tindex expand-or-complete
@item @t{expand-or-complete} (TAB) (unbound) (TAB)
Attempt shell expansion on the current word.
If that fails,
attempt completion.

@tindex expand-or-complete-prefix
@item @t{expand-or-complete-prefix}
Attempt shell expansion on the current word up to cursor.

@tindex expand-history
@item @t{expand-history} (ESC-space ESC-!) (unbound) (unbound)
Perform history expansion on the edit buffer.

@tindex expand-word
@item @t{expand-word} (^X*) (unbound) (unbound)
Attempt shell expansion on the current word.

@tindex list-choices
@item @t{list-choices} (ESC-^D) (^D =) (^D)
List possible completions for the current word.

@tindex list-expand
@item @t{list-expand} (^Xg ^XG) (^G) (^G)
List the expansion of the current word.

@tindex magic-space
@item @t{magic-space}
Perform history expansion and insert a space into the
buffer.  This is intended to be bound to space.

@tindex menu-complete
@pindex MENU_COMPLETE, use of
@item @t{menu-complete}
Like @t{complete-word}, except that menu completion is used.
See the @t{MENU_COMPLETE} option.

@tindex menu-expand-or-complete
@item @t{menu-expand-or-complete}
Like @t{expand-or-complete}, except that menu completion is used.

@tindex reverse-menu-complete
@item @t{reverse-menu-complete}
Perform menu completion, like @t{menu-complete}, except that if
a menu completion is already in progress, move to the @emph{previous}
completion rather than the next.

@tindex end-of-list
@item @t{end-of-list}
When a previous completion displayed a list below the prompt, this
widget can be used to move the prompt below the list.

@end table
@node Miscellaneous, , Completion, Zle Widgets

@subsection Miscellaneous
@noindent
@table @asis
@tindex accept-and-hold
@item @t{accept-and-hold} (ESC-A ESC-a) (unbound) (unbound)
Push the contents of the buffer on the buffer stack
and execute it.

@tindex accept-and-infer-next-history
@item @t{accept-and-infer-next-history}
Execute the contents of the buffer.
Then search the history list for a line matching the current one
and push the event following onto the buffer stack.

@tindex accept-line
@item @t{accept-line} (^J ^M) (^J ^M) (^J ^M)
Finish editing the buffer.  Normally this causes the buffer to be
executed as a shell command.

@tindex accept-line-and-down-history
@item @t{accept-line-and-down-history} (^O) (unbound) (unbound)
Execute the current line, and push the next history
event on the the buffer stack.

@tindex beep
@item @t{beep}
Beep, unless the @t{BEEP} option is unset.

@tindex vi-cmd-mode
@item @t{vi-cmd-mode} (^X^V) (unbound) (^[)
Enter command mode; that is, select the `@t{vicmd}' keymap.
Yes, this is bound by default in emacs mode.

@tindex vi-caps-lock-panic
@item @t{vi-caps-lock-panic}
Hang until any lowercase key is pressed.
This is for vi users without the mental capacity to keep
track of their caps lock key (like the author).

@tindex clear-screen
@item @t{clear-screen} (^L ESC-^L) (^L) (^L)
Clear the screen and redraw the prompt.

@tindex describe-key-briefly
@item @t{describe-key-briefly}
Reads a key sequence, then prints the function bound to that sequence.

@tindex exchange-point-and-mark
@item @t{exchange-point-and-mark} (^X^X) (unbound) (unbound)
Exchange the cursor position with the position of the mark.

@tindex execute-named-cmd
@item @t{execute-named-cmd} (ESC-x) (unbound) (unbound)
Read the name of an editor command and
execute it.  A restricted set of editing functions is available in the
mini-buffer.  An interrupt signal, as defined by the stty setting, will
abort the function. The allowed functions are:
@t{backward-delete-char},
@t{vi-backward-delete-char},
@t{clear-screen},
@t{redisplay},
@t{quoted-insert},
@t{vi-quoted-insert},
@t{backward-kill-word},
@t{vi-backward-kill-word},
@t{kill-whole-line},
@t{vi-kill-line},
@t{backward-kill-line},
@t{list-choices},
@t{delete-char-or-list},
@t{complete-word},
@t{accept-line},
@t{expand-or-complete} and
@t{expand-or-complete-prefix}.

@noindent
@t{kill-region} kills the last word,
and vi-cmd-mode is treated the same as accept-line.
The space and tab characters, if not bound to one of
these functions, will complete the name and then list the
possibilities if the @t{AUTO_LIST} option is set.
Any other character that is not bound to @t{self-insert} or
@t{self-insert-unmeta} will beep and be ignored.
The bindings of the current insert mode will be used.

@tindex execute-last-named-cmd
@item @t{execute-last-named-cmd} (ESC-z) (unbound) (unbound)
Redo the last function executed with @t{execute-named-cmd}.

@tindex get-line
@item @t{get-line} (ESC-G ESC-g) (unbound) (unbound)
Pop the top line off the buffer stack and insert it at the
cursor position.

@tindex pound-insert
@item @t{pound-insert} (unbound) (#) (unbound)
If there is no # character at the beginning of the buffer,
add one to the beginning of each line.
If there is one, remove a # from each line that has one.
In either case, accept the current line.
The @t{INTERACTIVE_COMMENTS} option must be set
for this to have any usefulness.

@tindex vi-pound-insert
@item @t{vi-pound-insert}
If there is no # character at the beginning of the current line,
add one.  If there is one, remove it.
The @t{INTERACTIVE_COMMENTS} option must be set
for this to have any usefulness.

@tindex push-input
@item @t{push-input}
Push the entire current multiline construct onto the buffer stack and
return to the top-level (@t{PS1}) prompt.
If the current parser construct is only a single line, this is exactly
like @t{push-line}.
Next time the editor starts up or is popped with @t{get-line}, the
construct will be popped off the top of the buffer stack and loaded
into the editing buffer.

@tindex push-line
@item @t{push-line} (^Q ESC-Q ESC-q) (unbound) (unbound)
Push the current buffer onto the buffer stack and clear
the buffer.
Next time the editor starts up, the buffer will be popped
off the top of the buffer stack and loaded into the editing
buffer.

@tindex push-line-or-edit
@item @t{push-line-or-edit}
At the top-level (@t{PS1}) prompt, equivalent to @t{push-line}.
At a secondary (@t{PS2}) prompt, move the entire current multiline
construct into the editor buffer.
The latter is equivalent to @t{push-input} followed by @t{get-line}.

@tindex redisplay
@item @t{redisplay} (unbound) (^R) (^R)
Redisplays the edit buffer.

@tindex send-break
@item @t{send-break} (^G ESC-^G) (unbound) (unbound)
Abort the current editor function, e.g. @t{execute-named-command}, or the
editor itself, e.g. if you are in @t{vared}. Otherwise abort the parsing of
the current line.

@tindex run-help
@item @t{run-help} (ESC-H ESC-h) (unbound) (unbound)
Push the buffer onto the buffer stack, and execute the
command `@t{run-help} @var{cmd}', where @var{cmd} is the current
command.  @t{run-help} is normally aliased to @t{man}.

@tindex vi-set-buffer
@item @t{vi-set-buffer} (unbound) (") (unbound)
Specify a buffer to be used in the following command.
There are 35 buffers that can be specified:
the 26 `named' buffers @t{"a} to @t{"z}
and the nine `queued' buffers @t{"1} to @t{"9}.  The named buffers can also
be specified as @t{"A} to @t{"Z}.

@noindent
When a buffer is specified for a cut command, the text being cut replaces
the previous contents of the specified buffer.  If a named buffer
is specified using a capital, the newly cut text is appended to the buffer
instead of overwriting it.

@noindent
If no buffer is specified for a cut command, @t{"1} is used, and the
contents of @t{"1} to @t{"8} are each shifted along one buffer; the contents of
@t{"9} is lost.

@tindex vi-set-mark
@item @t{vi-set-mark} (unbound) (m) (unbound)
Set the specified mark at the cursor position.

@tindex set-mark-command
@item @t{set-mark-command} (^@@) (unbound) (unbound)
Set the mark at the cursor position.

@tindex spell-word
@item @t{spell-word} (ESC-$ ESC-S ESC-s) (unbound) (unbound)
Attempt spelling correction on the current word.

@tindex undefined-key
@item @t{undefined-key}
This command is executed when a key sequence that is not bound to any
command is typed.  By default it beeps.

@tindex undo
@item @t{undo} (^_ ^Xu ^X^U) (unbound) (unbound)
Incrementally undo the last text modification.

@tindex redo
@item @t{redo}
Incrementally redo undone text modifications.

@tindex vi-undo-change
@item @t{vi-undo-change} (unbound) (u) (unbound)
Undo the last text modification.
If repeated, redo the modification.

@tindex what-cursor-position
@item @t{what-cursor-position} (^X=) (unbound) (unbound)
Print the character under the cursor, its code as an octal, decimal and
hexadecimal number, the current cursor position within the buffer and the
column of the cursor in the current line.

@tindex where-is
@item @t{where-is}
Read the name of an editor command and and print the listing of key
sequences that invoke the specified command.

@tindex which-command
@item @t{which-command} (ESC-?) (unbound) (unbound)
Push the buffer onto the buffer stack, and execute the
command `@t{which-command} @var{cmd}'. where @var{cmd} is the current
command.  @t{which-command} is normally aliased to @var{whence}.

@tindex vi-digit-or-beginning-of-line
@item @t{vi-digit-or-beginning-of-line} (unbound) (0) (unbound)
If the last command executed was a digit as part of an argument,
continue the argument.  Otherwise, execute vi-beginning-of-line.

@end table
@c (avoiding a yodl bug)
@c Yodl file: Zsh/compwid.yo
@node Completion Widgets, Completion System, Zsh Line Editor, Top

@chapter Completion Widgets
@noindent
@cindex completion, widgets
@cindex completion, programmable
@cindex completion, controlling

@section Description
@noindent
The shell's programmable completion mechanism can be manipulated in two
ways; here the low-level features supporting the newer, function-based
mechanism are defined.  A complete set of shell functions based on these
features is described in
the next chapter, @ref{Completion System},
and users with no interest in adding to that system (or, potentially,
writing their own --- see dictionary entry for `hubris') should skip this
section.  The older system based on the @t{compctl} builtin command is
described in
the chapter @ref{Completion Using compctl}.

@noindent
Completion widgets are defined by the @t{-C} option to the @t{zle}
builtin command provided by the @t{zsh/zle} module (see
@ref{The zsh/zle Module}). For example,

@noindent
@example
zle -C complete expand-or-complete completer
@end example

@noindent
defines a widget named `@t{complete}'.  The second argument is the name
of any of the builtin widgets that handle completions:
@t{complete-word}, @t{expand-or-complete},
@t{expand-or-complete-prefix}, @t{menu-complete},
@t{menu-expand-or-complete}, @t{reverse-menu-complete},
@t{list-choices}, or @t{delete-char-or-list}.  Note that this will still
work even if the widget in question has been re-bound.

@noindent
When this newly defined widget is bound to a key
using the @t{bindkey} builtin command defined in the @t{zsh/zle} module
(@ref{Zsh Line Editor}), typing that key will call the shell function `@t{completer}'. This
function is responsible for generating the possible matches using the
builtins described below.  As with other ZLE widgets, the function is
called with its standard input closed.

@noindent
Once the function returns, the completion code takes over control again
and treats the matches in the same manner as the specified builtin
widget, in this case @t{expand-or-complete}.

@noindent
@menu
* Special Parameters::
* Builtin Commands::
* Condition Codes::
* Matching Control::
* Completion Widget Example::
@end menu

@noindent
@node Special Parameters, Builtin Commands, , Completion Widgets

@section Special Parameters
@noindent

@noindent
Inside completion widgets, and any functions called from them, some
parameters have special meaning; outside these functions they are not
special to the shell in any way.  These parameters are used to pass
information between the completion code and the completion widget. Some of
the builtin commands and the condition codes use or change the current
values of these parameters.  Any existing values will be hidden during
execution of completion widgets; except for @t{compstate}, the parameters
are reset on each function exit (including nested function calls from
within the completion widget) to the values they had when the function was
entered.

@noindent
@table @asis
@vindex CURRENT
@item @t{CURRENT}
This is the number of the current word, i.e. the word the cursor is
currently on in the @t{words} array.  Note that this value is only
correct if the @t{ksharrays} option is not set.

@vindex IPREFIX
@item @t{IPREFIX}
Initially this will be set to the empty string.  This parameter functions
like @t{PREFIX}; it contains a string which precedes the one in @t{PREFIX}
and is not considered part of the list of matches.  Typically, a string is
transferred from the beginning of @t{PREFIX} to the end of @t{IPREFIX}, for
example:

@noindent
@example
IPREFIX=$@{PREFIX%%\=*@}=
PREFIX=$@{PREFIX#*=@}
@end example

@noindent
causes the part of the prefix up to and including the first equal sign not
to be treated as part of a matched string.  This can be done automatically
by the @t{compset} builtin, see below.

@vindex ISUFFIX
@item @t{ISUFFIX}
As @t{IPREFIX}, but for a suffix that should not be considered part
of the matches; note that the @t{ISUFFIX} string follows the @t{SUFFIX}
string.

@vindex PREFIX
@item @t{PREFIX}
Initially this will be set to the part of the current word from the
beginning of the word up to the position of the cursor; it may be altered
to give a common prefix for all matches.

@vindex QIPREFIX
@item @t{QIPREFIX}
This parameter is read-only and contains the quoted string up to the
word being completed. E.g. when completing `@t{"foo}', this parameter
contains the double quote. If the @t{-q} option of @t{compset} is used 
(see below), and the original string was `@t{"foo bar}' with the
cursor on the `@t{bar}', this parameter contains `@t{"foo }'.

@vindex QISUFFIX
@item @t{QISUFFIX}
Like @t{QIPREFIX}, but containing the suffix.

@vindex SUFFIX
@item @t{SUFFIX}
Initially this will be set to the part of the current word from the
cursor position to the end; it may be altered to give a common suffix for
all matches.  It is most useful when the option @t{COMPLETE_IN_WORD} is
set, as otherwise the whole word on the command line is treated as a
prefix.

@vindex compstate
@cindex completion widgets, examining and setting state in
@item @t{compstate}
This is an associative array with various keys and values that the
completion code uses to exchange information with the completion widget.
The keys are:

@noindent
@table @asis
@vindex all_quotes, compstate
@item @t{all_quotes}
The @t{-q} option of the @t{compset} builtin command (see below)
allows a quoted string to be broken into separate words; if the cursor is
on one of those words, that word will be completed, possibly invoking
`@t{compset -q}' recursively.  With this key it is possible to test the
types of quoted strings which are currently broken into parts in this
fashion.  Its value contains one character for each quoting level.  The
characters are a single quote or a double quote for strings quoted with
these characters and a backslash for strings not starting with a quote
character.  The first character in the value always corresponds to the
innermost quoting level.

@vindex context, compstate
@item @t{context}
This will be set by the completion code to the overall context
in which completion is attempted. Possible values are:

@noindent
@table @asis
@item @t{array_value}
when completing inside the value of an array parameter assignment; in
this case the @t{words} array contains the words inside the parentheses.

@item @t{brace_parameter}
when completing the name of a parameter in a parameter expansion beginning
with @t{$@{}.

@item @t{command}
when completing for a normal command (either in command position or for
an argument of the command).

@item @t{condition}
when completing inside a `@t{[[}...@t{]]}' conditional expression; in
this case the @t{words} array contains only the words inside the
conditional expression.

@item @t{math}
when completing in a mathematical environment such as a
`@t{((}...@t{))}' construct.

@item @t{parameter}
when completing the name of a parameter in a parameter expansion beginning
with @t{$} but not @t{$@{}.

@item @t{redirect}
when completing after a redirection operator.

@item @t{subscript}
when completing inside a parameter subscript.

@item @t{value}
when completing the value of a parameter assignment.

@end table

@vindex exact, compstate
@item @t{exact}
Controls the behaviour when the @t{REC_EXACT} option is set.  It will be
set to @t{accept} if an exact match would be accepted, and will be unset
otherwise.

@noindent
If it was set when at least one match equal to the string on the line
was generated, the match is accepted.

@vindex exact_string, compstate
@item @t{exact_string}
The string of an exact match if one was found, otherwise unset.

@vindex ignored, compstate
@item @t{ignored}
The number of words that were ignored because they matched one of the
patterns given with the @t{-F} option to the @t{compadd} builtin
command.

@vindex insert, compstate
@item @t{insert}
This controls the manner in which a match is inserted into the command
line.  On entry to the widget function, if it is unset the command line is
not to be changed; if set to @t{unambiguous}, any prefix common to all
matches is to be inserted; if set to @t{automenu-unambiguous}, the
common prefix is to be inserted and the next invocation of the
completion code may start menu completion (due to the @t{AUTO_MENU}
option being set); if set to @t{menu} or @t{automenu} menu completion
will be started for the matches currently generated (in the
latter case this will happen because the @t{AUTO_MENU} is set). The
value may also contain the string `@t{tab}' when the completion code
would normally not really do completion, but only insert the TAB
character.

@noindent
On exit it may be set to any of the values above (where setting it to
the empty string is the same as unsetting it), or to a number, in which
case the match whose number is given will be inserted into the command line.
Negative numbers count backward from the last match (with `@t{-1}'
selecting the last match) and out-of-range values are wrapped
around, so that a value of zero selects the last match and a value
one more than the maximum selects the first. Unless the value of this
key ends in a space, the match is inserted as in a menu completion,
i.e. without automatically appending a space.

@noindent
Both @t{menu} and @t{automenu} may also specify the the number of the
match to insert, given after a colon.  For example, `@t{menu:2}' says
to start menu completion, beginning with the second match.

@noindent
Note that a value containing the substring `@t{tab}' makes the
matches generated be ignored and only the TAB be inserted.

@noindent
Finally, it may also be set to @t{all}, which makes all matches
generated be inserted into the line.

@vindex insert_positions, compstate
@item @t{insert_positions}
When the completion system inserts an unambiguous string into the
line, there may be multiple places where characters are missing or
where the character inserted differs from at least one match.  The
value of this key contains a colon separated list of all these
positions, as indexes into the command line.

@vindex last_prompt, compstate
@item @t{last_prompt}
If this is set to a non-empty string for every match added, the
completion code will move the cursor back to the previous prompt after
the list of completions has been displayed.  Initially this is set or
unset according to the @t{ALWAYS_LAST_PROMPT} option.

@vindex list, compstate
@item @t{list}
This controls whether or how the list of matches will be displayed.  If it
is unset or empty they will never be listed; if its value begins with
@t{list}, they will always be listed; if it begins with @t{autolist}
or @t{ambiguous}, they will be listed when the @t{AUTO_LIST} or
@t{LIST_AMBIGUOUS} options respectively would normally cause them to
be.

@noindent
If the substring @t{force} appears in the value, this makes the
list be shown even if there is only one match. Normally, the list
would be shown only if there are at least two matches.

@noindent
The value contains the substring @t{packed} if the @t{LIST_PACKED}
option is set. If this substring is given for all matches added to a
group, this group will show the @t{LIST_PACKED} behavior. The same is
done for the @t{LIST_ROWS_FIRST} option with the substring @t{rows}.

@noindent
Finally, if the value contains the string @t{explanations}, only the
explanation strings, if any, will be listed and if it contains
@t{messages}, only the messages (added with the @t{-x} option of
@t{compadd}) will be listed.  If it contains both @t{explanations} and 
@t{messages} both kinds of explanation strings will be listed.  It
will be set appropriately on entry to a completion widget and may be
changed there.

@vindex list_lines, compstate
@item @t{list_lines}
This gives the number of lines that are needed to display the full
list of completions.  Note that to calculate the total number of lines
to display you need to add the number of lines needed for the command
line to this value, this is available as the value of the @t{BUFFERLINES}
special parameter.

@vindex list_max, compstate
@item @t{list_max}
Initially this is set to the value of the @t{LISTMAX} parameter.
It may be set to any other value; when the widget exits this value
will be used in the same way as the value of @t{LISTMAX}.

@vindex nmatches, compstate
@item @t{nmatches}
The number of matches generated and accepted by the completion code so
far.

@vindex old_insert, compstate
@item @t{old_insert}
On entry to the widget this will be set to the number of the match of
an old list of completions that is currently inserted into the command
line. If no match has been inserted, this is unset.

@noindent
As with @t{old_list}, the value of this key will only be used if it is the
string @t{keep}. If it was set to this value by the widget and there was an
old match inserted into the command line, this match will be kept and if
the value of the @t{insert} key specifies that another match should be
inserted, this will be inserted after the old one.

@vindex old_list, compstate
@item @t{old_list}
This is set to @t{yes} if there is still a valid list of completions
from a previous completion at the time the widget is invoked.  This will
usually be the case if and only if the previous editing operation was a
completion widget or one of the builtin completion functions.  If there is a
valid list and it is also currently shown on the screen, the value of this
key is @t{shown}.

@noindent
After the widget has exited the value of this key is only used if it
was set to @t{keep}.  In this case the completion code will continue
to use this old list.  If the widget generated new matches, they will
not be used.

@vindex parameter, compstate
@item @t{parameter}
The name of the parameter when completing in a subscript or in the
value of a parameter assignment.

@vindex pattern_insert, compstate
@item @t{pattern_insert}
Normally this is set to @t{menu}, which specifies that menu completion will
be used whenever a set of matches was generated using pattern matching.  If
it is set to any other non-empty string by the user and menu completion is
not selected by other option settings, the code will instead insert any
common prefix for the generated matches as with normal completion.

@vindex pattern_match, compstate
@item @t{pattern_match}
Locally controls the behaviour given by the @t{GLOB_COMPLETE} option.
Initially it is set to `@t{*}' if and only if the option is set.
The completion widget may set it to this value, to an empty string
(which has the same effect as unsetting it), or to any
other non-empty string.  If it is non-empty, unquoted metacharacters on the
command line will be treated as patterns; if it is `@t{*}', then
additionally a wildcard `@t{*}' is assumed at the cursor position; if
it is empty or unset, metacharacters will be treated literally.

@noindent
Note that the matcher specifications given to the @t{compadd} builtin
command are not used if this is set to a non-empty string.

@vindex quote, compstate
@item @t{quote}
When completing inside quotes, this contains the quotation character
(i.e. either a single quote, a double quote, or a backtick).  Otherwise it
is unset.

@vindex quoting, compstate
@item @t{quoting}
When completing inside single quotes, this is set to the string
@t{single}; inside double quotes, the string
@t{double}; inside backticks, the string @t{backtick}.
Otherwise it is unset.

@vindex redirect, compstate
@item @t{redirect}
The redirection operator when completing in a redirection position,
i.e. one of @t{<}, @t{>}, etc.

@vindex restore, compstate
@item @t{restore}
This is set to @t{auto} before a function is entered, which forces the
special parameters mentioned above (@t{words}, @t{CURRENT}, @t{PREFIX},
@t{IPREFIX}, @t{SUFFIX}, and @t{ISUFFIX}) to be restored to their
previous values when the function exits.   If a function unsets it or
sets it to any other string, they will not be restored.

@vindex to_end, compstate
@item @t{to_end}
Specifies the occasions on which the cursor is moved to the end of a string
when a match is inserted.  On entry to a widget function, it may be
@t{single} if this will happen when a single unambiguous match was inserted
or @t{match} if it will happen any time a match is inserted (for example,
by menu completion; this is likely to be the effect of the @t{ALWAYS_TO_END}
option).

@noindent
On exit, it may be set to @t{single} as above.  It may also be set to
@t{always}, or to the empty string or unset; in those cases the cursor will
be moved to the end of the string always or never respectively.  Any
other string is treated as @t{match}.

@vindex unambiguous, compstate
@item @t{unambiguous}
This key is read-only and will always be set to the common (unambiguous)
prefix the completion code has generated for all matches added so far.

@vindex unambiguous_cursor, compstate
@item @t{unambiguous_cursor}
This gives the position the cursor would be placed at if the
common prefix in the @t{unambiguous} key were inserted, relative to
the value of that key. The cursor would be placed before the character
whose index is given by this key.

@vindex unambiguous_positions, compstate
@item @t{unambiguous_positions}
This contains all positions where characters in the unambiguous string
are missing or where the character inserted differs from at least one
of the matches.  The positions are given as indexes into the string
given by the value of the @t{unambiguous} key.

@vindex vared, compstate
@item @t{vared}
If completion is called while editing a line using the @t{vared}
builtin, the value of this key is set to the name of the parameter
given as an argument to @t{vared}.  This key is only set while a @t{vared}
command is active.

@end table

@vindex words
@item @t{words}
This array contains the words present on the command line currently being
edited.

@end table

@noindent
@node Builtin Commands, Condition Codes, Special Parameters, Completion Widgets

@section Builtin Commands
@noindent
@table @asis
@findex compadd
@cindex completion widgets, adding specified matches
@item @t{compadd} [ @t{-akqQfenUl12C} ] [ @t{-F} @var{array} ]
@itemx [ @t{-P} @var{prefix} ] [ @t{-S} @var{suffix} ]
@itemx [ @t{-p} @var{hidden-prefix} ] [ @t{-s} @var{hidden-suffix} ]
@itemx [ @t{-i} @var{ignored-prefix} ] [ @t{-I} @var{ignored-suffix} ]
@itemx [ @t{-W} @var{file-prefix} ] [ @t{-d} @var{array} ]
@itemx [ @t{-J} @var{name} ] [ @t{-V} @var{name} ] [ @t{-X} @var{explanation} ] [ @t{-x} @var{message} ]
@itemx [ @t{-r} @var{remove-chars} ] [ @t{-R} @var{remove-func} ]
@itemx [ @t{-D} @var{array} ] [ @t{-O} @var{array} ] [ @t{-A} @var{array} ]
@itemx [ @t{-M} @var{match-spec} ] [ @t{--} ] [ @var{words} ... ]

@noindent
This builtin command can be used to add matches directly and control
all the information the completion code stores with each possible
match. The return value is zero if at least one match was added and
non-zero if no matches were added.

@noindent
The completion code breaks the string to complete into seven fields in
the order: 

@noindent
@quotation
@var{<ipre><apre><hpre><word><hsuf><asuf><isuf>}
@end quotation

@noindent
The first field
is an ignored prefix taken from the command line, the contents of the
@t{IPREFIX} parameter plus the string given with the @t{-i}
option. With the @t{-U} option, only the string from the @t{-i}
option is used. The field @var{<apre>} is an optional prefix string
given with the @t{-P} option.  The @var{<hpre>} field is a string
that is considered part of the match but that should not be shown when 
listing completions, given with the @t{-p} option; for example,
functions that do filename generation might specify
a common path prefix this way.  @var{<word>} is the part of the match that
should appear in the list of completions, i.e. one of the @var{words} given
at the end of the @t{compadd} command line. The suffixes @var{<hsuf>},
@var{<asuf>} and @var{<isuf>} correspond to the prefixes @var{<hpre>},
@var{<apre>} and @var{<ipre>} and are given by the options @t{-s}, @t{-S} and
@t{-I}, respectively.

@noindent
The supported flags are:

@noindent
@table @asis
@item @t{-P} @var{prefix}
This gives a string to be inserted before the given @var{words}.  The
string given is not considered as part of the match and any shell
metacharacters in it will not be quoted when the string is inserted.

@item @t{-S} @var{suffix}
Like @t{-P}, but gives a string to be inserted after the match.

@item @t{-p} @var{hidden-prefix}
This gives a string that should be inserted into the command line before the
match but that should not appear in the list of matches. Unless the
@t{-U} option is given, this string must be matched as part of the string
on the command line.

@item @t{-s} @var{hidden-suffix}
Like `@t{-p}', but gives a string to insert after the match.

@item @t{-i} @var{ignored-prefix}
This gives a string to insert into the command line just before any
string given with the `@t{-P}' option.  Without `@t{-P}' the string is
inserted before the string given with `@t{-p}' or directly before the
match.

@item @t{-I} @var{ignored-suffix}
Like @t{-i}, but gives an ignored suffix.

@item @t{-a}
With this flag the @var{words} are taken as names of arrays and the
possible matches are their values.  If only some elements of the
arrays are needed, the @var{words} may also contain subscripts, as in
`@t{foo[2,-1]}'.

@item @t{-k}
With this flag the @var{words} are taken as names of associative arrays
and the possible matches are their keys.  As for @t{-a}, the
@var{words} may also contain subscripts, as in `@t{foo[(R)*bar*]}'.

@item @t{-d} @var{array}
This adds per-match display strings. The @var{array} should contain one 
element per @var{word} given. The completion code will then display the 
first element instead of the first @var{word}, and so on. The
@var{array} may be given as the name of an array parameter or directly
as a space-separated list of words in parentheses.

@noindent
If there are fewer display strings than @var{words}, the leftover
@var{words} will be displayed unchanged and if there are more display
strings than @var{words}, the leftover display strings will be silently
ignored.

@item @t{-l}
This option only has an effect if used together with the @t{-d}
option. If it is given, the display strings are listed one per line,
not arrayed in columns.

@item @t{-J} @var{name}
Gives the name of the group of matches the words should be stored in.

@item @t{-V} @var{name}
Like @t{-J} but naming a unsorted group. These are in a different name 
space than groups created with the @t{-J} flag.

@item @t{-1}
If given together with the @t{-V} option, makes
only consecutive duplicates in the group be removed. If combined with
the @t{-J} option, this has no visible effect. Note that groups
with and without this flag are in different name spaces.

@item @t{-2}
If given together with the @t{-J} or @t{-V} option, makes all
duplicates be kept. Again, groups with and without this flag are in
different name spaces.

@item @t{-X} @var{explanation}
The @var{explanation} string will be printed with the list of matches,
above the group currently selected.

@item @t{-x} @var{message}
Like @t{-X}, but the @var{message} will be printed even if there are no 
matches in the group.

@item @t{-q}
The suffix given with @t{-S} will be automatically removed if 
the next character typed is a blank or does not insert anything, or if
the suffix consists of only one character and the next character typed 
is the same character.

@item @t{-r} @var{remove-chars}
This is a more versatile form of the @t{-q} option.
The suffix given with @t{-S} or the slash automatically added after
completing directories will be automatically removed if
the next character typed inserts one of the characters given in the
@var{remove-chars}.  This string is parsed as a characters class and
understands the backslash sequences used by the @t{print} command.  For
example, `@t{-r "a-z\t"}' removes the suffix if the next character typed
inserts a lowercase character or a TAB, and `@t{-r "^0-9"}' removes the
suffix if the next character typed inserts anything but a digit. One extra
backslash sequence is understood in this string: `@t{\-}' stands for
all characters that insert nothing. Thus `@t{-S "=" -q}' is the same
as `@t{-S "=" -r "= \t\n\-"}'.

@item @t{-R} @var{remove-func}
This is another form of the @t{-r} option. When a suffix 
has been inserted and the completion accepted, the function
@var{remove-func} will be called after the next character typed.  It is
passed the length of the suffix as an argument and can use the special
parameters available in ordinary (non-completion) zle widgets (see
@ref{Zsh Line Editor}) to analyse and modify the command line.

@item @t{-f}
If this flag is given, all of the matches built from @var{words} are
marked as being the names of files.  They are not required to be actual
filenames, but if they are, and the option @t{LIST_TYPES} is set, the
characters describing the types of the files in the completion lists will
be shown. This also forces a slash to be added when the name of a
directory is completed.

@item @t{-e}
This flag can be used to tell the completion code that the matches
added are parameter names for a parameter expansion. This will make
the @t{AUTO_PARAM_SLASH} and @t{AUTO_PARAM_KEYS} options be used for
the matches.

@item @t{-W} @var{file-prefix}
This string is a pathname that will be
prepended to each of the matches formed by the given @var{words} together 
with any prefix specified by the @t{-p} option to form a complete filename
for testing.  Hence it is only useful if combined with the @t{-f} flag, as
the tests will not otherwise be performed.

@item @t{-F} @var{array}
Specifies an array containing patterns. Words matching one of these
patterns are ignored, i.e. not considered to be possible matches.

@noindent
The @var{array} may be the name of an array parameter or a list of
literal patterns enclosed in parentheses and quoted, as in `@t{-F "(*?.o
*?.h)"}'. If the name of an array is given, the elements of the array are
taken as the patterns.

@item @t{-Q}
This flag instructs the completion 
code not to quote any metacharacters in the words when inserting them
into the command line.

@item @t{-M} @var{match-spec}
This gives local match specifications as described below in
@ref{Matching Control}. This option may be given more than once. In 
this case all @var{match-spec}s given are concatenated with spaces
between them to form the specification string to use.
Note that they will only be used if the @t{-U} option is not given.

@item @t{-n}
Specifies that the words added are to be used as possible
matches, but are not to appear in the completion listing.

@item @t{-U}
If this flag is given, all words given will be accepted and no matching
will be done by the completion code. Normally this is used in
functions that do the matching themselves.

@item @t{-O} @var{array}
If this option is given, the @var{words} are @emph{not} added to the set of
possible completions.  Instead, matching is done as usual and all of the
@var{words} given as arguments that match the string on the command line
will be stored in the array parameter whose name is given as @var{array}.

@item @t{-A} @var{array}
As the @t{-O} option, except that instead of those of the @var{words} which
match being stored in @var{array}, the strings generated internally by the
completion code are stored. For example,
with a matching specification of `@t{-M "L:|no="}', the string `@t{nof}'
on the command line and the string `@t{foo}' as one of the @var{words}, this
option stores the string `@t{nofoo}' in the array, whereas the @t{-O}
option stores the `@t{foo}' originally given.

@item @t{-D} @var{array}
As with @t{-O}, the @var{words} are not added to the set of possible
completions.  Instead, the completion code tests whether each @var{word} 
in turn matches what is on the line.  If the @var{n}'th @var{word} does not
match, the @var{n}'th element of the @var{array} is removed.  Elements
for which the corresponding @var{word} is matched are retained.

@item @t{-C}
This option adds a special match which expands to all other matches
when inserted into the line, even those that are added after this
option is used.  Together with the @t{-d} option it is possible to
specify a string that should be displayed in the list for this special 
match.  If no string is given, it will be shown as a string containing 
the strings that would be inserted for the other matches, truncated to 
the width of the screen.

@item @t{-}
@itemx @t{-}@t{-}
This flag ends the list of flags and options. All arguments after it
will be taken as the words to use as matches even if they begin with
hyphens.

@end table

@noindent
Except for the @t{-M} flag, if any of these flags is given more than
once, the first one (and its argument) will be used.

@findex compset
@cindex completion widgets, modifying special parameters
@item @t{compset -p} @var{number}
@itemx @t{compset -P} [ @var{number} ] @var{pattern}
@itemx @t{compset -s} @var{number}
@itemx @t{compset -S} [ @var{number} ] @var{pattern}
@itemx @t{compset -n} @var{begin} [ @var{end} ]
@itemx @t{compset -N} @var{beg-pat} [ @var{end-pat} ]
@itemx @t{compset -q}
This command simplifies modification of the special parameters,
while its return value allows tests on them to be carried out.

@noindent
The options are:

@noindent
@table @asis
@item @t{-p} @var{number}
If the contents of the @t{PREFIX} parameter is longer than @var{number}
characters, the first @var{number} characters are removed from it and
appended to the contents of the @t{IPREFIX} parameter.

@item @t{-P} [ @var{number} ] @var{pattern}
If the value of the @t{PREFIX} parameter begins with anything that
matches the @var{pattern}, the matched portion is removed from
@t{PREFIX} and appended to @t{IPREFIX}.

@noindent
Without the optional @var{number}, the longest match is taken, but
if @var{number} is given, anything up to the @var{number}'th match is
moved.  If the @var{number} is negative, the @var{number}'th longest
match is moved. For example, if @t{PREFIX} contains the string
`@t{a=b=c}', then @t{compset -P '*\='} will move the string `@t{a=b=}' 
into the @t{IPREFIX} parameter, but @t{compset -P 1 '*\='} will move only
the string `@t{a=}'.

@item @t{-s} @var{number}
As @t{-p}, but transfer the last @var{number} characters from the
value of @t{SUFFIX} to the front of the value of @t{ISUFFIX}.

@item @t{-S} [ @var{number} ] @var{pattern}
As @t{-P}, but match the last portion of @t{SUFFIX} and transfer the
matched portion to the front of the value of @t{ISUFFIX}.

@item @t{-n} @var{begin} [ @var{end} ]
If the current word position as specified by the parameter @t{CURRENT} 
is greater than or equal to @var{begin}, anything up to the
@var{begin}'th word is removed from the @t{words} array and the value
of the parameter @t{CURRENT} is decremented by @var{begin}.

@noindent
If the optional @var{end} is given, the modification is done only if
the current word position is also less than or equal to @var{end}. In
this case, the words from position @var{end} onwards are also removed from
the @t{words} array.

@noindent
Both @var{begin} and @var{end} may be negative to count backwards
from the last element of the @t{words} array.

@item @t{-N} @var{beg-pat} [ @var{end-pat} ]
If one of the elements of the @t{words} array before the one at the
index given by the value of the parameter @t{CURRENT} matches the
pattern @var{beg-pat}, all elements up to and including the matching one are
removed from the @t{words} array and the value of @t{CURRENT} is changed to
point to the same word in the changed array.

@noindent
If the optional pattern @var{end-pat} is also given, and there is an
element in the @t{words} array matching this pattern, the parameters
are modified only if the index of this word is higher than the one
given by the @t{CURRENT} parameter (so that the matching word has 
to be after the cursor). In this case, the words starting with the one
matching @t{end-pat} are also removed from the @t{words}
array. If @t{words} contains no word matching @var{end-pat}, the
testing and modification is performed as if it were not given.

@item @t{-q}
The word
currently being completed is split on spaces into separate words,
respecting the usual shell quoting conventions.  The 
resulting words are stored in the @t{words} array, and @t{CURRENT},
@t{PREFIX}, @t{SUFFIX}, @t{QIPREFIX}, and @t{QISUFFIX} are modified to
reflect the word part that is completed.

@end table

@noindent
In all the above cases the return value is zero if the test succeeded
and the parameters were modified and non-zero otherwise. This allows
one to use this builtin in tests such as:

@noindent
@example
if compset -P '*\='; then ...
@end example

@noindent
This forces anything up to and including the last equal sign to be
ignored by the completion code.

@item @t{compcall} [ @t{-TD} ]
This allows the use of completions defined with the @t{compctl} builtin
from within completion widgets.  The list of matches will be generated as
if one of the non-widget completion function (@t{complete-word}, etc.)
had been called, except that only @t{compctl}s given for specific commands
are used. To force the code to try completions defined with the @t{-T}
option of @t{compctl} and/or the default completion (whether defined by
@t{compctl -D} or the builtin default) in the appropriate places, the
@t{-T} and/or @t{-D} flags can be passed to @t{compcall}.

@noindent
The return value can be used to test if a matching @t{compctl}
definition was found. It is non-zero if a @t{compctl} was found and
zero otherwise.

@noindent
Note that this builtin is defined by the @t{zsh/compctl} module.

@end table

@noindent
@node Condition Codes, Matching Control, Builtin Commands, Completion Widgets

@section Condition Codes
@noindent
@cindex completion widgets, condition codes

@noindent
The following additional condition codes for use within the @t{[[ ... ]]}
construct are available in completion widgets.  These work on the special
parameters.  All of these tests can also be performed by the @t{compset}
builtin, but in the case of the condition codes the contents of the special
parameters are not modified.

@noindent
@table @asis
@item @t{-prefix} [ @var{number} ] @var{pattern}
true if the test for the @t{-P} option of @t{compset} would succeed.

@item @t{-suffix} [ @var{number} ] @var{pattern}
true if the test for the @t{-S} option of @t{compset} would succeed.

@item @t{-after} @var{beg-pat}
true if the test of the @t{-N} option with only the @var{beg-pat} given 
would succeed.

@item @t{-between} @var{beg-pat end-pat}
true if the test for the @t{-N} option with both patterns would succeed.

@end table

@noindent
@node Matching Control, Completion Widget Example, Condition Codes, Completion Widgets

@section Matching Control
@noindent

@noindent
It is possible by use of the
@t{-M} option of the @t{compadd} builtin command to specify how the
characters in the string to be completed (referred to here as the
command line) map onto the characters in the list of matches produced by
the completion code (referred to here as the trial completions). Note
that this is not used if the command line contains a glob pattern and
the @t{GLOB_COMPLETE} option is set or the @t{pattern_match} of the
@t{compstate} special association is set to a non-empty string.

@noindent
The @var{match-spec} given as the argument to the @t{-M} option (see
@ref{Builtin Commands}) consists of one or more matching descriptions separated by
whitespace.  Each description consists of a letter followed by a colon
and then the patterns describing which character sequences on the line match
which character sequences in the trial completion.  Any sequence of
characters not handled in this fashion must match exactly, as usual.

@noindent
The forms of @var{match-spec} understood are as follows. In each case, the
form with an uppercase initial character retains the string already
typed on the command line as the final result of completion, while with
a lowercase initial character the string on the command line is changed
into the corresponding part of the trial completion.

@noindent
@table @asis
@item @t{m:}@var{lpat}@t{=}@var{tpat}
@itemx @t{M:}@var{lpat}@t{=}@var{tpat}
Here, @var{lpat} is a pattern that matches on the command line,
corresponding to @var{tpat} which matches in the trial completion.

@item @t{l:}@var{lanchor}@t{|}@var{lpat}@t{=}@var{tpat}
@itemx @t{L:}@var{lanchor}@t{|}@var{lpat}@t{=}@var{tpat}
@itemx @t{l:}@var{lanchor}@t{||}@var{ranchor}@t{=}@var{tpat}
@itemx @t{L:}@var{lanchor}@t{||}@var{ranchor}@t{=}@var{tpat}
@itemx @t{b:}@var{lpat}@t{=}@var{tpat}
@itemx @t{B:}@var{lpat}@t{=}@var{tpat}
These letters are for patterns that are anchored by another pattern on
the left side. Matching for @var{lpat} and @var{tpat} is as for @t{m} and
@t{M}, but the pattern @var{lpat} matched on the command line must be
preceded by the pattern @var{lanchor}.  The @var{lanchor} can be blank to
anchor the match to the start of the command line string; otherwise the
anchor can occur anywhere, but must match in both the command line and
trial completion strings.

@noindent
If no @var{lpat} is given but a @var{ranchor} is, this matches the gap
between substrings matched by @var{lanchor} and @var{ranchor}. Unlike
@var{lanchor}, the @var{ranchor} only needs to match the trial
completion string.

@noindent
The @t{b} and @t{B} forms are similar to @t{l} and @t{L} with an empty 
anchor, but need to match only the beginning of the trial completion
or the word on the command line, respectively.

@item @t{r:}@var{lpat}@t{|}@var{ranchor}@t{=}@var{tpat}
@itemx @t{R:}@var{lpat}@t{|}@var{ranchor}@t{=}@var{tpat}
@itemx @t{r:}@var{lanchor}@t{||}@var{ranchor}@t{=}@var{tpat}
@itemx @t{R:}@var{lanchor}@t{||}@var{ranchor}@t{=}@var{tpat}
@itemx @t{e:}@var{lpat}@t{=}@var{tpat}
@itemx @t{E:}@var{lpat}@t{=}@var{tpat}
As @t{l}, @t{L}, @t{b} and @t{B}, with the difference that the command
line and trial completion patterns are anchored on the right side.
Here an empty @var{ranchor} and the @t{e} and @t{E} forms force the
match to the end of the trial completion or command line string.

@end table

@noindent
Each @var{lpat}, @var{tpat} or @var{anchor} is either an empty string or
consists of a sequence of literal characters (which may be quoted with a
backslash), question marks, character classes, and correspondence
classes; ordinary shell patterns are not used.  Literal characters match
only themselves, question marks match any character, and character
classes are formed as for globbing and match any character in the given
set.

@noindent
Correspondence classes are defined like character classes, but with two
differences: they are delimited by a pair of braces, and negated classes
are not allowed, so the characters @t{!} and @t{^} have no special
meaning directly after the opening brace.  They indicate that a range of
characters on the line match a range of characters in the trial
completion, but (unlike ordinary character classes) paired according to
the corresponding position in the sequence. For example, to make any
lowercase letter on the line match the corresponding uppercase letter in
the trial completion, you can use `@t{m:@{a-z@}=@{A-Z@}}'.  More than one
pair of classes can occur, in which case the first class before the
@t{=} corresponds to the first after it, and so on.  If one side has
more such classes than the other side, the superfluous classes behave
like normal character classes.  In anchor patterns correspondence classes
also behave like normal character classes.

@noindent
The pattern @var{tpat} may also be one or two stars, `@t{*}' or
`@t{**}'. This means that the pattern on the command line can match
any number of characters in the trial completion. In this case the
pattern must be anchored (on either side); in the case of a single
star, the @var{anchor} then determines how much of the trial completion
is to be included --- only the characters up to the next appearance of
the anchor will be matched. With two stars, substrings matched by the
anchor can be matched, too.

@noindent
Examples:

@noindent
The keys of the @t{options} association defined by the @t{parameter}
module are the option names in all-lowercase form, without
underscores, and without the optional @t{no} at the beginning even
though the builtins @t{setopt} and @t{unsetopt} understand option names
with uppercase letters, underscores, and the optional @t{no}.  The
following alters the matching rules so that the prefix @t{no} and any
underscore are ignored when trying to match the trial completions
generated and uppercase letters on the line match the corresponding
lowercase letters in the words:

@noindent
@example
compadd -M 'L:|[nN][oO]= M:_= M:@{A-Z@}=@{a-z@}' - \ 
  $@{(k)options@} 
@end example

@noindent
The first part says that the pattern `@t{[nN][oO]}' at the beginning
(the empty anchor before the pipe symbol) of the string on the
line matches the empty string in the list of words generated by
completion, so it will be ignored if present. The second part does the
same for an underscore anywhere in the command line string, and the
third part uses correspondence classes so that any
uppercase letter on the line matches the corresponding lowercase
letter in the word. The use of the uppercase forms of the
specification characters (@t{L} and @t{M}) guarantees that what has
already been typed on the command line (in particular the prefix
@t{no}) will not be deleted.

@noindent
Note that the use of @t{L} in the first part means that it matches
only when at the beginning of both the command line string and the
trial completion. I.e., the string `@t{_NO_f}' would not be
completed to `@t{_NO_foo}', nor would `@t{NONO_f}' be completed to
`@t{NONO_foo}' because of the leading underscore or the second
`@t{NO}' on the line which makes the pattern fail even though they are 
otherwise ignored. To fix this, one would use `@t{B:[nN][oO]=}'
instead of the first part. As described above, this matches at the
beginning of the trial completion, independent of other characters or
substrings at the beginning of the command line word which are ignored
by the same or other @var{match-spec}s.

@noindent
The second example makes completion case insensitive.  This is just
the same as in the option example, except here we wish to retain the
characters in the list of completions:

@noindent
@example
compadd -M 'm:@{a-z@}=@{A-Z@}' ... 
@end example

@noindent
This makes lowercase letters match their uppercase counterparts.
To make uppercase letters match the lowercase forms as well:

@noindent
@example
compadd -M 'm:@{a-zA-Z@}=@{A-Za-z@}' ... 
@end example

@noindent
A nice example for the use of @t{*} patterns is partial word
completion. Sometimes you would like to make strings like `@t{c.s.u}'
complete to strings like `@t{comp.source.unix}', i.e. the word on the
command line consists of multiple parts, separated by a dot in this
example, where each part should be completed separately --- note,
however, that the case where each part of the word, i.e. `@t{comp}',
`@t{source}' and `@t{unix}' in this example, is to be completed from
separate sets of matches
is a different problem to be solved by the implementation of the
completion widget.  The example can be handled by:

@noindent
@example
compadd -M 'r:|.=* r:|=*' \ 
  - comp.sources.unix comp.sources.misc ...
@end example

@noindent
The first specification says that @var{lpat} is the empty string, while
@var{anchor} is a dot; @var{tpat} is @t{*}, so this can match anything
except for the `@t{.}' from the anchor in
the trial completion word.  So in `@t{c.s.u}', the matcher sees `@t{c}',
followed by the empty string, followed by the anchor `@t{.}', and
likewise for the second dot, and replaces the empty strings before the
anchors, giving `@t{c}[@t{omp}]@t{.s}[@t{ources}]@t{.u}[@t{nix}]', where
the last part of the completion is just as normal.

@noindent
With the pattern shown above, the string `@t{c.u}' could not be
completed to `@t{comp.sources.unix}' because the single star means
that no dot (matched by the anchor) can be skipped. By using two stars 
as in `@t{r:|.=**}', however, `@t{c.u}' could be completed to
`@t{comp.sources.unix}'. This also shows that in some cases,
especially if the anchor is a real pattern, like a character class,
the form with two stars may result in more matches than one would like.

@noindent
The second specification is needed to make this work when the cursor is
in the middle of the string on the command line and the option
@t{COMPLETE_IN_WORD} is set. In this case the completion code would
normally try to match trial completions that end with the string as
typed so far, i.e. it will only insert new characters at the cursor
position rather then at the end.  However in our example we would like
the code to recognise matches which contain extra characters after the
string on the line (the `@t{nix}' in the example).  Hence we say that the
empty string at the end of the string on the line matches any characters
at the end of the trial completion.

@noindent
More generally, the specification

@noindent
@example
compadd -M 'r:|[.,_-]=* r:|=*' ... 
@end example

@noindent
allows one to complete words with abbreviations before any of the
characters in the square brackets.  For example, to
complete @t{veryverylongfile.c} rather than @t{veryverylongheader.h}
with the above in effect, you can just type @t{very.c} before attempting
completion.

@noindent
The specifications with both a left and a right anchor are useful to
complete partial words whose parts are not separated by some
special character. For example, in some places strings have to be
completed that are formed `@t{LikeThis}' (i.e. the separate parts are
determined by a leading uppercase letter) or maybe one has to
complete strings with trailing numbers. Here one could use the simple
form with only one anchor as in:

@noindent
@example
compadd -M 'r:|[A-Z0-9]=* r:|=*' LikeTHIS FooHoo 5foo123 5bar234
@end example

@noindent
But with this, the string `@t{H}' would neither complete to `@t{FooHoo}'
nor to `@t{LikeTHIS}' because in each case there is an uppercase
letter before the `@t{H}' and that is matched by the anchor. Likewise, 
a `@t{2}' would not be completed. In both cases this could be changed
by using `@t{r:|[A-Z0-9]=**}', but then `@t{H}' completes to both
`@t{LikeTHIS}' and `@t{FooHoo}' and a `@t{2}' matches the other
strings because characters can be inserted before every uppercase
letter and digit. To avoid this one would use:

@noindent
@example
compadd -M 'r:[^A-Z0-9]||[A-Z0-9]=** r:|=*' \ 
    LikeTHIS FooHoo foo123 bar234
@end example

@noindent
By using these two anchors, a `@t{H}' matches only uppercase `@t{H}'s that 
are immediately preceded by something matching the left anchor
`@t{[^A-Z0-9]}'. The effect is, of course, that `@t{H}' matches only
the string `@t{FooHoo}', a `@t{2}' matches only `@t{bar234}' and so on.

@noindent
When using the completion system (see
@ref{Completion System}), users can define match specifications that are to be used for
specific contexts by using the @t{matcher} and @t{matcher-list}
styles. The values for the latter will be used everywhere.

@noindent
@node Completion Widget Example, , Matching Control, Completion Widgets

@section Completion Widget Example
@noindent
@cindex completion widgets, example

@noindent
The first step is to define the widget:

@noindent
@example
zle -C complete complete-word complete-files
@end example

@noindent
Then the widget can be bound to a key using the @t{bindkey} builtin
command:

@noindent
@example
bindkey '^X\t' complete
@end example

@noindent
After that the shell function @t{complete-files} will be invoked
after typing control-X and TAB. The function should then generate the
matches, e.g.:

@noindent
@example
complete-files () @{ compadd - * @}
@end example

@noindent
This function will complete files in the current directory matching the 
current word.
@c (avoiding a yodl bug)
@c Yodl file: Zsh/compsys.yo
@node Completion System, Completion Using compctl, Completion Widgets, Top

@chapter Completion System
@noindent
@cindex completion system
@cindex completion, programmable
@cindex completion, controlling

@section Description
@noindent

@noindent
This describes the shell code for the new completion system.  It consists
of various shell functions; those beginning `@t{comp}' are to be called
directly by the user, while those beginning `@t{_}' are called by the
completion code.  The shell functions of the second set which implement
completion behaviour and which may be bound to keystrokes, are referred to
as `widgets'.

@noindent
@menu
* Initialization::
* Completion System Configuration::
* Control Functions::
* Bindable Commands::
* Completion Functions::
* Completion Directories::
@end menu

@noindent
@node Initialization, Completion System Configuration, , Completion System

@section Initialization
@noindent
@findex compinstall
@cindex completion system, installing

@noindent
If the system was installed completely, it should be enough to
call the shell function @t{compinit} from your initialization file; see the
next section.  However, the function @t{compinstall} can be run by a user
to configure various aspects of the completion system.

@noindent
Usually, @t{compinstall} will insert code into @t{.zshrc}, although if
that is not writable it will save it in another file and tell you that
file's location.  Note that it is up to you to make sure that the lines
added to @t{.zshrc} are actually run; you may, for example, need to move
them to an earlier place in the file if @t{.zshrc} usually returns early.
So long as you keep them all together (including the comment lines at the
start and finish), you can rerun @t{compinstall} and it will correctly
locate and modify these lines.  Note, however, that any code you add to
this section by hand is likely to be lost if you rerun @t{compinstall},
although lines using the command `@t{zstyle}' should be gracefully handled.

@noindent
The new code will take effect next time you start the shell, or run
@t{.zshrc} by hand; there is also an option to make them take effect
immediately.  However, if @t{compinstall} has removed definitions, you will
need to restart the shell to see the changes.

@noindent
To run @t{compinstall} you will need to make sure it is in a directory
mentioned in your @t{fpath} parameter, which should already be the case if
zsh was properly configured as long as your startup files do not remove the
appropriate directories from @t{fpath}.  Then it must be autoloaded
(`@t{autoload -U compinstall}' is recommended).  You can abort the
installation any time you are being prompted for information, and your
@t{.zshrc} will not be altered at all; changes only take place right at the
end, where you are specifically asked for confirmation.

@noindent

@subsection Use of compinit
@noindent
@findex compinit
@cindex completion system, initializing

@noindent
This section describes the use of @t{compinit} to initialize completion for
the current session when run directly by the user; if you have run
@t{compinstall} it will be called automatically from your @t{.zshrc}.

@noindent
To initialize the system, the function @t{compinit} should be in a
directory mentioned in the @t{fpath} parameter, and should be autoloaded
(`@t{autoload -U compinit}' is recommended), and then run simply as
`@t{compinit}'.  This will define a
few utility functions, arrange for all the necessary shell functions to be
autoloaded, and will then re-define all widgets that do completion to use the
new system.  If you use the @t{menu-select} widget, which is part of the
@t{zsh/complist} module, you should make sure that that module is loaded
before the call to @t{compinit} so that that widget is also
re-defined.  If completion styles (see below) are set up to perform
expansion as well as completion by default, and the TAB key is bound to
@t{expand-or-complete}, @t{compinit} will rebind it to @t{complete-word};
this is necessary to use the correct form of expansion.

@noindent
Should you need to use the original completion commands, you can still
bind keys to the old widgets by putting a `@t{.}' in front of the
widget name, e.g. `@t{.expand-or-complete}'.

@noindent
To speed up the running of @t{compinit}, it can be made to produce a dumped
configuration which will be read in on future invocations; this is the
default, although it can be turned off by calling @t{compinit} with the
option @t{-D}.  The dumped file is @t{.zcompdump} in the same
directory as the startup files (i.e. @t{$ZDOTDIR} or @t{$HOME});
alternatively, an explicit file name can be given by `@t{compinit -d}
@var{dumpfile}'.  On the next call to @t{compinit}, it will read the dumped
file instead of performing a full initialization.

@noindent
If the number of completion files changes, @t{compinit} will recognise this
and produce a new dump file.  However, if the name of a function or the
arguments in the first line of a @t{#compdef} function (as described below)
change, it is easiest to delete the dump file by hand so that
@t{compinit} will re-create it the next time it is run.  The check
performed to see if there are new functions can be omitted by giving
the option @t{-C}.  In this case the dump file will only be created if
there isn't one already.

@noindent
The dumping is actually done by another function, @t{compdump}, but you
will only need to run this yourself if you change the configuration
(e.g. using @t{compdef}) and then want to dump the new one.  The name of
the old dumped file will be remembered for this purpose.

@noindent
If the parameter @t{_compdir} is set, @t{compinit} uses it as a directory
where completion functions can be found; this is only necessary if they are
not already in the function search path.

@noindent
For security reasons @t{compinit} also checks if the completion system
would use files not owned by root or by the current user, or files in
directories that are world- or group-writable or that are not owned by 
root or by the current user.  If such files or directories are found,
@t{compinit} will ask if the completion system should really be used.  To
avoid these tests and make all files found be used without asking, use the
option @t{-u}, and to make @t{compinit} silently ignore all insecure files
and directories use the option @t{-i}.  This security check is skipped
entirely when the @t{-C} option is given.

@noindent
@findex compaudit
The security check can be retried at any time by running the function
@t{compaudit}.  This is the same check used by @t{compinit}, but when it
is executed directly any changes to @t{fpath} are made local to the
function so they do not persist.  The directories to be checked may be
passed as arguments; if none are given, @t{compaudit} uses @t{fpath} and
@t{_compdir} to find completion system directories, adding missing ones
to @t{fpath} as necessary.  To force a check of exactly the directories
currently named in @t{fpath}, set @t{_compdir} to an empty string before
calling @t{compaudit} or @t{compinit}.

@noindent

@subsection Autoloaded files
@noindent
@cindex completion system, autoloaded functions

@noindent
The convention for autoloaded functions used in completion is that they
start with an underscore; as already mentioned, the @t{fpath/FPATH}
parameter must contain the directory in which they are stored.  If @t{zsh}
was properly installed on your system, then @t{fpath/FPATH} automatically
contains the required directories for the standard functions.

@noindent
For incomplete installations, if @t{compinit} does not find enough files
beginning with an underscore (fewer than twenty) in the search path, it
will try to find more by adding the directory @t{_compdir} to the search
path.  If that directory has a subdirectory named @t{Base}, all
subdirectories will be added to the path.  Furthermore, if the subdirectory
@t{Base} has a subdirectory named @t{Core}, @t{compinit} will add all
subdirectories of the subdirectories is to the path: this allows
the functions to be in the same format as in the @t{zsh} source
distribution.

@noindent
@cindex compdef, use of by compinit
When @t{compinit} is run, it searches all such files accessible via
@t{fpath/FPATH} and reads the first line of each of them.  This line should
contain one of the tags described below.  Files whose first line does not
start with one of these tags are not considered to be part of the
completion system and will not be treated specially.

@noindent
The tags are:

@noindent
@table @asis
@item @t{#compdef} @var{names...}
The file will be made autoloadable and the function defined 
in it will be called when completing @var{names}, each of which is
either the name of a command whose arguments are to be completed or one of
a number of special contexts in the form @t{-}@var{context}@t{-} described
below for the @t{_complete} function.

@noindent
Each @var{name} may also be of the form `@var{cmd}@t{=}@var{service}'.  This
is used by functions that offer multiple services, i.e. different
completion behaviour for multiple commands.  Such a string
makes the completion system call the function when completing
arguments for the command `@t{cmd}', setting the parameter @t{$service} 
to the string `@t{service}'.  The function can then use that parameter 
to decide what to complete.

@item @t{#compdef -p} @var{pattern}
The file will be made autoloadable and the function defined in it will be
called when completing for a command whose name matches the given
@var{pattern} (a standard globbing pattern).  Note that only one
@var{pattern} may be given.

@item @t{#compdef -P} @var{pattern}
Like the previous one, but the function will be called only if no
completion function for the command on the line could be found.

@item @t{#compdef -k} @var{style key-sequences...}
This can be used to bind special completion functions to the
@var{key-sequences} specified.  It creates a widget behaving like the
builtin widget @var{style}, which must be one of those that perform
completion, namely @t{complete-word}, @t{delete-char-or-list},
@t{expand-or-complete}, @t{expand-or-complete-prefix}, @t{list-choices},
@t{menu-complete}, @t{menu-expand-or-complete}, or
@t{reverse-menu-complete}.  If the @t{zsh/complist} module is loaded (see
@ref{The zsh/complist Module}), the same happens to the @t{menu-select} widget.

@noindent
The widget is then bound to all the @var{key-sequences} given, if any: when
one of the @var{key-sequences} is typed, the function in the file will
be invoked to generate the matches.  Note that a key will not be re-bound
if if it already was (that is, was bound to something other than
@t{undefined-key}).  The widget created has the same name as the file and
can be bound to any other keys using @t{bindkey} as usual.

@item @t{#compdef -K} @var{widget-name} @var{style} @var{key-sequences} ...
This is similar to @t{-k}, with the same @var{style} and @var{key-sequences}
arguments, preceded by a string giving the name of a widget.
In this case only one @var{key-sequences} argument may be given, but the
entire set of three arguments may be repeated with a different set of
arguments.  In particular, the @var{widget-name} must be distinct in each
set.  It should begin with `@t{_}', else one will be added, and should not
clash with the name of any existing widget: names based on the name of the
function are most useful.  For example,

@noindent
@example
#compdef -K _foo_complete complete-word "^X^C" \ 
  _foo_list list-choices "^X^D"
@end example

@noindent
(all on one line) defines a widget @t{_foo_complete} for completion, bound
to `@t{^X^C}', and a widget @t{_foo_list} for listing, bound to `@t{^X^D}'.

@item @t{#autoload} [ @var{options} ]
This is used for files defining utility functions that are not to be
called directly as completion functions but should be loaded automatically
when invoked.  Typically they are to be called from within one of the
completion functions.

@noindent
The @var{options} will be given to the @t{autoload} builtin command
when making the function autoloaded.  Most often, this will be @t{+X} to
force the function to be loaded immediately.  Note that the @t{-U} flag is
always implicitly added.

@end table

@noindent
The @t{#} is part of the tag name and no white space is allowed after it.
The @t{#compdef} tags use the @t{compdef} function described below; the
main difference is that the name of the function is supplied implicitly.

@noindent
Note also that the functions for the completion system assume that the
@t{KSH_AUTOLOAD} option is not set and cannot be loaded when it is
set.  To avoid having to unset @t{KSH_AUTOLOAD}, you can instead use one or
more @t{zwc} file(s) which have been created with the command @t{zcompile
-z} to load the functions for the completion system; see
@ref{Shell Builtin Commands}.  This forces the functions to be autoloaded the way zsh normally
loads functions.

@noindent

@subsection Functions
@noindent

@noindent
The @t{compinit} file defines the following function, which may
also be called directly by the user.

@noindent
@findex compdef
@cindex completion system, adding definitions
@table @asis
@item @t{compdef} [ @t{-an} ] @var{function names...}
@itemx @t{compdef -d} @var{names...}
@itemx @t{compdef -p} [ @t{-a} ] @var{function pattern}
@itemx @t{compdef -P} [ @t{-a} ] @var{function pattern}
@itemx @t{compdef -k} [ @t{-an} ] @var{function style key-sequences...}
@itemx @t{compdef -K} [ @t{-an} ] @var{function name style key-sequences ...}
The first form tells the completion system to call the given
@var{function} when completing for the contexts or commands
whose @var{names} are given:  this is like the @t{#compdef} tag unless
the first word contains an equal sign.  In this case all words have to 
be of the form `@var{cmd}@t{=}@var{service}' where @var{service} is the
name of a command or of a service defined by an autoloaded function
with the @t{#compdef} tag and an argument of the form
`@var{cmd}@t{=}@var{service}'.  This kind of use makes the arguments of
the @var{cmd}s be completed as those for the @var{services}.

@noindent
If the
@t{-n} option is given, any existing completion behaviour for particular
contexts or commands will not be altered.  These definitions can be deleted
by giving the @t{-d} option as in the second form.

@noindent
The form with @t{-p} is similar to the first, but @var{function} will be
called for all commands whose name matches the @var{pattern}; this is like
the @t{#compdef -p} function tag.

@noindent
The form with @t{-P} is like the third, but the @var{function} will be
called only if no function for the command itself was found or if one
was found and it set the @t{_compskip} parameter to a value @emph{not}
containing the substring @t{patterns}.

@noindent
The form with @t{-k} defines a widget with the same name as the @var{function}
which will be called for each of the @var{key-sequences}; this is like the
@t{#compdef -k} tag.  The function should generate the completions needed
and will otherwise behave like the builtin widget whose name is given as
the @var{style} argument. The widgets usable for this are:
@t{complete-word}, @t{delete-char-or-list}, @t{expand-or-complete},
@t{expand-or-complete-prefix}, @t{list-choices}, @t{menu-complete},
@t{menu-expand-or-complete}, and @t{reverse-menu-complete}, as well as
@t{menu-select} if the @t{zsh/complist} module is loaded.  The option @t{-n}
prevents the key being bound if it is already to bound to something other
than @t{undefined-key}.

@noindent
The form with @t{-K} is similar and defines multiple widgets based on the
same @var{function}, each of which requires the set of three arguments
@var{name}, @var{style} and @var{key-sequences}, where the latter two are as
for @t{-k} and the first must be a unique widget name beginning with an
underscore.

@noindent
In each of the forms supporting it the @t{-a} option makes the
@var{function} autoloadable (exactly equivalent to
@t{autoload -U }@var{function}).

@end table

@noindent
The @t{compdef} function is the place to turn to when one wants to
define what the completion system should complete for a certain
command.  The function named can of course be one of the functions
supplied or one written by the user.  For example, if one has a
command @t{foo} that gets process identifiers as arguments, one could
do:

@noindent
@example
compdef _pids foo
@end example

@noindent
using the @t{_pids} function from the distribution to generate the
process identifiers.  Not also the @t{_gnu_generic} function described
below, which can be used to complete options for commands that
understand the `@t{-}@t{-help}' option.

@noindent
@node Completion System Configuration, Control Functions, Initialization, Completion System

@section Completion System Configuration
@noindent
@cindex completion system, configuration

@noindent
This section gives a short overview of how the completion system works,
and then more detail on how users can configure how and when matches are
generated.

@noindent

@subsection Overview
@noindent

@noindent
When completion is attempted somewhere on a command line the
completion system first tries to find out the context where completion 
was tried.  The context depends on such things as the name of the
command when completing an argument, and possibly also
the name of an option when completing an argument to that option.

@noindent
The `context' of a completion is a string consisting of multiple fields. This
is used to look up styles that can be used to configure the
completion system.  Since it is not possible to build the whole context 
string in advance, completion functions may modify some of the fields and 
hence the context used for lookup may vary during the same call
to the completion system.

@noindent
The context string always consists of the following fields, separated
by colons and with a leading colon before the first:

@noindent
@itemize @bullet

@noindent
@item 
The literal string @t{completion}, saying that this style is used by
the completion system.

@item 
The @var{function}; in many cases this field will be blank, but when
the completion system is called from other functions, like
@t{predict-on} or one of the functions in the @t{Command} directory of 
the distribution, this field contains the name of that function, often
in an abbreviated form.

@item 
The @var{completer} currently active, which is the name of the function
without the leading underscore.  A `completer' is in
overall control of how completion is to be performed; `@t{complete}'
is the basic one for ordinary completion, but completers may perform
various related tasks such as correction, or modify the behaviour of a
later completer (see
@ref{Control Functions} 
for more information).  

@item 
The @var{context} or @var{command}.  This is either one of the special
context names such as @t{-condition-} as explained for the
@t{_complete} completer below, or the name of the command we are
completing arguments for.  Completion functions for commands that have
sub-commands usually modify this field to contain the name of the
command followed by a minus sign and the sub-command (e.g. the
completion function for the @t{cvs} command sets this field to strings
such as @t{cvs-add} when completing for the @t{add} sub-command).

@item 
The @var{argument}, describing which argument we are
completing.  Normally this is either a string of the form
@t{argument-}@var{n}, where @var{n} is the number of the argument or it
is a string of the form @t{option-}@var{opt}@t{-}@var{n} when completing the
@var{n}'th argument of the option @var{opt}.

@item 
The @var{tag}.  Tags are used to discriminate between the types
of matches a completion function can generate in a certain context.

@end itemize

@noindent
As an example, the context name

@noindent
@example
@t{:completion::complete:dvips:option-o-1:files}
@end example

@noindent
says that normal completion was attempted on an argument of the @t{dvips}
command (more precisely: completion was attempted on the first argument
after the @t{-o} option) and the completion function will generate
filenames for this context.

@noindent
In many of the possible contexts the completion system can generate
matches, often multiple types of matches.  These types are represented as
simple names called `tags'.  The completion system will decide internally
what sort of tags are allowed; a list of the standard possibilities is given
below.  To determine in which order the tags are to be used by the
completion function, the `@t{tag-order}' style for the appropriate
context may be set, as described in the list of standard styles below.
Only those types of matches whose tags were selected by this style
will be produced, and in the order given, although the default is to try
all relevant tags in an order determined by the particular completion in
use.

@noindent
The @t{_complete_help} bindable command described in 
@ref{Bindable Commands}
can be invoked to find out the context and tag names and styles used at a
particular point in completion.  It shows the list of contexts and tags 
that would be used in if completion were tried at the current cursor
position.  Hence one can easily find out all the information needed to
change the behaviour of the @t{tag-order} style for a particular context.

@noindent
Completion behaviour can be modified by various other
styles defined with the @t{zstyle} builtin command (@ref{The zsh/zutil Module}).
When looking up styles the completion system uses full context names,
including the tag.

@noindent
Styles determine such things as how the matches are generated; some of them
correspond to shell options (for example, the use of menu completion), but
styles provide more specific control.  They can have any number of strings as
their value.  Looking up the value of a style therefore consists of two
things:  the context, which may be matched as a pattern, and the name of
the style itself, which must be given exactly.

@noindent
For example, many completion functions can generate matches in a
simple and a verbose form and use the @t{verbose} style to decide
which form should be used.  To make all such functions use the verbose form,
put

@noindent
@example
zstyle ':completion:*' verbose yes
@end example

@noindent
in one of the startup files like @t{.zshrc}; this sort of style can also be
configured with the @t{compinstall} function.  This definition simply
means that the @t{verbose} style has @t{yes} as its value in every
context inside the completion system.  If the context pattern were `@t{*}',
the verbose style would have this value anywhere the style mechanism is
used, not just in completion.

@noindent
As a more specific example, the completion function for the @t{kill}
builtin command uses the @t{verbose} style to decide if jobs and processes
are listed only as job numbers and process identifiers or if they are
listed with the full job texts and the command lines of the processes (the
latter is achieved by calling the @t{ps} command).  To make this builtin
list the matches only as numbers one could call:

@noindent
@example
zstyle ':completion:*:*:kill:*' verbose no
@end example

@noindent
Furthermore, if one wanted to see the command lines for processes but not the
job texts one could use the fact that the context name contains the tag name
when styles are looked up.  As the function for the @t{kill}
builtin command uses the tags @t{jobs} and @t{processes}, we can use:

@noindent
@example
zstyle ':completion:*:*:kill:*:jobs' verbose no
@end example

@noindent
To have more control over when certain values for styles are used one
can use the special parameters available in completion widgets (see
@ref{Completion Widgets})) and the @t{-e} option to @t{zstyle} that makes the value be
evaluated when looked up.  For example, to make the @t{completer}
style have a different value when completing for the @t{cvs} command,
one could use the @t{words} special array:

@noindent
@example
zstyle -e ':completion:*' completer '
    if [[ $words[1] = cvs ]]; then
      reply=(_complete)
    else
      reply=(_complete _approximate)
    fi'
@end example

@noindent
One should be careful not to use too complicated code with this
option, at least for the styles that are looked up quite often.  These 
are basically those that define some global completion behaviour but
allow that to be different for all matches or groups of matches (such
as the @t{menu} and @t{list-rows-first} styles).  Alternatively one
can always use a less general pattern for the context than in the
example above and use a second call to @t{zstyle} with a generic
pattern and without using the @t{-e} option to define the default
behaviour.

@noindent
Note that the order in which styles are @emph{defined} does not matter; the
style mechanism uses the most specific possible match for a particular
style to determine the set of values.  More precisely, strings are
preferred over patterns (for example, `@t{:completion::complete:foo}' is
more specific than `@t{:completion::complete:*'}), and longer patterns are
preferred over shorter patterns.

@noindent
As with tags, completion functions can use any style they choose, so
there can't be a complete list.  However, the following two sections
list those tags and styles that are used in many places of the
completion system.

@noindent

@subsection Standard Tags
@noindent
@cindex completion system, tags

@noindent
Here are the tags currently used by the completion system.  Some of them
are only used when looking up styles and do not refer to a particular type
of match.

@noindent
@table @asis
@kindex accounts, completion tag
@item @t{accounts}
used to look up the @t{users-hosts} style

@kindex all-expansions, completion tag
@item @t{all-expansions}
used by the @t{_expand} completer when adding the single string containing
all possible expansions

@kindex all-files, completion tag
@item @t{all-files}
for the names of all files (as distinct from a particular subset, see the
@t{globbed-files} tag).

@kindex arguments, completion tag
@item @t{arguments}
when an argument of a command may be completed

@kindex arrays, completion tag
@item @t{arrays}
for names of array parameters

@kindex association-keys, completion tag
@item @t{association-keys}
for keys of associative arrays; used when completing inside a
subscript of a parameter of this type

@kindex bookmarks, completion tag
@item @t{bookmarks}
when completing bookmarks (e.g. for URLs and the @t{zftp} function suite)

@kindex builtins, completion tag
@item @t{builtins}
for names of builtin commands

@kindex characters, completion tag
@item @t{characters}
used for commands like @t{stty} when completing characters; also used
when completing character classes after an opening bracket

@kindex colormapids, completion tag
@item @t{colormapids}
for X colormap ids

@kindex colors, completion tag
@item @t{colors}
for color names

@kindex commands, completion tag
@item @t{commands}
for names of external commands and names of sub-commands (used by some 
commands like @t{cvs})

@kindex contexts, completion tag
@item @t{contexts}
for contexts used by the zstyle builtin command

@kindex corrections, completion tag
@item @t{corrections}
used by the @t{_approximate} and @t{_correct} completers for the possible
corrections

@kindex cursors, completion tag
@item @t{cursors}
for cursor names used by X programs

@kindex default, completion tag
@item @t{default}
used to look up default values for various styles that may also be set 
for tags that are used when generating matches; note that this tag is
used when only the @var{function} field of the context name is set up

@kindex descriptions, completion tag
@item @t{descriptions}
used when looking up the value of the @t{format} style for
descriptions

@kindex devices, completion tag
@item @t{devices}
for names of device special files

@kindex directories, completion tag
@item @t{directories}
for names of directories

@kindex directory-stack, completion tag
@item @t{directory-stack}
for entries in the directory stack

@kindex displays, completion tag
@item @t{displays}
for X display names

@kindex domains, completion tag
@item @t{domains}
for network domains

@kindex expansions, completion tag
@item @t{expansions}
used by the @t{_expand} completer for individual possibilities resulting
from expansion of a word

@kindex extensions, completion tag
@item @t{extensions}
for X server extensions

@kindex file-descriptors, completion tag
@item @t{file-descriptors}
for the numbers of open file descriptors

@kindex files, completion tag
@item @t{files}
the generic file-matching tag used by completion functions that can
complete the names of some kind of file

@kindex fonts, completion tag
@item @t{fonts}
used for X font names

@kindex functions, completion tag
@item @t{functions}
names of functions, normally shell functions although certain commands may
understand other kinds of function

@kindex globbed-files, completion tag
@item @t{globbed-files}
for names of files matching the glob pattern used by completion
functions that expect a certain type of file

@kindex groups, completion tag
@item @t{groups}
used when completing names of user groups

@kindex history-words, completion tag
@item @t{history-words}
for words from the history

@kindex hosts, completion tag
@item @t{hosts}
for hostnames

@kindex indexes, completion tag
@item @t{indexes}
used for array indexes

@kindex jobs, completion tag
@item @t{jobs}
used for jobs

@kindex keymaps, completion tag
@item @t{keymaps}
for names of zsh keymaps

@kindex keysyms, completion tag
@item @t{keysyms}
for names of X keysyms

@kindex libraries, completion tag
@item @t{libraries}
for names of system libraries

@kindex limits, completion tag
@item @t{limits}
for system limits

@kindex local-directories, completion tag
@item @t{local-directories}
for names of directories which are subdirectories of the current working
directory when completing for the @t{cd} and related builtin commands

@kindex manuals, completion tag
@item @t{manuals}
for names of manual pages

@kindex maps, completion tag
@item @t{maps}
for map names (e.g. NIS maps)

@kindex messages, completion tag
@item @t{messages}
used to look up the @t{format} style for messages

@kindex modifiers, completion tag
@item @t{modifiers}
for names of X modifiers

@kindex modules, completion tag
@item @t{modules}
for modules (e.g. @t{zsh} modules)

@kindex my-accounts, completion tag
@item @t{my-accounts}
used to look up the @t{users-hosts} style

@kindex named-directories, completion tag
@item @t{named-directories}
for named directories (you wouldn't have guessed that, would you?)

@kindex names, completion tag
@item @t{names}
for all kinds of names

@kindex nicknames, completion tag
@item @t{nicknames}
for nicknames of NIS maps

@kindex options, completion tag
@item @t{options}
for command options

@kindex original, completion tag
@item @t{original}
used by the @t{_approximate}, @t{_correct} and @t{_expand} completers when
adding the original string

@kindex other-accounts, completion tag
@item @t{other-accounts}
used to look up the @t{users-hosts} style

@kindex packages, completion tag
@item @t{packages}
for packages (e.g. @t{rpm} or installed @t{Debian} packages)

@kindex parameters, completion tag
@item @t{parameters}
for names of parameters

@kindex path-directories, completion tag
@item @t{path-directories}
for names of directories found by searching the @t{cdpath} array when
completing for the @t{cd} and related builtin commands

@kindex paths, completion tag
@item @t{paths}
used to look up the values of the @t{expand}, @t{ambiguous} and
@t{special-dirs} styles

@kindex pods, completion tag
@item @t{pods}
for perl pods (documentation files)

@kindex ports, completion tag
@item @t{ports}
for communication ports

@kindex prefixes, completion tag
@item @t{prefixes}
for prefixes (like those of a URL)

@kindex printers, completion tag
@item @t{printers}
for printer names

@kindex processes, completion tag
@item @t{processes}
for process identifiers

@kindex processes-names, completion tag
@item @t{processes-names}
used to look up the @t{command} style when generating the names of
processes for @t{killall}

@kindex sequences, completion tag
@item @t{sequences}
for sequences (e.g. @t{mh} sequences)

@kindex sessions, completion tag
@item @t{sessions}
for sessions in the @t{zftp} function suite

@kindex signals, completion tag
@item @t{signals}
for signal names

@kindex strings, completion tag
@item @t{strings}
for strings (e.g. the replacement strings for the @t{cd} builtin
command)

@kindex styles, completion tag
@item @t{styles}
for styles used by the zstyle builtin command

@kindex tags, completion tag
@item @t{tags}
for tags (e.g. @t{rpm} tags)

@kindex targets, completion tag
@item @t{targets}
for makefile targets

@kindex types, completion tag
@item @t{types}
for types of whatever (e.g. address types for the @t{xhost} command)

@kindex urls, completion tag
@item @t{urls}
used to look up the @t{urls} and @t{local} styles when completing URLs

@kindex users, completion tag
@item @t{users}
for usernames

@kindex values, completion tag
@item @t{values}
when completing a value out of a set of values (or a list of such
values)

@kindex version, completion tag
@item @t{version}
used by @t{_call_program} to look up the command to run to determine the installed
version of various other commands (such as @t{diff} and @t{make}).

@kindex warnings, completion tag
@item @t{warnings}
used to look up the @t{format} style for warnings

@kindex widgets, completion tag
@item @t{widgets}
for zsh widget names

@kindex windows, completion tag
@item @t{windows}
for IDs of X windows

@kindex zsh-options, completion tag
@item @t{zsh-options}
for shell options

@end table

@noindent

@subsection Standard Styles
@noindent
@cindex completion system, styles

@noindent
Here are the names of the styles used by the completion system.  Note
that the values of several of these styles represent boolean
values; here, any of the strings `@t{true}', `@t{on}',
`@t{yes}', and `@t{1}' can be used for the truth value `true' and
the strings `@t{false}', `@t{off}', `@t{no}', and `@t{0}' are
interpreted as `false'.  The behavior for any other value is undefined 
unless the description for the particular style mentions other
possible values; in particular, the default value may be either on or off
if the style is not set.

@noindent
Some of these styles are tested for every tag used to add possible
matches and for the @t{default} tag (most notably @t{menu},
@t{list-colors} and the styles controlling the completion listing like 
@t{list-packed} and @t{last-prompt}). When tested for the @t{default}
tag, only the @var{function} field of the context will be set up, so
the default value will normally be set like:

@noindent
@example
zstyle ':completion:*:default' menu ...
@end example

@noindent
@table @asis
@kindex accept-exact, completion style
@item @t{accept-exact}
This is tested for the default tag and the tags used when generating
matches.  If it is set to `true' for at least one match which is the
same as the string on the line, this match will immediately be
accepted.

@noindent
When completing pathnames (where it is looked up for the @t{paths}
tag), this style also accepts any number of patterns as the value. If
this is used, pathnames matching one of these patterns will be
accepted immediately even if the command line contains some more
partially typed pathname components and these match no file under the
directory accepted.

@noindent
Note that this is also used by the @t{_expand} completer to decide if
words beginning with a tilde or parameter expansion should be
expanded. This means that if, for example, there are parameters
@t{foo} and @t{foobar}, the string `@t{$foo}' will only be expanded if 
@t{accept-exact} is set to `true'.

@kindex add-space, completion style
@item @t{add-space}
This style is used by the @t{_expand} completer.  If it is `true' (the
default), a space will be inserted after all words resulting from the 
expansion (except for directory names which get a slash).  The value
may also be the string `@t{file}' to make the completer add a space
only to names of existing files.  Finally, the `true' values and
`@t{file}' may be combined with `@t{subst}' to keep the completer from 
adding a space when the resulting words were generated by expanding a
substitution of the form `@t{$(...)}' or `@t{$@{...@}}'.

@noindent
It is also used by the @t{_prefix} completer as a simple boolean value
to decide if a space should be inserted before the suffix.

@kindex ambiguous, completion style
@item @t{ambiguous}
This applies when completing non-final components of filename paths.
If it is set, the cursor is left after the first ambiguous component, even
if menu completion is in use.  It is tested with the @t{paths} tag.

@kindex assign-list, completion style
@item @t{assign-list}
When completing after an equals sign, the completion system normally
completes only one filename.  In some cases, particularly for certain
parameters such as @t{PATH}, a list of filenames separated by colons is
required.  This style can be set to a list of patterns matching the names
of such parameters.

@noindent
The default is to complete lists when the word on the line already
contains a colon.

@kindex auto-description, completion style
@item @t{auto-description}
If set, this style's value will be used as the description for options which
are not described by the completion functions, but that have exactly
one argument.  The sequence `@t{%d}' in the value will be replaced by
the description for this argument.  Depending on personal preferences,
it may be useful to set this style to something like `@t{specify: %d}'. 
Note that this may not work for some commands.

@kindex avoid-completer, completion style
@item @t{avoid-completer}
This is used by the @t{_all_matches} completer to decide if the string 
consisting of all matches should be added to the list currently being
generated.  Its value is a list of names of completers.  If any of
these is the name of the completer that generated the matches in this
completion, the string will not be added.

@noindent
The default value for this style is `@t{_expand _old_list _correct
_approximate}', i.e. it contains the completers for which a string
with all matches will almost never be wanted.

@kindex cache-path, completion style
@item @t{cache-path}
This style defines the path where any cache files containing dumped
completion data are stored.  Defaults to `@t{$ZDOTDIR/.zcompcache}', or
`@t{$HOME/.zcompcache}' if @t{$ZDOTDIR} is not defined.  The completion
layer will not be used unless the @t{use-cache} style is set.

@kindex call-command, completion style
@item @t{call-command}
Currently this is only used by the function completing @t{make}
targets.  If it is set to `true' and the installed version of the
@t{make} command allows it, @t{make} is called in a way to generate
all possible targets.  The default value of this style is `false'
because calling @t{make} can potentially take a very long time and in
some cases may even cause actions from the makefile be executed
despite the options given to @t{make}.

@kindex command, completion style
@item @t{command}
In many places, completion functions need to call external commands to
generate the list of completions.  This style can be used to override the
command which is called in some such cases.  The elements of the value are
joined with spaces to form a command line to execute.  The value can also
start with a hyphen, in which case the usual command will be added to the
end; this is most useful for putting `@t{builtin}' or `@t{command}' in
front to make sure the appropriate version of a command is called, for
example to avoid calling a shell function with the same name as an external
command.

@noindent
As an example, the function generating process IDs as matches uses this
style with the @t{processes} tag to generate the IDs to complete and
the list of processes to display (if the @t{verbose} style is `true').
The list produced by the command should look like the output of the
@t{ps} command.  The first line is not displayed, but is searched for
the string `@t{PID}' (or `@t{pid}') to find the position of the
process IDs in the following lines.  If the line does not contain
`@t{PID}', the first numbers in each of the other lines are taken as the 
process IDs to complete.

@noindent
Note that the completion function generally has to call the command
every time it is called.  Because of that care should be taken to
specify only commands that take a short time to run (and that will
eventually stop at all).

@kindex commands, completion style
@item @t{commands}
This is used by the function completing sub-commands for the system
initialisation scripts (residing in @t{/etc/init.d} or somewhere not
too far away from that).  It's values give the default commands to
complete for those commands for which the completion function isn't
able to find them out automatically.  The default for this style are
the two strings `@t{start}' and `@t{stop}'.

@kindex complete, completion style
@item @t{complete}
This is used by the @t{_expand_alias} function when invoked as a
bindable command.  If it set to `true' and the word on the command
line is not the name of an alias, matching alias names will be
completed.

@kindex completer, completion style
@item @t{completer}
The strings given as the value of this style provide the names of the
completer functions to use. The available completer functions are
described in
@ref{Control Functions}.

@noindent
Each string may be the name of a completer function or a string of the 
form `@var{function}@t{:}@var{name}'. In the first case the
@var{completer} field of the context will contain the name of the
completer without the leading underscore and with all other
underscores replaced by hyphens.  In the second case the
@var{function} is the name of the completer to call, but the context
will contain the @var{name} in the @var{completer} field of the
context.  If the @var{name} starts with a hyphen, the string for the
context will be build from the name of the completer function as in
the first case with the @var{name} appended to it.  For example: 

@noindent
@example
zstyle ':completion:*' completer _complete _complete:-foo
@end example

@noindent
Here, completion will call the @t{_complete} completer twice, once
using `@t{complete}' and once using `@t{complete-foo}' in the
@var{completer} field of the context.  Normally, using the same
completer more than once makes only sense when used with the
`@var{functions}@t{:}@var{name}' form, because otherwise the context
name will be the same in all calls to the completer; possible
exceptions to this rule are the @t{_ignored} and @t{_prefix}
completers.

@noindent
The default value for this style is @t{_complete _ignored},
i.e. normally only completion will be done, first using the
@t{ignored-patterns} style and the @t{$fignore} array and then without 
ignoring matches.

@kindex condition, completion style
@item @t{condition}
This style is used by the @t{_list} completer function to decide if
insertion of matches should be delayed unconditionally. The default is 
`true'.

@kindex disabled, completion style
@item @t{disabled}
If this is set to `true', the @t{_expand_alias} completer and bindable 
command will try to expand disabled aliases, too.  The default is
`@t{false}'.

@kindex disable-stat, completion style
@item @t{disable-stat}
This is used with an empty tag by the function completing for the
@t{cvs} command to decide if the @t{zsh/stat} module should be used to
generate names of modified files in the appropriate places (this is its
only use).  If set, completion will use the @t{ls} command.

@kindex domains, completion style
@item @t{domains}
If set, gives the names of network domains that should be
completed.  If this is not set by the user domain names will be taken from
the file @t{/etc/resolv.conf}.

@kindex expand, completion style
@item @t{expand}
This style is used when completing strings consisting of multiple
parts, such as path names.  If one of its values is
the string `@t{prefix}', the partially typed word from
the line will be expanded as far as possible even if trailing parts
cannot be completed.  If one of its values is the string `@t{suffix}',
matching names for
components after the first ambiguous one will also be added.  This
means that the resulting string is the longest unambiguous string
possible, but if menu completion is started on the list of matches
generated this way,
this will also cycle through the names of the files in pathname
components after the first ambiguous one.

@kindex fake-files, completion style
@item @t{fake-files}
This style is used when completing files and looked up 
without a tag.  Its values are of the form
`@var{dir}@t{:}@var{names...}'.  This will add the @var{names} (strings
separated by spaces) as
possible matches when completing in the directory @var{dir}, even if no 
such files really exist.

@noindent
This can be useful on systems that support special filesystems whose
top-level pathnames can not be listed or generated with glob patterns.
It can also be used for directories for which one does not have read
permission.

@kindex fake-parameters, completion style
@item @t{fake-parameters}
This is used by the completion function generating parameter names as
matches.  Its values are names of parameters which might not yet be
set, but which should be completed nonetheless.  Each name may also be 
followed by a colon and a string specifying the type of the parameter
(like `@t{scalar}', `@t{array}' or `@t{integer}').  If such a type is
given, the name will only be completed if parameters of that type are
requested in the particular context.  Names for which no type is
specified will always be completed.

@kindex file-patterns, completion style
@item @t{file-patterns}
In most places where filenames are completed, the function @t{_files}
is used which can be configured with this style.  If the style is
unset, @t{_files} offers, one after another, up to three tags:
`@t{globbed-files}',
`@t{directories}' and `@t{all-files}', depending on the types of files
expected by the caller of @t{_files}.

@noindent
If the @t{file-patterns} style is set, the default tags are not
used.  Instead, the value of the style says which tags and which
patterns are to be offered.  The strings in the value contain
specifications of the form
`@var{pattern}@t{:}@var{tag}'; each string may contain any number of
such specifications.  The @var{pattern} gives a glob 
pattern that is to be used to generate
filenames.  If it contains the sequence `@t{%p}', that is replaced by
the pattern(s) given by the calling function.
Colons in the pattern must be preceded by a backslash to
make them distinguishable from the colon before the @var{tag}.  If more
than one pattern is needed, the patterns can be given inside braces,
separated by commas.  The
@var{tag}s of all strings in the value will be offered by @t{_files}
(again, one after another) and used when looking up other styles.  For
strings containing more than one specification, the filenames for all
specifications will be generated at the same try.  If
no `@t{:}@var{tag}' is given the `@t{files}' tag will be used.  The
@var{tag} may also be
followed by an optional second colon and a description.  If that is
given, this description will be used for the `@t{%d}' in the value of
the @t{format} style (if that is set) instead of the default
description supplied by the completion function.  If the description
given here contains itself a `@t{%d}', that is replaced with the
description supplied by the completion function.

@noindent
For example, to make the @t{rm} command first complete only names of
object files and the names of all files if no object file matches
the string on the line, one would do:

@noindent
@example
zstyle ':completion:*:*:rm:*' file-patterns \ 
    '*.o:object-files' '%p:all-files'
@end example

@noindent
Another interesting example is to change the default behaviour that
makes completion first offer files matching the patterns given by the
calling function, then directories and then all files.  Many people 
prefer to get both the files matching the given patterns and the
directories in the first try and all files at the second try.  To
achieve this, one could do:

@noindent
@example
zstyle ':completion:*' file-patterns \ 
    '%p:globbed-files *(-/):directories' '*:all-files'
@end example

@noindent
This works even for contexts in which all files would be completed,
because @t{_files} will not try a pattern more than once and it stops
when the pattern `@t{*}' was tried.

@noindent
Note also that during the execution of completion functions, the
@t{EXTENDED_GLOB} option is in effect, so the characters `@t{#}',
`@t{~}' and `@t{^}' have special meanings in the patterns.

@kindex file-sort, completion style
@item @t{file-sort}
The completion function that generates filenames as possible matches
uses this style without a tag to determine in which order the 
names should be listed and completed when using menu completion.  The
value may be one of `@t{size}' to sort them by the size of the file,
`@t{links}' to sort them by the number of links to the file,
`@t{modification}' (or `@t{time}' or `@t{date}') to sort them by the last
modification time, `@t{access}' to sort them by the last access time, or
`@t{inode}' (or `@t{change}') to sort them by the last inode change
time.  If the style is set to any other value, or is unset, files will be
sorted alphabetically by name.  If the value contains the string
`@t{reverse}', sorting is done in decreasing order.

@kindex force-list, completion style
@item @t{force-list}
This forces a list of completions to be shown at any point where listing is
done, even in cases where the list would usually be suppressed.
For example, normally the list is only shown if
there are at least two different matches.  By setting this style to
`@t{always}', the list will always be shown, even if there is only a
single match which is immediately accepted.  The style may also
be set to a number.  In this case the list will be shown if there are
at least that many matches, even if they would all insert the same
string.

@noindent
This style is tested for the default tag and all tags used when
generating matches. This allows one to turn unconditional listing on
for certain types of matches.

@kindex format, completion style
@item @t{format}
If this is set for the @t{descriptions} tag, its value is used as a
string to display above matches in completion lists.  The sequence
`@t{%d}' in this string will be replaced with a short description of
what these matches are.  This string may also contain the sequences to
specify output attributes, such as `@t{%B}', `@t{%S}' and
`@t{%@{}...@t{%@}}'.

@noindent
For the same purpose, this style is also tested with the tags used when
matches are generated before it is tested for the @t{descriptions}
tag.  This provides the possibility of defining different format
strings for different types of matches.

@noindent
Note also that some completer functions define additional
`@t{%}'-sequences.  These are described for the completer functions that 
make use of them.

@noindent
For the @t{messages} tag, this style defines a string used by some
completion functions to display messages.  Here, the `@t{%d}' is
replaced with a message given by the completion function.

@noindent
Finally, when set with the @t{warnings} tag, the format string is
printed when no matches could be generated at all.  In this case the
`@t{%d}' is replaced with the descriptions for the matches that were
expected separated by spaces and the sequence `@t{%D}' is replaced with
those descriptions separated by newlines.

@noindent
The `@t{%}' for the sequences that are replaced by strings provided by 
the completion functions like the `@t{%d}' may be followed by field
width specifications as  described for the @t{zformat} builtin command
from the @t{zsh/zutil} module, see
@ref{The zsh/zutil Module}.

@kindex glob, completion style
@item @t{glob}
This is used by the @t{_expand} completer.  If
it is set to `true' (the default), globbing will be attempted on the
words resulting from substitution (see the @t{substitute} style) or
the original string from the line.

@kindex global, completion style
@item @t{global}
If this is set to `true' (the default), the @t{_expand_alias}
completer and bindable command will try to expand global aliases.

@kindex group-name, completion style
@item @t{group-name}
The completion system can put different types of matches in different
groups which are then displayed separately in the list of possible
completions.  This style can be used to give the names for these groups
for particular tags.  For example, in command position the completion
system generates names of builtin and external commands, names of
aliases, shell functions and parameters and reserved words as possible
completions.  To have the external commands and shell functions listed
separately, one can set:

@noindent
@example
zstyle ':completion:*:*:-command-:*:commands' group-name commands
zstyle ':completion:*:*:-command-:*:functions' group-name functions
@end example

@noindent
This also means that if the same name is used for different types of
matches, then those matches will be displayed together in the same
group.

@noindent
If the name given is the empty string, then the name of the tag for
the matches will be used as the name of the group. So, to have all
different types of matches displayed separately, one can just set:

@noindent
@example
zstyle ':completion:*' group-name @value{dsq}
@end example

@noindent
All matches for which no group name is defined will be put in a group
named @t{-default-}.

@kindex group-order, completion style
@item @t{group-order}
This style is to be used together with the @t{group-name} style.  Once
different types of matches are put into different groups, this style
can be used to define in which order these groups should appear when listing 
(compare @t{tag-order}, which determines which completions appear at
all).  The strings in the value are taken as group names and the named
groups will be shown in the order in which their names appear in the
value.  All groups whose names are not given in the value of this style 
will appear in the order defined by the function generating the
matches.

@noindent
For example, to have names of builtin commands, shell functions and
external commands appear in this order when completing in command
position one would set:

@noindent
@example
zstyle ':completion:*:*:-command-:*' group-order \ 
       builtins functions commands
@end example

@kindex groups, completion style
@item @t{groups}
A style holding the names of the groups that should be completed. If
this is not set by the user, the group names from the YP database or
the file `@t{/etc/group}' will be used.

@kindex hidden, completion style
@item @t{hidden}
If this is set to one of the `true' values, the matches for the tags
for which this is set will not appear in the list; only the
description for the matches as set with the @t{format} style will be
shown.  If this is set to `@t{all}', not even the description will be
displayed.

@noindent
Note that the matches will still be completed; they are just not shown 
in the list.  To avoid having matches considered as possible
completions at all, the @t{tag-order} style can be modified as described
below.

@kindex hosts, completion style
@item @t{hosts}
A style holding the names of hosts that should be completed. If this
is not set by the user the hostnames in `@t{/etc/hosts}' will be used.

@kindex hosts-ports, completion style
@item @t{hosts-ports}
This style is used by commands that need or accept hostnames and
ports.  The strings in the value should be of the form
`@var{host}@t{:}@var{port}'.  These hostnames and ports are completed
depending on the information already on the line, so that if, for
example, the hostname is already typed, only those ports specified for that
host will be completed.  Multiple ports for the same host may appear.

@kindex ignore-line, completion style
@item @t{ignore-line}
This style is tested for the tags used when generating matches.  If it
is set to `true', then none of the words that are already on the line
will be considered possible completions.  If it is set to
`@t{current}', the word the cursor is on will not be considered a
possible completion.  The same happens if the value is
`@t{current-shown}', but only if the list of completions is currently
shown on the screen.  Finally, if it is set to `@t{other}' all words
except the current one will not be considered to be a possible
completion.

@noindent
The values `@t{current}' and `@t{current-shown}' are a bit like the
opposite of @t{accept-exact}. They mean that only strings with
missing characters will be completed.

@noindent
Note that you almost certainly don't want to set this to `true' or
`@t{other}' for a general
context such as `@t{:completion:*}'.  This is because it would disallow
completion of, for example, options multiple times even if the command
in question accepts the option more than once.

@kindex ignore-parents, completion style
@item @t{ignore-parents}
The style is tested by the function completing pathnames without a tag to
determine whether to ignore
the names of directories already mentioned in the current word, or the
name of the current working directory.  The value must include one or both
of the following strings:

@noindent
@table @asis
@item @t{parent}
The name of any directory whose path is already contained in the word on
the line is ignored.  For example, when completing after @t{foo/../}, the
directory @t{foo} will not be considered a valid completion.

@item @t{pwd}
The name of the current working directory will not be completed, so that,
for example, completion after @t{../} will not use the name of the current
directory.

@end table

@noindent
In addition, the value may include one or both of:

@noindent
@table @asis
@item @t{..}
Ignore the specified directories only when the word on the line contains
the substring `@t{../}'.

@item @t{directory}
Ignore only when names of directories are completed, not when completing
names of files.

@end table

@noindent
Note that names of directories ignored because of one of the tests
will be ignored in the same way as the matches ignored because of the
@t{ignored-patterns} style.  I.e., by using the @t{_ignored} completer
it is possible to complete these directories nonetheless.

@kindex ignored-patterns, completion style
@item @t{ignored-patterns}
This style can be used to specify a list of patterns which are tested
against against the trial completions in a given context; any matching
completions will be removed from the list of possibilities.  The
@t{_ignored} completer can appear in the list of completers to produce a
list which includes these matches once more.  This is a more configurable
version of the shell parameter @t{$fignore}.

@noindent
Note that during the execution of completion functions, the
@t{EXTENDED_GLOB} option is in effect, so the characters `@t{#}',
`@t{~}' and `@t{^}' have special meanings in the patterns.

@kindex insert-ids, completion style
@item @t{insert-ids}
When completing process IDs, for example as arguments to the @t{kill} and
@t{wait} builtins, completion allows the user to type the name of a
command, which will be converted to the appropriate process ID.  A problem
arises when the process name typed is not unique.  By default (or if this
style is set explicitly to `@t{menu}') the name will be converted
immediately to a set of possible IDs, and menu completion will be started
to cycle through them.  If the value of the style is `@t{single}', however,
the shell will wait until the user has typed enough to make the command
unique before converting the name to an ID; the user must type any
additional characters required.  If the value is any other string, menu
completion will be started when the string typed by the user is longer than
the common prefix of the corresponding IDs.

@kindex insert-tab, completion style
@item @t{insert-tab}
If this has one of the `true' values, the completion system will
insert a TAB character (assuming it was used to start completion) instead
of performing completion when there is no non-blank character to the left
of the cursor.  If set to `false', completion will be done even there.

@noindent
The value may also contain the substrings `@t{pending}' or
`@t{pending=}@var{val}' to make the character typed to start completion 
be inserted instead of completion being tried when there is input
pending which has not yet been processed by the shell. If a @var{val}
is given, completion will not be done if there are at least that many
characters of unprocessed input. This is often useful to have set when 
pasting characters into a terminal. Note however, that it relies on
the @t{$PENDING} special parameter from the @t{zsh/zle} module being set
properly which is not guaranteed on all platforms.

@noindent
The default value of this style is `true' unless when completing
inside the @t{vared} builtin command, where it defaults to `false'.

@kindex insert-unambiguous, completion style
@item @t{insert-unambiguous}
This is used by the @t{_match} and @t{_approximate} completer
functions, where the possible completions may not have a common prefix so
that menu completion is often the most useful may of choosing completions.
If the style is set to `true', the completer will start menu
completion only if no unambiguous string could be generated that is at
least as long as the original string typed by the user.  Note that the
@t{_approximate} completer uses it after setting the completer field
in the context name to one of @t{correct-}@var{num} or
@t{approximate-}@var{num}, where @var{num} is the number of errors that
were accepted.

@noindent
When used for the @t{_match} completer, the style may also be set to
the string `@t{pattern}'.  This makes the pattern on the line be left
unchanged if it didn't match unambiguously.

@kindex keep-prefix, completion style
@item @t{keep-prefix}
This style is used by the @t{_expand} completer.  If it is `true', the
completer will try to keep a prefix containing a tilde or parameter
expansion.  I.e., the string `@t{~/f*}' would be expanded to
`@t{~/foo}' instead of `@t{/home/user/foo}'.  If the style is set to
`@t{changed}' (the default), the prefix will only be left unchanged if
there were other changes between the expanded words and the original
word from the command line.  Any other value makes the prefix be
expanded unconditionally.

@noindent
Note that with one of the `true' values, the @t{_expand} completer
returns if there is only one expansion and that is, after restoring
the original prefix, the same as the original word.  This means that
other completers will be called immediately after @t{_expand}.

@kindex last-prompt, completion style
@item @t{last-prompt}
This is used to determine if the completion code should try to put the
cursor back onto the previous command line after showing a completion
listing (as for the @t{ALWAYS_LAST_PROMPT} option).  As with several other
styles, it is tested for the @t{default} tag as well as all the possible
tags when generating matches.  The cursor will be moved back to the
previous line if this style is `true' for all types of matches added.  Note
also that this is independent of the numeric argument, unlike the
@t{ALWAYS_LAST_PROMPT} option.

@kindex list, completion style
@item @t{list}
This style is used by the @t{_history_complete_word} bindable command.
If it is set to `true' it has no effect, but if it is set to `false'
the matches will not be listed, overriding the setting of the options
that control listing behaviour, especially @t{AUTO_LIST}. Use the
context prefix `@t{:completion:history-words}'.

@kindex list-colors, completion style
@item @t{list-colors}
If the @t{zsh/complist} module is used, this style can be used to set
color specifications as with the @t{ZLS_COLORS} and @t{ZLS_COLOURS}
parameters, which will not be honored under this completion system (see
@ref{The zsh/complist Module}).

@noindent
If this style is set for the @t{default} tag, the strings in the value 
are taken as specifications that are to be used everywhere.  If it is
set for other tags, the specifications are used only for matches of
the type described by the tag.  For this to work best, the @t{group-name}
style must be set to an empty string.  If the @t{group-name} tag
specifies other names for the groups the matches in these groups can
be colored by using these names together with the `@t{(group)...}'
syntax described for the @t{ZLS_COLORS} and @t{ZLS_COLOURS} parameters 
and adding the specifications to the value for this style with the
@t{default} tag (although in most cases it should work by setting this 
style for the appropriate tags).

@noindent
It is possible to use the same specifications set up for the GNU
version of the @t{ls} command:

@noindent
@example
zstyle ':completion:*:default' list-colors $@{(s.:.)LS_COLORS@}
@end example

@noindent
The default colors are the same as for the GNU @t{ls} command and can be
obtained by setting the style to an empty string (i.e. @t{@value{dsq}}).

@kindex list-packed, completion style
@item @t{list-packed}
Like the @t{list-colors} style, this is tested with the @t{default}
tag and all tags used when generating matches.  If it is set to `true'
for a tag, the matches added for it will be listed as if the
@t{LIST_PACKED} option were set.  If it is set to `false',
they are listed normally.

@kindex list-prompt, completion style
@item @t{list-prompt}
If this style is set for the @t{default} tag,
completion lists that don't fit on the screen can be scrolled (see
@ref{The zsh/complist Module}).  The value, if not the empty string, will be displayed after every
screenful and the shell will prompt for a key press; if the style is
set to the empty string,
a default prompt will be used.  The value may contain the escape sequences
`@t{%l}' or `@t{%L}', which will be replaced by the number of the last line
displayed and the total number of lines; `@t{%m}' or `@t{%M}', which will
be replaced by the number of the  last match shown and the total number of
matches; and `@t{%p}' and `@t{%P}', which will be replaced by `@t{Top}'
when at the beginning of the list, `@t{Bottom}' when at the end and the
position shown in percent of the total length otherwise.  In each of these
cases the form with the uppercase letter is replaced by a string of fixed
width, padded to the  right with spaces.  As in other prompt strings, the
escape sequences `@t{%S}', `@t{%s}', `@t{%B}', `@t{%b}', `@t{%U}',
`@t{%u}', and `@t{%@{}...@t{%@}}' for entering and leaving the display modes
standout, bold and underline are also available.

@kindex list-rows-first, completion style
@item @t{list-rows-first}
This style is tested in the same way as the @t{list-packed} style and
determines if matches are to be listed in a rows-first fashion, as for the
@t{LIST_ROWS_FIRST} option.

@kindex list-suffixes, completion style
@item @t{list-suffixes}
This style is used by the function used to complete filenames.  If
completion is attempted on a string containing multiple partially
typed pathname components and this style is set to `true', all
components starting with the first one for which more than one match
could be generated will be shown.

@kindex local, completion style
@item @t{local}
This style is used by completion functions which generate URLs as
possible matches to add suitable matches when a URL points to a
local web server, that is, one whose files are available directly on the
local file system.  Its value should consist of three strings: a
hostname, the path to the default web pages for the server and the
directory name used by a user placing web pages within their home
area.  For example, completion after `@t{http://toast/~yousir/}' will
attempt to match the name `@t{toast}' against the first argument to the
style, and if successful will look in the directory under @t{~yousir} given
by the third argument to the style for possible completions.

@kindex match-original, completion style
@item @t{match-original}
This is used by the @t{_match} completer.  If it is set to
@t{only}, @t{_match} will try to generate matches without inserting a
`@t{*}' at the cursor position.  If set to any other non-empty value,
it will first try to generate matches without inserting the `@t{*}'
and if that yields no matches, it will try again with the `@t{*}'
inserted.  If it is unset or set to the empty string, matching will
only be done with the `@t{*}' inserted.

@kindex matcher, completion style
@item @t{matcher}
This style is tested for tags used when generating matches.  Its value
is used as an match specification additional to any given by the
@t{matcher-list} style which should be in the form described in
@ref{Matching Control}.

@kindex matcher-list, completion style
@item @t{matcher-list}
This style is used by the main completion function to retrieve match
specifications that are to be used everywhere.  Its value should be a
list of such specifications.  The completion system will try them one
after another for each completer selected. For example, to first try
simple completion and, if that generates no matches, case-insensitive
completion one would do:

@noindent
@example
zstyle ':completion:*' matcher-list @value{dsq} 'm:@{a-zA-Z@}=@{A-Za-z@}'
@end example

@noindent
By default every specification replaces previous ones. If specification
is prefixed with @t{+}, it is added to the existing list. This allows
testing more general patterns without repeating the whole list every
time, as in:

@noindent
@example
zstyle ':completion:*' matcher-list @value{dsq} '+m@{a-Z@}=@{A-Z@}' '+m@{A-Z@}=@{a-z@}'
@end example

@noindent
The style allows even finer control by specifying a particular completer,
without the leading underscore, in the third field of the completion
context.  For example, if one uses the completers @t{_complete} and
@t{_prefix} but wants to try case-insensitive completion only when using
the @t{_complete} completer, one would do:

@noindent
@example
zstyle ':completion:*' completer _complete _prefix
zstyle ':completion:*:complete:*' matcher-list \ 
       @value{dsq} 'm:@{a-zA-Z@}=@{A-Za-z@}'
@end example

@noindent
Note that the @t{completer} style allows user-defined names to 
be used in the context instead of the name of the completer.
This is useful if, for example, one wants to try
normal completion without a match specification and with
case-insensitive matching first, correction if that doesn't generate
any matches and partial-word completion if that doesn't yield any
matches either.  In this case one can give the @t{_complete}
completer more than once in the @t{completer} style and define different
match specifications for each occurrence, as in:

@noindent
@example
zstyle ':completion:*' completer _complete _correct _complete:foo
zstyle ':completion:*:complete:*' matcher-list \ 
    @value{dsq} 'm:@{a-zA-Z@}=@{A-Za-z@}'
zstyle ':completion:*:foo:*' matcher-list \ 
    'm:@{a-zA-Z@}=@{A-Za-z@} r:|[-_./]=* r:|=*'
@end example

@noindent
If the style is unset in any context no match specification is applied;
further, some completers such as @t{_correct} and @t{_approximate} do not
use the match specifications at all.  However, it is always safe
to use the simple form for this style (as in the first example above),
since any completers which do not use match specifications will only ever
be called once, rather than once per specification.

@noindent
Since the specification-strings in this style have to be tried one after
another, it is a good idea to keep their number low.  In most cases
one to three strings (each of which may, without to large a performance 
hit, consist of more than one single match specification) will give
acceptable performance.

@kindex max-errors, completion style
@item @t{max-errors}
This is used by the @t{_approximate} and @t{_correct} completer functions
to determine the maximum number of errors to allow.  The completer will try
to generate completions by first allowing one error, then two errors, and
so on, until either a match or matches were found or the maximum number of
errors given by this style has been reached.

@noindent
If the value for this style contains the string `@t{numeric}', the 
completer function will take any numeric argument as the
maximum number of errors allowed. For example, with

@noindent
@example
zstyle ':completion:*:approximate:::' max-errors 2 numeric
@end example

@noindent
two errors are allowed if no numeric argument is given, but with
a numeric argument of six (as in `@t{ESC-6 TAB}'), up to six
errors are accepted.  Hence with a value of `@t{0 numeric}', no correcting
completion will be attempted unless a numeric argument is given.

@noindent
If the value contains the string `@t{not-numeric}', the completer
will @emph{not} try to generate corrected
completions when given a numeric argument, so in this case the number given
should be greater than zero.  For example, `@t{2 not-numeric}' specifies that
correcting completion with two errors will usually be performed, but if a
numeric argument is given, correcting completion will not be
performed.

@noindent
The default value for this style is `@t{2 numeric}'.

@kindex menu, completion style
@item @t{menu}
If this is set to true in a given context, using any of the tags defined
for a given completion, menu completion will be used.  The tag
`@t{default}' can be used to set the default value, but a specific tag will take
precedence.  If none of the values found in this way is true but at least
one is set to `@t{auto}' the behaviour will be as for the @t{AUTO_MENU}
option.  Finally, if one of the values is explicitly set to false, menu
completion will be turned off even if it would otherwise be active (for
example, with the @t{MENU_COMPLETE} option).

@noindent
Using the form `@t{yes=}@var{num}', where `@t{yes}' may be any of the
true values (`@t{yes}', `@t{true}', `@t{on}' and `@t{1}') turns on
menu completion if there at least @var{num} matches.  Using this for one
of the `false' values (as in `@t{no=10}') makes menu completion
@emph{not} be used if there are @var{num} or more matches.  Of course,
this is only useful when menu completion is normally used, e.g. by
setting the @t{MENU_COMPLETE} option.  The `true' values may also be
used in the form `@t{yes=long}' to turn on menu completion
if the list does not fit onto the screen.  This will start menu
completion only if normal completion was attempted, not when only the
list of possible completions was requested.  To start menu completion
even then, the value `@t{yes=long-list}' can be used.

@noindent
In addition to (or instead of) the above possibilities, the value may
contain the string `@t{select}', optionally followed by an equals sign and a
number.  In this case menu selection (as defined by the @t{zsh/complist}
module) will be started.  Without the optional number, it will be started
unconditionally and with a number it will be started only if at least that
many matches are generated; if the values for more than one tag provide a
number, the smallest number is taken.  Menu selection can be turned off
explicitly by defining a value containing the string `@t{no-select}'.

@noindent
It is also possible to start menu selection only if the list of
matches does not fit on the screen by using the value
`@t{select=long}'.  This will only start menu selection if the widget
invoked does completion, not simply listing as done by
@t{delete-char-or-list}; to start menu selection even here, use the value
`@t{select=long-list}'.

@noindent
To turn on menu completion or menu selection when a certain number of
matches is generated @emph{or} the list of matches does not fit onto the
screen, both of `@t{yes=}' and `@t{select=}' can be given twice, once
with a number and once with `@t{long}' or `@t{long-list}'.

@kindex numbers, completion style
@item @t{numbers}
This is used with the @t{jobs} tag.  If it is `true', the shell will
complete the job numbers instead of the shortest unambiguous strings
of the jobs' command lines.  If the value is a number, job numbers will
only be used if that many words from the job descriptions are required to
resolve ambiguities.  For example, if the value is `@t{1}', strings will
only be used if all jobs differ in the first word on their command lines.

@kindex old-list, completion style
@item @t{old-list}
This is used by the @t{_oldlist} completer.  If it is set to `@t{always}',
then standard widgets which perform listing will retain the current list of
matches, however they were generated; this can be turned off explicitly
with the value `@t{never}', giving the behaviour without the @t{_oldlist}
completer.  If the style is unset, or any other value, then the existing
list of completions is displayed if it is not already; otherwise, the
standard completion list is generated; this is the default behaviour of
@t{_oldlist}.  However, if there is an old list and this style contains
the name of the completer function that generated the list, then the
old list will be used even if it was generated by a widget which does
not do listing.

@noindent
For example, suppose you type @t{^Xc} to use the @t{_correct_word}
widget, which generates a list of corrections for the word under the
cursor.  Usually, typing @t{^D} would generate a standard list of
completions for the word on the command line, and show that.  With
@t{_oldlist}, it will instead show the list of corrections already
generated.

@noindent
As another example consider the @t{_match} completer: with the
@t{insert-unambiguous} style set to `true' it inserts only a common prefix
string, if there is any.  However, this may remove parts of the original
pattern, so that further completion could produce more matches than on the
first attempt.  By using the @t{_oldlist} completer and setting this style
to @t{_match}, the list of matches generated on the first attempt will be
used again.

@kindex old-matches, completion style
@item @t{old-matches}
This is used by the @t{_all_matches} completer to decide if an old
list of matches should be used if one exists.  It may be set to one of 
the `true' values or to the string `@t{only}' to use such a list.  If
it is set to `@t{only}', @t{_all_matches} will only use an old list
and won't have any effect on the list of matches currently being
generated.

@kindex old-menu, completion style
@item @t{old-menu}
This is used by the @t{_oldlist} completer.  It controls how menu
completion behaves when a completion has already been inserted and the
user types a standard completion key type such as @t{TAB}.  The default
behaviour of @t{_oldlist} is that menu completion always continues
with the existing list of completions.  If this style is set to
`false', however, a new completion is started if the old list was
generated by a different completion command; this is the behaviour without
the  @t{_oldlist} completer.

@noindent
For example, suppose you type @t{^Xc} to generate a list of corrections,
and menu completion is started in one of the usual ways.  Usually, or with
this style set to @t{false}, typing @t{TAB} at this point would start
trying to complete the line as it now appears.  With @t{_oldlist}, it
instead continues to cycle through the list of corrections.

@kindex original, completion style
@item @t{original}
This is used by the @t{_approximate} and @t{_correct}
completers to decide if the original string should be added as
one possible completion.  Normally, this is done only if there are
at least two possible corrections, but if this style is set to `true', it
is always added.  Note that these completers use this style after
setting the completer field in the context name to
@t{correct-}@var{num} or @t{approximate-}@var{num}, where @var{num} is
the number of errors that were accepted.

@kindex packageset, completion style
@item @t{packageset}
This style is used when completing arguments of the Debian `@t{dpkg}'
program.  It contains an override for the default package set
for a given context.  For example,

@noindent
@example
zstyle ':completion:*:complete:dpkg:option--status-1:*' \ 
               packageset avail
@end example

@noindent
causes available packages, rather than only installed packages,
to be completed for `dpkg --status'.

@kindex path, completion style
@item @t{path}
The function that completes color names uses this style with the 
@t{colors} tag.  The value should be the pathname of a file
containing color names in the format of an X11 @t{rgb.txt} file.  If
the style is not set but this file is found in one of various standard
locations it will be used as the default.

@kindex ports, completion style
@item @t{ports}
A style holding the service names of ports to complete.  If this is
not set by the user, the service names from `@t{/etc/services}' will
be used.

@kindex prefix-hidden, completion style
@item @t{prefix-hidden}
This is used when matches with a common prefix are added (e.g. option
names).  If it is `true', this prefix will not be shown in the list of
matches.

@noindent
The default value for this style is `false'.

@kindex prefix-needed, completion style
@item @t{prefix-needed}
This, too, is used for matches with a common prefix.  If it is set to
`true' this common prefix has to be typed by the user to generate the
matches.  E.g. for options this means that the `@t{-}', `@t{+}', or
`@t{-}@t{-}' has to be on the line to make option names be completed at
all.

@noindent
The default value for this style is `true'.

@kindex preserve-prefix, completion style
@item @t{preserve-prefix}
This style is used when completing path names.  Its value should be a
pattern matching an initial prefix of the word to complete that should
be left unchanged under all circumstances.  For example, on some Unices
an initial `@t{//}' (double slash) has a special meaning and hence
should be kept.  For that one could set this style to the string
`@t{//}'.  As another example, setting this style to `@t{?:/}' under
Cygwin would allow completion after `@t{a:/...}' and the like.

@kindex range, completion style
@item @t{range}
This is used by the @t{_history} completer and the
@t{_history_complete_word} bindable command to decide which words
should be completed.  It may be set to a number, @var{N}, to say that
only the last @var{N} words from the history should be completed.  The
value may also be of the form `@var{max}@t{:}@var{slice}'.  This means
that first the last @var{slice} words will be completed.  If that
yields no matches, the @var{slice} words before those will be tried and 
so on, until either at least one match is generated or @var{max} words
have been tried.  The default is to complete all words from the
history at once.

@kindex regular, completion style
@item @t{regular}
This style is used by the @t{_expand_alias} completer and bindable 
command.  If set to `true' (the default), regular aliases will be
expanded but only in command position.  If it is set to `false', regular
aliases will never be expanded and if it is set to the string
`@t{always}', regular aliases will be expanded even if not in command
position.

@kindex remove-all-dups, completion style
@item @t{remove-all-dups}
The @t{_history_complete_word} bindable command and the @t{_history}
completer use this to decide if all duplicate matches should be
removed, rather than just consecutive duplicates.

@kindex select-prompt, completion style
@item @t{select-prompt}
If this is set for the @t{default} tag, its
value will be displayed during menu selection (see the @t{menu} style
above) when the completion list does not fit on the screen as a
whole.  The same escapes as for the @t{list-prompt} style are
understood, but give the number of the match or line the mark is
on.  A default prompt is used when the value is the empty string.

@kindex select-scroll, completion style
@item @t{select-scroll}
This style is tested for the @t{default} tag and determines how a
completion list is scrolled during a menu selection (see the @t{menu}
style above) when the completion list does not fit on the screen as a
whole.  Its value should be `@t{0}' (zero) to scroll by
half-screenfuls, a positive integer to scroll by that many lines and a
negative number to scroll by the number of lines of the screen minus
that number (or plus the number, since it is negative).  The default is to
scroll by single lines.

@kindex separate-sections, completion style
@item @t{separate-sections}
This style is used with the @t{manuals} tag when completing names of
manual pages.  If it is `true', entries for different sections are
added separately using tag names of the form `@t{manual.}@var{X}',
where @var{X} is the section number.  This means that it is possible to
make pages from different sections be listed separately by setting the
@t{group-name} style.  The default for this style is `false'.

@kindex single-ignored, completion style
@item @t{single-ignored}
This is used by the @t{_ignored} completer.  It specifies what
should be done if it can generate only one match, which is often a
special case.  If its value is `@t{show}', the single match will be
displayed but not inserted.  If the value is `@t{menu}', then the single
match and the original string are both added as matches and menu completion
is started so that one can easily select either of them.

@kindex sort, completion style
@item @t{sort}
If set to `true', completion functions that generate words from the
history as possible matches sort these words alphabetically instead of
keeping them in the order in which they appear in the history (from
youngest to oldest).

@noindent
This is also used by the @t{_expand} completer.  Here, if it is set to
`true', the expansions generated will always be sorted.  If it is set
to `@t{menu}', then the expansions are only sorted when they are offered 
as single strings (not in the string containing all possible
expansions).

@kindex special-dirs, completion style
@item @t{special-dirs}
Normally, the completion code will not produce the directory names
`@t{.}' and `@t{..}' as possible completions.  If this style is set to
`true', it will add both `@t{.}' and `@t{..}' as possible completions;
if it is set to `@t{..}', only `@t{..}' will be added.

@kindex squeeze-slashes, completion style
@item @t{squeeze-slashes}
If set to `true', sequences of slashes (as in `@t{foo//bar}') will be
treated as if they were only one slash when completing pathnames.  This
is the usual behaviour of UNIX paths.  However, by default the file
completion function behaves as if there were a `@t{*}' between
the slashes.

@kindex stop, completion style
@item @t{stop}
If set to `true', the @t{_history_complete_word} bindable
command will stop once when reaching the beginning or end of the
history.  Invoking @t{_history_complete_word} will then wrap around to 
the opposite end of the history.  If this style is set to `false' (the 
default), @t{_history_complete_word} will loop immediately as in a
menu completion.

@kindex subst-globs-only, completion style
@item @t{subst-globs-only}
This is used by the @t{_expand} completer.  If it is set to `true',
the expansion will only be used if it resulted from globbing; hence,
if expansions resulted from the use of the @t{substitute} style
described below, but these were not further changed by globbing, the
expansions will be rejected.

@noindent
The default for this style is `false'.

@kindex substitute, completion style
@item @t{substitute}
This boolean style controls whether the @t{_expand} completer will
first try to expand all substitutions in the string (such as
`@t{$(...)}' and `@t{$@{...@}}').

@noindent
The default is `true'.

@kindex suffix, completion style
@item @t{suffix}
This is used by the @t{_expand} completer if the word starts with a
tilde or contains a parameter expansion. If it is set to `true', the word will
only be expanded if it doesn't have a suffix, i.e. if it is something
like `@t{~foo}' or `@t{$foo}', but not if it is `@t{~foo/}' or
`@t{$foo/bar}', unless that suffix itself contains characters eligible
for expansion.  The default for this style is `true'.

@kindex tag-order, completion style
@item @t{tag-order}
This provides a mechanism for sorting how the tags available in a
particular context will be used.

@noindent
The values for the style are sets of space-separated lists of tags.
The tags in each value will be tried at the same time; if no match is
found, the next value is used.  (See the @t{file-patterns} style for
an exception to this behavior.)

@noindent
For example:

@noindent
@example
zstyle ':completion:*:complete:-command-:*' tag-order \ 
    'commands functions'
@end example

@noindent
specifies that completion in command position should offer only
completions for external commands and shell functions immediately.

@noindent
In addition to tag names, each string in the value may take one of the
following forms:

@noindent
@table @asis
@item @t{-}
If any string in the value consists of only a hyphen,
then @emph{only} the tags specified by the other strings in the value are
generated.  Normally all tags not explicitly selected are tried last
if the specified tags fail to generate any matches.  This means 
that a value consisting only of a single hyphen turns off completion.

@item @t{!} @var{tags}...
A string starting with an exclamation mark
specifies names of tags that are @emph{not} to be used.  The effect is
the same as if all other possible tags for the context had been
listed.

@item @var{tag}@t{:}@var{label} ...
In strings not starting with an exclamation mark, it is also possible
to specify tag labels instead of only tags, where @var{tag} is one of
the tags offered
by the completion function for the current context and @var{label} is a 
name.  For this, the completion function will generate matches in the
same way as for the @var{tag} but it will use the @var{label} in place
of the tag in the context names used to look up styles.  If the
@var{label} starts with a hyphen, the @var{tag} is prepended to the
@var{label} to form the name used for lookup.  This can be
used to make the completion system try a certain tag more than once,
supplying different style settings for each attempt, see below for an
example.

@noindent
The @var{label} may optionally be followed by a second colon and a
description.  This description will then be used for the `@t{%d}' in
the value of the @t{format} style instead of the default description
supplied by the completion function.  Spaces in the description have to 
be quoted by preceding them with a backslash and a `@t{%d}' appearing
in the description is replaced with the description given by the
completion function.

@end table

@noindent
In each of the cases above, the tag may also be a pattern or more than 
one pattern inside braces and separated by commas.  In this
case all of the offered tags matching the pattern(s) will be used except 
for those that are given explicitly in the same string.  There are
probably two main uses of this.  One is the case where one wants to try
one of the tags more than once, setting other styles differently for
each try, but still wants to use all the other tags without having to
repeat them all.  For example, to make completion of function names in
command position ignore all the completion functions starting with an
underscore the first time completion is tried, one could do:

@noindent
@example
zstyle ':completion:*:*:-command-:*' tag-order \ 
    'functions:-non-comp *' functions
zstyle ':completion:*:functions-non-comp' ignored-patterns '_*'
@end example

@noindent
Here, the completion system will first try all tags offered, but will
use the tag label @t{functions-non-comp} when looking up styles for
the function names completed.  For this, the @t{ignored-patterns} style 
is set to exclude functions starting with an underscore from the set
of possible matches.  If none of the generated matches match the string 
on the line, the completion system will use the second value of the
@t{tag-order} style and complete functions names again, but this time
using the name @t{functions} to look up styles, so that the
@t{ignored-patterns} style is not used and all function names
are considered.

@noindent
Of course, this can also be used to split the matches for one tag into 
different groups. For example:

@noindent
@example
zstyle ':completion:*' tag-order \ 
    'options:-long:long\ options
     options:-short:short\ options
     options:-single-letter:single\ letter\ options'

@noindent
zstyle ':completion:*:options-long' ignored-patterns '[-+](|-|[^-]*)'
zstyle ':completion:*:options-short' ignored-patterns '--*' '[-+]?'
zstyle ':completion:*:options-single-letter' ignored-patterns '???*'
@end example

@noindent
With the @t{group-names} style set, this makes options beginning with
`@t{-}@t{-}', options beginning with a single `@t{-}' or `@t{+}' but
containing multiple characters, and single-letter options be displayed
in separate groups with different descriptions.

@noindent
The second interesting use of patterns is the case where one wants to
try multiple match specifications one after another.  The
@t{matcher-list} style offers something similar, but it is tested very
early in the completion system and hence can't be set for single
commands nor for more specific contexts.  Here is how to
try normal completion without any match specification and, if that
generates no matches, try again with case-insensitive matching, restricting
the effect to arguments of the command @t{foo}:
@example
zstyle ':completion:*:*:foo:*' tag-order '*' '*:-case'
zstyle ':completion:*-case' matcher 'm:@{a-z@}=@{A-Z@}'
@end example

@noindent
First, all the tags offered when completing after @t{foo} are tried using
the normal tag name.  If that generates no matches, the second value of
@t{tag-order} is used, which tries all tags again except that this time
each has @t{-case} appended to its name for lookup of styles.  Hence this
time the value for the @t{matcher} style from the second call to @t{zstyle}
in the example is used to make completion case-insensitive.

@noindent
Using the @t{-e} option of the @t{zstyle} builtin command, it is
possible to specify conditions saying when certain tags are to be
used. For example:

@noindent
@example
zstyle -e '*:-command-:*' tag-order '
    if [[ -n $PREFIX ]]; then
      reply=( )
    else
      reply=( - )
    fi'
@end example

@noindent
Makes completion in command position happen only if the string on 
the line is not empty.  This is tested using the @t{PREFIX}
parameter which is special in completion widgets; see
@ref{Completion Widgets}
for a description of these special parameters.
Setting @t{reply} to an empty array ensures that only the default
behaviour of trying all tags at once is used and setting it to an
array containing only a hyphen disables that default behaviour -- thus 
keeping all tags from being tried.

@noindent
If no style has been defined for a context, the strings
`@t{(|*-)argument-* (|*-)option-* values}' and `@t{options}' plus all
tags offered by the completion function will be used to provide a
sensible default behavior that causes arguments (whether normal command
arguments or arguments of options) to be completed before option names for
most commands.

@kindex urls, completion style
@item @t{urls}
This is used together with the the @t{urls} tag by completion
functions that generate URLs as possible matches.  If the value
consists of more than one string or if the only string does not name a 
file or directory, the strings are used as the URLs to complete.

@noindent
If the value contains only one string and that is the name of a normal 
file, the URLs are taken from that file (where the URLs may be
separated by white space or newlines).

@noindent
Finally, if the only string in the value names a directory, that
should contain sub-directories named after the
retrieval methods which occur as the first part of a URL, i.e.
`@t{http}', `@t{ftp}', `@t{bookmark}', and so on.  These
sub-directories should contain files and other sub-directories whose
pathnames are possible completions after the initial `@t{http://}',
`@t{ftp://}', etc. See the description in the file @t{_urls} in the
@t{User} sub-directory of the completion system for more information.

@kindex use-cache, completion style
@item @t{use-cache}
If this is set, the completion caching layer is activated for any completions
which use it (via the @t{_store_cache}, @t{_retrieve_cache}, and
@t{_cache_invalid} functions).  The directory containing the cache
files can be changed with the @t{cache-path} style.

@kindex use-compctl, completion style
@item @t{use-compctl}
If this style is set to a string @emph{not} equal to @t{false}, @t{0},
@t{no}, and @t{off}, the completion system may use any completion
specifications defined with the @t{compctl} builtin command.  If the
style is unset, this is done only if the @t{zsh/compctl} module
is loaded.  The string may also contain the substring `@t{first}' to
make the definition for `@t{compctl -T}' be used, and the substring
`@t{default}' to make the one for `@t{compctl -D}' be used.

@noindent
Note that this is only intended to smooth the transition from
@t{compctl} to the new completion system and may disappear in the
future.

@noindent
Note also that the definitions from @t{compctl} will only be used if
there is no specific completion function for the command in question.  For
example, while completing arguments to the command @t{foo}, if this was
handled by a command function @t{_foo}, @t{compctl} would never be tried,
while if it was handled by @t{_default}, @t{compctl} would be tried.

@kindex users, completion style
@item @t{users}
This may be set to a list of names that should be completed whenever 
a username is needed. If it is not set or the string on the line
doesn't match any of the strings in this list, all usernames will be
completed.

@kindex users-hosts, completion style
@item @t{users-hosts}
The values of this style should be of the form
`@var{user}@t{@@}@var{host}' or `@var{user}@t{:}@var{host}'. It is used for
commands that need pairs of
user- and hostnames.  For such commands, only the pairs from this style 
are used and if, for example, the username is already typed, then only 
the hostnames for which there is a pair with that username is defined.

@noindent
If set for the @t{my-accounts} tag, this is used for commands such as
@t{rlogin} and @t{ssh}; in this case the style should contain the names of
the user's own accounts on remote hosts.  If set for the @t{other-accounts}
tag, it is used for commands such as @t{talk} and @t{finger} and should
contain other people's accounts.  Finally, it may also be used by some
commands with the @t{accounts} tag.

@kindex users-hosts-ports, completion style
@item @t{users-hosts-ports}
Like @t{users-hosts} but used for commands like @t{telnet} and
containing strings of the form `@var{user}@t{@@}@var{host}@t{:}@var{port}'.

@kindex verbose, completion style
@item @t{verbose}
This is used in several contexts to decide if only a simple or a
verbose list of matches should be generated. For example some commands 
show descriptions for option names if this style is `true'.

@noindent
The default value for this style is `true'.

@kindex word, completion style
@item @t{word}
This is used by the @t{_list} completer, which prevents the insertion of
completions until a second completion attempt when the line has not
changed.  The normal way of finding out if the line has changed is to
compare its entire contents between the two occasions.  If this style is
true, the comparison is instead performed only on the current word.
Hence if completion is performed on another word with the same contents,
completion will not be delayed.

@end table

@noindent
@node Control Functions, Bindable Commands, Completion System Configuration, Completion System

@section Control Functions
@noindent
@cindex completion system, choosing completers

@noindent
The initialization script @t{compinit} redefines all the widgets
which perform completion to call the supplied widget function
@t{_main_complete}.  This function acts as a wrapper calling the
so-called `completer' functions that generate matches.  If
@t{_main_complete} is called with arguments, these are taken as the
names of completer functions to be called in the order given.  If no
arguments are given, the set of functions to try is taken from the
@t{completer} style.  For example, to use normal completion and
correction if that doesn't generate any matches:

@noindent
@example
zstyle ':completion:*' completer _complete _correct
@end example

@noindent
after calling @t{compinit}. The default value for this style is
`@t{_complete _ignored}', i.e. normally only ordinary completion is tried,
first with the effect of the @t{ignored-patterns} style and then without
it.  The @t{_main_complete} function uses the return value of the completer
functions to decide if other completers should be called.  If the return
value is zero, no other completers are tried and the @t{_main_complete}
function returns.

@noindent
If the first argument to @t{_main_complete} is a single hyphen, the
arguments will not be taken as names of completers. Instead, the
second argument gives a name to use in the @var{completer} field of the 
context and the other arguments give a command name and arguments to
call to generate the matches.

@noindent
The following completer functions are contained in the distribution (users
may write their own):

@noindent
@cindex completion system, completers
@table @asis
@findex _all_matches
@item @t{_all_matches}
This completer can be used to add a string consisting of all other
matches.  To ensure, that this string is always added, this completer
has to be used as the first completer in the list.  The
@t{avoid-completer} style is used to decide if the string should be
added.  This will only be done if the matches were generated by a
completer not named by one of the values of the style.

@noindent
This function also uses the style @t{old-matches}.  If it is set to
`true' or to the string `@t{only}' and there is a list of matches from 
a previous completion, those matches will be inserted in the command
line.  If it is set to the the string `@t{only}', it will only insert
an old list and won't add the string for all matches of the list
currently being generated.

@noindent
With the @t{old-matches} style set, this completer should probably not 
be called unconditionally.  Instead one could use the @t{-e} option of 
the @t{zstyle} builtin command to add a condition to the @t{completer} 
or to the @t{old-matches} style.  Alternatively, one could use the
@t{_generic} function to bind @t{_all_matches} to a separate key
binding, for example:

@noindent
@example
zle -C all-matches complete-word _generic
bindkey '^Xa' all-matches
zstyle ':completion:all-matches::::' old-matches only
zstyle ':completion:all-matches:*' completer _all_matches
@end example

@findex _approximate
@item @t{_approximate}
This completer function uses the @t{_complete} completer to generate
a list of strings for the context the cursor is currently in, allowing 
you to specify a maximum number of errors:  see the description of
approximate matching in
@ref{Filename Generation}
for how errors are counted.  The resulting list of corrected and completed
strings is then presented to the user.  The intended use of this completer
function is to try after the normal @t{_complete} completer by setting:

@noindent
@example
zstyle ':completion:*' completer _complete _approximate
@end example

@noindent
This will give correcting completion if and only if
normal completion yields no possible completions.  When
corrected completions are found, the completer will normally start
menu completion allowing you to cycle through these strings.

@noindent
This completer uses the tags @t{corrections} and @t{original} when
generating the possible corrections and the original string.  The
@t{format} style for the former may contain the additional sequences
`@t{%e}' and `@t{%o}' which will be replaced by the number of errors
accepted to generate the corrections and the original string,
respectively.

@noindent
As with all completers, @t{_approximate} uses its name without the
underscore in the @var{completer} field of the context name.  Once it
has started trying to generate matches, it will append a minus sign
and the number of errors accepted to its name.  @t{_approximate} will
first look for completions with one error, then two, and on so up to the
limit on the number of errors set by the @t{max-errors} style.
Hence on the first try the completer field of the context contains
`@t{approximate-1}', on the second try `@t{approximate-2}', and so on.

@noindent
When @t{_approximate} is called from another function, the number of
errors to accept may be given with the @t{-a} option.  Its argument
should be the same as the value of the @t{max-errors} style, all in one
string.

@noindent
Note that this completer (and the @t{_correct} completer mentioned
below) can be quite expensive to call, especially when a large number
of errors are allowed.  One way to avoid this is to set up the
@t{completer} style using the @t{-e} option to zstyle so that some
completers are only used when completion is attempted a second time on 
the same string, e.g.:

@noindent
@example
zstyle ':completion:*' completer '
  if [[ $_last_try != "$HISTNO$BUFFER$CURSOR" ]]; then
    _last_try="$HISTNO$BUFFER$CURSOR"
    reply=(_complete _match _prefix)
  else
    reply=(_ignored _correct _approximate)
  fi'
@end example

@noindent
This uses the @t{HISTNO} parameter and the @t{BUFFER} and @t{CURSOR}
special parameters that are available inside zle and completion
widgets to find out if the command line hasn't changed since the last
time completion was tried.  Only then are the @t{_ignored},
@t{_correct} and @t{_approximate} completers called.

@findex _complete
@item @t{_complete}
This completer generates all possible completions in a context-sensitive
manner, i.e. using the settings defined with the @t{compdef} function
explained above and the current settings of all special parameters.
This gives the normal completion behaviour.

@noindent
To complete arguments of commands, @t{_complete} uses the utility function
@t{_normal}, which is in turn responsible for finding the particular
function; it is described below.  Various contexts of the form
@t{-}@var{context}@t{-}, as mentioned above for the @t{#compdef} tag, are
handled specially.  These are:

@noindent
@table @asis
@kindex -array-value-, completion context
@item @t{-array-value-}
for completion on the right hand side of an array-assignment
(`@t{foo=(...)}').

@kindex -brace-parameter-, completion context
@item @t{-brace-parameter-}
for completing the name of a parameter expansion within braces
(`@t{$@{...@}}').

@kindex -command-, completion context
@item @t{-command-}
for completing in a command position.

@kindex -condition-, completion context
@item @t{-condition-}
for completion inside conditions (`@t{[[...]]}').

@kindex -default-, completion context
@item @t{-default-}
for generating completions when no special completion function is used.

@kindex -equal-, completion context
@item @t{-equal-}
for completion of words beginning with an equals sign

@kindex -first-, completion context
@item @t{-first-}
for adding completions before any other completion functions are
tried; if this
function sets the @t{_compskip} parameter to @t{all}, no other
completion functions will be called, if it is set to a string
containing the substring @t{patterns}, no pattern completion functions
will be called, and if it is set to a string containing @t{default}
the function for the `@t{-default-}' context will not be called, but
functions defined for commands will.

@kindex -math-, completion context
@item @t{-math-}
for completion inside mathematical contexts, such as
`@t{((}...@t{))}'.

@kindex -parameter-, completion context
@item @t{-parameter-}
for completing the name of a parameter expansion (`@t{$...}').

@kindex -redirect-, completion context
@item @t{-redirect-}
for completion after a redirection operator.

@kindex -subscript-, completion context
@item @t{-subscript-}
for completion inside subscripts.

@kindex -tilde-, completion context
@item @t{-tilde-}
for completion after a tilde (`@t{~}') character, but before a slash.

@kindex -value-, completion context
@item @t{-value-}
for completion on the right hand side of an assignment.

@end table

@noindent
Default implementations are supplied for each of these
contexts, in most cases named after the context itself
(e.g. completion for the `@t{-tilde-}' context is done by the function 
named `@t{_tilde}').

@noindent
Before trying to find a function for a specific context, @t{_complete} 
checks if the parameter `@t{compcontext}' is set.  If it is set to an
array, the elements are taken to be the possible matches which will be
completed using the tag `@t{values}' and the description
`@t{value}'.   If it is set to an associative array, the keys are used
as the possible completions and the values (if non-empty) are used as
descriptions for the matches.  If `@t{compcontext}' is set to a string
containing colons, it should be of
the form `@var{tag}@t{:}@var{descr}@t{:}@var{action}'.  In this case the
@var{tag} and @var{descr} give the tag and description to use and the
@var{action} says what should be completed in one of the forms
described for the @t{_arguments} utility function below.

@noindent
Finally, if `@t{compcontext}' is set to a string without colons, the
value is taken as the name of the context to use and the function
defined for that context will be called.  For this purpose, there is a
special context named @t{-command-line-} that completes whole command
lines (commands and their arguments) and is not used by the completion
system itself, but has a function handling completion for it.

@findex _correct
@item @t{_correct}
Generate corrections, but not completions, for the current word; this is
similar to @t{_approximate} but will not allow any number of extra
characters at the cursor as that completer does, hence this is
similar to spell-checking.  It calls @t{_approximate} but uses a
different @var{completer} field in the context name.

@noindent
For example, with:

@noindent
@example
zstyle ':completion:::::' completer _complete _correct _approximate
zstyle ':completion:*:correct:::' max-errors 2 not-numeric
zstyle ':completion:*:approximate:::' max-errors 3 numeric
@end example

@noindent
correction will accept up to two errors.  If a numeric argument is
given, correction will not be performed, but correcting completion
will be, and will accept as many errors as given by the numeric
argument.  Without a numeric argument, first correction and then
correcting completion will be tried, with the first one accepting two
errors and the second one accepting three errors.

@noindent
When @t{_correct} is called as a function, the number of errors to accept
may be given following the @t{-a} option.  The argument should be the same
as the value of the @t{accept} style, all in one string.

@noindent
This completer function is intended to be used without the
@t{_approximate} completer or, as in the example, just before
it.  Using it after the @t{_approximate} completer is useless since
@t{_approximate} will at least generate the corrected strings
generated by the @t{_correct} completer -- and probably more.

@findex _expand
@item @t{_expand}
This completer function does not really do completion, but instead
checks if the word on the command line is eligible for expansion and,
if it is, gives detailed control over how this expansion is done.  When
using this, one should not use the @t{expand-or-complete} widget, but
instead use @t{complete-word}, as @t{expand-or-complete}
will expand the string on the line before the completion widget is
called.  Also, this completer should be called before the @t{_complete} 
completer function.

@noindent
The tags used when generating expansions are @t{all-expansions} for
the string containing all possible expansions, @t{expansions} when
adding the possible expansions as single matches and @t{original} when 
adding the original string from the line.  In which order these strings 
are generated and which of these strings are generated at all can be
controlled by using the @t{group-order} style and by modifying the
@t{tag-order} style, as usual.

@noindent
The format string for @t{all-expansions} and for @t{expansions} may
contain the sequence `@t{%o}' which will be replaced by the original
string from the line.

@noindent
Which kind of expansion is tried is controlled by the @t{substitute},
@t{glob} and @t{subst-globs-only} styles.

@noindent
When @t{_expand} is called as a function, the different modes may be
selected with options.  The @t{-s} to @t{substitute}, @t{-g} to
@t{glob} and @t{-o} to @t{subst-globs-only}.

@findex _expand_alias
@item @t{_expand_alias}
If the word the cursor is on is an alias, it is expanded and no other
completers are called.  The types of aliases which are to be expanded can
be controlled with the @t{regular}, @t{global} and @t{disabled}
styles.

@noindent
This function is also a bindable command, see
@ref{Bindable Commands}.

@findex _history
@item @t{_history}
Complete words from the shell's command  history.  This completer 
uses the @t{remove-all-dups}, and @t{sort} styles also used by the
@t{_history_complete_word} bindable command, see
@ref{Bindable Commands}
and
@ref{Completion System Configuration}.

@findex _ignored
@item @t{_ignored}
The @t{ignored-patterns} style can be set to a list of patterns which are
compared against possible completions; matching ones are removed.
With this completer those matches can be reinstated, as
if no @t{ignored-patterns} style were set.  The completer actually
generates its own list of matches; which completers are used
for this is determined in the same way as for the @t{_prefix}
completer.

@noindent
The @t{single-ignored} style is used if only one
match could be generated.  It can be set to @t{show} to prevent that match 
from being displayed or inserted into the line, or it can be set to
@t{menu}, in which case the single match and the original string from the
line will be offered in a menu completion.

@findex _list
@item @t{_list}
This completer allows one to delay the insertion of matches until
completion is attempted a second time without the word on the line
being changed.  On the first attempt, only the list of matches will be
shown.  It is affected by the styles @t{condition} and @t{word}, see
@ref{Completion System Configuration}.

@findex _match
@item @t{_match}
This completer is intended to be used after the @t{_complete}
completer. It allows one to give patterns on the command line and
to complete all strings matching these patterns from the set of
possible completions for the context the cursor is in, without having
to set the @t{GLOB_COMPLETE} option.

@noindent
Normally this will be done by taking the pattern from the line,
inserting a `@t{*}' at the cursor position and comparing the resulting
pattern with the possible completions generated.  However, if the
@t{match-original} style has a value of @t{only}, no `@t{*}' will be
inserted.  If @t{match-original} has any other non-empty string as its
value, this completer will first try to generate matches without, then
with a `@t{*}' inserted at the cursor position.

@noindent
The generated matches will be offered in a menu completion unless the
@t{insert-unambiguous} style is set to `true'.  In
this case menu completion will only be started if no unambiguous string
could be generated that is at least as long as the original string.
The style may also be set to the string `@t{pattern}'.  This will keep 
the pattern on the line intact as long as there isn't an unambiguous
completion with which it could be replaced.

@noindent
Note that the matcher specifications defined globally or used by the
completion functions will not be used.

@findex _menu
@item @t{_menu}
This completer is a simple example function implemented to show how
menu completion can be done in shell code.  It should be used as the
first completer and has the effect of making the code perform
menu completion.  Note that this is independent of the setting of the
@t{MENU_COMPLETE} option and does not work with the other
menu completion widgets such as @t{reverse-menu-complete}, or
@t{accept-and-menu-complete}.

@findex _oldlist
@item @t{_oldlist}
This completer controls how the standard completion widgets behave
when there is an existing list of completions which may have been
generated by a special completion (i.e. a separately-bound completion
command).  It allows the ordinary completion keys to continue to use the
list of completions thus generated, instead of producing a new list of
ordinary contextual completions.
It should appear in the list of completers before any of
the widgets which generate matches.  It uses two styles: @t{old-list} and
@t{old-menu}, see
@ref{Completion System Configuration}.

@findex _prefix
@item @t{_prefix}
This completer can be used to try completion with the suffix (everything
after the cursor) ignored.  In other words, the suffix will not be
considered to be
part of the word to complete and hence does not need to be matched.  It
uses the @t{completer} style to decide which other completers to call to
try to generate matches.  If this style is unset, the list of completers
set for the current context is used -- except, of course,
the @t{_prefix} completer itself.  Furthermore, if this completer appears
more than once in the list of completers only those completers not
already tried by the last invocation of @t{_prefix} will be
called.

@noindent
For example, consider this global @t{completer} style:

@noindent
@example
zstyle ':completion:*' completer \ 
    _complete _prefix _correct _prefix:foo
@end example

@noindent
Here, the @t{_prefix} completer tries normal completion but ignoring the
suffix.  If that doesn't generate any matches, and neither does
the call to the @t{_correct} completer after it, @t{_prefix} will 
be called a second time and, now only trying correction with the
suffix ignored.  If you want to use @t{_prefix} as the last resort and
try only normal completion, you can use:

@noindent
@example
zstyle ':completion:*' completer _complete ... _prefix
zstyle ':completion::prefix:*' completer _complete
@end example

@noindent
The @t{add-space} style is also used.  If it is set to `true' then
@t{_prefix} will insert a space between the matches generated (if any) 
and the suffix.

@noindent
Note that this completer is only useful if the
@t{COMPLETE_IN_WORD} option is set; otherwise, the cursor will
be moved to the end of the current word before the completion code is
called and hence there will be no suffix.

@findex bashcompinit
@item @t{bashcompinit}
This function provides compatibility with bash's programmable completion
system. When run it will define the functions, @t{compgen} and
@t{complete} which correspond to the bash builtins with the same names. It
will then be possible to use completion specifications and functions
written for bash.

@end table

@noindent
@node Bindable Commands, Completion Functions, Control Functions, Completion System

@section Bindable Commands
@noindent
@cindex completion system, bindable commands

@noindent
In addition to the context-dependent completions provided, which are
expected to work in an intuitively obvious way, there are a few widgets
implementing special behaviour which can be bound separately to keys.  The
following is a list of these and their default bindings.

@noindent
@table @asis
@findex _bash_completions
@item @t{_bash_completions}
This function is used by two widgets, @t{_bash_complete-word} and
@t{_bash_list-choices}.  It exists to provide compatibility with
completion bindings in bash.  The last character of the binding determines
what is completed: `@t{!}', command names; `@t{$}', environment variables;
`@t{@@}', host names; `@t{/}', file names; `@t{~}' user names.  In bash, the
binding preceded by `@t{\e}' gives completion, and preceded by `@t{^X}'
lists options.  As some of these bindings clash with standard zsh
bindings, only `@t{\e~}' and `@t{^X~}' are bound by default.  To add the
rest, the following should be added to @t{.zshrc} after @t{compinit} has
been run:

@noindent
@example
for key in '!' '$' '@@' '/' '~'; do
  bindkey "\e$key" _bash_complete-word
  bindkey "^X$key" _bash_list-choices
done
@end example

@noindent
This includes the bindings for `@t{~}' in case they were already bound to
something else; the completion code does not override user bindings.

@findex _correct_filename (^XC)
@item @t{_correct_filename (^XC)}
Correct the filename path at the cursor position.  Allows up to six errors
in the name.  Can also be called with an argument to correct
a filename path, independently of zle; the correction is printed on
standard output.

@findex _correct_word (^Xc)
@item @t{_correct_word} (^Xc)
Performs correction of the current argument using the usual contextual
completions as possible choices. This stores the string
`@t{correct-word}' in the @var{function} field of the context name and
then calls the @t{_correct} completer.

@findex _expand_alias (^Xa)
@item @t{_expand_alias (^Xa)}
This function can be used as a completer and as a bindable command.
It expands the word the cursor is on if it is an alias.  The types of
aliases expanded can be controlled with the @t{regular}, @t{global} and
@t{disabled} styles.

@noindent
When used as a bindable command there is one additional feature that
can be selected by setting the @t{complete} style to `true'.  In this
case, if the word isn't the name of an alias, @t{_expand_alias} tries
to complete the word to a full alias name without expanding it (but
leaving the cursor directly after the completed word so that invoking
@t{_expand_alias} once more will expand the now-complete alias name).

@findex _expand_word (^Xe)
@item @t{_expand_word (^Xe)}
Performs expansion on the current word:  equivalent to the standard
@t{expand-word} command, but using the @t{_expand} completer.  Before
calling it, the @var{function} field is set to `@t{expand-word}'.

@findex _generic
@item @t{_generic}
This function is not defined as a widget and not bound by
default. However, it can be used to define a widget and will then
store the name of the widget in the @var{function} field of the context 
and call the completion system. This allows custom completion widgets
with their own set of style settings to be easily defined. For example, 
to define a widget that does normal completion and starts
menu selection, one could do:

@noindent
@example
zle -C foo complete-word _generic
bindkey '...' foo
zstyle ':completion:foo:*' menu yes select=1
@end example

@findex _history_complete_word (\e/))
@item @t{_history_complete_word} (\e/)
Complete words from the shell's command history. This uses the
@t{list}, @t{remove-all-dups}, @t{sort}, and @t{stop} styles.

@findex _most_recent_file (^Xm)
@item @t{_most_recent_file (^Xm)}
Complete the name of the most recently modified file matching the pattern
on the command line (which may be blank).  If given a numeric argument
@var{N}, complete the @var{N}th most recently modified file.  Note the
completion, if any, is always unique.

@findex _next_tags (^Xn)
@item @t{_next_tags} (^Xn)
This command alters the set of matches used to that for the next tag, or
set of tags, either as given by the @t{tag-order} style or as set by
default; these matches would otherwise not be available.
Successive invocations of the command cycle through all possible sets of
tags.

@findex _read_comp (^X^R)
@item @t{_read_comp (^X^R)}
Prompt the user for a string, and use that to perform completion on the
current word.  There are two possibilities for the string.  First, it can
be a set of words beginning `@t{_}', for example `@t{_files -/}', in which
case the function with any arguments will be called to generate the
completions.  Unambiguous parts of the function name will be completed
automatically (normal completion is not available at this point) until a
space is typed.

@noindent
Second, any other string will be passed as a set of arguments to
@t{compadd} and should hence be an expression specifying what should
be completed.

@noindent
A very restricted set of editing commands is available when reading the
string:  `@t{DEL}' and `@t{^H}' delete the last character; `@t{^U}' deletes
the line, and `@t{^C}' and `@t{^G}' abort the function, while `@t{RET}'
accepts the completion.  Note the string is used verbatim as a command
line, so arguments must be quoted in accordance with standard shell rules.

@noindent
Once a string has been read, the next call to @t{_read_comp} will use the
existing string instead of reading a new one.  To force a new string to be
read, call @t{_read_comp} with a numeric argument.

@findex _complete_debug (^X?)
@item @t{_complete_debug (^X?)}
This widget performs ordinary completion, but captures in a temporary file
a trace of the shell commands executed by the completion system.  Each
completion attempt gets its own file.  A command to view each of these
files is pushed onto the editor buffer stack.

@findex _complete_help (^Xh)
@item @t{_complete_help (^Xh)}
This widget displays information about the context names, 
the tags, and the completion functions used 
when completing at the current cursor position. If given a numeric
argument other than @t{1} (as in `@t{ESC-2 ^Xh}'), then the styles
used and the contexts for which they are used will be shown, too.

@noindent
Note that the information about styles may be incomplete; it depends on the
information available from the completion functions called, which in turn
is determined by the user's own styles and other settings.

@findex _complete_tag (^Xt)
@item @t{_complete_tag (^Xt)}
This widget completes symbol tags created by the @t{etags} or @t{ctags}
programmes (note there is no connection with the completion system's tags)
stored in a file @t{TAGS}, in the format used by @t{etags}, or @t{tags}, in the
format created by @t{ctags}.  It will look back up the path hierarchy for
the first occurrence of either file; if both exist, the file @t{TAGS} is
preferred.  You can specify the full path to a @t{TAGS} or @t{tags} file by
setting the parameter @t{$TAGSFILE} or @t{$tagsfile} respectively.
The corresponding completion tags used are @t{etags} and @t{vtags}, after
emacs and vi respectively.

@end table

@noindent
@node Completion Functions, Completion Directories, Bindable Commands, Completion System

@section Utility Functions
@noindent
@cindex completion system, utility functions

@noindent
Descriptions follow for utility functions that may be
useful when writing completion functions.  Most of these reside in the
@t{Base} subdirectory. Like the example 
functions for commands in the distribution, the utility functions
generating matches all follow the convention of returning zero if they
generated completions and non-zero if no matching completions could be 
added.

@noindent
When writing completion functions or other ZLE widgets that call
completion, it might be interesting to know about two more features
offered by the @t{_main_complete} function. The arrays
@t{compprefuncs} and @t{comppostfuncs} may be set to contain names of
functions that are to be called immediately before or after completion 
has been tried. The functions will only be called once, unless they
put themselves into the arrays again.

@noindent
@table @asis
@findex _all_labels
@item @t{_all_labels} [ @t{-12VJ} ] @var{tag} @var{name} @var{descr} [ @var{command} @var{args} ... ]
This is a convenient interface to the @t{_next_label} function below,
implementing the loop shown in the @t{_next_label} example.  The
@var{command} is the one that should be called to generate the matches. The
options stored in the parameter @var{name} will automatically be inserted
into the @var{args} given to the @var{command}.  Normally, they are put
directly after the @var{command}, but if one of the @var{args} is a single
hyphen, they are inserted directly before that. If the hyphen is the last
argument, that will be removed from the argument list before the
@var{command} is called. This allows @t{_all_labels} to be used in almost all
cases where the matches can be generated by a single call to the
@t{compadd} builtin command or by a call to one of the utility functions.

@noindent
For example:

@noindent
@example
local expl
...
if _requested foo; then
  ...
  _all_labels foo expl '...' compadd ... - $matches
fi
@end example

@noindent
Will complete the strings from the @t{matches} parameter, using
@t{compadd} with additional options which will take precedence over
those generated by @t{_all_labels}.

@findex _alternative
@item @t{_alternative} [ @t{-C} @var{name} ] @var{specs} ...
This function is useful in simple cases where multiple tags are available.
Essentially, it implements a loop like the one described for the @t{_tags}
function above.

@noindent
The tags to use and the action to perform if a tag is requested are
described using the @var{specs} which are of the form:
`@var{tag}@t{:}@var{descr}@t{:}@var{action}'. The @var{tag}s are offered using
@t{_tags} and if the tag is requested, the @var{action} is executed with the
given description @var{descr}.  The @var{action}s supported are those used
by the @t{_arguments} function (described below), without the
`@t{->}@var{state}' and `@t{=}@var{...}' forms.

@noindent
For example, the @var{action} may be a simple function call. With that
one could do:

@noindent
@example
_alternative \ 
    'users:user:_users' \ 
    'hosts:host:_hosts'
@end example

@noindent
to offer usernames and hostnames as possible matches (which are
generated by the @t{_users} and @t{_hosts} functions respectively).

@noindent
Note that, like @t{_arguments} this will also use @t{_all_labels} to execute 
the actions, so one doesn't need to call that explicitly unless
another tag is to be used, for example in a function called from
@t{_alternative}.

@noindent
Like @t{_tags} this function supports the @t{-C} option to give a
different name for the argument context field.

@findex _arguments
@item @t{_arguments} [ @t{-ACS} ] [ @t{-O} @var{name} ] [ @t{-M} @var{matchspec} ] @var{spec} ...
This function can be used to complete words on the line by describing the
options and arguments which may be passed to the command for which
completion is being performed.  The description is given as arguments to
this function, with each @var{spec} describing one option or normal
argument of the command.  The forms of @var{spec} understood are:

@noindent
@table @asis
@item @var{n}@t{:}@var{message}@t{:}@var{action}
@itemx @var{n}@t{::}@var{message}@t{:}@var{action}
This describes the @var{n}'th normal argument.  The @var{message} will be 
printed above the matches generated and the @var{action} says what can
be completed in this position (see below).  If there are two colons
before the @var{message}, this describes an optional argument.  If the
@var{message} contains only white space, nothing will be printed above
the matches unless the action adds an explanation string itself.

@item @t{:}@var{message}@t{:}@var{action}
@itemx @t{::}@var{message}@t{:}@var{action}
Like the previous one, but describing the @emph{next} argument. I.e. if
you want to describe all arguments a command can get, you can leave
out the numbers in the description and just use this form to describe
them one after another in the order they have to appear on the line.

@item @t{*:}@var{message}@t{:}@var{action}
@itemx @t{*::}@var{message}@t{:}@var{action}
@itemx @t{*:::}@var{message}@t{:}@var{action}
This describes how arguments (usually non-option arguments, those not
beginning with @t{-} or @t{+}) are to be completed when no description
with one of the first two forms was given. This also means that any number
of arguments can be completed.

@noindent
With two colons before the @var{message}, the @t{words} special array and
the @t{CURRENT} special parameter are modified to refer only to the
normal arguments when the @var{action} is executed or evaluated.  With
three colons before the @var{message} they are modified to refer only to
the normal arguments covered by this description.

@item @var{optspec}[@var{description} ...]
This describes an option and (if @var{description} is given) the arguments
that have to come after the option.  If no @var{description} is given, this
means to offer only the option name as a possible completion in the right
places.  (Note that the brackets, above, around @var{description}, indicate
that zero or more @var{description}s may appear; but the brackets are not
themselves part of this format.  If brackets are used, they are part of
the @var{optspec}; see below.)

@noindent
In the descriptions below, the option names represented by @var{optname}
are normally taken to be multi-character names, and a word from the line
is considered to contain only one option (or none).  By giving the @t{-s}
option to @t{_arguments} before the first @var{spec}, each @var{optname} is
considered to be a single character and each word from the line may
contain more than one such option letter.  However, words beginning with
two hyphens (like `@t{-}@t{-prefix}') are still considered to contain only
one option name.  This allows the use of the `@t{-s}' option to describe
single-letter options together with such long option names.

@noindent
The @t{-s} option may be combined with the option @t{-w} to say that more
option characters are to be expected even after an option that takes an
argument.  For example, if a command takes the options `@t{a}' and `@t{b}',
where `@t{a}' takes an argument in the next word, @t{_arguments} would
normally not complete the other option directly after `@t{-a}', but it would
allow that if given the @t{-w} option.

@noindent
Similarly, the option @t{-W} may be given together with @t{-s} to force
completion of single-letter options even after options that get an
argument in the same word.  For example, if a command takes the options
`@t{a}' and `@t{b}', where `@t{a}' needs an argument in the same word,
directly after the option character, @t{_arguments} would normally only
execute the action for that argument and not offer other single-letter
options as possible completions.  If given the @t{-W} option, it will
offer other options as possible completions after executing the action
for the argument.  Note that, depending on the action, this may mean
that the other options can't really be completed, but at least they will
be listed.  For more control, use an utility function like @t{_guard} in
the argument's action.

@noindent
The forms of @var{optspec} are:

@noindent
@table @asis
@item @t{*}@var{optspec}
If the option may be given more than once, a star (`@t{*}') must be
added in front of one of the following forms of @var{optspec}.  Otherwise,
if the option is already on the line and to the left of the cursor, it
is not offered as a possible completion again.

@item @t{-}@var{optname}
@itemx @t{+}@var{optname}
In the simplest form the @var{optspec} is just the option name beginning
with a minus or a plus sign, such as `@t{-foo}'.  The first argument for
the option (if any) must follow as a @emph{separate} word directly after the
option.

@noindent
If the command accepts the option with either a leading minus or a leading
plus sign, use either `@t{-+}@var{optname}' or `@t{+-}@var{optname}' to
define both variants at once.

@noindent
In all the following forms, the leading `@t{-}' may be replaced or paired
with `@t{+}' in this way.

@item @t{-}@var{optname}@t{-}
The first argument of the option must come directly after the option name
@emph{in the same word}, as in `@t{-foo-:}@var{...}'.

@item @t{-}@var{optname}@t{+}
The first argument may appear immediately after @var{optname} in the same
word, or may instead appear as a separate word after the option.

@item @t{-}@var{optname}@t{=}
The argument may appear as the next word, or in same word as the option
name provided that it is separated from it by an equals sign.

@item @t{-}@var{optname}@t{=-}
The argument to the option must appear after an equals sign in the same
word, and may not be given in the next argument.

@item @var{optspec}@t{[}@var{explanation}@t{]}
An explanation string may be appended to any of the preceding forms of
@var{optspec} by enclosing it in brackets, as in `@t{-q[query operation]}'.

@noindent
The @t{verbose} style is used to decide if these explanation strings
should be displayed with the option in a completion listing.

@noindent
If no bracketed explanation string is given but the @t{auto-description}
style is set and only one argument is described for this @var{optspec}, the
value of the style is displayed, with any appearance of the sequence
`@t{%d}' in it replaced by the @var{message} of the first @var{description}
that follows the @var{optspec}; see below.

@end table

@noindent
Note that the special meaning of a leading or trailing @t{-} or @t{+} in
@var{optspec} means that when the command to be completed accepts options
like `@t{-+}' or `@t{-=}', the second character has to be quoted with a
backslash, as in `@t{-\+}'.

@noindent
Each @var{description} following an @var{optspec} must take one of the
following forms:

@noindent
@table @asis
@item @t{:}@var{message}@t{:}@var{action}
@itemx @t{::}@var{message}@t{:}@var{action}
Describes a mandatory argument with one colon, or an optional argument
with two colons.  As in other forms of @var{spec}, the @var{message} will be
printed above the matches generated (unless it contains only white
space, see above) and the @var{action} says what can be
completed in this position.

@item @t{:*}@var{pattern}@t{:}@var{message}@t{:}@var{action}
@itemx @t{:*}@var{pattern}@t{::}@var{message}@t{:}@var{action}
@itemx @t{:*}@var{pattern}@t{:::}@var{message}@t{:}@var{action}
This describes multiple arguments.  Only the @emph{last} description may be
given in this form.  If the @var{pattern} is empty (i.e., @t{:*:}), all
following words on the line are to be completed as described by the
@var{action}; otherwise, all words up to a word matching the @var{pattern}
are to be completed using the @var{action}.

@noindent
When the @var{message} is preceded by two colons, the @t{words} special
array and the @t{CURRENT} special parameter are modified during the
execution or evaluation of the @var{action} to refer only to the words
after the option.  When preceded by three colons, they are modified to
refer only to the words covered by this description.

@noindent
Note that only one such `@t{:*}'-specification is useful
and no other argument specification may be given after it.

@end table

@end table

@noindent
To include a colon in any @var{optname}, @var{message}, or @var{action}
anywhere above, it has to be preceded by a backslash, as `@t{\:}'.

@noindent
Each of the six forms of @var{spec} (yes, there are six, keep track of
the nestings) may be preceded by a list
of option names and argument numbers with which the option or argument
described is mutually exclusive.  This list is given in parentheses, as
in `@t{(-two -three 1)-one:...}' or `@t{(-foo):...}'.  In the first
example, the options `@t{-two}' and `@t{-three}' and the first
argument will not be offered as possible completions if the option
`@t{-one}' is on the line before the cursor, and in the second example
the option `@t{-foo}' will not be offered if the argument described by
the specification is on the line.

@noindent
The list may also contain a single star (@t{*}) as one of its elements to
specify that the description for the rest arguments (i.e. a specification
of the form `@t{*:...}') should not be used, a colon (@t{:}) to specify
that the descriptions for all normal (non-option-) arguments should not be
used and a hyphen (@t{-}) to specify that the descriptions for all options
should not be used.  This paragraph desperately needs rewriting.

@noindent
To simplify writing writing functions that call @t{_arguments} more
than once, the @var{specs} may also start with the character `@t{!}'
(exclamation mark) to make the spec @emph{not} be completed.  However, if
this is used with one of the forms describing options, the option (and 
its arguments, if it takes any) will be understood and skipped if they 
appear on the command line.  It's just that the option itself will not
be completed. This is intended to be used with an array containing the 
options used in the first call to @t{arguments}.  The second call can
then use `@t{\!$@{^global_options@}}' to ignore those options and
complete only the ones understood in the current context.

@noindent
In every case above, the @var{action} determines how the possible
completions should be generated.  In places where no sensible matches can
be generated, the action should consist of only a space. This will make
the @var{message} be displayed but no possible completions listed. Note
that even in this case the colon at the end of the @var{message} is
needed. The only case where it can be left is when neither a @var{message},
nor a @var{action} is given.

@noindent
Except for the `@t{->}@var{string}' form below, the @var{action} will be
executed by calling the @t{_all_labels} function to process all tag labels,
so one doesn't need to call that explicitly unless another tag is to
be used, for example in a function called in the @var{action}.

@noindent
When only one of a fixed set of strings can be completed, the @var{action}
can consist of these strings as a list in parentheses, as in:

@noindent
@example
@t{:foo:(foo bar baz}@t{)}
@end example

@noindent
Such a list in doubled parentheses should contain strings consisting of
the string to complete followed by `@t{\:}' and a description, as in:

@noindent
@example
@t{:foo:((a\:bar b\:baz}@t{))}
@end example

@noindent
The matches will be listed together with their descriptions if the
@t{description} style for the @t{values} tag is set.

@noindent
@vindex context, use of
@vindex line, use of
@vindex opt_args, use of
An @var{action} of the form `@t{->}@var{string}' is used by functions
that implement a state machine. In this case, the `@var{string}'s (with
all leading and trailing spaces and tabs removed) of all actions that
have to be used will be stored in the global array @t{state}.  The
function returns with a non-zero return value if the cursor is not in
a position where options can be completed or if the current word could 
not be completed to an option.  But if the @t{-R} option is given to
@t{_arguments}, the function will instead return with a return
value of 300 (to make it distinguishable from other return values)
after setting the global `@t{context}', `@t{line}' and `@t{opt_args}'
parameters as described below, and without resetting any changes made
to the special parameters such as @t{PREFIX} and @t{words}.  This
enables wrapper functions around @t{_arguments} to be able to find out
if they have to make sure that the special completion parameters are
not reset when they return.

@noindent
Note that this means that a function calling @t{_arguments} with at least
one action containing such a `@t{->}@var{string}' has to declare
appropriate local parameters as in:

@noindent
@example
local context state line
typeset -A opt_args
@end example

@noindent
This will ensure that @t{_arguments} does not create unused global
parameters.

@noindent
@vindex expl, use of
A string in braces is evaluated to generate the matches and if the
@var{action} does not begin with an opening parentheses or brace, it
is also split into separate words and executed. If the @var{action}
starts with a space, this list of words will be invoked unchanged,
otherwise it will be invoked with some extra strings placed after the
first word which can be given as arguments to the @t{compadd} builtin
command and which make sure that the @var{message} given
in the description will be shown above the matches. These arguments
are taken from the array parameter `@t{expl}' which will be set up
before executing the @var{action} and hence may be used in it (normally 
in an expansion like `@t{$expl[@@]}').

@noindent
If the @var{action} starts with `@t{= }' (an equals sign followed by a
space), @t{_arguments} will insert the contents of the @var{argument}
field of the current context as the new first element in the @t{words} 
special array and increments the value of the @t{CURRENT} special
parameter. In other words, it inserts a dummy element in the @t{words} 
array and makes @t{CURRENT} still point to the word in that array
where the cursor is. This is only really useful when used with one of
the forms that make @t{_arguments} modify the @t{words} array to
contain only some of the words from the line, i.e. one of the argument 
description forms where the @var{message} is preceded by two or three
colons. For example, when the function called in the action for such
an argument itself uses @t{_arguments}, the dummy element is needed to 
make that second call to @t{_arguments} use all words from the
restricted range for argument parsing. Without the inserted dummy
element, the first word in the range would be taken (by the second
@t{_arguments}) to be the command name and hence ignored.

@noindent
During the evaluation or execution of the action the array `@t{line}'
will be set to the command name and normal arguments from the command
line, i.e. to the words from the command line excluding all options
and their arguments. These are stored in the associative array
`@t{opt_args}', using the option names as keys and their arguments as
the values. For options that have more than one argument these are
given as one string, separated by colons. All colons in the original
arguments are preceded with backslashes.

@noindent
The parameter `@t{context}' (set only in the calling function when
using an action of the form `@t{->}@var{string}', not during the
evaluation of other @var{action}s) is set to the automatically
created context names. These are either strings of the form
`@t{option}@var{-opt}@t{-}@var{n}' for the @var{n}'th argument of the
option @var{-opt}, or strings of the form `@t{argument-}@var{n}' for
the @var{n}'th argument (for rest arguments the @var{n} is the string
`@t{rest}'). For example, when completing the argument of the @t{-o}
option, the name is `@t{option-o-1}' and for the second normal
(non-option-) argument it is `@t{argument-2}'.

@noindent
Also, during the evaluation of the @var{action}, the context name in
the @t{curcontext} parameter is changed by appending the same
string that is stored in the @t{context} parameter.

@noindent
It is also possible to specify multiple sets of options and
arguments with the sets separated by single hyphens.  The specifications
before the first hyphen are shared by all sets given after the first
hyphen.  The first word in every other set gives the name of the
set. This name may appear in exclusion lists in the specifications,
either alone or before one of the possible values described above
(with a `@t{-}' between the name and the rest).

@noindent
For example:

@noindent
@example
_arguments \ 
    -a \ 
  - set1 \ 
    -c \ 
  - set2 \ 
    -d \ 
    ':arg:(x2 y2)'
@end example

@noindent
This defines two sets. When the command line contains the option
`@t{-c}', the `@t{-d}' option and the argument will not be considered
possible completions. When it contains `@t{-d}' or an argument, the
option `@t{-c}' will not be completed any more, but if `@t{-a}' is
given, both sets will still be considered valid, because it appears
before the first hyphen, so both sets contain this option.

@noindent
If the name-string is of the form `@t{(}@var{name}@t{)}' then 
all specifications in the set have an implicit exclusion list
containing the name of the set, i.e. all specifications are mutual
exclusive with all other specifications in the same set. This is
useful for defining multiple sets of options which are mutually
exclusive and in which the options are aliases for each other. E.g.:

@noindent
@example
_arguments \ 
    -a -b \ 
  - '(compress)' \ 
    @{-c,--compress@}'[compress]' \ 
  - '(uncompress)' \ 
    @{-d,--decompress@}'[decompress]'
@end example

@noindent
Note that using multiple sets will be slower than using only one set
because the completion code has to parse the command line once for
every set. So more than one set should only be used if the command
syntax is too complicated. Note also that an option specification with
rest-arguments (as in `@t{-foo:*:...}') often allows the use of
multiple sets to be avoided.

@noindent
To simplify the specifications for commands with standard option
parsing, the options @t{-S} and @t{-A} may be given.  With @t{-S}, no
option will be completed after a `@t{-}@t{-}' on the line and this
argument will otherwise be ignored. With @t{-A}, no options will be
completed after the first non-option argument on the line.  The @t{-A} 
has to be followed by a pattern matching all strings which are not to
be taken as arguments. For example, to make @t{_arguments} stop
completing options after the first normal argument, but ignoring all
strings starting with a hyphen even if they are not described by one
of the @var{optspec}s, one would use: `@t{-A "-*"}'.

@noindent
Another option supported is `@t{-O} @var{name}'. The @var{name} will be
taken as the name of an array and its elements will be given to
functions called to generate matches when executing the
@var{actions}. For example, this allows one to give options for the
@t{compadd} builtin that should be used for all @var{action}s.

@noindent
Also, the @t{-M} option followed by a string may be given before the
first description. The string will be used as the match specification
when completing option names and values instead of the default
`@t{r:|[_-]=* r:|=*}'. 

@noindent
Finally, the option @t{-C} can be given to make @t{_arguments} modify
the @t{curcontext} parameter when an action of the form
`@t{->}@var{state}' is used. This parameter is used to keep track of
the current context and in this case it (and not the parameter
@t{context} as explained above) has to be made local to make sure that 
calling functions don't use the modified value. Also, the local
version of @t{curcontext} has to be initialised with the old value as
in:

@noindent
@example
local curcontext="$curcontext"
@end example

@noindent
The function can also be made to automatically complete long options
for commands that support the `@t{-}@t{-help}' option as, for example,
most of the GNU commands do. For this, the string `@t{-}@t{-}' must be
given as one argument and if it is, the command from the line is
invoked with the `@t{-}@t{-help}' option and its output is parsed to find
possible option names. Note that this means that you should be careful
to make sure that this feature is not used for a command that does not
support this option.

@noindent
For such automatically found options that get an argument after an
`@t{=}', the function also tries
to automatically find out what should be completed as the argument.
The possible completions for option-arguments can be described with
the arguments after the `@t{-}@t{-}' (which are not used as described
above). Each argument contains one description of the form
`@var{pattern}@t{:}@var{message}@t{:}@var{action}'. The @var{message} and
the @var{action} have the same format as for the normal option
descriptions described above. The @var{action} will be executed to
complete arguments of options whose description in the output of the
command from the line with the `@t{-}@t{-help}' option matches the
@var{pattern}. For example:

@noindent
@example
_arguments -- '*\*:toggle:(yes no)' \ 
              '*=FILE*:file:_files' \ 
              '*=DIR*:directory:_files -/'
@end example

@noindent
Here, `@t{yes}' and `@t{no}' will be completed as the argument of
options whose description ends in a star, file names for options that
contain the substring `@t{=FILE}' in the description, and paths for
options whose description contains `@t{=DIR}'. In fact, the last two
patterns are not needed since this function always completes files
for option descriptions containing `@t{=FILE}' and paths for option
descriptions that contain `@t{=DIR}' or `@t{=PATH}'. These builtin
patterns can be overridden by patterns given as arguments, however.

@noindent
Note also that @t{_arguments} tries to find out automatically if the
argument for an option is optional. If it fails to automatically
detect this, the colon before the @var{message} can be doubled to tell
it about this as described for the normal option descriptions above.

@noindent
If the @var{pattern} ends in `@t{(-)}', this will removed from the
pattern and the @var{action} will be used only directly after the
`@t{=}', not in the next word. I.e., this is like a normal
specification as described above using `@t{=-}'.

@noindent
The option `@t{-i} @var{patterns}' (which must be given after the
`@t{-}@t{-}') can be used to give patterns for options which should not be
completed. The patterns can be given as the name of an array parameter
or as a literal list in parentheses. E.g. `@t{-i
"(-}@t{-(en|dis)able-FEATURE*)"}' will make the options
`@t{-}@t{-enable-FEATURE}' and `@t{-}@t{-disable-FEATURE}' be ignored. The
option `@t{-s} @var{pairs}' (again, after the `@t{-}@t{-}') can be used to
describe option aliases. Each @var{pair} consists of a pattern and a
replacement. E.g. some @t{configure}-scripts describe options only as
`@t{-}@t{-enable-foo}', but also accept `@t{-}@t{-disable-foo}'. To allow
completion of the second form, one would use `@t{-s "(#-}@t{-enable-
-}@t{-disable-)"}'.

@noindent
Example:

@noindent
@example
_arguments '-l+:left border:' \ 
           '-format:paper size:(letter A4)' \ 
           '*-copy:output file:_files::resolution:(300 600)' \ 
           ':postscript file:_files -g \*.\(ps\|eps\)' \ 
           '*:page number:'
@end example

@noindent
This describes three options: `@t{-l}', `@t{-format}', and
`@t{-copy}'. The first one gets one argument described as `@var{left
border}' for which no completion will be offered because of the empty
action. The argument may come directly after the `@t{-l}' or it may be 
given as the next word on the line. The `@t{-format}' option gets one
argument (in the next word) described as `@var{paper size}' for which
only the strings `@t{letter}' and `@t{A4}' will be completed. The
`@t{-copy}' option differs from the first two in that it may appear
more than once on the command line and in that it accepts two
arguments. The first one is mandatory and will be completed as a
filename. The second one is optional (because of the second colon
before the description `@var{resolution}') and will be completed from
the strings `@t{300}' and `@t{600}'.

@noindent
The last two descriptions say what should be completed as
arguments. The first one describes the first argument as a
`@var{postscript file}' and makes files ending in `@t{ps}' or `@t{eps}' 
be completed. The last description says that all other arguments are
`@var{page numbers}' but does not give possible completions.

@findex _cache_invalid
@item @t{_cache_invalid} @var{cache_identifier}
This function returns 0 if the completions cache corresponding to the
given cache identifier needs rebuilding.  It determines this by
looking up the @t{cache-policy} style for the current context, and
if it exists, runs the function of the same name, supplying the full
path to the relevant cache file as the only argument.

@noindent
Example:

@noindent
@example
_example_caching_policy () @{
    # rebuild if cache is more than a week old
    oldp=( "$1"(Nmw+1) )
    (( $#oldp ))
@}
@end example

@findex _call_function
@item @t{_call_function} @var{return} @var{name} [ @var{args} ... ]
If a function @var{name} exists, it is called with the arguments
@var{args}. Unless it is the empty string or a single hyphen,
@var{return} is taken as the name of a parameter and the return status
from the called function is stored in it.
The return value of @t{_call_function} itself is zero if the function
@var{name} exists and was called and non-zero otherwise.

@findex _call_program
@item @t{_call_program} @var{tag} @var{string} ...
This function is used in places where a command is called, making it
possible for the user to override the default command call.  It looks up
the @t{command} style with the supplied @var{tag}.  If the style is set, its
value is used as the command to execute.

@noindent
In any case, the @var{string}s from the call to @t{_call_program} or from the
style are concatenated with spaces between them and the resulting
string is evaluated.  The return value is the return value of the
command called.

@findex _combination
@item @t{_combination} [ @t{-s} @var{pattern} ] @var{tag} @var{style} @var{specs} ... @var{field} @var{opts} ...
This function is used to complete combinations of values such as pairs 
of hostnames and usernames.  The possible values will be taken from the 
@var{style} whose name is given as the second argument.  The first argument
is the @var{tag} to use to do the lookup.

@noindent
The style name should consist of multiple parts separated by
hyphens which are then used as field names.  Known values for such
fields can be given after the second argument in arguments of the form 
`@var{field}@t{=}@var{pattern}'.  The first argument without an equals sign 
is taken as the name of the field for which completions should be
generated.

@noindent
The matches generated will be taken from the value of the style.  These 
values should contain the possible values for the combinations where
the values for the different fields are separated by colons or
characters matching the pattern given after the @t{-s} option to
@t{_combination}; normally this is used to define character classes
like the `@t{-s "[:@@]"}' used for the @t{users-hosts} style.

@noindent
Only the values for the requested fields for which the patterns given
in the `@var{field}@t{=}@var{pattern}' match the respective fields in
the strings from the style value are generated as possible matches.

@noindent
If no style with the given name is defined for the given tag but a
function named with the name of the requested field preceded by an
underscore is defined, that function will be called to generate the
matches.  This is also done if none of the strings in the value of the
style match all the patterns given as arguments.

@noindent
If the same name is used for more than one field, in both the
`@var{field}@t{=}@var{pattern}' and the argument that gives the field
name to complete for, the number of the field (starting with one) may
be given after the fieldname, separated from it by a colon.

@noindent
All arguments after the requested field name are passed to
@t{compadd} when generating matches from the style value, or to 
the functions for the fields if they are called.

@findex _contexts
@item @t{_contexts} @var{names} ...
This function looks up the definitions for the context and command
names given as arguments and calls the handler functions for them if
there is a definition (given with the @t{compdef} function).  For
example, the function completing inside subscripts might use
`@t{_contexts -math-}' to include the completions generated for
mathematical environments.

@findex _describe
@item @t{_describe} [ @t{-o} ] @var{descr} @var{name1} [ @var{name2} ] @var{opts} ... @t{-}@t{-} ...
This function is useful for preparing a list of command options or
arguments, together with their descriptions @var{descr}, as matches.
Multiple groups separated by @t{-}@t{-} can be supplied, potentially with
different completion options @var{opts}.

@noindent
The @var{descr} is taken as a string to display above the matches if the
@t{format} style for the @t{descriptions} tag is set.  After this come one
or two names of arrays followed by options to pass to @t{compadd}.  The
first array contains the possible completions with their descriptions in
the form `@var{completion}@t{:}@var{description}'.  If a second array is
given, it should have the same number of elements as the first one and the
corresponding elements are added as possible completions instead of the
@var{completion} strings from the first array.  The completion list will
retain the descriptions from the first array.  Finally, a set of completion
options can appear.

@noindent
If the option `@t{-o}' appears before the first argument, the matches added
will be treated as option names (typically following a `@t{-}',
`@t{-}@t{-}' or `@t{+}' on the command line).  This makes @t{_describe} use
the @t{prefix-hidden}, @t{prefix-needed} and @t{verbose} styles to find out
if the strings should be added at all and if the descriptions should be
shown.  Without the `@t{-o}' option, only the @t{verbose} style is used.

@noindent
@t{_describe} uses the @t{_all_labels} function to generate the matches, so
it does not need to appear inside a loop over tag labels.

@findex _description
@item @t{_description} [ @t{-12VJ} ] @var{tag} @var{name} @var{descr} [ @var{specs} ... ]
This function is called before completions are added (typically by a call
to @t{compadd}); it tests various styles and arranges for any necessary
options to be passed on to @t{compadd}.  The styles are tested in the
current context using the given @var{tag}; options are put into the array
called @var{name} for passing on to @t{compadd}; the description for the
current set of matches is passed in @var{descr}.  The styles tested are:
@t{format} (which is first tested for the given @var{tag} and then for the
@t{descriptions} tag if that isn't defined), @t{hidden}, @t{matcher},
@t{ignored-patterns} and @t{group-name} (the last are tested only for the
tag given as the first argument).  This function also calls the @t{_setup}
function which tests some more styles.

@noindent
The string returned by the @t{format} style (if any) will be modified so
that the sequence `@t{%d}' is replaced by the @var{descr} given as the third
argument without any leading or trailing white space.  If, after
removing the white space, the @var{descr} is the empty string, the format
style will not be used and the options put into the @var{name} array will
not contain an explanation string to be displayed above the matches.  If
@t{_description} is called with more than three arguments,
the additional @var{specs} should be of the form `@var{char}@t{:}@var{str}'
and every appearance of `@t{%}@var{char}' in the format string will be
replaced by @var{string}.

@noindent
The options placed in the array will also make sure that the matches
are placed in a separate group, depending on the value of the
@t{group-name} style.  Normally a sorted group will be used for this
(with the `@t{-J}' option), but if an option starting with `@t{-V}',
`@t{-J}', `@t{-1}', or `@t{-2}' is given, that option will be included
in the array, so that it is possible to make the group unsorted by
giving the option `@t{-V}', `@t{-1V}', or `@t{-2V}'. 

@noindent
In most cases, the function will be used like this:

@noindent
@example
local expl
_description files expl file
compadd "$expl[@@]" - "$files[@@]"
@end example

@noindent
Note the use of the parameter @t{expl}, the hyphen, and the list of
matches.  Almost all calls to @t{compadd} within the completion system use
a similar format; this ensures that user-specified styles are correctly
passed down to the builtins which implement the internals of completion.

@findex _files
@item @t{_files}
The function @t{_files} uses the @t{file-patterns} style and calls
@t{_path_files} with all the arguments it was passed except for @t{-g} 
and @t{-/}.  These two options are used depending on the setting of the 
@t{file-patterns} style.

@noindent
See @t{_path_files} below for a description of the full set of options
accepted by @t{_files}.

@findex _gnu_generic
@item @t{_gnu_generic}
This function is a simple wrapper around the @t{_arguments} function
described above.  It can be used to automatically complete long
options for commands that understand the `@t{-}@t{-help}' option.
It is not intended to be used from completion functions but as a
top-level completion function in its own right.  For example, to
enable option completion for the commands @t{foo} and @t{bar}, one
would call:

@noindent
@example
compdef _gnu_generic foo bar
@end example

@noindent
in one of the initialization files after the call to @t{compinit}.

@noindent
The default installation uses this function only to generate
completions for some GNU-commands because to complete the options, the 
command has to be called and hence it shouldn't be used if one can't
be sure that the command understands the `@t{-}@t{-help}' option.

@findex _guard
@item @t{_guard} [ @var{options} ] @var{pattern} [ @var{descr} ]
This function is intended to be used in an action of functions like
@t{_arguments}.  It returns immediately with a non-zero return value if
the string to be completed does not match the @var{pattern}.  If the
pattern matches, the @var{descr} is displayed and the function returns
zero if the word to complete is not empty and non-zero otherwise.

@noindent
The @var{pattern} may be preceded by those options understood by
@t{compadd} that are passed down from @t{_description}, namely @t{-M},
@t{-J}, @t{-V}, @t{-1}, @t{-2}, @t{-n}, @t{-F} and @t{-X}.  All of these
options, except @t{-X}, will be ignored.  If the @t{-X} option appears,
the description following it will be used as the string to display if
the @var{pattern} matches, unless the option @var{descr} is given to
@t{_guard} itself, which will then take precedence.

@noindent
As an example, consider a command taking the options @t{-n} and
@t{-none}, where @t{-n} has to be followed by a numeric value in the
same word.  By using either of:

@noindent
@example
_argument '-n-:numeric value:_guard "[0-9]#"' '-none'
@end example

@noindent
or

@noindent
@example
_argument '-n-: :_guard "[0-9]#" "numeric value"' '-none'
@end example

@noindent
@t{_arguments} can be made to both display the message `@t{numeric
value}' and complete options after `@t{-n<TAB>}'.  If the `@t{-n}' is
already followed by one or more digits (matching the pattern given to
@t{_guard}), only the message will be displayed and if the `@t{-n}' is
followed by another character, only options are completed.

@findex _message
@item @t{_message} [ -r ] @var{descr}
The @var{descr} is used like the third
argument to the @t{_description} function. However, the resulting
string will always be shown whether or not matches were
generated. This is useful to display help texts in places where no
completions can be generated automatically.

@noindent
This function also uses the @t{format} style for the @t{messages} tag in
preference to the @t{format} style for the @t{descriptions} tag. The
latter is used only if the former is unset.

@noindent
If the @t{-r} option is given, no style is used and the @var{descr} is
used literally as the string to display. This is only used in cases
where that string is taken from some pre-processed argument list
containing an expanded description.

@findex _multi_parts
@item @t{_multi_parts} @var{sep} @var{array}
This function receives two arguments: a separator character and an
array.  As usual, the @var{array} may be either the
name of an array parameter or a literal array in the form
`@t{(foo bar}@t{)}' (i.e. a list of words separated by white 
space in parentheses).  With these arguments, this function will
complete to strings from the array where the parts separated by the
separator character are completed independently.  For example, the
@t{_tar} function from the distribution caches the pathnames from the
tar file in an array, and then calls this function to complete these
names in the way normal filenames are completed by the
@t{_path_files} function, by using `@t{_multi_parts} @t{/}
@var{patharray}'.

@noindent
If the @t{-i} option is present, then any time there is a unique match it
will immediately be inserted even if that requires additional separators to
be inserted as well.  When completing from a fixed set of possible
completions which are really words, this is often the expected behaviour;
however, if @t{_multi_parts} should behave like completing pathnames, the
@t{-i} option should not be used.

@noindent
Like other utility functions, this function accepts the `@t{-V}',
`@t{-J}', `@t{-1}', `@t{-2}', `@t{-n}', `@t{-f}', `@t{-X}', `@t{-M}',
`@t{-P}', `@t{-S}', `@t{-r}', `@t{-R}', and `@t{-q}' options and passes
them to the @t{compadd} builtin.

@findex _next_label
@item @t{_next_label} [ @t{-12VJ} ] @var{tag} @var{name} @var{descr} [ @var{options} ... ]
This function should be called repeatedly to generate the tag
labels. On each call it will check if another tag label is to be used 
and, if there is at least one, zero is returned. If no more tag
labels are to be used, a non-zero status is returned.

@noindent
The @t{-12JV} options and the first three arguments are given to the
@t{_description} function using the tag label instead of the first
argument as appropriate. The @var{options} given after the @var{descr}
should be other options to be used for @t{compadd} or whatever
function is to be called to add the matches. @t{_next_label} will store these 
@var{options} in the parameter whose @var{name} is given as the second
argument. This is done in such a way that the description given by the 
user to the @t{tag-order} style is preferred over the one given to
@t{_next_label}.

@noindent
Note that this function must not be called without a previous call to
@t{_tags} or @t{_requested} because it uses the tag label
for the current tag found by these functions.

@noindent
A normal use of this function for the tag labels of the tag @t{foo}
looks like this:

@noindent
@example
local expl ret=1
...
if _requested foo; then
  ...
  while _next_label foo expl '...'; do
    compadd "$expl[@@]" ... && ret=0
  done
  ...
fi
return ret

@end example

@findex _normal
@item @t{_normal}
This function is used for normal command completion.  It has two tasks:
completing the first word on the command line as the name of a command, and
completing the arguments to this command.  In the second case, the name of
the command is looked up to see if special completions exists, including
completions defined for patterns which match the name.  If none is found,
completion is performed for the context @t{-default-}.

@noindent
The function can also be called by other completion functions which need to
treat a range of words as a command line.  For example, the function to
complete after the pre-command specifiers such as @t{nohup} removes the
first word from the @t{words} array, decrements the @t{CURRENT} parameter,
then calls @t{_normal} again, with the effect that `@t{nohup} @var{cmd ...}'
is treated the same way was `@var{cmd ...}'.

@noindent
If the command name matches a pattern, the parameter @t{_compskip} is
checked after the call to the corresponding completion function.  This has
the same effect here as in the @t{-first-} context: if it is set, no more
completion functions are called even if there are no matches so far.

@findex _options
@item @t{_options}
This can be used to complete option names.  It uses a matching
specification that ignores a leading `@t{no}', ignores underscores and 
allows the user to type upper-case letters which will match their
lower-case counterparts.  All arguments passed to this function are
propagated unchanged to the @t{compadd} builtin.

@findex _options_set
@findex _options_unset
@item @t{_options_set} and @t{_options_unset}
These functions complete only set or unset options, with the same
matching specification used in the @t{_options} function.

@noindent
Note that you need to uncomment a few lines in the @t{_main_complete}
function for these functions to work properly.  The lines in question
are used to store the option settings in effect before the completion
widget locally sets the options it needs.  Hence these options are not
generally used by the completion system.

@findex _parameters
@item @t{_parameters}
This should be used to complete parameter names.  @t{_parameters} can
take a @t{-g @var{pattern}} option which specifies that only parameters
whose type matches the @var{pattern} should be completed.  Strings of
the same form as those returned by the @t{t} parameter expansion flag
are used here when matching the type.  All other arguments are passed
unchanged to the @t{compadd} builtin.

@findex _path_files
@item @t{_path_files}
The function @t{_path_files} is used throughout the completion system
to complete filenames.  It allows completion of partial paths.  For
example, the string `@t{/u/i/s/sig}' may be completed to
`@t{/usr/include/sys/signal.h}'.

@noindent
The options accepted by both @t{_path_files} and @t{_files} are:

@noindent
@table @asis
@item @t{-f}
Complete all filenames.  This is the default.

@item @t{-/}
Specifies that only directories should be completed.

@item @t{-g} @var{pattern}
Specifies that only files matching the @var{pattern} should be completed.

@item @t{-W} @var{paths}
Specifies path prefixes that are to be prepended to the string from the
line to generate the filenames but that should not be inserted in the line
or shown in a completion listing.  Here, @var{paths} may be the name of an
array parameter, a literal list of paths enclosed in parentheses or an
absolute pathname.

@item @t{-F}
This option from the @t{compadd} builtin gives direct control over which
filenames should be ignored.  If the option is not present, the
@t{ignored-patterns} style is used.

@end table

@noindent
These functions also accept the `@t{-J}', `@t{-V}', `@t{-1}',
`@t{-2}', `@t{-n}', `@t{-X}', `@t{-M}', `@t{-P}', `@t{-S}', `@t{-q}',
`@t{-r}', and `@t{-R}' options from the @t{compadd} builtin.

@noindent
Finally, the @t{_path_files} function  uses the styles @t{expand},
@t{ambiguous}, @t{special-dirs}, @t{list-suffixes} and @t{file-sort}.

@findex _regex_arguments
@item @t{_regex_arguments} @var{name} @var{specs} ...
This function is a compiler to generate a completion function.  The
first argument specifies the name of the generated function while the
remaining arguments specify a completion as a set of regular
expressions with actions.  The generated function has the structure of a
finite-state machine whose states correspond to the state (i.e. the
context) of the completion. This state machine uses a command line,
which comes from the concatenation of the @t{words} array up to the
current cursor position using null characters as separators with no extra
quotation.  This is analysed and at the end the appropriate action is
executed.

@noindent
Specification arguments take one of following forms, in which
metacharacters such as `@t{(}', `@t{)}', `@t{#}' and `@t{|}'
should be quoted.

@noindent
@table @asis
@item @t{/}@var{pattern}@t{/} [@t{%}@var{lookahead}@t{%}] [@t{-}@var{guard}] [@t{:}@var{tag}@t{:}@var{descr}@t{:}@var{action}]
This is a primitive element, corresponding to one
state of the compiled state machine.  The state is entered if
`@t{(#b)((#B)}@var{pattern}@t{)(#B)}@var{lookahead}@t{*}' matches
the command line string.  If it matches, `@var{guard}' is evaluated and
its return status is examined; if this is successful, the state is entered,
otherwise the test fails and other candidates are tried.  The @var{pattern}
string `@t{[]}' is guaranteed never to match.

@noindent
If the test succeeds and the state is entered, the left part of the
command line string matched as @var{pattern} is removed and the 
next state is tried, proceeding from inside to outside and from left to
right.

@noindent
If no test succeeds and the remaining command line string contains no null
character, the completion target is restricted to the remainder of the
command line string and @var{action}s for the target are executed.
In this case, nothing is actually removed from the command line string
so that any previous or neighbouring state may also have @var{actions}s.
@var{actions}s evaluation are ordered by the @t{tag-order} style and specified
@var{tag} by @t{_alternative}.  So, the various formats supported by
@t{_alternative} can be used in @var{action}.  @var{descr} is used for
setting up the array parameter @t{expl}.

@item @t{/}@var{pattern}@t{/+} [@t{%}@var{lookahead}@t{%}] [@t{-}@var{guard}] [@t{:}@var{tag}@t{:}@var{descr}@t{:}@var{action}]
This is similar to `@t{/}@var{pattern}@t{/} ...' but the left part of the
command line string is also considered as part of the completion target.

@item @t{/}@var{pattern}@t{/-} [@t{%}@var{lookahead}@t{%}] [@t{-}@var{guard}] [@t{:}@var{tag}@t{:}@var{descr}@t{:}@var{action}]
This is similar to `@t{/}@var{pattern}@t{/} ...' but the @var{action}s of the
current and previous states are ignored even if the following state's
`@var{pattern}' matches the empty string.

@item @t{(} @var{spec} @t{)}
This groups @var{spec}s.

@item @var{spec} @t{#}
This allows any number of repetitions of @var{spec}.

@item @var{spec} @var{spec}
This represents the concatenation of two @var{spec}s.

@item @var{spec} @t{|} @var{spec}
Either of the two @var{spec}s can be matched.

@end table

@findex _requested
@item @t{_requested} [ @t{-12VJ} ] @var{tag} [ @var{name} @var{descr} [ @var{command} @var{args} ... ] ]
This function is called to decide whether a tag already registered by a
call to @t{_tags} (see below) is requested and hence completion should be
performed for it; it returns status zero if the tag is requested and
non-zero otherwise.  This will usually be done in a loop such as the
following:

@noindent
@example
_tags foo bar baz
while _tags; do
  if _requested foo; then
    ... # perform completion for foo
  fi
  ... # test the tags bar and baz in the same way
  ... # exit loop if matches were generated
done
@end example

@noindent
Note that the test for whether matches were generated is not performed
until the end of the @t{_tags} loop.  This is so that the user can specify
a set of tags to be tested at the same time in the @t{tag-order}
parameter.

@noindent
If the @var{name} and the @var{descr} are given, @t{_requested} calls the
@t{_description} function with these arguments, including the options.

@noindent
If the @var{command} is given, the @t{_all_labels} function will be called
immediately with the same arguments.  This is often useful to do both the
testing of the tag, getting the description for the matches and adding the
matches at once.  For example:

@noindent
@example
local expl ret=1
_tags foo bar baz
while _tags; do
  _requested foo expl 'description' \ 
      compadd foobar foobaz && ret=0
  ...
  (( ret )) || break
done
@end example

@noindent
Note that this means that the @var{command} has to accept the options
that have to be passed down to @t{compadd}.

@findex _retrieve_cache
@item @t{_retrieve_cache} @var{cache_identifier}
This function retrieves completion information from the file given by
@var{cache_identifier}, stored in a directory specified by the
@t{cache-path} style (defaults to @t{~/.zsh/cache}).  The return value
is zero if retrieval was successful.  It will only attempt retrieval
if the @t{use-cache} style is set, so you can call this function
without worrying about whether the user wanted to use the caching
layer.

@noindent
See @t{_store_cache} below for more details.

@findex _sep_parts
@item @t{_sep_parts}
This function is passed alternating arrays and separators as arguments.
The arrays specify completions for parts of strings to be separated by the
separators.  The arrays may be the names of array parameters or
a quoted list of words in parentheses.  For example, with the array
`@t{hosts=(ftp news)}' the call `@t{_sep_parts '(foo bar)' @@ hosts}' will
complete the string  `@t{f}' to `@t{foo}' and the string `@t{b@@n}' to
`@t{bar@@news}'.

@noindent
This function passes the `@t{-V}', `@t{-J}', `@t{-1}', `@t{-2}',
`@t{-n}', `@t{-X}', `@t{-M}', `@t{-P}', `@t{-S}', `@t{-r}', `@t{-R}',
and `@t{-q}' options and their arguments to the @t{compadd} builtin
used to add the matches.

@findex _setup
@item @t{_setup} @var{tag} [ @var{group} ]
This function expects a tag as its argument and sets up the special
parameters used by the completion system appropriately for the tag,
using styles such as @t{list-colors} and @t{last-prompt}.

@noindent
The optional @var{group} gives the name of the group in which the
matches will be placed. If it is not given, the @var{tag} is used as
the group name.

@noindent
Note that this function is called automatically from @t{_description}
so that one normally doesn't have to call it explicitly.

@findex _store_cache
@item @t{_store_cache} @var{cache_identifier} @var{vars} ...
This function, when combined with @t{_retrieve_cache} and
@t{_cache_invalid}, makes it easy to implement a caching layer for
your completion functions.  If a completion function needs to perform
a costly operation in order to generate data which is used to
calculate completions, you can store that data in variables, and use
this function to dump the values of those variables to a file.  Then,
if they are needed in subsequent shell invocations, they can be
retrieved quickly from that file via @t{_retrieve_cache}, avoiding the
need for repeating the costly operation.

@noindent
The @var{cache_identifier} specifies the file which the data should be
dumped to, and is stored in a directory specified by the
@t{cache-path} style (defaults to @t{~/.zsh/cache}).  The remaining
@var{vars} arguments are the variables to dump to the file.

@noindent
The return value is zero if storage was successful.  The function will
only attempt storage if the @t{use-cache} style is set, so you can
call this function without worrying about whether the user wanted to
use the caching layer.

@noindent
If your completion function avoids calling _retrieve_cache when it
already has the completion data in the environment, it should probably
at least call @t{_cache_invalid} to check whether this data and the
data cached on disk is still valid.

@noindent
See the _perl_modules completion function for a simple example of
usage of this caching layer.

@findex _tags
@item @t{_tags} [ @t{-C} @var{name} [ @var{tags} ... ] ]
If called with arguments, these are taken as the names of the tags for 
the types of matches the calling completion function can generate in
the current context.  These tags are stored internally and sorted by
using the @t{tag-order} style.  Following calls to this function
without arguments from the same function will then select the first,
second, etc. set of tags requested by the user.  To test if a certain
tag should be tried, the @t{_requested} function has to be called (see 
above).

@noindent
The return value is zero if at least one of the tags is requested and
non-zero otherwise. 

@noindent
This function also accepts the @t{-C} option followed by a
@var{name}. This name is temporarily (i.e. not visible outside
@t{_tags}) stored in the argument field of the context name in the
@t{curcontext} parameter. This allows @t{_tags} to be made to use a more
specific context name without having to change and reset the
@t{curcontext} parameter (which would otherwise have the same effect).

@findex _values
@item @t{_values} @var{specs} ...
This is used to complete values (strings) and their arguments or
lists of such values.  It can be used in two ways.

@noindent
If the first argument is the option `@t{-O} @var{name}', this will be used
in the same way as by the @t{_arguments} function, in other words the
elements of the @var{name} array will be given to calls to @t{compadd}
and when executing an action.

@noindent
Otherwise, if the first argument (or the first argument after the
`@t{-O} @var{name}' option if that is used) is the option `@t{-s}', the
next argument is used as the character that separates multiple values.
Thus the values completed appear in the same word on the command line,
unlike completion using @t{_arguments}.

@noindent
The first argument (after the options and separator character if they
are given) is used as a string to print as a description before
listing the values.

@noindent
All other arguments describe the possible values and their
arguments in the same format used for the description of options by
the @t{_arguments} function (see above).  The only differences are that
no minus or plus sign is required at the beginning, that
values can have only one argument and that those forms of actions
beginning with an equal sign are not supported.

@noindent
The character separating a value from its argument can be set using the
option @t{-S} (like @t{-s}, followed by the character to use as the
separator in the next argument).  If this option is not used, the equal
sign will be used as the separator.

@noindent
Example:

@noindent
@example
_values -s , 'description' \ 
        '*foo[bar]' \ 
        '(two)*one[number]:first count:' \ 
        'two[another number]::second count:(1 2 3)'
@end example

@noindent
This describes three possible values: `@t{foo}', `@t{one}', and
`@t{two}'.  The first is described as `@t{bar}', takes no argument 
and may appear more than once.  The second is described as
`@t{number}', may appear more than once, and takes one mandatory
argument described as `@t{first count}' for which no action is
specified so that it will not be completed automatically.  The
`@t{(two)}' at the beginning says that if the value `@t{one}' is on
the line, the value `@t{two}' will not be considered to be a possible
completion anymore.  Finally, the last value (`@t{two}') is described
as `@t{another number}' and takes an optional argument described as
`@t{second count}' which will be completed from the strings `@t{1}',
`@t{2}', and `@t{3}'. The @t{_values} function will complete lists of
these values separated by commas.

@noindent
Like @t{_arguments} this function temporarily adds another context
name component to the current context name while executing the
@var{action}.  Here this name is just the name of the value for which
the argument is completed.

@noindent
To decide if the descriptions for the values (not those for the
arguments) should be printed, the style @t{verbose} is used.

@noindent
One last difference from @t{_arguments} is that this function uses the
associative array
@t{val_args} to report values and their arguments, although otherwise this
is the same as the @t{opt_args} association used by
@t{_arguments}.  This also means that the function calling @t{_values} 
should declare the @t{state}, @t{line}, @t{context} and @t{val_args}
parameters as in:

@noindent
@example
local context state line
typeset -A val_args
@end example

@noindent
when using an action of the form `@t{->}@var{string}'.  With this
function the @t{context} parameter will be set to the name of the
value whose argument is to be completed.

@noindent
Note also that @t{_values} normally adds the character used as the
separator between values as an auto-removable suffix so that users don't
have to type it themselves.  But when using a `@t{->}@var{string}' action
@t{_values} can't do that because the matches for the argument will be
generated by the calling function.  To get the usual behaviour, the
implementor of the calling function has to add the suffix directly by
passing the options `@t{-qS} @var{x}' (where @var{x} is the separator
character specified with the @t{-s} option of @t{_values}) to the
function generating the matches or to the @t{compadd} builtin.

@noindent
Like @t{_arguments}, @t{_values} supports the @t{-C} option in
which case you have to make the parameter @t{curcontext} local instead 
of @t{context} (as described above).

@findex _wanted
@item @t{_wanted} [ @t{-C} @var{name} ]  [ @t{-12VJ} ] @var{tag} @var{name} @var{descr} @var{command} @var{args} ...
In many contexts, completion will generate one particular set of
matches (usually corresponding to a single tag); however, it is
still necessary to decide whether the user requires matches of this type.
This function is useful in such a case.

@noindent
Like @t{_requested}, it should be passed arguments as for @t{_description}.
It calls @t{_tags} with the given @var{tag} and if that returns zero 
(so that the @var{tag} is requested by the user) it calls
@t{_description}.  Hence to offer only one tag and immediately
use the description generated:

@noindent
@example
_wanted tag expl 'description' \ 
    compadd matches...
@end example

@noindent
Unlike @t{_requested}, however, @t{_wanted} cannot be called without
the @var{command}.  This is because @t{_wanted} also implements the loop
over the tags, not just the one for the labels; conversely, it should not
be called in the middle of a @t{_tags} loop.

@noindent
Note that, as for @t{_requested}, the @var{command} has to accept the options
that have to be passed down to @t{compadd}.

@noindent
Like @t{_tags} this function supports the @t{-C} option to give a
different name for the argument context field.

@end table

@noindent
@node Completion Directories, , Completion Functions, Completion System

@section Completion Directories
@noindent
@cindex completion system, directory structure

@noindent
In the source distribution, the files are contained in various
subdirectories of the @t{Completion} directory.  They may have been
installed in the same structure, or into one single function directory.
The following is a description of the files found in the original directory
structure.  If you wish to alter an installed file, you will need to copy
it to some directory which appears earlier in your @t{fpath} than the
standard directory where it appears.

@noindent
@table @asis
@item @t{Base}
The core functions and special completion widgets automatically bound
to keys.  You will certainly need most of these, though will
probably not need to alter them.  Many of these are documented above.

@item @t{Zsh}
Functions for completing arguments of shell builtin commands and
utility functions for this.  Some of these are also used by functions from
the @t{Unix} directory.

@item @t{Unix}
Functions for completing arguments of external commands and suites of
commands.  They may need modifying for your system, although in many cases
some attempt is made to decide which version of a command is present.  For
example, completion for the @t{mount} command tries to determine the system
it is running on, while completion for many other utilities try to decide
whether the GNU version of the command is in use, and hence whether the
@t{--help} option is supported..

@item @t{X}, @t{AIX}, @t{BSD}, ...
Completion and utility function for commands available only on some systems.

@end table
@c (avoiding a yodl bug)
@c Yodl file: Zsh/compctl.yo
@node Completion Using compctl, Zsh Modules, Completion System, Top

@chapter Completion Using compctl
@noindent
@cindex completion, programmable
@cindex completion, controlling

@section Types of completion
@noindent
This version of zsh has two ways of performing completion of words on the
command line.  New users of the shell may prefer to use the newer
and more powerful system based on shell functions; this is described
in @ref{Completion System}, and the basic shell mechanisms which support
it are described in @ref{Completion Widgets}.  This chapter describes
the older @t{compctl} command.
@findex compctl

@section Description
@noindent
@table @asis
@item @t{compctl} [ @t{-CDT} ] @var{options} [ @var{command} ... ]
@item @t{compctl} [ @t{-CDT} ] @var{options} [ @t{-x} @var{pattern} @var{options} @t{-} ... @t{--} ] [ @t{+} @var{options} [ @t{-x} ... @t{--} ] ... [@t{+}] ] [ @var{command} ... ]
@item @t{compctl} @t{-M} @var{match-specs} ...
@item @t{compctl} @t{-L} [ @t{-CDTM} ] [ @var{command} ... ]
@item @t{compctl} @t{+} @var{command} ...
@item
@end table

@noindent
Control the editor's completion behavior according to the supplied set
of @var{options}.  Various editing commands, notably
@t{expand-or-complete-word}, usually bound to tab, will
attempt to complete a word typed by the user, while others, notably
@t{delete-char-or-list}, usually bound to ^D in EMACS editing
mode, list the possibilities; @t{compctl} controls what those
possibilities are.  They may for example be filenames (the most common
case, and hence the default), shell variables, or words from a
user-specified list.
@menu
* Command Flags::
* Option Flags::
* Alternative Completion::
* Extended Completion::
* Example::
@end menu

@noindent
@node Command Flags, Option Flags, , Completion Using compctl

@section Command Flags
@noindent
Completion of the arguments of a command may be different for each
command or may use the default.  The behavior when completing the
command word itself may also be separately specified.  These
correspond to the following flags and arguments, all of which (except
for @t{-L}) may be combined with any combination of the
@var{options} described subsequently in @ref{Option Flags}:

@noindent
@table @asis
@item @var{command} ...
controls completion for the named commands, which must be listed last
on the command line.  If completion is attempted for a command with a
pathname containing slashes and no completion definition is found, the
search is retried with the last pathname component. If the command starts
with a @t{=}, completion is tried with the pathname of the command.

@noindent
Any of the @var{command} strings may be patterns of the form normally
used for filename generation.  These should be be quoted to protect them
from immediate expansion; for example the command string @t{'foo*'}
arranges for completion of the words of any command beginning with
@t{foo}.  When completion is attempted, all pattern completions are
tried in the reverse order of their definition until one matches.  By
default, completion then proceeds as normal, i.e. the shell will try to
generate more matches for the specific command on the command line; this
can be overridden by including @t{-tn} in the flags for the pattern
completion.

@noindent
Note that aliases
are expanded before the command name is determined unless the
@t{COMPLETE_ALIASES} option is set.  Commands may not be combined
with the @t{-C}, @t{-D} or @t{-T} flags.

@item @t{-C}
controls completion when the command word itself is being completed.
If no @t{compctl -C} command has been issued,  the names of any
executable command (whether in the path or specific to the shell, such
as aliases or functions) are completed.

@item @t{-D}
controls default completion behavior for the arguments of commands not
assigned any special behavior.  If no @t{compctl -D} command has
been issued, filenames are completed.

@item @t{-T}
supplies completion flags to be used before any other processing is
done, even before processing for @t{compctl}s defined for specific
commands.  This is especially useful when combined with extended
completion (the @t{-x} flag, see @ref{Extended Completion} below).
Using this flag you can define default behavior
which will apply to all commands without exception, or you can alter
the standard behavior for all commands.  For example, if your access
to the user database is too slow and/or it contains too many users (so
that completion after `@t{~}' is too slow to be usable), you can use

@noindent
@example
compctl -T -x 's[~] C[0,[^/]#]' -k friends -S/ -tn
@end example

@noindent
to complete the strings in the array @t{friends} after a `@t{~}'.
The @t{C[...]} argument is necessary so that this form of ~-completion is
not tried after the directory name is finished.

@item @t{-L}
lists the existing completion behavior in a manner suitable for
putting into a start-up script; the existing behavior is not changed.
Any combination of the above forms, or the @t{-M} flag (which must
follow the @t{-L} flag), may be specified, otherwise all defined
completions are listed.  Any other flags supplied are ignored.

@item @emph{no argument}
If no argument is given, @t{compctl} lists all defined completions
in an abbreviated form;  with a list of @var{options}, all completions
with those flags set (not counting extended completion) are listed.

@end table

@noindent
If the @t{+} flag is alone and followed immediately by the @var{command}
list, the completion behavior for all the commands in the list is reset to
the default.  In other words, completion will subsequently use the
options specified by the @t{-D} flag.

@noindent
The form with @t{-M} as the first and only option defines global
matching specifications (see
@ref{Matching Control}). The match specifications given will be used for every completion
attempt (only when using @t{compctl}, not with the new completion
system) and are tried in the order in which they are defined until one 
generates at least one match. E.g.:

@noindent
@example
compctl -M @value{dsq} 'm:@{a-zA-Z@}=@{A-Za-z@}'
@end example

@noindent
This will first try completion without any global match specifications 
(the empty string) and, if that generates no matches, will try case
insensitive completion.

@noindent
@node Option Flags, Alternative Completion, Command Flags, Completion Using compctl

@section Option Flags
@noindent
@table @asis
@item [ @t{-fcFBdeaRGovNAIOPZEnbjrzu/12} ]
@item [ @t{-k} @var{array} ] [ @t{-g} @var{globstring} ] [ @t{-s} @var{subststring} ]
@item [ @t{-K} @var{function} ]
@item [ @t{-Q} ] [ @t{-P} @var{prefix} ] [ @t{-S} @var{suffix} ]
@item [ @t{-W} @var{file-prefix} ] [ @t{-H} @var{num pattern} ]
@item [ @t{-q} ] [ @t{-X} @var{explanation} ] [ @t{-Y} @var{explanation} ]
@item [ @t{-y} @var{func-or-var} ] [ @t{-l} @var{cmd} ] [ @t{-h} @var{cmd} ] [ @t{-U} ]
@item [ @t{-t} @var{continue} ] [ @t{-J} @var{name} ] [ @t{-V} @var{name} ]
@item [ @t{-M} @var{match-spec} ]
@item
@end table

@noindent
The remaining @var{options} specify the type of command arguments
to look for during completion.  Any combination of these flags may be
specified; the result is a sorted list of all the possibilities.  The
options are as follows.
@menu
* Simple Flags::
* Flags with Arguments::
* Control Flags::
@end menu

@noindent
@node Simple Flags, Flags with Arguments, , Option Flags

@subsection Simple Flags
@noindent
These produce completion lists made up by the shell itself:

@noindent
@table @asis
@item @t{-f}
Filenames and filesystem paths.

@item @t{-/}
Just filesystem paths.

@item @t{-c}
Command names, including aliases, shell functions, builtins
and reserved words.

@item @t{-F}
Function names.

@item @t{-B}
Names of builtin commands.

@item @t{-m}
Names of external commands.

@item @t{-w}
Reserved words.

@item @t{-a}
Alias names.

@item @t{-R}
Names of regular (non-global) aliases.

@item @t{-G}
Names of global aliases.

@item @t{-d}
This can be combined with @t{-F}, @t{-B}, @t{-w},
@t{-a}, @t{-R} and @t{-G} to get names of disabled
functions, builtins, reserved words or aliases.

@item @t{-e}
This option (to show enabled commands) is in effect by default, but
may be combined with @t{-d}; @t{-de} in combination with
@t{-F}, @t{-B}, @t{-w}, @t{-a}, @t{-R} and @t{-G}
will complete names of functions, builtins, reserved words or aliases
whether or not they are disabled.

@item @t{-o}
Names of shell options (see
@ref{Options}).

@item @t{-v}
Names of any variable defined in the shell.

@item @t{-N}
Names of scalar (non-array) parameters.

@item @t{-A}
Array names.

@item @t{-I}
Names of integer variables.

@item @t{-O}
Names of read-only variables.

@item @t{-p}
Names of parameters used by the shell (including special parameters).

@item @t{-Z}
Names of shell special parameters.

@item @t{-E}
Names of environment variables.

@item @t{-n}
Named directories.

@item @t{-b}
Key binding names.

@item @t{-j}
Job names:  the first word of the job leader's command line.  This is useful
with the @t{kill} builtin.

@item @t{-r}
Names of running jobs.

@item @t{-z}
Names of suspended jobs.

@item @t{-u}
User names.

@end table

@noindent
@node Flags with Arguments, Control Flags, Simple Flags, Option Flags

@subsection Flags with Arguments
@noindent
These have user supplied arguments to determine how the list of
completions is to be made up:

@noindent
@table @asis
@item @t{-k} @var{array}
Names taken from the elements of @t{$}@var{array} (note that the `@t{$}'
does not appear on the command line).
Alternatively, the argument @var{array} itself may be a set
of space- or comma-separated values in parentheses, in which any
delimiter may be escaped with a backslash; in this case the argument
should be quoted.  For example,

@noindent
@example
compctl -k "(cputime filesize datasize stacksize
	       coredumpsize resident descriptors)" limit
@end example

@item @t{-g} @var{globstring}
The @var{globstring} is expanded using filename globbing; it should be
quoted to protect it from immediate expansion. The resulting
filenames are taken as the possible completions.  Use `@t{*(/)}' instead of
`@t{*/}' for directories.  The @t{fignore} special parameter is not
applied to the resulting files.  More than one pattern may be given
separated by blanks. (Note that brace expansion is @emph{not} part of
globbing.  Use the syntax `@t{(either|or)}' to match alternatives.)

@item @t{-s} @var{subststring}
The @var{subststring} is split into words and these words are than
expanded using all shell expansion mechanisms (see
@ref{Expansion}).  The resulting words are taken as possible
completions.  The @t{fignore} special parameter is not applied to the
resulting files.  Note that @t{-g} is faster for filenames.

@item @t{-K} @var{function}
@vindex reply, use of
Call the given function to get the completions.  Unless the name
starts with an underscore, the function is
passed two arguments: the prefix and the suffix of the word on which
completion is to be attempted, in other words those characters before
the cursor position, and those from the cursor position onwards.  The
whole command line can be accessed with the @t{-c} and @t{-l} flags
of the @t{read} builtin. The
function should set the variable @t{reply} to an array containing
the completions (one completion per element); note that @t{reply}
should not be made local to the function.  From such a function the
command line can be accessed with the @t{-c} and @t{-l} flags to
the @t{read} builtin.  For example,

@noindent
@example
function whoson @{ reply=(`users`); @}
compctl -K whoson talk
@end example

@noindent
completes only logged-on users after `@t{talk}'.  Note that `@t{whoson}' must
return an array, so `@t{reply=`users`}' would be incorrect.

@item @t{-H} @var{num pattern}
The possible completions are taken from the last @var{num} history
lines.  Only words matching @var{pattern} are taken.  If @var{num} is
zero or negative the whole history is searched and if @var{pattern} is
the empty string all words are taken (as with `@t{*}').  A typical
use is

@noindent
@example
compctl -D -f + -H 0 @value{dsq}
@end example

@noindent
which forces completion to look back in the history list for a word if
no filename matches.

@end table

@noindent
@node Control Flags, , Flags with Arguments, Option Flags

@subsection Control Flags
@noindent
These do not directly specify types of name to be completed, but
manipulate the options that do:

@noindent
@table @asis
@item @t{-Q}
This instructs the shell not to quote any metacharacters in the possible
completions.  Normally the results of a completion are inserted into
the command line with any metacharacters quoted so that they are
interpreted as normal characters.  This is appropriate for filenames
and ordinary strings.  However, for special effects, such as inserting
a backquoted expression from a completion array (@t{-k}) so that
the expression will not be evaluated until the complete line is
executed, this option must be used.

@item @t{-P} @var{prefix}
The @var{prefix} is inserted just before the completed string; any
initial part already typed will be completed and the whole @var{prefix}
ignored for completion purposes.  For example,

@noindent
@example
compctl -j -P "%" kill
@end example

@noindent
inserts a `%' after the kill command and then completes job names.

@item @t{-S} @var{suffix}
When a completion is found the @var{suffix} is inserted after
the completed string.  In the case of menu completion the suffix is
inserted immediately, but it is still possible to cycle through the
list of completions by repeatedly hitting the same key.

@item @t{-W} @var{file-prefix}
With directory @var{file-prefix}:  for command, file, directory and
globbing completion (options @t{-c}, @t{-f}, @t{-/}, @t{-g}), the file
prefix is implicitly added in front of the completion.  For example,

@noindent
@example
compctl -/ -W ~/Mail maildirs
@end example

@noindent
completes any subdirectories to any depth beneath the directory
@t{~/Mail}, although that prefix does not appear on the command line.
The @var{file-prefix} may also be of the form accepted by the @t{-k}
flag, i.e. the name of an array or a literal list in parenthesis. In
this case all the directories in the list will be searched for
possible completions.

@item @t{-q}
If used with a suffix as specified by the @t{-S} option, this
causes the suffix to be removed if the next character typed is a blank
or does not insert anything or if the suffix consists of only one character
and the next character typed is the same character; this the same rule used
for the @t{AUTO_REMOVE_SLASH} option.  The option is most useful for list
separators (comma, colon, etc.).

@item @t{-l} @var{cmd}
This option restricts the range
of command line words that are considered to be arguments.  If
combined with one of the extended completion patterns `@t{p[}...@t{]}',
`@t{r[}...@t{]}', or `@t{R[}...@t{]}'  (see @ref{Extended Completion}
below) the range is restricted to the range of arguments
specified in the brackets.  Completion is then performed as if these
had been given as arguments to the @var{cmd} supplied with the
option. If the @var{cmd} string is empty the first word in the range
is instead taken as the command name, and command name completion
performed on the first word in the range.  For example,

@noindent
@example
compctl -x 'r[-exec,;]' -l @value{dsq} -- find
@end example

@noindent
completes arguments between `@t{-exec}' and the following `@t{;}' (or the end
of the command line if there is no such string) as if they were
a separate command line.

@item @t{-h} @var{cmd}
Normally zsh completes quoted strings as a whole. With this option,
completion can be done separately on different parts of such
strings. It works like the @t{-l} option but makes the completion code 
work on the parts of the current word that are separated by
spaces. These parts are completed as if they were arguments to the
given @var{cmd}. If @var{cmd} is the empty string, the first part is
completed as a command name, as with @t{-l}.

@item @t{-U}
Use the whole list of possible completions, whether or not they
actually match the word on the command line.  The word typed so far
will be deleted.  This is most useful with a function (given by the
@t{-K} option) which can examine the word components passed to it
(or via the @t{read} builtin's @t{-c} and @t{-l} flags) and
use its own criteria to decide what matches.  If there is no
completion, the original word is retained.  Since the produced 
possible completions seldom have interesting common prefixes
and suffixes, menu completion is started immediately if @t{AUTO_MENU} is
set and this flag is used.

@item @t{-y} @var{func-or-var}
@vindex reply, use of
The list provided by @var{func-or-var} is displayed instead of the list
of completions whenever a listing is required; the actual completions
to be inserted are not affected.  It can be provided in two
ways. Firstly, if @var{func-or-var} begins with a @t{$} it defines a
variable, or if it begins with a left parenthesis a literal
array, which contains the list.  A variable may have been set by a
call to a function using the @t{-K} option.  Otherwise it contains the
name of a function which will be executed to create the list.  The
function will be passed as an argument list all matching completions,
including prefixes and suffixes expanded in full, and should set the
array @t{reply} to the result.  In both cases, the display list will
only be retrieved after a complete list of matches has been created.

@noindent
Note that the returned list does not have to correspond, even in
length, to the original set of matches, and may be passed as a scalar
instead of an array.  No special formatting of characters is
performed on the output in this case; in particular, newlines are
printed literally and if they appear output in columns is suppressed.

@item @t{-X} @var{explanation}
Print @var{explanation} when trying completion on the current set of
options. A `@t{%n}' in this string is replaced by the number of
matches that were added for this explanation string.
The explanation only appears if completion was tried and there was
no unique match, or when listing completions. Explanation strings 
will be listed together with the matches of the group specified
together with the @t{-X} option (using the @t{-J} or @t{-V}
option). If the same explanation string is given to multiple @t{-X}
options, the string appears only once (for each group) and the number
of matches shown for the `@t{%n}' is the total number of all matches
for each of these uses. In any case, the explanation string will only
be shown if there was at least one match added for the explanation
string.

@noindent
The sequences @t{%B}, @t{%b}, @t{%S}, @t{%s}, @t{%U}, and @t{%u} specify
output attributes (bold, standout, and underline) and @t{%@{...%@}} can
be used to include literal escape sequences as in prompts.

@item @t{-Y} @var{explanation}
Identical to @t{-X}, except that the @var{explanation} first undergoes
expansion following the usual rules for strings in double quotes.
The expansion will be carried out after any functions are called for
the @t{-K} or @t{-y} options, allowing them to set variables.

@item @t{-t} @var{continue}
The @var{continue}-string contains a character that specifies which set
of completion flags should be used next.  It is useful:

@noindent
(i) With @t{-T}, or when trying a list of pattern completions, when
@t{compctl} would usually continue with ordinary processing after
finding matches; this can be suppressed with `@t{-tn}'.

@noindent
(ii) With a list of alternatives separated by @t{+}, when @t{compctl}
would normally stop when one of the alternatives generates matches.  It
can be forced to consider the next set of completions by adding `@t{-t+}'
to the flags of the alternative before the `@t{+}'.

@noindent
(iii) In an extended completion list (see below), when @t{compctl} would
normally continue until a set of conditions succeeded, then use only
the immediately following flags.  With `@t{-t-}', @t{compctl} will
continue trying extended completions after the next `@t{-}'; with
`@t{-tx}' it will attempt completion with the default flags, in other
words those before the `@t{-x}'.

@item @t{-J} @var{name}
This gives the name of the group the matches should be placed in. Groups
are listed and sorted separately; likewise, menu completion will offer
the matches in the groups in the order in which the groups were
defined. If no group name is explicitly given, the matches are stored in
a group named @var{default}. The first time a group name is encountered,
a group with that name is created. After that all matches with the same
group name are stored in that group.

@noindent
This can be useful with non-exclusive alternative completions.  For
example, in

@noindent
@example
compctl -f -J files -t+ + -v -J variables foo
@end example

@noindent
both files and variables are possible completions, as the @t{-t+} forces
both sets of alternatives before and after the @t{+} to be considered at
once.  Because of the @t{-J} options, however, all files are listed
before all variables.

@item @t{-V} @var{name}
Like @t{-J}, but matches within the group will not be sorted in listings
nor in menu completion. These unsorted groups are in a different name
space from the sorted ones, so groups defined as @t{-J files} and @t{-V
files} are distinct.

@item @t{-1}
If given together with the @t{-V} option, makes
only consecutive duplicates in the group be removed. Note that groups
with and without this flag are in different name spaces.

@item @t{-2}
If given together with the @t{-J} or @t{-V} option, makes all
duplicates be kept. Again, groups with and without this flag are in
different name spaces.

@item @t{-M} @var{match-spec}
This defines additional matching control specifications that should be used
only when testing words for the list of flags this flag appears in. The format
of the @var{match-spec} string is described in 
@ref{Matching Control}.

@end table

@noindent
@node Alternative Completion, Extended Completion, Option Flags, Completion Using compctl

@section Alternative Completion
@noindent
@table @asis
@item @t{compctl} [ @t{-CDT} ] @var{options} @t{+} @var{options} [ @t{+} ... ] [ @t{+} ] @var{command} ...
@item
@end table

@noindent
The form with `@t{+}' specifies alternative options. Completion is
tried with the options before the first `@t{+}'. If this produces no
matches completion is tried with the flags after the `@t{+}' and so on. If
there are no flags after the last `@t{+}' and a match has not been found
up to that point, default completion is tried.
If the list of flags contains a @t{-t} with a @t{+} character, the next
list of flags is used even if the current list produced matches.

@noindent
@node Extended Completion, Example, Alternative Completion, Completion Using compctl

@section Extended Completion
@noindent
@table @asis
@item @t{compctl} [ @t{-CDT} ] @var{options} @t{-x} @var{pattern} @var{options} @t{-} ... @t{--}@*
  [ @var{command} ... ]
@item @t{compctl} [ @t{-CDT} ] @var{options} [ @t{-x} @var{pattern} @var{options} @t{-} ... @t{--} ]@*
  [ @t{+} @var{options} [ @t{-x} ... @t{--} ] ... [@t{+}] ] [ @var{command} ... ]
@item
@end table

@noindent
The form with `@t{-x}' specifies extended completion for the
commands given; as shown, it may be combined with alternative
completion using `@t{+}'.  Each @var{pattern} is examined in turn; when a
match is found, the corresponding @var{options}, as described in
@ref{Option Flags} above, are used to generate possible
completions.  If no @var{pattern} matches, the @var{options} given
before the @t{-x} are used.

@noindent
Note that each pattern should be supplied as a single argument and
should be quoted to prevent expansion of metacharacters by the
shell.

@noindent
A @var{pattern} is built of sub-patterns separated by commas; it
matches if at least one of these sub-patterns matches (they are
`or'ed). These sub-patterns are in turn composed of other
sub-patterns separated by white spaces which match if all of the
sub-patterns match (they are `and'ed).  An element of the
sub-patterns is of the form `@var{c}@t{[}...@t{][}...@t{]}', where the pairs of
brackets may be repeated as often as necessary, and matches if any of
the sets of brackets match (an `or').  The example below makes this
clearer.

@noindent
The elements may be any of the following:

@noindent
@table @asis
@item @t{s[}@var{string}@t{]}...
Matches if the current word on the command line starts with
one of the strings given in brackets.  The @var{string} is not removed
and is not part of the completion.

@item @t{S[}@var{string}@t{]}...
Like @t{s[}@var{string}@t{]} except that the @var{string} is part of the
completion.

@item @t{p[}@var{from}@t{,}@var{to}@t{]}...
Matches if the number of the current word is between one of
the @var{from} and @var{to} pairs inclusive. The comma and @var{to}
are optional; @var{to} defaults to the same value as @var{from}.  The
numbers may be negative: @t{-}@var{n} refers to the @var{n}'th last word
on the line.

@item @t{c[}@var{offset}@t{,}@var{string}@t{]}...
Matches if the @var{string} matches the word offset by
@var{offset} from the current word position.  Usually @var{offset}
will be negative.

@item @t{C[}@var{offset}@t{,}@var{pattern}@t{]}...
Like @t{c} but using pattern matching instead.

@item @t{w[}@var{index}@t{,}@var{string}@t{]}...
Matches if the word in position @var{index} is equal
to the corresponding @var{string}.  Note that the word count is made
after any alias expansion.

@item @t{W[}@var{index}@t{,}@var{pattern}@t{]}...
Like @t{w} but using pattern matching instead.

@item @t{n[}@var{index}@t{,}@var{string}@t{]}...
Matches if the current word contains @var{string}.  Anything up to and
including the @var{index}th occurrence of this string will not be
considered part of the completion, but the rest will.  @var{index} may
be negative to count from the end: in most cases, @var{index} will be
1 or -1.  For example,

@noindent
@example
compctl -s '`users`' -x 'n[1,@@]' -k hosts -- talk
@end example

@noindent
will usually complete usernames, but if you insert an @t{@@} after the
name, names from the array @var{hosts} (assumed to contain hostnames,
though you must make the array yourself) will be completed.  Other
commands such as @t{rcp} can be handled similarly.

@item @t{N[}@var{index}@t{,}@var{string}@t{]}...
Like @t{n} except that the string will be
taken as a character class.  Anything up to and including the
@var{index}th occurrence of any of the characters in @var{string}
will not be considered part of the completion.

@item @t{m[}@var{min}@t{,}@var{max}@t{]}...
Matches if the total number of words lies between @var{min} and
@var{max} inclusive.

@item @t{r[}@var{str1}@t{,}@var{str2}@t{]}...
Matches if the cursor is after a word with prefix @var{str1}.  If there
is also a word with prefix @var{str2} on the command line after the one 
matched by @var{str1} it matches
only if the cursor is before this word. If the comma and @var{str2} are
omitted, it matches if the cursor is after a word with prefix @var{str1}.

@item @t{R[}@var{str1}@t{,}@var{str2}@t{]}...
Like @t{r} but using pattern matching instead.

@item @t{q[}@var{str}@t{]}...
Matches the word currently being completed is in single quotes and the 
@var{str} begins with the letter `s', or if completion is done in
double quotes and @var{str} starts with the letter `d', or if
completion is done in backticks and @var{str} starts with a `b'.

@end table

@noindent
@node Example, , Extended Completion, Completion Using compctl

@section Example
@noindent

@noindent
@example
compctl -u -x 's[@t{+}] c[-1,-f],s[-f+]' \ 
  -g '~/Mail/*(:t)' - 's[-f],c[-1,-f]' -f -- mail
@end example

@noindent
This is to be interpreted as follows:

@noindent
If the current command is @t{mail}, then

@noindent
@quotation

@noindent
if ((the current word begins with @t{+} and the previous word is @t{-f})
or (the current word begins with @t{-f+})), then complete the
non-directory part (the `@t{:t}' glob modifier) of files in the directory
@t{~/Mail}; else

@noindent
if the current word begins with @t{-f} or the previous word was @t{-f}, then
complete any file; else

@noindent
complete user names.

@end quotation
@c (avoiding a yodl bug)
@c Yodl file: Zsh/modules.yo
@node Zsh Modules, Zftp Function System, Completion Using compctl, Top

@chapter Zsh Modules
@noindent
@cindex modules

@section Description
@noindent
Some optional parts of zsh are in modules, separate from the core
of the shell.  Each of these modules may be linked in to the
shell at build time,
or can be dynamically linked while the shell is running
if the installation supports this feature.  The modules that
are bundled with the zsh distribution are:

@noindent
@c Yodl file: Zsh/modlist.yo
@table @asis
@item @t{zsh/cap}
Builtins for manipulating POSIX.1e (POSIX.6) capability (privilege) sets.

@item @t{zsh/clone}
A builtin that can clone a running shell onto another terminal.

@item @t{zsh/compctl}
The @t{compctl} builtin for controlling completion.

@item @t{zsh/complete}
The basic completion code.

@item @t{zsh/complist}
Completion listing extensions.

@item @t{zsh/computil}
A module with utility builtins needed for the shell function based
completion system.

@item @t{zsh/deltochar}
A ZLE function duplicating EMACS' @t{zap-to-char}.

@item @t{zsh/example}
An example of how to write a module.

@item @t{zsh/files}
Some basic file manipulation commands as builtins.

@item @t{zsh/mapfile}
Access to external files via a special associative array.

@item @t{zsh/mathfunc}
Standard scientific functions for use in mathematical evaluations.

@item @t{zsh/parameter}
Access to internal hash tables via special associative arrays.

@item @t{zsh/sched}
A builtin that provides a timed execution facility within the shell.

@item @t{zsh/stat}
A builtin command interface to the @t{stat} system call.

@item @t{zsh/termcap}
Interface to the termcap database.

@item @t{zsh/terminfo}
Interface to the terminfo database.

@item @t{zsh/zftp}
A builtin FTP client.

@item @t{zsh/zle}
The Zsh Line Editor, including the @t{bindkey} and @t{vared} builtins.

@item @t{zsh/zleparameter}
Access to internals of the Zsh Line Editor via parameters.

@item @t{zsh/zprof}
A module allowing profiling for shell functions.

@item @t{zsh/zpty}
A builtin for starting a command in a pseudo-terminal.

@item @t{zsh/zutil}
Some utility builtins, e.g. the one for supporting configuration via 
styles.

@end table
@c Yodl file: Zsh/modmenu.yo
@menu
* The zsh/cap Module::
* The zsh/clone Module::
* The zsh/compctl Module::
* The zsh/complete Module::
* The zsh/complist Module::
* The zsh/computil Module::
* The zsh/deltochar Module::
* The zsh/example Module::
* The zsh/files Module::
* The zsh/mapfile Module::
* The zsh/mathfunc Module::
* The zsh/parameter Module::
* The zsh/sched Module::
* The zsh/stat Module::
* The zsh/termcap Module::
* The zsh/terminfo Module::
* The zsh/zftp Module::
* The zsh/zle Module::
* The zsh/zleparameter Module::
* The zsh/zprof Module::
* The zsh/zpty Module::
* The zsh/zutil Module::
@end menu
@c (avoiding a yodl bug)
@node The zsh/cap Module, The zsh/clone Module, , Zsh Modules

@section The zsh/cap Module
@noindent
@c Yodl file: Zsh/mod_cap.yo

The @t{zsh/cap} module is used for manipulating POSIX.1e (POSIX.6) capability
sets.  If the operating system does not support this interface, the
builtins defined by this module will do nothing.
The builtins in this module are:

@noindent
@table @asis
@findex cap
@cindex capabilities, setting
@item @t{cap} [ @var{capabilities} ]
Change the shell's process capability sets to the specified @var{capabilities},
otherwise display the shell's current capabilities.

@findex getcap
@cindex capabilities, getting from files
@item @t{getcap} @var{filename} ...
This is a built-in implementation of the POSIX standard utility.  It displays
the capability sets on each specified @var{filename}.

@findex setcap
@cindex capabilities, setting on files
@item @t{setcap} @var{capabilities} @var{filename} ...
This is a built-in implementation of the POSIX standard utility.  It sets
the capability sets on each specified @var{filename} to the specified
@var{capabilities}.

@end table
@c (avoiding a yodl bug)
@node The zsh/clone Module, The zsh/compctl Module, The zsh/cap Module, Zsh Modules

@section The zsh/clone Module
@noindent
@c Yodl file: Zsh/mod_clone.yo

The @t{zsh/clone} module makes available one builtin command:

@noindent
@table @asis
@findex clone
@cindex shell, cloning
@cindex cloning the shell
@cindex terminal
@item @t{clone} @var{tty}
Creates a forked instance of the current shell, attached to the specified
@var{tty}.  In the new shell, the @t{PID}, @t{PPID} and @t{TTY} special
parameters are changed appropriately.  @t{$!} is set to zero in the new
shell, and to the new shell's PID in the original shell.

@noindent
The return value of the builtin is zero in both shells if successful,
and non-zero on error.

@end table
@c (avoiding a yodl bug)
@node The zsh/compctl Module, The zsh/complete Module, The zsh/clone Module, Zsh Modules

@section The zsh/compctl Module
@noindent
@c Yodl file: Zsh/mod_compctl.yo

The @t{zsh/compctl} module makes available two builtin commands. @t{compctl},
is the old, deprecated way to control completions for ZLE.  See
@ref{Completion Using compctl}.
The other builtin command, @t{compcall} can be used in user-defined
completion widgets, see
@ref{Completion Widgets}.
@c (avoiding a yodl bug)
@node The zsh/complete Module, The zsh/complist Module, The zsh/compctl Module, Zsh Modules

@section The zsh/complete Module
@noindent
@c Yodl file: Zsh/mod_complete.yo

The @t{zsh/complete} module makes available several builtin commands which
can be used in user-defined completion widgets, see
@ref{Completion Widgets}.
@c (avoiding a yodl bug)
@node The zsh/complist Module, The zsh/computil Module, The zsh/complete Module, Zsh Modules

@section The zsh/complist Module
@noindent
@c Yodl file: Zsh/mod_complist.yo

@cindex completion, listing
@cindex completion, coloured listings
@cindex completion, scroll listings
The @t{zsh/complist} module offers three extensions to completion listings:
the ability to highlight matches in such a list, the ability to
scroll through long lists and a different style of menu completion.

@noindent

@subsection Colored completion listings
@noindent
Whenever one of the parameters @t{ZLS_COLORS} or @t{ZLS_COLOURS} is set 
and the @t{zsh/complist} module is loaded or linked into the shell,
completion lists will be colored.  Note, however, that @t{complist} will
not automatically be loaded if it is not linked in:  on systems with
dynamic loading, `@t{zmodload zsh/complist}' is required.

@noindent
@vindex ZLS_COLORS
@vindex ZLS_COLOURS
The parameters @t{ZLS_COLORS} and @t{ZLS_COLOURS} describe how matches
are highlighted.  To turn on highlighting an empty value suffices, in
which case all the default values given below will be used.  The format of
the value of these parameters is the same as used by the GNU version of the
@t{ls} command: a colon-separated list of specifications of the form
`@var{name}=@var{value}'.  The @var{name} may be one of the following strings,
most of which specify file types for which the @var{value} will be used.
The strings and their default values are:

@noindent
@table @asis
@item @t{no 0}
for normal text (i.e. when displaying something other than a matched file)

@item @t{fi 0}
for regular files

@item @t{di 32}
for directories

@item @t{ln 36}
for symbolic links

@item @t{pi 31}
for named pipes (FIFOs)

@item @t{so 33}
for sockets

@item @t{bd 44;37}
for block devices

@item @t{cd 44;37}
for character devices

@item @t{ex 35}
for executable files

@item @t{mi} @var{none}
for a non-existent file (default is the value defined for @t{fi})

@item @t{lc \e[}
for the left code (see below)

@item @t{rc m}
for the right code

@item @t{tc 0}
for the character indicating the file type  printed after filenames if
the @t{LIST_TYPES} option is set

@item @t{sp 0}
for the spaces printed after matches to align the next column

@item @t{ec} @var{none}
for the end code

@end table

@noindent
Apart from these strings, the @var{name} may also be an asterisk
(`@t{*}') followed by any string. The @var{value} given for such a
string will be used for all files whose name ends with the string.
The @var{name} may also be an equals sign (`@t{=}') followed by a
pattern.  The @var{value} given for this pattern will be used for all
matches (not just filenames) whose display string are matched by
the pattern.  Definitions for both of these take precedence over the
values defined for file types and the form with the leading asterisk 
takes precedence over the form with the leading equal sign.

@noindent
The last form also allows different parts of the displayed
strings to be colored differently.  For this, the pattern has to use the
`@t{(#b)}' globbing flag and pairs of parentheses surrounding the
parts of the strings that are to be colored differently.  In this case 
the @var{value} may consist of more than one color code separated by
equal signs.  The first code will be used for all parts for which no
explicit code is specified and the following codes will be used for
the parts matched by the sub-patterns in parentheses.  For example,
the specification `@t{=(#b)(?)*(?)=0=3=7}' will be used for all
matches which are at least two characters long and will use
the code `@t{3}' for the first character, `@t{7}' for the last
character and `@t{0}' for the rest.

@noindent
All three forms of @var{name} may be preceded by a pattern in
parentheses.  If this is given, the @var{value} will be used
only for matches in groups whose names are matched by the pattern
given in the parentheses.  For example, `@t{(g*)m*=43}' highlights all
matches beginning with `@t{m}' in groups whose names  begin with
`@t{g}' using the color code `@t{43}'.  In case of the `@t{lc}',
`@t{rc}', and `@t{ec}' codes, the group pattern is ignored.

@noindent
Note also that all patterns are tried in the order in which they
appear in the parameter value until the first one matches which is
then used.

@noindent
When printing a match, the code prints the value of @t{lc}, the value
for the file-type or the last matching specification with a `@t{*}',
the value of @t{rc}, the string to display for the match itself, and
then the value of @t{ec} if that is defined or the values of @t{lc},
@t{no}, and @t{rc} if @t{ec} is not defined.

@noindent
The default values are ISO 6429 (ANSI) compliant and can be used on
vt100 compatible terminals such as @t{xterm}s.  On monochrome terminals
the default values will have no visible effect.  The @t{colors}
function from the contribution can be used to get associative arrays
containing the codes for ANSI terminals (see
@ref{Other Functions}).  For example, after loading @t{colors}, one could use
`@t{$colors[red]}' to get the code for foreground color red and
`@t{$colors[bg-green]}' for the code for background color green.

@noindent
If the completion system invoked by compinit is used, these
parameters should not be set directly because the system controls them 
itself.  Instead, the @t{list-colors} style should be used (see
@ref{Completion System Configuration}).

@noindent

@subsection Scrolling in completion listings
@noindent
To enable scrolling through a completion list, the @t{LISTPROMPT}
parameter must be set.  Its value will be used as the prompt; if it
is the empty string, a default prompt will be used.  The value may
contain escapes of the form `@t{%x}'.  It supports the escapes
`@t{%B}', `@t{%b}', `@t{%S}', `@t{%s}', `@t{%U}', `@t{%u}' and
`@t{%@{...%@}}' used also in shell prompts as well as three pairs of
additional sequences: a `@t{%l}' or `@t{%L}' is replaced by the number
of the last line shown and the total number of lines in the form
`@var{number}@t{/}@var{total}'; a `@t{%m}' or `@t{%M}' is replaced with
the number of the last match shown and the total number of matches; and 
`@t{%p}' or `@t{%P}' is replaced with `@t{Top}', `@t{Bottom}' or the
position of the first line shown in percent of the total number of
lines, respectively.  In each of these cases the form with the uppercase
letter will be replaced with a string of fixed width, padded to the
right with spaces, while the lowercase form will not be padded.

@noindent
If the parameter @t{LISTPROMPT} is set, the completion code will not ask if
the list should be shown.  Instead it immediately starts displaying the
list, stopping after the first screenful, showing the prompt at the bottom,
waiting for a keypress after temporarily switching to the @t{listscroll}
keymap.  Some of the zle functions have a special meaning while scrolling
lists:

@noindent
@table @asis
@item @t{send-break}
stops listing discarding the key pressed

@item @t{accept-line}, @t{down-history}, @t{down-line-or-history}
@itemx @t{down-line-or-search}, @t{vi-down-line-or-history}
scrolls forward one line

@item @t{complete-word}, @t{menu-complete}, @t{expand-or-complete}
@itemx @t{expand-or-complete-prefix}, @t{menu-complete-or-expand}
scrolls forward one screenful

@end table

@noindent
Every other character stops listing and immediately processes the key
as usual.  Any key that is not bound in the @t{listscroll} keymap or
that is bound to @t{undefined-key} is looked up in the keymap
currently selected.

@noindent
As for the @t{ZLS_COLORS} and @t{ZLS_COLOURS} parameters,
@t{LISTPROMPT} should not be set directly when using the shell
function based completion system.  Instead, the @t{list-prompt} style
should be used.

@noindent

@subsection Menu selection
@noindent
@cindex completion, selecting by cursor
@vindex MENUSELECT
@tindex menu-select
The @t{zsh/complist} module also offers an alternative style of selecting
matches from a list, called menu selection, which can be used if the
shell is set up to return to the last prompt after showing a
completion list (see the @t{ALWAYS_LAST_PROMPT} option in
@ref{Options}).  It can be invoked directly by
the widget @t{menu-select} defined by the module.  Alternatively,
the parameter @t{MENUSELECT} can be set to an integer, which gives the
minimum number of matches that must be present before menu selection is
automatically turned on.  This second method requires that menu completion
be started, either directly from a widget such as @t{menu-complete}, or due
to one of the options @t{MENU_COMPLETE} or @t{AUTO_MENU} being set.  If
@t{MENUSELECT} is set, but is 0, 1 or empty, menu selection will always be
started during an ambiguous menu completion.

@noindent
When using the completion system based on shell functions, the
@t{MENUSELECT} parameter should not be used (like the @t{ZLS_COLORS}
and @t{ZLS_COLOURS} parameters described above).  Instead, the @t{menu} 
style should be used with the @t{select=}@var{...} keyword.

@noindent
After menu selection is started, the matches will be listed. If there
are more matches than fit on the screen, only the first screenful is
shown.  The
matches to insert into the command line can be selected from this
list.  In the list one match is highlighted using the value for @t{ma}
from the @t{ZLS_COLORS} or @t{ZLS_COLOURS} parameter.  The default
value for this is `@t{7}' which forces the selected match to be
highlighted using standout mode on a vt100-compatible terminal.  If
neither @t{ZLS_COLORS} nor @t{ZLS_COLOURS} is set, the same terminal
control sequence as for the `@t{%S}' escape in prompts is used.

@noindent
If there are more matches than fit on the screen and the parameter
@t{MENUPROMPT} is set, its value will be shown below the matches.  It
supports the same escape sequences as @t{LISTPROMPT}, but the number
of the match or line shown will be that of the one where the mark is
placed.  If its value is the empty string, a default prompt will be
used.

@noindent
The @t{MENUSCROLL} parameter can be used to specify how the list is
scrolled.  If the parameter is unset, this is done line by line, if it
is set to `@t{0}' (zero), the list will scroll half the number of
lines of the screen.  If the value is positive, it gives the number of
lines to scroll and if it is negative, the list will be scrolled
the number of lines of the screen minus the (absolute) value.

@noindent
As for the @t{ZLS_COLORS}, @t{ZLS_COLOURS} and @t{LISTPROMPT}
parameters, neither @t{MENUPROMPT} nor @t{MENUSCROLL} should be
set directly when using the shell function based completion
system.  Instead, the @t{select-prompt} and @t{select-scroll} styles
should be used.

@noindent
The completion code sometimes decides not to show all of the matches
in the list.  These hidden matches are either matches for which the
completion function which added them explicitly requested that they
not appear in the list (using the @t{-n} option of the @t{compadd}
builtin command) or they are matches which duplicate a string already
in the list (because they differ only in things like prefixes or
suffixes that are not displayed).  In the list used for menu selection,
however, even these matches are shown so that it is possible to select
them.  To highlight such matches the @t{hi} and @t{du} capabilities in
the @t{ZLS_COLORS} and @t{ZLS_COLOURS} parameters are supported for
hidden matches of the first and second kind, respectively.

@noindent
Selecting matches is done by moving the mark around using the zle movement
functions.  When not all matches can be shown on the screen at the same 
time, the list will scroll up and down when crossing the top or
bottom line.  The following zle functions have special meaning during
menu selection:

@noindent
@table @asis
@item @t{accept-line}
accepts the current match and leaves menu selection

@item @t{send-break}
leaves menu selection and restores the previous contents of the
command line

@item @t{redisplay}, @t{clear-screen}
execute their normal function without leaving menu selection

@item @t{accept-and-hold}, @t{accept-and-menu-complete}
accept the currently inserted match and continue selection allowing to 
select the next match to insert into the line

@item @t{accept-and-infer-next-history}
accepts the current match and then tries completion with
menu selection again;  in the case of files this allows one to select
a directory and immediately attempt to complete files in it;  if there 
are no matches, a message is shown and one can use @t{undo} to go back 
to completion on the previous level, every other key leaves menu
selection (including the other zle functions which are otherwise
special during menu selection)

@item @t{undo}
removes matches inserted during the menu selection by one of the three 
functions before

@item @t{down-history}, @t{down-line-or-history}
@itemx @t{vi-down-line-or-history},  @t{down-line-or-search}
moves the mark one line down

@item @t{up-history}, @t{up-line-or-history}
@itemx @t{vi-up-line-or-history}, @t{up-line-or-search}
moves the mark one line up

@item @t{forward-char}, @t{vi-forward-char}
moves the mark one column right

@item @t{backward-char}, @t{vi-backward-char}
moves the mark one column left

@item @t{forward-word}, @t{vi-forward-word}
@itemx @t{vi-forward-word-end}, @t{emacs-forward-word}
moves the mark one screenful down

@item @t{backward-word}, @t{vi-backward-word}, @t{emacs-backward-word}
moves the mark one screenful up

@item @t{vi-forward-blank-word}, @t{vi-forward-blank-word-end}
moves the mark to the first line of the next group of matches

@item @t{vi-backward-blank-word}
moves the mark to the last line of the previous group of matches

@item @t{beginning-of-history}
moves the mark to the first line

@item @t{end-of-history}
moves the mark to the last line

@item @t{beginning-of-buffer-or-history}, @t{beginning-of-line}
@itemx @t{beginning-of-line-hist}, @t{vi-beginning-of-line}
moves the mark to the leftmost column

@item @t{end-of-buffer-or-history}, @t{end-of-line}
@itemx @t{end-of-line-hist}, @t{vi-end-of-line}
moves the mark to the rightmost column

@item @t{complete-word}, @t{menu-complete}, @t{expand-or-complete}
@itemx @t{expand-or-complete-prefix}, @t{menu-expand-or-complete}
moves the mark to the next match

@item @t{reverse-menu-complete}
moves the mark to the previous match

@end table

@noindent
All movement functions wrap around at the edges; any other zle function not
listed leaves menu selection and executes that function.  It is possible to
make widgets in the above list do the same by using the form of the widget
with a `@t{.}' in front.  For example, the widget `@t{.accept-line}' has
the effect of leaving menu selection and accepting the entire command line.

@noindent
During this selection the widget uses the keymap @t{menuselect}.  Any
key that is not defined in this keymap or that is bound to
@t{undefined-key} is looked up in the keymap currently selected.  This
is used to ensure that the most important keys used during selection
(namely the cursor keys, return, and TAB) have sensible defaults.  However,
keys in the @t{menuselect} keymap can be modified directly using the
@t{bindkey} builtin command (see
@ref{The zsh/zle Module}). For example, to make the return key leave menu selection without
accepting the match currently selected one could call

@noindent
@quotation
@t{bindkey -M menuselect '^M' send-break}
@end quotation

@noindent
after loading the @t{zsh/complist} module.
@c (avoiding a yodl bug)
@node The zsh/computil Module, The zsh/deltochar Module, The zsh/complist Module, Zsh Modules

@section The zsh/computil Module
@noindent
@c Yodl file: Zsh/mod_computil.yo

@cindex completion, utility
The @t{zsh/computil} module adds several builtin commands that are used by
some of the completion functions in the completion system based on shell
functions (see 
@ref{Completion System}
).  Except for @t{compquote} these builtin commands are very
specialised and thus not very interesting when writing your own
completion functions.  In summary, these builtin commands are:

@noindent
@table @asis
@findex comparguments
@item @t{comparguments}
This is used by the @t{_arguments} function to do the argument and
command line parsing.  Like @t{compdescribe} it has an option @t{-i} to 
do the parsing and initialize some internal state and various options
to access the state information to decide what should be completed.

@findex compdescribe
@item @t{compdescribe}
This is used by the @t{_describe} function to build the displays for
the matches and to get the strings to add as matches with their
options.  On the first call one of the options @t{-i} or @t{-I} should be
supplied as the first argument.  In the first case, display strings without
the descriptions will be generated, in the second case, the string used to
separate the matches from their descriptions must be given as the
second argument and the descriptions (if any) will be shown.  All other 
arguments are like the definition arguments to @t{_describe} itself.

@noindent
Once @t{compdescribe} has been called with either the @t{-i} or the
@t{-I} option, it can be repeatedly called with the @t{-g} option and
the names of five arrays as its arguments.  This will step through the
different sets of matches and store the options in the first array,
the strings with descriptions in the second, the matches for these in
the third, the strings without descriptions in the fourth, and the
matches for them in the fifth array.  These are then directly given to
@t{compadd} to register the matches with the completion code.

@findex compfiles
@item @t{compfiles}
Used by the @t{_path_files} function to optimize complex recursive
filename generation (globbing).  It does three things.  With the
@t{-p} and @t{-P} options it builds the glob patterns to use,
including the paths already handled and trying to optimize the
patterns with respect to the prefix and suffix from the line and the
match specification currently used.  The @t{-i} option does the
directory tests for the @t{ignore-parents} style and the @t{-r} option 
tests if a component for some of the matches are equal to the string
on the line and removes all other matches if that is true.

@findex compgroups
@item @t{compgroups}
Used by the @t{_tags} function to implement the internals of the
@t{group-order} style.  This only takes its arguments as names of
completion groups and creates the groups for it (all six types: sorted 
and unsorted, both without removing duplicates, with removing all
duplicates and with removing consecutive duplicates).

@findex compquote
@item @t{compquote} [ @t{-p} ] @var{names} ...
There may be reasons to write completion functions that have to add
the matches using the @t{-Q} option to @t{compadd} and perform quoting
themselves.  Instead of interpreting the first character of the
@t{all_quotes} key of the @t{compstate} special association and using
the @t{q} flag for parameter expansions, one can use this builtin
command.  The arguments are the names of scalar or array parameters
and the values of these parameters are quoted as needed for the
innermost quoting level.  If the @t{-p} option is given, quoting is
done as if there is some prefix before the values of the parameters,
so that a leading equal sign will not be quoted.

@noindent
The return value is non-zero in case of an error and zero otherwise.

@findex comptags
@findex comptry
@item @t{comptags}
@itemx @t{comptry}
These implement the internals of the tags mechanism.

@findex compvalues
@item @t{compvalues}
Like @t{comparguments}, but for the @t{_values} function.

@end table
@c (avoiding a yodl bug)
@node The zsh/deltochar Module, The zsh/example Module, The zsh/computil Module, Zsh Modules

@section The zsh/deltochar Module
@noindent
@c Yodl file: Zsh/mod_deltochar.yo

The @t{zsh/deltochar} module makes available two ZLE functions:

@noindent
@table @asis
@tindex delete-to-char
@item @t{delete-to-char}
Read a character from the keyboard, and
delete from the cursor position up to and including the next
(or, with repeat count @var{n}, the @var{n}th) instance of that character.
Negative repeat counts mean delete backwards.

@tindex zap-to-char
@item @t{zap-to-char}
This behaves like @t{delete-to-char}, except that the final occurrence of
the character itself is not deleted.

@end table
@c (avoiding a yodl bug)
@node The zsh/example Module, The zsh/files Module, The zsh/deltochar Module, Zsh Modules

@section The zsh/example Module
@noindent
@c Yodl file: Zsh/mod_example.yo

The @t{zsh/example} module makes available one builtin command:

@noindent
@table @asis
@findex example
@cindex modules, example
@cindex modules, writing
@cindex writing modules
@item @t{example} [ @t{-flags} ] [ @var{args} ... ]
Displays the flags and arguments it is invoked with.

@end table

@noindent
The purpose of the module is to serve as an example of how to write a
module.
@c (avoiding a yodl bug)
@node The zsh/files Module, The zsh/mapfile Module, The zsh/example Module, Zsh Modules

@section The zsh/files Module
@noindent
@c Yodl file: Zsh/mod_files.yo

@cindex files, manipulating
The @t{zsh/files} module makes some standard commands available as builtins:

@noindent
@table @asis
@findex chgrp
@item @t{chgrp} [ @t{-Rs} ] @var{group} @var{filename} ...
Changes group of files specified.  This is equivalent to @t{chown} with
a @var{user-spec} argument of `@t{:}@var{group}'.

@findex chown
@item @t{chown} [ @t{-Rs} ] @var{user-spec} @var{filename} ...
Changes ownership and group of files specified.

@noindent
The @var{user-spec} can be in four forms:

@noindent
@table @asis
@item @var{user}
change owner to @var{user}; do not change group
@item @var{user}@t{::}
change owner to @var{user}; do not change group
@item @var{user}@t{:}
change owner to @var{user}; change group to @var{user}'s primary group
@item @var{user}@t{:}@var{group}
change owner to @var{user}; change group to @var{group}
@item @t{:}@var{group}
do not change owner; change group to @var{group}
@end table

@noindent
In each case, the `@t{:}' may instead be a `@t{.}'.  The rule is that
if there is a `@t{:}' then the separator is `@t{:}', otherwise
if there is a `@t{.}' then the separator is `@t{.}', otherwise
there is no separator.

@noindent
Each of @var{user} and @var{group} may be either a username (or group name, as
appropriate) or a decimal user ID (group ID).  Interpretation as a name
takes precedence, if there is an all-numeric username (or group name).

@noindent
The @t{-R} option causes @t{chown} to recursively descend into directories,
changing the ownership of all files in the directory after
changing the ownership of the directory itself.

@noindent
The @t{-s} option is a zsh extension to @t{chown} functionality.  It enables
paranoid behaviour, intended to avoid security problems involving
a @t{chown} being tricked into affecting files other than the ones
intended.  It will refuse to follow symbolic links, so that (for example)
@value{dsbq}@t{chown luser /tmp/foo/passwd}@value{dsq} can't accidentally chown @t{/etc/passwd}
if @t{/tmp/foo} happens to be a link to @t{/etc}.  It will also check
where it is after leaving directories, so that a recursive chown of
a deep directory tree can't end up recursively chowning @t{/usr} as
a result of directories being moved up the tree.

@findex ln
@item @t{ln} [ @t{-dfis} ] @var{filename} @var{dest}
@itemx @t{ln} [ @t{-dfis} ] @var{filename} ... @var{dir}
Creates hard (or, with @t{-s}, symbolic) links.  In the first form, the
specified @var{dest}ination is created, as a link to the specified
@var{filename}.  In the second form, each of the @var{filename}s is
taken in turn, and linked to a pathname in the specified @var{dir}ectory
that has the same last pathname component.

@noindent
Normally, @t{ln} will not attempt to create hard links to
directories.  This check can be overridden using the @t{-d} option.
Typically only the super-user can actually succeed in creating
hard links to directories.
This does not apply to symbolic links in any case.

@noindent
By default, existing files cannot be replaced by links.
The @t{-i} option causes the user to be queried about replacing
existing files.  The @t{-f} option causes existing files to be
silently deleted, without querying.  @t{-f} takes precedence.

@findex mkdir
@item @t{mkdir} [ @t{-p} ] [ @t{-m} @var{mode} ] @var{dir} ...
Creates directories.  With the @t{-p} option, non-existing parent
directories are first created if necessary, and there will be
no complaint if the directory already exists.
The @t{-m} option can be used to specify (in octal) a set of file permissions
for the created directories, otherwise mode 777 modified by the current
@t{umask} (see man page umask(2)) is used.

@findex mv
@item @t{mv} [ @t{-fi} ] @var{filename} @var{dest}
@itemx @t{mv} [ @t{-fi} ] @var{filename} ... @var{dir}
Moves files.  In the first form, the specified @var{filename} is moved
to the specified @var{dest}ination.  In the second form, each of the
@var{filename}s is
taken in turn, and moved to a pathname in the specified @var{dir}ectory
that has the same last pathname component.

@noindent
By default, the user will be queried before replacing any file
that the user cannot write to, but writable files will be silently
removed.
The @t{-i} option causes the user to be queried about replacing
any existing files.  The @t{-f} option causes any existing files to be
silently deleted, without querying.  @t{-f} takes precedence.

@noindent
Note that this @t{mv} will not move files across devices.
Historical versions of @t{mv}, when actual renaming is impossible,
fall back on copying and removing files; if this behaviour is desired,
use @t{cp} and @t{rm} manually.  This may change in a future version.

@findex rm
@item @t{rm} [ @t{-dfirs} ] @var{filename} ...
Removes files and directories specified.

@noindent
Normally, @t{rm} will not remove directories (except with the @t{-r}
option).  The @t{-d} option causes @t{rm} to try removing directories
with @t{unlink} (see man page unlink(2)), the same method used for files.
Typically only the super-user can actually succeed in unlinking
directories in this way.
@t{-d} takes precedence over @t{-r}.

@noindent
By default, the user will be queried before removing any file
that the user cannot write to, but writable files will be silently
removed.
The @t{-i} option causes the user to be queried about removing
any files.  The @t{-f} option causes files to be
silently deleted, without querying, and suppresses all error indications.
@t{-f} takes precedence.

@noindent
The @t{-r} option causes @t{rm} to recursively descend into directories,
deleting all files in the directory before removing the directory with
the @t{rmdir} system call (see man page rmdir(2)).

@noindent
The @t{-s} option is a zsh extension to @t{rm} functionality.  It enables
paranoid behaviour, intended to avoid common security problems involving
a root-run @t{rm} being tricked into removing files other than the ones
intended.  It will refuse to follow symbolic links, so that (for example)
@value{dsbq}@t{rm /tmp/foo/passwd}@value{dsq} can't accidentally remove @t{/etc/passwd}
if @t{/tmp/foo} happens to be a link to @t{/etc}.  It will also check
where it is after leaving directories, so that a recursive removal of
a deep directory tree can't end up recursively removing @t{/usr} as
a result of directories being moved up the tree.

@findex rmdir
@item @t{rmdir} @var{dir} ...
Removes empty directories specified.

@findex sync
@item @t{sync}
Calls the system call of the same name (see man page sync(2)), which
flushes dirty buffers to disk.  It might return before the I/O has
actually been completed.

@end table
@c (avoiding a yodl bug)
@node The zsh/mapfile Module, The zsh/mathfunc Module, The zsh/files Module, Zsh Modules

@section The zsh/mapfile Module
@noindent
@c Yodl file: Zsh/mod_mapfile.yo

@cindex parameter, file access via
The @t{zsh/mapfile} module provides one special associative array parameter of
the same name.

@noindent
@table @asis
@vindex mapfile
@item @t{mapfile}
This associative array takes as keys the names of files; the resulting
value is the content of the file.  The value is treated identically to any
other text coming from a parameter.  The value may also be assigned to, in
which case the file in question is written (whether or not it originally
existed); or an element may be unset, which will delete the file in
question.  For example, `@t{vared mapfile[myfile]}' works as expected,
editing the file `@t{myfile}'.

@noindent
When the array is accessed as a whole, the keys are the names of files in
the current directory, and the values are empty (to save a huge overhead in
memory).  Thus @t{$@{(k)mapfile@}} has the same affect as the glob operator
@t{*(D)}, since files beginning with a dot are not special.  Care must be
taken with expressions such as @t{rm $@{(k)mapfile@}}, which will delete
every file in the current directory without the usual `@t{rm *}' test.

@noindent
The parameter @t{mapfile} may be made read-only; in that case, files
referenced may not be written or deleted.

@end table

@noindent

@subsection Limitations
@noindent

@noindent
Although reading and writing of the file in question is efficiently
handled, zsh's internal memory management may be arbitrarily baroque.  Thus
it should not automatically be assumed that use of @t{mapfile} represents a
gain in efficiency over use of other mechanisms.  Note in particular that
the whole contents of the file will always reside physically in memory when
accessed (possibly multiple times, due to standard parameter substitution
operations).  In particular, this means handling of sufficiently long files
(greater than the machine's swap space, or than the range of the pointer
type) will be incorrect.

@noindent
No errors are printed or flagged for non-existent, unreadable, or
unwritable files, as the parameter mechanism is too low in the shell
execution hierarchy to make this convenient.

@noindent
It is unfortunate that the mechanism for loading modules does not yet allow
the user to specify the name of the shell parameter to be given the special
behaviour.
@c (avoiding a yodl bug)
@node The zsh/mathfunc Module, The zsh/parameter Module, The zsh/mapfile Module, Zsh Modules

@section The zsh/mathfunc Module
@noindent
@c Yodl file: Zsh/mod_mathfunc.yo

@cindex functions, mathematical
@cindex mathematical functions
The @t{zsh/mathfunc} module provides standard
mathematical functions for use when
evaluating mathematical formulae.  The syntax agrees with normal C and
FORTRAN conventions, for example,

@noindent
@example
(( f = sin(0.3) ))
@end example

@noindent
assigns the sine of 0.3 to the parameter f.

@noindent
Most functions take floating point arguments and return a floating point
value.  However, any necessary conversions from or to integer type will be
performed automatically by the shell.  Apart from @t{atan} with a second
argument and the @t{abs}, @t{int} and @t{float} functions, all functions
behave as noted in the manual page for the corresponding C function,
except that any arguments out of range for the function in question will be
detected by the shell and an error reported.

@noindent
The following functions take a single floating point argument: @t{acos},
@t{acosh}, @t{asin}, @t{asinh}, @t{atan}, @t{atanh}, @t{cbrt}, @t{ceil},
@t{cos}, @t{cosh}, @t{erf}, @t{erfc}, @t{exp}, @t{expm1}, @t{fabs},
@t{floor}, @t{gamma}, @t{j0}, @t{j1}, @t{lgamma}, @t{log}, @t{log10},
@t{log1p}, @t{logb}, @t{sin}, @t{sinh}, @t{sqrt}, @t{tan}, @t{tanh},
@t{y0}, @t{y1}.  The @t{atan} function can optionally take a second
argument, in which case it behaves like the C function @t{atan2}.
The @t{ilogb} function takes a single floating point argument, but
returns an integer.

@noindent
The function @t{signgam} takes no arguments, and returns an integer, which
is the C variable of the same name, as described in man page gamma(3).  Note
that it is therefore only useful immediately after a call to @t{gamma} or
@t{lgamma}.  Note also that `@t{signgam()}' and `@t{signgam}' are distinct
expressions.

@noindent
The following functions take two floating point arguments: @t{copysign},
@t{fmod}, @t{hypot}, @t{nextafter}.

@noindent
The following take an integer first argument and a floating point second
argument: @t{jn}, @t{yn}.

@noindent
The following take a floating point first argument and an integer second
argument: @t{ldexp}, @t{scalb}.

@noindent
The function @t{abs} does not convert the type of its single argument; it
returns the absolute value of either a floating point number or an
integer.  The functions @t{float} and @t{int} convert their arguments into
a floating point or integer value (by truncation) respectively.

@noindent
Note that the C @t{pow} function is available in ordinary math evaluation
as the `@t{**}' operator and is not provided here.
@c (avoiding a yodl bug)
@node The zsh/parameter Module, The zsh/sched Module, The zsh/mathfunc Module, Zsh Modules

@section The zsh/parameter Module
@noindent
@c Yodl file: Zsh/mod_parameter.yo

@cindex parameters, special
The @t{zsh/parameter} module gives access to some of the internal hash
tables used by the shell by defining some special parameters.

@noindent
@table @asis
@vindex options
@item @t{options}
The keys for this associative array are the names of the options that
can be set and unset using the @t{setopt} and @t{unsetopt}
builtins. The value of each key is either the string @t{on} if the
option is currently set, or the string @t{off} if the option is unset.
Setting a key to one of these strings is like setting or unsetting
the option, respectively. Unsetting a key in this array is like
setting it to the value @t{off}.

@vindex commands
@item @t{commands}
This array gives access to the command hash table. The keys are the
names of external commands, the values are the pathnames of the files
that would be executed when the command would be invoked. Setting a
key in this array defines a new entry in this table in the same way as
with the @t{hash} builtin. Unsetting a key as in `@t{unset
"commands[foo]"}' removes the entry for the given key from the command 
hash table.

@vindex functions
@item @t{functions}
This associative array maps names of enabled functions to their
definitions. Setting a key in it is like defining a function with the
name given by the key and the body given by the value. Unsetting a key
removes the definition for the function named by the key.

@vindex dis_functions
@item @t{dis_functions}
Like @t{functions} but for disabled functions.

@vindex builtins
@item @t{builtins}
This associative array gives information about the builtin commands
currently enabled. The keys are the names of the builtin commands and
the values are either `@t{undefined}' for builtin commands that will
automatically be loaded from a module if invoked or `@t{defined}' for
builtin commands that are already loaded.

@vindex dis_builtins
@item @t{dis_builtins}
Like @t{builtins} but for disabled builtin commands.

@vindex reswords
@item @t{reswords}
This array contains the enabled reserved words.

@vindex dis_reswords
@item @t{dis_reswords}
Like @t{reswords} but for disabled reserved words.

@vindex aliases
@item @t{aliases}
This maps the names of the regular aliases currently enabled to their
expansions.

@vindex dis_aliases
@item @t{dis_aliases}
Like @t{raliases} but for disabled regular aliases.

@vindex galiases
@item @t{galiases}
Like @t{raliases}, but for global aliases.

@vindex dis_galiases
@item @t{dis_galiases}
Like @t{galiases} but for disabled global aliases.

@vindex parameters
@item @t{parameters}
The keys in this associative array are the names of the parameters
currently defined. The values are strings describing the type of the
parameter, in the same format used by the @t{t} parameter flag, see
@ref{Parameter Expansion}
.
Setting or unsetting keys in this array is not possible.

@vindex modules
@item @t{modules}
An associative array giving information about modules. The keys are the names
of the modules loaded, registered to be autoloaded, or aliased. The
value says which state the named module is in and is one of the
strings `@t{loaded}', `@t{autoloaded}', or `@t{alias:}@var{name}',
where @var{name} is the name the module is aliased to.

@noindent
Setting or unsetting keys in this array is not possible.

@vindex dirstack
@item @t{dirstack}
A normal array holding the elements of the directory stack. Note that
the output of the @t{dirs} builtin command includes one more
directory, the current working directory.

@vindex history
@item @t{history}
This associative array maps history event numbers to the full history lines.

@vindex historywords
@item @t{historywords}
A special array containing the words stored in the history.

@vindex jobdirs
@item @t{jobdirs}
This associative array maps job numbers to the directories from which the
job was started (which may not be the current directory of the job).

@vindex jobtexts
@item @t{jobtexts}
This associative array maps job numbers to the texts of the command lines
that were used to start the jobs.

@vindex jobstates
@item @t{jobstates}
This associative array gives information about the states of the jobs
currently known. The keys are the job numbers and the values are
strings of the form
`@var{job-state}:@var{mark}:@var{pid}@t{=}@var{state}@t{...}'. The
@var{job-state} gives the state the whole job is currently in, one of
`@t{running}', `@t{suspended}', or `@t{done}'. The @var{mark} is
`@t{+}' for the current job, `@t{-}' for the previous job and empty
otherwise. This is followed by one `@var{pid}@t{=}@var{state}' for every
process in the job. The @var{pid}s are, of course, the process IDs and
the @var{state} describes the state of that process.

@vindex nameddirs
@item @t{nameddirs}
This associative array maps the names of named directories to the pathnames
they stand for.

@vindex userdirs
@item @t{userdirs}
This associative array maps user names to the pathnames of their home
directories.

@vindex funcstack
@item @t{funcstack}
This array contains the names of the functions currently being
executed. The first element is the name of the function using the
parameter.

@end table
@c (avoiding a yodl bug)
@node The zsh/sched Module, The zsh/stat Module, The zsh/parameter Module, Zsh Modules

@section The zsh/sched Module
@noindent
@c Yodl file: Zsh/mod_sched.yo

The @t{zsh/sched} module makes available one builtin command:

@noindent
@table @asis
@findex sched
@cindex timed execution
@cindex execution, timed
@item @t{sched} [@t{+}]@var{hh}@t{:}@var{mm} @var{command} ...
@itemx @t{sched} [ @t{-}@var{item} ]
Make an entry in the scheduled list of commands to execute.
The time may be specified in either absolute or relative time.
With no arguments, prints the list of scheduled commands.
With the argument `@t{-}@var{item}', removes the given item
from the list.

@end table
@c (avoiding a yodl bug)
@node The zsh/stat Module, The zsh/termcap Module, The zsh/sched Module, Zsh Modules

@section The zsh/stat Module
@noindent
@c Yodl file: Zsh/mod_stat.yo

The @t{zsh/stat} module makes available one builtin command:

@noindent
@table @asis
@findex stat
@cindex files, listing
@cindex files, examining
@item @t{stat} [ @t{-gnNolLtTrs} ] [ @t{-f} @var{fd} ] [ @t{-H} @var{hash} ] [ @t{-A} @var{array} ] [ @t{-F} @var{fmt} ] [ @t{+}@var{element} ] [ @var{file} ... ]
The command acts as a front end to the @t{stat} system call (see
man page stat(2)).
If the @t{stat} call fails, the appropriate system error message
printed and status 1 is returned.
The fields of @t{struct stat} give information about
the files provided as arguments to the command.  In addition to those
available from the @t{stat} call, an extra element `@t{link}' is provided.
These elements are:

@noindent
@table @asis
@item @t{device}
The number of the device on which the file resides.

@item @t{inode}
The unique number of the file on this device (`@emph{inode}' number).

@item @t{mode}
The mode of the file; that is, the file's type and access permissions.
With the @t{-s} option, this will
be returned as a string corresponding to the first column in the
display of the @t{ls -l} command.

@item @t{nlink}
The number of hard links to the file.

@item @t{uid}
The user ID of the owner of the file.  With the @t{-s}
option, this is displayed as a user name.

@item @t{gid}
The group ID of the file.  With the @t{-s} option, this
is displayed as a group name.

@item @t{rdev}
The raw device number.  This is only useful for special devices.

@item @t{size}
The size of the file in bytes.

@item @t{atime}
@itemx @t{mtime}
@itemx @t{ctime}
The last access, modification and inode change times
of the file, respectively, as the number of seconds since
midnight GMT on 1st January, 1970.  With the @t{-s} option,
these are printed as strings for the local time zone; the format
can be altered with the @t{-F} option, and with the @t{-g}
option the times are in GMT.

@item @t{blksize}
The number of bytes in one allocation block on the
device on which the file resides.

@item @t{block}
The number of disk blocks used by the file.

@item @t{link}
If the file is a link and the @t{-L} option is in
effect, this contains the name of the file linked to, otherwise
it is empty.  Note that if this element is selected (@value{dsbq}@t{stat +link}@value{dsq})
then the @t{-L} option is automatically used.

@end table

@noindent
A particular element may be selected by including its name
preceded by a `@t{+}' in the option list; only one element is allowed.
The element may be shortened to any unique set of leading
characters.  Otherwise, all elements will be shown for all files.

@noindent
Options:

@noindent
@table @asis
@item @t{-A} @var{array}
Instead of displaying the results on standard
output, assign them to an @var{array}, one @t{struct stat} element per array
element for each file in order.  In this case neither the name
of the element nor the name of the files appears in @var{array} unless the
@t{-t} or @t{-n} options were given, respectively.  If @t{-t} is given,
the element name appears as a prefix to the
appropriate array element; if @t{-n} is given, the file name
appears as a separate array element preceding all the others.
Other formatting options are respected.

@item @t{-H} @var{hash}
Similar to @t{-A}, but instead assign the values to @var{hash}.  The keys
are the elements listed above.  If the @t{-n} option is provided then the
name of the file is included in the hash with key @t{name}.

@item @t{-f} @var{fd}
Use the file on file descriptor @var{fd} instead of
named files; no list of file names is allowed in this case.

@item @t{-F} @var{fmt}
Supplies a @t{strftime} (see man page strftime(3)) string for the
formatting of the time elements.  The @t{-s} option is implied.

@item @t{-g}
Show the time elements in the GMT time zone.  The
@t{-s} option is implied.

@item @t{-l}
List the names of the type elements (to standard
output or an array as appropriate) and return immediately;
options other than @t{-A} and arguments are ignored.

@item @t{-L}
Perform an @t{lstat} (see man page lstat(2)) rather than a @t{stat}
system call.  In this case, if the file is a link, information
about the link itself rather than the target file is returned.
This option is required to make the @t{link} element useful.

@item @t{-n}
Always show the names of files.  Usually these are
only shown when output is to standard output and there is more
than one file in the list.

@item @t{-N}
Never show the names of files.

@item @t{-o}
If a raw file mode is printed, show it in octal, which is more useful for
human consumption than the default of decimal.  A leading zero will be
printed in this case.  Note that this does not affect whether a raw or
formatted file mode is shown, which is controlled by the @t{-r} and @t{-s}
options, nor whether a mode is shown at all.

@item @t{-r}
Print raw data (the default format) alongside string
data (the @t{-s} format); the string data appears in parentheses
after the raw data.

@item @t{-s}
Print @t{mode}, @t{uid}, @t{gid} and the three time
elements as strings instead of numbers.  In each case the format
is like that of @t{ls -l}.

@item @t{-t}
Always show the type names for the elements of
@t{struct stat}.  Usually these are only shown when output is to
standard output and no individual element has been selected.

@item @t{-T}
Never show the type names of the @t{struct stat} elements.

@end table

@end table
@c (avoiding a yodl bug)
@node The zsh/termcap Module, The zsh/terminfo Module, The zsh/stat Module, Zsh Modules

@section The zsh/termcap Module
@noindent
@c Yodl file: Zsh/mod_termcap.yo

The @t{zsh/termcap} module makes available one builtin command:

@noindent
@table @asis
@findex echotc
@cindex termcap value, printing
@item @t{echotc} @var{cap} [ @var{arg} ... ]
Output the termcap value corresponding to the capability
@var{cap}, with optional arguments.

@end table

@noindent
The @t{zsh/termcap} module makes available one parameter:

@noindent
@table @asis
@vindex termcap
@item @t{termcap}
An associative array that maps termcap capability codes to
their values.

@end table
@c (avoiding a yodl bug)
@node The zsh/terminfo Module, The zsh/zftp Module, The zsh/termcap Module, Zsh Modules

@section The zsh/terminfo Module
@noindent
@c Yodl file: Zsh/mod_terminfo.yo

The @t{zsh/terminfo} module makes available one builtin command:

@noindent
@table @asis
@findex echoti
@cindex terminfo value, printing
@item @t{echoti} @var{cap} [ @var{arg} ]
Output the terminfo value corresponding to the capability
@var{cap}, instantiated with @var{arg} if applicable.

@end table

@noindent
The @t{zsh/terminfo} module makes available one parameter:

@noindent
@table @asis
@vindex terminfo
@item @t{terminfo}
An associative array that maps terminfo capability names to
their values.

@end table
@c (avoiding a yodl bug)
@node The zsh/zftp Module, The zsh/zle Module, The zsh/terminfo Module, Zsh Modules

@section The zsh/zftp Module
@noindent
@c Yodl file: Zsh/mod_zftp.yo

The @t{zsh/zftp} module makes available one builtin command:

@noindent
@table @asis
@findex zftp
@cindex FTP
@cindex files, transferring
@item @t{zftp} @var{subcommand} [ @var{args} ]
The @t{zsh/zftp} module is a client for FTP (file transfer protocol).  It
is implemented as a builtin to allow full use of shell command line
editing, file I/O, and job control mechanisms.  Often, users will
access it via shell functions providing a more powerful interface; a set is
provided with the @t{zsh} distribution and is described in
@ref{Zftp Function System}.  However, the @t{zftp} command is entirely usable in its
own right.

@noindent
All commands consist of the command name @t{zftp} followed by the name
of a subcommand.  These are listed below.  The return status of each
subcommand is supposed to reflect the success or failure of the remote
operation.  See a description of the variable @t{ZFTP_VERBOSE} for
more information on how responses from the server may be printed.

@end table

@noindent

@subsection Subcommands
@noindent
@cindex zftp, subcommands

@noindent
@table @asis
@cindex FTP, starting a session
@item @t{open} @var{host} [ @var{user} [ @var{password} [ @var{account} ] ] ]
Open a new FTP session to @var{host}, which may be the name of a TCP/IP
connected host or an IP number in the standard dot notation.
Remaining arguments are passed to the @t{login} subcommand.  Note that
if no arguments beyond @var{host} are supplied, @t{open} will @emph{not}
automatically call @t{login}.  If no arguments at all are supplied,
@t{open} will use the parameters set by the @t{params} subcommand.

@noindent
After a successful open, the shell variables @t{ZFTP_HOST},
@t{ZFTP_IP} and @t{ZFTP_SYSTEM} are available; see `Variables'
below.

@item @t{login} [ @var{name} [ @var{password} [ @var{account} ] ] ]
@itemx @t{user} [ @var{name} [ @var{password} [ @var{account} ] ] ]
Login the user @var{name} with parameters @var{password} and @var{account}.
Any of the parameters can be omitted, and will be read from standard
input if needed (@var{name} is always needed).  If 
standard input is a terminal, a prompt for each one will be printed on
standard error and @var{password} will not be echoed.  If any of the
parameters are not used, a warning message is printed.

@noindent
After a successful login, the shell variables @t{ZFTP_USER},
@t{ZFTP_ACCOUNT} and @t{ZFTP_PWD} are available; see `Variables'
below.

@noindent
This command may be re-issued when a user is already logged in, and
the server will first be reinitialized for a new user.

@item @t{params} [ @var{host} [ @var{user} [ @var{password} [ @var{account} ] ] ] ]
@itemx @t{params} @t{-}
Store the given parameters for a later @t{open} command with no
arguments.  Only those given on the command line will be remembered.
If no arguments are given, the parameters currently set are printed,
although the password will appear as a line of stars; the return value is
one if no parameters were set, zero otherwise.

@noindent
Any of the parameters may be specified as a `@t{?}', which
may need to be quoted to protect it from shell expansion.  In this case,
the appropriate parameter will be read from stdin as with the
@t{login} subcommand, including special handling of @var{password}.  If the
`@t{?}' is followed by a string, that is used as the prompt for reading the
parameter instead of the default message (any necessary punctuation and
whitespace should be included at the end of the prompt).  The first letter
of the parameter (only) may be quoted with a `@t{\}'; hence an argument
@t{"\\$word"} guarantees that the string from the shell parameter @t{$word}
will be treated literally, whether or not it begins with a `@t{?}'.

@noindent
If instead a single `@t{-}' is given, the existing parameters, if any,
are deleted.  In that case, calling @t{open} with no arguments will
cause an error.

@noindent
The list of parameters is not deleted after a @t{close}, however it
will be deleted if the @t{zsh/zftp} module is unloaded.

@noindent
For example,

@noindent
@example
zftp params ftp.elsewhere.xx juser '?Password for juser: '
@end example

@noindent
will store the host @t{ftp.elsewhere.xx} and the user @t{juser} and
then prompt the user for the corresponding password with the given prompt.

@item @t{test}
Test the connection; if the server has reported
that it has closed the connection (maybe due to a timeout), return
status 2; if no connection was open anyway, return status 1; else
return status 0.  The @t{test} subcommand is
silent, apart from messages printed by the @t{$ZFTP_VERBOSE}
mechanism, or error messages if the connection closes.  There is no
network overhead for this test.

@noindent
The test is only supported on systems with either the @t{select(2)} or
@t{poll(2)} system calls; otherwise the message `@t{not
supported on this system}' is printed instead.

@noindent
The @t{test} subcommand will automatically be called at the start of any
other subcommand for the current session when a connection is open.

@item @t{cd} @var{directory}
Change the remote directory to @var{directory}.  Also alters the shell
variable @t{ZFTP_PWD}.

@item @t{cdup}
Change the remote directory to the one higher in the directory tree.
Note that @t{cd ..} will also work correctly on non-UNIX systems.

@item @t{dir} [ @var{args...} ]
Give a (verbose) listing of the remote directory.  The @var{args} are
passed directly to the server. The command's behaviour is implementation
dependent, but a UNIX server will typically interpret @var{args} as
arguments to the @t{ls} command and with no arguments return the
result of `@t{ls -l}'. The directory is listed to standard output.

@item @t{ls} [ @var{args} ]
Give a (short) listing of the remote directory.  With no @var{args},
produces a raw list of the files in the directory, one per line.
Otherwise, up to vagaries of the server implementation, behaves
similar to @t{dir}.

@item @t{type} [ @var{type} ]
Change the type for the transfer to @var{type}, or print the current type
if @var{type} is absent.  The allowed values are `@t{A}' (ASCII),
`@t{I}' (Image, i.e. binary), or `@t{B}' (a synonym for `@t{I}').

@noindent
The FTP default for a transfer is ASCII.  However, if @t{zftp} finds
that the remote host is a UNIX machine with 8-bit byes, it will
automatically switch to using binary for file transfers upon
@t{open}.  This can subsequently be overridden.

@noindent
The transfer type is only passed to the remote host when a data
connection is established; this command involves no network overhead.

@item @t{ascii}
The same as @t{type A}.

@item @t{binary}
The same as @t{type I}.

@item @t{mode} [ @t{S} | @t{B} ]
Set the mode type to stream (@t{S}) or block (@t{B}).  Stream mode is
the default; block mode is not widely supported.

@item @t{remote} @var{files...}
@itemx @t{local} [ @var{files...} ]
Print the size and last modification time of the remote or local
files.  If there is more than one item on the list, the name of the
file is printed first.  The first number is the file size, the second
is the last modification time of the file in the format
@t{CCYYMMDDhhmmSS} consisting of year, month, date, hour, minutes and
seconds in GMT.  Note that this format, including the length, is
guaranteed, so that time strings can be directly compared via the
@t{[[} builtin's @t{<} and @t{>} operators, even if they are too long
to be represented as integers.

@noindent
Not all servers support the commands for retrieving this information.
In that case, the @t{remote} command will print nothing and return
status 2, compared with status 1 for a file not found.

@noindent
The @t{local} command (but not @t{remote}) may be used with no
arguments, in which case the information comes from examining file
descriptor zero.  This is the same file as seen by a @t{put} command
with no further redirection.

@item @t{get} @var{file} [...]
Retrieve all @var{file}s from the server, concatenating them
and sending them to standard output.

@item @t{put} @var{file} [...]
For each @var{file}, read a file from standard input and send that to
the remote host with the given name.

@item @t{append} @var{file} [...]
As @t{put}, but if the remote @var{file} already exists, data is
appended to it instead of overwriting it.

@item @t{getat} @var{file} @var{point}
@itemx @t{putat} @var{file} @var{point}
@itemx @t{appendat} @var{file} @var{point}
Versions of @t{get}, @t{put} and @t{append} which will start the
transfer at the given @var{point} in the remote @var{file}.  This is
useful for appending to an incomplete local file.  However, note that
this ability is not universally supported by servers (and is not quite
the behaviour specified by the standard).

@item @t{delete} @var{file} [...]
Delete the list of files on the server.

@item @t{mkdir} @var{directory}
Create a new directory @var{directory} on the server.

@item @t{rmdir} @var{directory}
Delete the directory @var{directory}  on the server.

@item @t{rename} @var{old-name} @var{new-name}
Rename file @var{old-name} to @var{new-name} on the server.

@item @t{site} @var{args...}
Send a host-specific command to the server.  You will probably
only need this if instructed by the server to use it.

@item @t{quote} @var{args...}
Send the raw FTP command sequence to the server.  You should be
familiar with the FTP command set as defined in RFC959 before doing
this.  Useful commands may include @t{STAT} and @t{HELP}.  Note also
the mechanism for returning messages as described for the variable
@t{ZFTP_VERBOSE} below, in particular that all messages from the
control connection are sent to standard error.

@item @t{close}
@itemx @t{quit}
Close the current data connection.  This unsets the shell parameters
@t{ZFTP_HOST}, @t{ZFTP_IP}, @t{ZFTP_SYSTEM}, @t{ZFTP_USER},
@t{ZFTP_ACCOUNT}, @t{ZFTP_PWD}, @t{ZFTP_TYPE} and @t{ZFTP_MODE}.

@item @t{session} [ @var{sessname} ]
Allows multiple FTP sessions to be used at once.  The name of the session
is an arbitrary string of characters; the default session is called
`@t{default}'.  If this command is called without an argument, it will list
all the current sessions; with an argument, it will either switch to the
existing session called @var{sessname}, or create a new session of that name.

@noindent
Each session remembers the status of the connection, the set of
connection-specific shell parameters (the same set as are unset when a
connection closes, as given in the description of @t{close}), and any user
parameters specified with the @t{params} subcommand.  Changing to a
previous session restores those values; changing to a new session
initialises them in the same way as if @t{zftp} had just been loaded.  The
name of the current session is given by the parameter @t{ZFTP_SESSION}.

@item @t{rmsession} [ @var{sessname} ]
Delete a session; if a name is not given, the current session is deleted.
If the current session is deleted, the earliest existing session becomes
the new current session, otherwise the current session is not changed.
If the session being deleted is the only one, a new session called
`@t{default}' is created and becomes the current session; note that this is
a new session even if the session being deleted is also called
`@t{default}'. It is recommended that sessions not be deleted while
background commands which use @t{zftp} are still active.

@end table

@noindent

@subsection Parameters
@noindent
@cindex zftp, parameters
The following shell parameters are used by @t{zftp}.  Currently none
of them are special.

@noindent
@table @asis
@vindex ZFTP_TMOUT
@item @t{ZFTP_TMOUT}
Integer.  The time in seconds to wait for a network operation to
complete before returning an error.  If this is not set when the
module is loaded, it will be given the default value 60.  A value of
zero turns off timeouts.  If a timeout occurs on the control
connection it will be closed.  Use a larger value if this occurs too
frequently.

@vindex ZFTP_IP
@item @t{ZFTP_IP}
Readonly.  The IP address of the current connection in dot notation.

@vindex ZFTP_HOST
@item @t{ZFTP_HOST}
Readonly.  The hostname of the current remote server.  If the host was
opened as an IP number, @t{ZFTP_HOST} contains that instead; this
saves the overhead for a name lookup, as IP numbers are most commonly
used when a nameserver is unavailable.

@vindex ZFTP_SYSTEM
@item @t{ZFTP_SYSTEM}
Readonly.  The system type string returned by the server in response
to an FTP @t{SYST} request.  The most interesting case is a string
beginning @t{"UNIX Type: L8"}, which ensures maximum compatibility
with a local UNIX host.

@vindex ZFTP_TYPE
@item @t{ZFTP_TYPE}
Readonly.  The type to be used for data transfers , either `@t{A}' or
`@t{I}'.   Use the @t{type} subcommand to change this.

@vindex ZFTP_USER
@item @t{ZFTP_USER}
Readonly.  The username currently logged in, if any.

@vindex ZFTP_ACCOUNT
@item @t{ZFTP_ACCOUNT}
Readonly.  The account name of the current user, if any.  Most servers
do not require an account name.

@vindex ZFTP_PWD
@item @t{ZFTP_PWD}
Readonly.  The current directory on the server.

@vindex ZFTP_CODE
@item @t{ZFTP_CODE}
Readonly.  The three digit code of the last FTP reply from the server
as a string.  This can still be read after the connection is closed, and
is not changed when the current session changes.

@vindex ZFTP_REPLY
@item @t{ZFTP_REPLY}
Readonly.  The last line of the last reply sent by the server.  This
can still be read after the connection is closed, and is not changed when
the current session changes.

@vindex ZFTP_SESSION
@item @t{ZFTP_SESSION}
Readonly.  The name of the current FTP session; see the description of the
@t{session} subcommand.

@vindex ZFTP_PREFS
@item @t{ZFTP_PREFS}
A string of preferences for altering aspects of @t{zftp}'s behaviour.
Each preference is a single character.  The following are defined:

@noindent
@table @asis
@item @t{P}
Passive:  attempt to make the remote server initiate data transfers.
This is slightly more efficient than sendport mode.  If the letter
@t{S} occurs later in the string, @t{zftp} will use sendport mode if
passive mode is not available.

@item @t{S}
Sendport:  initiate transfers by the FTP @t{PORT} command.  If this
occurs before any @t{P} in the string, passive mode will never be
attempted.

@item @t{D}
Dumb:  use only the bare minimum of FTP commands.  This prevents
the variables @t{ZFTP_SYSTEM} and @t{ZFTP_PWD} from being set, and
will mean all connections default to ASCII type.  It may prevent
@t{ZFTP_SIZE} from being set during a transfer if the server
does not send it anyway (many servers do).

@end table

@noindent
If @t{ZFTP_PREFS} is not set when @t{zftp} is loaded, it will be set to a
default of `@t{PS}', i.e. use passive mode if available, otherwise
fall back to sendport mode.

@vindex ZFTP_VERBOSE
@item @t{ZFTP_VERBOSE}
A string of digits between 0 and 5 inclusive, specifying which
responses from the server should be printed.  All responses go to
standard error.  If any of the numbers 1 to 5 appear in the string,
raw responses from the server with reply codes beginning with that
digit will be printed to standard error.  The first digit of the three
digit reply code is defined by RFC959 to correspond to:

@noindent
@table @asis
@item 1.
A positive preliminary reply.

@item 2.
A positive completion reply.

@item 3.
A positive intermediate reply.

@item 4.
A transient negative completion reply.

@item 5.
A permanent negative completion reply.

@end table

@noindent
It should be noted that, for unknown reasons, the reply `Service not
available', which forces termination of a connection, is classified as
421, i.e. `transient negative', an interesting interpretation of the word
`transient'.

@noindent
The code 0 is special:  it indicates that all but the last line of
multiline replies read from the server will be printed to standard
error in a processed format.  By convention, servers use this
mechanism for sending information for the user to read.  The
appropriate reply code, if it matches the same response, takes
priority.

@noindent
If @t{ZFTP_VERBOSE} is not set when @t{zftp} is loaded, it will be
set to the default value @t{450}, i.e., messages destined for the user
and all errors will be printed.  A null string is valid and
specifies that no messages should be printed.

@end table

@noindent

@subsection Functions
@noindent
@cindex zftp, functions

@noindent
@table @asis
@findex zftp_chpwd, specification
@item @t{zftp_chpwd}
If this function is set by the user, it is called every time the
directory changes on the server, including when a user is logged
in, or when a connection is closed.  In the last case, @t{$ZFTP_PWD}
will be unset; otherwise it will reflect the new directory.

@findex zftp_progress, specification
@item @t{zftp_progress}
If this function is set by the user, it will be called during
a @t{get}, @t{put} or @t{append} operation each time sufficient data
has been received from the host.  During a @t{get}, the data is sent
to standard output, so it is vital that this function should write
to standard error or directly to the terminal, @emph{not} to standard
output.

@noindent
When it is called with a transfer in progress, the following
additional shell parameters are set:

@noindent
@table @asis
@vindex ZFTP_FILE
@item @t{ZFTP_FILE}
The name of the remote file being transferred from or to.

@vindex ZFTP_TRANSFER
@item @t{ZFTP_TRANSFER}
A @t{G} for a @t{get} operation and a @t{P} for a @t{put} operation.

@vindex ZFTP_SIZE
@item @t{ZFTP_SIZE}
The total size of the complete file being transferred:
the same as the first value provided by the
@t{remote} and @t{local} subcommands for a particular file.
If the server cannot supply this value for a remote file being
retrieved, it will not be set.  If input is from a pipe the value may
be incorrect and correspond simply to a full pipe buffer.

@vindex ZFTP_COUNT
@item @t{ZFTP_COUNT}
The amount of data so far transferred; a number between zero and
@t{$ZFTP_SIZE}, if that is set.  This number is always available.

@end table

@noindent
The function is initially called with @t{ZFTP_TRANSFER} set
appropriately and @t{ZFTP_COUNT} set to zero.  After the transfer is
finished, the function will be called one more time with
@t{ZFTP_TRANSFER} set to @t{GF} or @t{PF}, in case it wishes to tidy
up.  It is otherwise never called twice with the same value of
@t{ZFTP_COUNT}.

@noindent
Sometimes the progress meter may cause disruption.  It is up to the
user to decide whether the function should be defined and to use
@t{unfunction} when necessary.

@end table

@noindent

@subsection Problems
@noindent
@cindex zftp, problems

@noindent
A connection may not be opened in the left hand side of a pipe as this
occurs in a subshell and the file information is not updated in the main
shell.  In the case of type or mode changes or closing the connection in a
subshell, the information is returned but variables are not updated until
the next call to @t{zftp}.  Other status changes in subshells will not be
reflected by changes to the variables (but should be otherwise harmless).

@noindent
Deleting sessions while a @t{zftp} command is active in the background can
have unexpected effects, even if it does not use the session being deleted.
This is because all shell subprocesses share information on the state of
all connections, and deleting a session changes the ordering of that
information.

@noindent
On some operating systems, the control connection is not valid after a
fork(), so that operations in subshells, on the left hand side of a
pipeline, or in the background are not possible, as they should be.  This
is presumably a bug in the operating system.
@c (avoiding a yodl bug)
@node The zsh/zle Module, The zsh/zleparameter Module, The zsh/zftp Module, Zsh Modules

@section The zsh/zle Module
@noindent
@c Yodl file: Zsh/mod_zle.yo

The @t{zsh/zle} module contains the Zsh Line Editor.  See
@ref{Zsh Line Editor}.
@c (avoiding a yodl bug)
@node The zsh/zleparameter Module, The zsh/zprof Module, The zsh/zle Module, Zsh Modules

@section The zsh/zleparameter Module
@noindent
@c Yodl file: Zsh/mod_zleparameter.yo

@cindex parameters, special
The @t{zsh/zleparameter} module defines two special parameters that can be 
used to access internal information of the Zsh Line Editor (see
@ref{Zsh Line Editor}).

@noindent
@table @asis
@vindex keymaps
@item @t{keymaps}
This array contains the names of the keymaps currently defined.

@vindex widgets
@item @t{widgets}
This associative array contains one entry per widget defined. The name 
of the widget is the key and the value gives information about the
widget. It is either the string `@t{builtin}' for builtin widgets, a
string of the form `@t{user:}@var{name}' for user-defined widgets,
where @var{name} is the name of the shell function implementing the
widget, or it is a string of the form
`@t{completion:}@var{type}@t{:}@var{name}', for completion widgets. In
the last case @var{type} is the name of the builtin widgets the
completion widget imitates in its behavior and @var{name} is the name
of the shell function implementing the completion widget.

@end table
@c (avoiding a yodl bug)
@node The zsh/zprof Module, The zsh/zpty Module, The zsh/zleparameter Module, Zsh Modules

@section The zsh/zprof Module
@noindent
@c Yodl file: Zsh/mod_zprof.yo

@cindex functions, profiling
When loaded, the @t{zsh/zprof} causes shell functions to be profiled.
The profiling results can be obtained with the @t{zprof}
builtin command made available by this module.  There is no way to turn 
profiling off other than unloading the module.

@noindent
@table @asis
@findex zprof
@item @t{zprof} [ @t{-c} ]
Without the @t{-c} option, @t{zprof} lists profiling results to
standard output.  The format is comparable to that of commands like
@t{gprof}.

@noindent
At the top there is a summary listing all functions that were called
at least once.  This summary is sorted in decreasing order of the
amount of time spent in each.  The lines contain
the number of the function in order, which is used in 
other parts of the list in suffixes of the form
`@t{[}@var{num}@t{]}', then the number of calls made to the function.
The next three columns list the time in
milliseconds spent in the function and its descendents, the average
time in milliseconds spent in the function and its descendents per
call and the percentage of time spent in all shell functions used in
this function and its descendents.  The following three columns give
the same information, but counting only the time spent in the function 
itself.  The final column shows the name of the function.

@noindent
After the summary, detailed information about every function that was
invoked is listed, sorted in decreasing order of the amount of time spent
in each function and its descendents.  Each of these entries consists of
descriptions for the functions that called the function described, the
function itself, and the functions that were called from it.  The
description for the function itself has the same format as in the summary
(and shows the same information).  The other lines don't show the number of
the function at the beginning and have their function named indented to
make it easier to distinguish the line showing the function described in
the section from the surrounding lines.

@noindent
The information shown in this case is almost the same as in the summary,
but only refers to the call hierarchy being displayed.  For example, for a
calling function the column showing the total running time lists the time
spent in the described function and its descendents only for the times when
it was called from that particular calling function.  Likewise, for a
called function, this columns lists the total time spent in the called
function and its descendents only for the times when it was called from the
function described.

@noindent
Also in this case, the column showing the number of calls to a function
also shows a slash and then the total number of invocations made to the
called function.

@noindent
As long as the @t{zsh/zprof} module is loaded, profiling will be done and
multiple invocations of the @t{zprof} builtin command will show the
times and numbers of calls since the module was loaded.  With the
@t{-c} option, the @t{zprof} builtin command will reset its internal
counters and will not show the listing.
)
@end table
@c (avoiding a yodl bug)
@node The zsh/zpty Module, The zsh/zutil Module, The zsh/zprof Module, Zsh Modules

@section The zsh/zpty Module
@noindent
@c Yodl file: Zsh/mod_zpty.yo

The @t{zsh/zpty} module offers one builtin:

@noindent
@table @asis
@findex zpty
@item @t{zpty} [ @t{-e} ] [ @t{-b} ] @var{name} [ @var{arg ...} ]
The arguments following @var{name} are concatenated with spaces between,
then executed as a command, as if passed to the @t{eval} builtin.  The
command runs under a newly assigned pseudo-terminal; this is useful for
running commands non-interactively which expect an interactive
environment.  The @var{name} is not part of the command, but is used to
refer to this command in later calls to @t{zpty}.

@noindent
With the @t{-e} option, the pseudo-terminal is set up so that input
characters are echoed.

@noindent
With the @t{-b} option, input to and output from the pseudo-terminal are
made non-blocking.

@item @t{zpty} @t{-d} [ @var{names} ... ]
The second form, with the @t{-d} option, is used to delete commands
previously started, by supplying a list of their @var{name}s.  If no
@var{names} are given, all commands are deleted.  Deleting a command causes
the HUP signal to be sent to the corresponding process.

@item @t{zpty} @t{-w} [ @t{-n} ] @var{name} [ @var{strings ...} ]
The @t{-w} option can be used to send the to command @var{name} the given
@var{strings} as input (separated by spaces).  If the @t{-n} option is
@emph{not} given, a newline is added at the end.

@noindent
If no @var{strings} are provided, the standard input is copied to the
pseudo-terminal; this may stop before copying the full input if the
pseudo-terminal is non-blocking.

@noindent
Note that the command under the pseudo-terminal sees this input as if it
were typed, so beware when sending special tty driver characters such as
word-erase, line-kill, and end-of-file.

@item @t{zpty} @t{-r} [ @t{-t} ] @var{name} [ @var{param} [ @var{pattern} ] ]
The @t{-r} option can be used to read the output of the command @var{name}.
With only a @var{name} argument, the output read is copied to the standard
output.  Unless the pseudo-terminal is non-blocking, copying continues
until the command under the pseudo-terminal exits; when non-blocking, only
as much output as is immediately available is copied.  The return value is
zero if any output is copied.

@noindent
When also given a @var{param} argument, at most one line is read and stored
in the parameter named @var{param}.  Less than a full line may be read if
the pseudo-terminal is non-blocking.  The return value is zero if at least
one character is stored in @var{param}.

@noindent
If a @var{pattern} is given as well, output is read until the whole string
read matches the @var{pattern}, even in the non-blocking case.  The return
value is zero if the string read matches the pattern, or if the command
has exited but at least one character could still be read.  As of this
writing, a maximum of one megabyte of output can be consumed this way; if
a full megabyte is read without matching the pattern, the return value is
non-zero.

@noindent
In all cases, the return value is non-zero if nothing could be read, and
is @t{2} if this is because the command has finished.

@noindent
If the @t{-r} option is combined with the @t{-t} option, @t{zpty} tests
whether output is available before trying to read.  If no output is
available, @t{zpty} immediately returns the value @t{1}.

@item @t{zpty} @t{-t} @var{name}
The @t{-t} option without the @t{-r} option can be used to test
whether the command @var{name} is still running.  It returns a zero
value if the command is running and a non-zero value otherwise.

@item @t{zpty} [ @t{-L} ]
The last form, without any arguments, is used to list the commands
currently defined.  If the @t{-L} option is given, this is done in the
form of calls to the @t{zpty} builtin.

@end table
@c (avoiding a yodl bug)
@node The zsh/zutil Module, , The zsh/zpty Module, Zsh Modules

@section The zsh/zutil Module
@noindent
@c Yodl file: Zsh/mod_zutil.yo

@cindex builtins, utility
The @t{zsh/zutil} module only adds some builtins:

@noindent
@table @asis
@findex zstyle
@item @t{zstyle} [ @t{-L} ]
@itemx @t{zstyle} [ @t{-e} | @t{-} | @t{-}@t{-} ] @var{pattern} @var{style} @var{strings} ...
@itemx @t{zstyle -d} [ @var{pattern} [ @var{styles} ... ] ]
@itemx @t{zstyle -g} @var{name} [ @var{pattern} [ @var{style} ] ]
@itemx @t{zstyle -abs} @var{context} @var{style} @var{name} [ @var{sep} ]
@itemx @t{zstyle -Tt} @var{context} @var{style} [ @var{strings} ...]
@itemx @t{zstyle -m} @var{context} @var{style} @var{pattern}
This builtin command is used to define and lookup styles.  Styles are
pairs of names and values, where the values consist of any number of
strings.  They are stored together with patterns and lookup is done by
giving a string, called the `context', which is compared to the
patterns.  The definition stored for the first matching pattern will be 
returned.

@noindent
For ordering of comparisons, patterns are searched from most specific to
least specific, and patterns that are equally specific keep the order in 
which they were defined.  A pattern is considered to be more specific
than another if it contains more components (substrings separated by
colons) or if the patterns for the components are more specific, where 
simple strings are considered to be more specific than patterns and
complex patterns are considered to be more specific than the pattern
`@t{*}'.

@noindent
The first form (without arguments) lists the definitions in the order
@t{zstyle} will test them. If the @t{-L} option is given, listing is
done in the form of calls to @t{zstyle}.  Forms with arguments:

@noindent
@table @asis
@item @t{zstyle} [ @t{-} | @t{-}@t{-} | @t{-e} ] @var{pattern} @var{style} @var{strings} ...
@vindex reply, use of
Defines the given @var{style} for the @var{pattern} with the @var{strings} as
the value.  If the @t{-e} option is given, the @var{strings} will be
concatenated (separated by spaces) and the resulting string will be
evaluated (in the same way as it is done by the @t{eval} builtin
command) when the style is looked up.  In this case the parameter
`@t{reply}' must be assigned to set the strings returned after the
evaluation.  Before evaluating the value, @t{reply} is unset, and
if it is still unset after the evaluation, the style is treated as if
it were not set.

@item @t{zstyle -d} [ @var{pattern} [ @var{styles} ... ] ]
Delete style definitions. Without arguments all definitions are deleted,
with a @var{pattern} all definitions for that pattern are deleted and if
any @var{styles} are given, then only those styles are deleted for the
@var{pattern}.

@item @t{zstyle -g} @var{name} [ @var{pattern} [ @var{style} ] ]
Retrieve a style definition. The @var{name} is
used as the name of an array in which the results are stored. Without
any further arguments, all @var{patterns} defined are returned. With a
@var{pattern} the styles defined for that pattern are returned and with 
both a @var{pattern} and a @var{style}, the value strings of that
combination is returned.

@end table

@noindent
The other forms can be used to look up or test patterns.

@noindent
@table @asis
@item @t{zstyle -s} @var{context} @var{style} @var{name} [ @var{sep} ]
The parameter @var{name} is set to the value of the style interpreted as a
string.  If the value contains several strings they are concatenated with
spaces (or with the @var{sep} string if that is given) between them.

@item @t{zstyle -b} @var{context} @var{style} @var{name}
The value is stored in @var{name} as a boolean, i.e. as the string
`@t{yes}' if the value has only one string and that string is equal to one
of `@t{yes}', `@t{true}', `@t{on}', or `@t{1}'. If the value is any other
string or has more than one string, the parameter is set to `@t{no}'.

@item @t{zstyle -a} @var{context} @var{style} @var{name}
The value is stored in @var{name} as an array. If @var{name} is declared 
as an associative array,  the first, third, etc. strings are used as the
keys and the other strings are used as the values.

@item @t{zstyle -t} @var{context} @var{style} [ @var{strings} ...]
@itemx @t{zstyle -T} @var{context} @var{style} [ @var{strings} ...]
Test the value of a style, i.e. the @t{-t} option only returns a status
(sets @t{$?}).  Without any @var{strings} the return status is zero if the
style is defined for at least one matching pattern, has only one string in
its value, and that is equal to one of `@t{true}', `@t{yes}', `@t{on}' or
`@t{1}'. If any @var{strings} are given the status is zero if and only if
at least one of the @var{strings} is equal to at least one of the strings
in the value. If the style is not defined, the status is @t{2}.

@noindent
The @t{-T} option tests the values of the style like @t{-t}, but it
returns zero (rather than @t{2}) if the style is not defined for any
matching pattern.

@item @t{zstyle -m} @var{context} @var{style} @var{pattern}
Match a value. Returns status zero if the 
@var{pattern} matches at least one of the strings in the value.

@end table

@findex zformat
@item @t{zformat -f} @var{param} @var{format} @var{specs} ...
@itemx @t{zformat -a} @var{array} @var{sep} @var{specs} ...
This builtin provides two different forms of formatting. The first form 
is selected with the @t{-f} option. In this case the @var{format}
string will be modified by replacing sequences starting with a percent 
sign in it with strings from the @var{specs}.  Each @var{spec} should be
of the form `@var{char}@t{:}@var{string}' which will cause every
appearance of the sequence `@t{%}@var{char}' in @var{format} to be replaced 
by the @var{string}.  The `@t{%}' sequence may also contain optional
minimum and maximum field width specifications between the `@t{%}' and 
the `@var{char}' in the form `@t{%}@var{min}@t{.}@var{max}@t{c}',
i.e. the minimum field width is given first and if the maximum field
width is used, it has to be preceded by a dot.  Specifying a minimum field
width makes the result be padded with spaces to the right if the
@var{string} is shorter than the requested width.  Padding to the left
can be achieved by giving a negative minimum field width.  If a maximum 
field width is specified, the @var{string} will be truncated after that
many characters.  After all `@t{%}' sequences for the given @var{specs}
have been processed, the resulting string is stored in the parameter
@var{param}.

@noindent
The second form, using the @t{-a} option, can be used for aligning
strings.  Here, the @var{specs} are of the form
`@var{left}@t{:}@var{right}' where `@var{left}' and `@var{right}' are
arbitrary strings.  These strings are modified by replacing the colons
by the @var{sep} string and padding the @var{left} strings with spaces 
to the right so that the @var{sep} strings in the result (and hence the 
@var{right} strings after them) are all aligned if the strings are
printed below each other.  All strings without a colon are left
unchanged and all strings with an empty @var{right} string have the
trailing colon removed.  In both cases the lengths of the strings
are not used to determine how the other strings are to be aligned.
The resulting strings are stored in the @var{array}.

@findex zregexparse
@item @t{zregexparse}
This implements some internals of the @t{_regex_arguments} function.

@findex zparseopts
@item @t{zparseopts} [ @t{-D} ] [ @t{-K} ] [ @t{-E} ] [ @t{-a} @var{array} ] [ @t{-A} @var{assoc} ] @var{specs}
This builtin simplifies the parsing of options in positional parameters,
i.e. the set of arguments given by @t{$*}.  Each @var{spec} describes one
option and must be of the form `@var{opt}[@t{=}@var{array}]'.  If an option
described by @var{opt} is found in the positional parameters it is copied
into the @var{array} specified with the @t{-a} option; if the optional
`@t{=}@var{array}' is given, it is instead copied into that array.

@noindent
Note that it is an error to give any @var{spec} without an
`@t{=}@var{array}' unless one of the @t{-a} or @t{-A} options is used.

@noindent
Unless the @t{-E} option is given, parsing stops at the first string
that isn't described by one of the @var{specs}.  Even with @t{-E},
parsing always stops at a positional parameter equal to `@t{-}' or
`@t{-}@t{-}'.

@noindent
The @var{opt} description must be one of the following.  Any of the special
characters can appear in the option name provided it is preceded by a
backslash.

@noindent
@table @asis
@item @var{name}
@itemx @var{name}@t{+}
The @var{name} is the name of the option without the leading `@t{-}'.  To
specify a GNU-style long option, one of the usual two leading `@t{-}' must
be included in @var{name}; for example, a `@t{--file}' option is
represented by a @var{name} of `@t{-file}'.

@noindent
If a `@t{+}' appears after @var{name}, the option is appended to @var{array}
each time it is found in the positional parameters; without the `@t{+}'
only the @emph{last} occurrence of the option is preserved.

@noindent
If one of these forms is used, the option takes no argument, so parsing
stops if the next positional parameter does not also begin with `@t{-}'
(unless the @t{-E} option is used).

@item @var{name}@t{:}
@itemx @var{name}@t{:-}
@itemx @var{name}@t{::}
If one or two colons are given, the option takes an argument; with one
colon, the argument is mandatory and with two colons it is optional.  The
argument is appended to the @var{array} after the option itself.

@noindent
An optional argument is put into the same array element as the option name
(note that this makes empty strings as arguments indistinguishable).  A
mandatory argument is added as a separate element unless the `@t{:-}' form
is used, in which case the argument is put into the same element.

@noindent
A `@t{+}' as described above may appear between the @var{name} and the
first colon.

@end table

@noindent
The options of @t{zparseopts} itself are:

@noindent
@table @asis
@item @t{-a} @var{array}
As described above, this names the default array in which to store the
recognised options.

@item @t{-A} @var{assoc}
If this is given, the options and their values are also put into an
associative array with the option names as keys and the arguments (if any)
as the values.

@item @t{-D}
If this option is given, all options found are removed from the positional
parameters of the calling shell or shell function, up to but not including
any not described by the @var{specs}.  This is similar to using the @t{shift}
builtin.

@item @t{-K}
With this option, the arrays specified with the @t{-a} and @t{-A}
options and with the `@t{=}@var{array}' forms are kept unchanged when none
of the @var{specs} for them is used.  This allows assignment of default
values to them before calling @t{zparseopts}.

@item @t{-E}
This changes the parsing rules to @emph{not} stop at the first string
that isn't described by one of the @var{spec}s.  It can be used to test
for or (if used together with @t{-D}) extract options and their
arguments, ignoring all other options and arguments that may be in the
positional parameters.

@end table

@noindent
For example,

@noindent
@example
set -- -a -bx -c y -cz baz -cend
zparseopts a=foo b:=bar c+:=bar
@end example

@noindent
will have the effect of

@noindent
@example
foo=(-a)
bar=(-b x -c y -c z)
@end example

@noindent
The arguments from `@t{baz}' on will not be used.

@noindent
As an example for the @t{-E} option, consider:

@noindent
@example
set -- -a x -b y -c z arg1 arg2
zparseopts -E -D b:=bar
@end example

@noindent
will have the effect of

@noindent
@example
bar=(-b y)
set -- -a x -c z arg1 arg2
@end example

@noindent
I.e., the option @t{-b} and its arguments are taken from the
positional parameters and put into the array @t{bar}.

@end table
@c (avoiding a yodl bug)
@c (avoiding a yodl bug)
@c (avoiding a yodl bug)
@c Yodl file: Zsh/zftpsys.yo
@node Zftp Function System, User Contributions, Zsh Modules, Top

@chapter Zftp Function System
@noindent
@cindex zftp function system
@cindex FTP, functions for using shell as client

@section Description
@noindent

@noindent
This describes the set of shell functions supplied with the source
distribution as an interface to the @t{zftp} builtin command, allowing you
to perform FTP operations from the shell command line or within functions
or scripts.  The interface is similar to a traditional FTP client (e.g. the
@t{ftp} command itself, see man page ftp(1)), but as it is entirely done
within the shell all the familiar completion, editing and globbing features,
and so on, are present, and macros are particularly simple to write as they
are just ordinary shell functions.

@noindent
The prerequisite is that the @t{zftp} command, as described in
@ref{The zsh/zftp Module}
, must be available in the
version of @t{zsh} installed at your site.  If the shell is configured to
load new commands at run time, it probably is: typing `@t{zmodload zsh/zftp}'
will make sure (if that runs silently, it has worked).  If this is not the
case, it is possible @t{zftp} was linked into the shell anyway: to test
this, type `@t{which zftp}' and if @t{zftp} is available you will get the
message `@t{zftp: shell built-in command}'.

@noindent
Commands given directly with @t{zftp} builtin may be interspersed between
the functions in this suite; in a few cases, using @t{zftp} directly may
cause some of the status information stored in shell parameters to become
invalid.  Note in particular the description of the variables
@t{$ZFTP_TMOUT}, @t{$ZFTP_PREFS} and @t{$ZFTP_VERBOSE} for @t{zftp}.

@noindent
@menu
* Installation::
* Zftp Functions::
* Miscellaneous Features::
@end menu

@noindent
@node Installation, Zftp Functions, , Zftp Function System

@section Installation
@noindent

@noindent
You should make sure all the functions from the @t{Functions/Zftp}
directory of the source distribution are available; they all begin with the
two letters `@t{zf}'.  They may already have been installed on your system;
otherwise, you will need to find them and copy them.  The directory should
appear as one of the elements of the @t{$fpath} array (this should already
be the case if they were installed), and at least the function @t{zfinit}
should be autoloaded; it will autoload the rest.  Finally, to initialize
the use of the system you need to call the @t{zfinit} function.  The
following code in your @t{.zshrc} will arrange for this; assume the
functions are stored in the directory @t{~/myfns}:

@noindent
@example
fpath=(~/myfns $fpath)
autoload -U zfinit
zfinit
@end example

@noindent
Note that @t{zfinit} assumes you are using the @t{zmodload} method to
load the @t{zftp} command.  If it is already built into the shell, change
@t{zfinit} to @t{zfinit -n}.  It is helpful (though not essential) if the
call to @t{zfinit} appears after any code to initialize the new completion
system, else unnecessary @t{compctl} commands will be given.

@noindent
@node Zftp Functions, Miscellaneous Features, Installation, Zftp Function System

@section Functions
@noindent

@noindent
The sequence of operations in performing a file transfer is essentially the
same as that in a standard FTP client.  Note that, due to a quirk of the
shell's @t{getopts} builtin, for those functions that handle options you
must use `@t{-}@t{-}' rather than `@t{-}' to ensure the remaining arguments
are treated literally (a single `@t{-}' is treated as an argument).

@noindent

@subsection Opening a connection
@noindent
@table @asis
@findex zfparams
@item @t{zfparams [ @var{host} [ @var{user} [ @var{password} ... ] ] ]}
Set or show the parameters for a future @t{zfopen} with no arguments.  If
no arguments are given, the current parameters are displayed (the password
will be shown as a line of asterisks).  If a host is given, and either the
@var{user} or @var{password} is not, they will be prompted for; also, any
parameter given as `@t{?}' will be prompted for, and if the `@t{?}' is
followed by a string, that will be used as the prompt.  As @t{zfopen} calls
@t{zfparams} to store the parameters, this usually need not be called
directly.

@noindent
A single argument `@t{-}' will delete the stored parameters.  This will
also cause the memory of the last directory (and so on) on the other host
to be deleted.

@findex zfopen
@item @t{zfopen [ -1 ] [ @var{host} [ @var{user} [ @var{password} [ @var{account} ] ] ] ]}
If @var{host} is present, open a connection to that host under username
@var{user} with password @var{password} (and, on the rare occasions when it
is necessary, account @var{account}).  If a necessary parameter is missing or
given as `@t{?}' it will be prompted for.  If @var{host} is not present, use
a previously stored set of parameters.

@noindent
If the command was successful, and the terminal is compatible with
@t{xterm} or is @t{sun-cmd}, a summary will appear in the title bar,
giving the local @t{host:directory} and the remote @t{host:directory};
this is handled by the function @t{zftp_chpwd}, described below.

@noindent
Normally, the @var{host}, @var{user} and @var{password} are internally
recorded for later re-opening, either by a @t{zfopen} with no arguments, or
automatically (see below).  With the option `@t{-1}', no information is
stored.  Also, if an open command with arguments failed, the parameters
will not be retained (and any previous parameters will also be deleted).
A @t{zfopen} on its own, or a @t{zfopen -1}, never alters the stored
parameters.

@noindent
Both @t{zfopen} and @t{zfanon} (but not @t{zfparams}) understand URLs of
the form @t{ftp://}@var{host}/@var{path...} as meaning to connect to the
@var{host}, then change directory to @var{path} (which must be a directory,
not a file).  The `@t{ftp://}' can be omitted; the trailing `@t{/}' is enough
to trigger recognition of the @var{path}.  Note prefixes other than
`@t{ftp:}' are not recognized, and that all characters after the first
slash beyond @var{host} are significant in @var{path}.

@findex zfanon
@item @t{zfanon [ -1 ] @var{host}}
Open a connection @var{host} for anonymous FTP.  The username used is
`@t{anonymous}'.  The password (which will be reported the first time) is
generated as @var{user}@t{@@}@var{host}; this is then stored in the shell
parameter @t{$EMAIL_ADDR} which can alternatively be set manually to a
suitable string.

@end table

@noindent

@subsection Directory management
@noindent
@table @asis
@findex zfcd
@item @t{zfcd [ @var{dir} ]}
@itemx @t{zfcd -}
@itemx @t{zfcd @var{old} @var{new}}
Change the current directory on the remote server:  this is implemented to
have many of the features of the shell builtin @t{cd}.

@noindent
In the first form with @var{dir} present, change to the directory @var{dir}.
The command `@t{zfcd ..}' is treated specially, so is guaranteed to work on
non-UNIX servers (note this is handled internally by @t{zftp}).  If @var{dir}
is omitted, has the effect of `@t{zfcd ~}'.

@noindent
The second form changes to the directory previously current.

@noindent
The third form attempts to change the current directory by replacing the
first occurrence of the string @var{old} with the string @var{new} in the
current directory.

@noindent
Note that in this command, and indeed anywhere a remote filename is
expected, the string which on the local host corresponds to `@t{~}' is
converted back to a `@t{~}' before being passed to the remote machine.
This is convenient because of the way expansion is performed on the command
line before @t{zfcd} receives a string.  For example, suppose the command
is `@t{zfcd ~/foo}'.  The shell will expand this to a full path such as
`@t{zfcd /home/user2/pws/foo}'.  At this stage, @t{zfcd} recognises the
initial path as corresponding to `@t{~}' and will send the directory to
the remote host as @t{~/foo}, so that the `@t{~}' will be expanded by the
server to the correct remote host directory.  Other named directories of
the form `@t{~name}' are not treated in this fashion.

@findex zfhere
@item @t{zfhere}
Change directory on the remote server to the one corresponding to the
current local directory, with special handling of `@t{~}' as in @t{zfcd}.
For example, if the current local directory is @t{~/foo/bar}, then
@t{zfhere} performs the effect of `@t{zfcd ~/foo/bar}'.

@findex zfdir
@item @t{zfdir [ -rfd ] [ - ] [ @var{dir-options} ] [ @var{dir} ]}
Produce a long directory listing.  The arguments @var{dir-options} and
@var{dir} are passed directly to the server and their effect is
implementation dependent, but specifying a particular remote directory
@var{dir} is usually possible.  The output is passed through a pager
given by the environment variable @t{$PAGER}, or `@t{more}' if that is not
set.

@noindent
The directory is usually cached for re-use.  In fact, two caches are
maintained.  One is for use when there is no @var{dir-options} or @var{dir},
i.e. a full listing of the current remote directory; it is flushed
when the current remote directory changes.  The other is
kept for repeated use of @t{zfdir} with the same arguments; for example,
repeated use of `@t{zfdir /pub/gnu}' will only require the directory to be
retrieved on the first call.  Alternatively, this cache can be re-viewed with
the @t{-r} option.  As relative directories will confuse
@t{zfdir}, the @t{-f} option can be used to force the cache to be flushed
before the directory is listed.  The option @t{-d} will delete both
caches without showing a directory listing; it will also delete the cache
of file names in the current remote directory, if any.

@findex zfls
@item @t{zfls} [ @var{ls-options} ] [ @var{dir} ]
List files on the remote server.  With no arguments, this will produce a
simple list of file names for the current remote directory.  Any arguments
are passed directly to the server.  No pager and no caching is used.

@end table

@noindent

@subsection Status commands
@noindent
@table @asis
@findex zftype
@item @t{zftype} [ @var{type} ]
With no arguments, show the type of data to be transferred, usually ASCII
or binary.  With an argument, change the type: the types `@t{A}' or
`@t{ASCII}' for ASCII data and `@t{B}' or `@t{BINARY}', `@t{I}' or
`@t{IMAGE}' for binary data are understood case-insensitively.

@findex zfstat
@item @t{zfstat} [ -v ]
Show the status of the current or last connection, as well as the status of
some of @t{zftp}'s status variables.  With the @t{-v} option, a more
verbose listing is produced by querying the server for its version of
events, too.

@end table

@noindent

@subsection Retrieving files
@noindent
The commands for retrieving files all take at least two options. @t{-G}
suppresses remote filename expansion which would otherwise be performed
(see below for a more detailed description of that).  @t{-t} attempts
to set the modification time of the local file to that of the remote file:
this requires version 5 of @t{perl}, see the description of the function
@t{zfrtime} below for more information.

@noindent
@table @asis
@findex zfget
@item @t{zfget [ -Gtc ] @var{file1} ...}
Retrieve all the listed files @var{file1} ... one at a time from the remote
server.  If a file contains a `@t{/}', the full name is passed to the
remote server, but the file is stored locally under the name given by the
part after the final `@t{/}'.  The option @t{-c} (cat) forces all files to
be sent as a single stream to standard output; in this case the @t{-t}
option has no effect.

@findex zfuget
@item @t{zfuget [ -Gvst ] @var{file1} ...}
As @t{zfget}, but only retrieve files where the version on the remote
server is newer (has a later modification time), or where the local file
does not exist.  If the remote file is older but the files have different
sizes, or if the sizes are the same but the remote file is newer, the user
will usually be queried.  With the option @t{-s}, the command runs silently
and will always retrieve the file in either of those two cases.  With the
option @t{-v}, the command prints more information about the files while it
is working out whether or not to transfer them.

@findex zfcget
@item @t{zfcget [ -Gt ] @var{file1} ...}
As @t{zfget}, but if any of the local files exists, and is shorter than
the corresponding remote file, the command assumes that it is the result of
a partially completed transfer and attempts to transfer the rest of the
file.  This is useful on a poor connection which keeps failing.

@noindent
Note that this requires a commonly implemented, but non-standard, version
of the FTP protocol, so is not guaranteed to work on all servers.

@findex zfgcp
@item @t{zfgcp [ -Gt ] @var{remote-file} @var{local-file}}
@itemx @t{zfgcp [ -Gt ] @var{rfile1} ... @var{ldir}}
This retrieves files from the remote server with arguments behaving
similarly to the @t{cp} command.

@noindent
In the first form, copy @var{remote-file} from the server to the local file
@var{local-file}.

@noindent
In the second form, copy all the remote files @var{rfile1} ... into the
local directory @var{ldir} retaining the same basenames.  This assumes UNIX
directory semantics.

@end table

@noindent

@subsection Sending files
@noindent
@table @asis
@findex zfput
@item @t{zfput [ -r ] @var{file1} ...}
Send all the @var{file1} ... given separately to the remote server.  If a
filename contains a `@t{/}', the full filename is used locally to find the
file, but only the basename is used for the remote file name.

@noindent
With the option @t{-r}, if any of the @var{files} are directories they are
sent recursively with all their subdirectories, including files beginning
with `@t{.}'.  This requires that the remote machine understand UNIX file
semantics, since `@t{/}' is used as a directory separator.

@findex zfuput
@item @t{zfuput [ -vs ] @var{file1} ...}
As @t{zfput}, but only send files which are newer than their local
equivalents, or if the remote file does not exist.  The logic is the same
as for @t{zfuget}, but reversed between local and remote files.

@findex zfcput
@item @t{zfcput @var{file1} ...}
As @t{zfput}, but if any remote file already exists and is shorter than the
local equivalent, assume it is the result of an incomplete transfer and
send the rest of the file to append to the existing part.  As the FTP
append command is part of the standard set, this is in principle more
likely to work than @t{zfcget}.

@findex zfpcp
@item @t{zfpcp @var{local-file} @var{remote-file}}
@itemx @t{zfpcp @var{lfile1} ... @var{rdir}}
This sends files to the remote server with arguments behaving similarly to
the @t{cp} command.

@noindent
With two arguments, copy @var{local-file} to the server as
@var{remote-file}.

@noindent
With more than two arguments, copy all the local files @var{lfile1} ... into
the existing remote directory @var{rdir} retaining the same basenames.  This
assumes UNIX directory semantics.

@noindent
A problem arises if you attempt to use @t{zfpcp} @var{lfile1} @var{rdir},
i.e. the second form of copying but with two arguments, as the command has
no simple way of knowing if @var{rdir} corresponds to a directory or a
filename.  It attempts to resolve this in various ways.  First, if the
@var{rdir} argument is `@t{.}' or `@t{..}' or ends in a slash, it is assumed
to be a directory.  Secondly, if the operation of copying to a remote file
in the first form failed, and the remote server sends back the expected
failure code 553 and a reply including the string `@t{Is a directory}',
then @t{zfpcp} will retry using the second form.

@end table

@noindent

@subsection Closing the connection
@noindent
@table @asis
@findex zfclose
@item @t{zfclose}
Close the connection.

@end table

@noindent

@subsection Session management
@noindent
@table @asis
@findex zfsession
@item @t{zfsession} [ @t{-lvod} ] [ @var{sessname} ]
Allows you to manage multiple FTP sessions at once.  By default,
connections take place in a session called `@t{default}'; by giving the
command `@t{zfsession} @var{sessname}' you can change to a new or existing
session with a name of your choice.  The new session remembers its own
connection, as well as associated shell parameters, and also the host/user
parameters set by @t{zfparams}.  Hence you can have different sessions set
up to connect to different hosts, each remembering the appropriate host,
user and password.

@noindent
With no arguments, @t{zfsession} prints the name of the current session;
with the option @t{-l} it lists all sessions which currently exist, and
with the option @t{-v} it gives a verbose list showing the host and
directory for each session, where the current session is marked with an
asterisk.  With @t{-o}, it will switch to the most recent previous session.

@noindent
With @t{-d}, the given session (or else the current one) is removed;
everything to do with it is completely forgotten.  If it was the only
session, a new session called `@t{default}' is created and made current.
It is safest not to delete sessions while background commands using
@t{zftp} are active.

@findex zftransfer
@item @t{zftransfer} @var{sess1}@t{:}@var{file1} @var{sess2}@t{:}@var{file2}
Transfer files between two sessions; no local copy is made.  The file
is read from the session @var{sess1} as @var{file1} and written to session
@var{sess2} as file @var{file2}; @var{file1} and @var{file2} may be relative to
the current directories of the session.  Either @var{sess1} or @var{sess2}
may be omitted (though the colon should be retained if there is a
possibility of a colon appearing in the file name) and defaults to the
current session; @var{file2} may be omitted or may end with a slash, in
which case the basename of @var{file1} will be added.  The sessions
@var{sess1} and @var{sess2} must be distinct.

@noindent
The operation is performed using pipes, so it is required that the
connections still be valid in a subshell, which is not the case under 
versions of some operating systems, presumably due to a system bug.

@end table

@noindent

@subsection Bookmarks
@noindent
The two functions @t{zfmark} and @t{zfgoto} allow you to `bookmark' the
present location (host, user and directory) of the current FTP connection
for later use.  The file to be used for storing and retrieving bookmarks is
given by the parameter @t{$ZFTP_BMFILE}; if not set when one of the two
functions is called, it will be set to the file @t{.zfbkmarks} in the
directory where your zsh startup files live (usually @t{~}).

@noindent
@table @asis
@findex zfmark
@item @t{zfmark [ }@var{bookmark}@t{ ]}
If given an argument, mark the current host, user and directory under the
name @var{bookmark} for later use by @t{zfgoto}.  If there is no connection
open, use the values for the last connection immediately before it was
closed; it is an error if there was none.  Any existing bookmark
under the same name will be silently replaced.

@noindent
If not given an argument, list the existing bookmarks and the points to
which they refer in the form @var{user}@t{@@}@var{host}@t{:}@var{directory};
this is the format in which they are stored, and the file may be edited
directly.

@findex zfgoto
@item @t{zfgoto [ -n ] }@var{bookmark}
Return to the location given by @var{bookmark}, as previously set by
@t{zfmark}.  If the location has user `@t{ftp}' or `@t{anonymous}', open
the connection with @t{zfanon}, so that no password is required.  If the
user and host parameters match those stored for the current session, if
any, those will be used, and again no password is required.  Otherwise a
password will be prompted for.

@noindent
With the option @t{-n}, the bookmark is taken to be a nickname stored by
the @t{ncftp} program in its bookmark file, which is assumed to be
@t{~/.ncftp/bookmarks}.  The function works identically in other ways.
Note that there is no mechanism for adding or modifying @t{ncftp} bookmarks
from the zftp functions.

@end table

@noindent

@subsection Other functions
@noindent
Mostly, these functions will not be called directly (apart from
@t{zfinit}), but are described here for completeness.  You may wish to
alter @t{zftp_chpwd} and @t{zftp_progress}, in particular.

@noindent
@table @asis
@findex zfinit
@item @t{zfinit [ -n ]}
As described above, this is used to initialize the zftp function system.
The @t{-n} option should be used if the zftp command is already built into
the shell.

@findex zfautocheck
@item @t{zfautocheck [ -dn ]}
This function is called to implement automatic reopening behaviour, as
described in more detail below.  The options must appear in the first
argument; @t{-n} prevents the command from changing to the old directory,
while @t{-d} prevents it from setting the variable @t{do_close}, which it
otherwise does as a flag for automatically closing the connection after a
transfer.  The host and directory for the last session are stored in the
variable @t{$zflastsession}, but the internal host/user/password parameters
must also be correctly set.

@findex zfcd_match
@item @t{zfcd_match @var{prefix} @var{suffix}}
This performs matching for completion of remote directory names.  If the
remote server is UNIX, it will attempt to persuade the server to list the
remote directory with subdirectories marked, which usually works but is not
guaranteed.  On other hosts it simply calls @t{zfget_match} and hence
completes all files, not just directories.  On some systems, directories
may not even look like filenames.

@findex zfget_match
@item @t{zfget_match @var{prefix} @var{suffix}}
This performs matching for completion of remote filenames.  It caches files
for the current directory (only) in the shell parameter @t{$zftp_fcache}.
It is in the form to be called by the @t{-K} option of @t{compctl}, but
also works when called from a widget-style completion function with
@var{prefix} and @var{suffix} set appropriately.

@findex zfrglob
@item @t{zfrglob @var{varname}}
Perform remote globbing, as describes in more detail below.  @var{varname}
is the name of a variable containing the pattern to be expanded; if there
were any matches, the same variable will be set to the expanded set of
filenames on return.

@findex zfrtime
@item @t{zfrtime @var{lfile} @var{rfile} [ @var{time} ]}
Set the local file @var{lfile} to have the same modification time as the
remote file @var{rfile}, or the explicit time @var{time} in FTP format
@t{CCYYMMDDhhmmSS} for the GMT timezone.

@noindent
Currently this requires @t{perl} version 5 to perform the conversion from
GMT to local time.  This is unfortunately difficult to do using shell code
alone.

@findex zftp_chpwd, supplied version
@item @t{zftp_chpwd}
This function is called every time a connection is opened, or closed, or
the remote directory changes.  This version alters the title bar of an
@t{xterm}-compatible or @t{sun-cmd} terminal emulator to reflect the 
local and remote hostnames and current directories.  It works best when
combined with the function @t{chpwd}.  In particular, a function of 
the form

@noindent
@example
chpwd() @{
  if [[ -n $ZFTP_USER ]]; then
    zftp_chpwd
  else
    # usual chpwd e.g put host:directory in title bar
  fi
@}
@end example

@noindent
fits in well.

@findex zftp_progress, supplied version
@item @t{zftp_progress}
This function shows the status of the transfer.  It will not write anything
unless the output is going to a terminal; however, if you transfer files in
the background, you should turn off progress reports by hand using
`@t{zstyle ':zftp:*' progress none}'.  Note also that if you alter it, any
output @emph{must} be to standard error, as standard output may be a file
being received.  The form of the progress meter, or whether it is used at
all, can be configured without altering the function, as described in the
next section.

@findex zffcache
@item @t{zffcache}
This is used to implement caching of files in the current directory for
each session separately.  It is used by @t{zfget_match} and @t{zfrglob}.

@end table

@noindent
@node Miscellaneous Features, , Zftp Functions, Zftp Function System

@section Miscellaneous Features
@noindent

@noindent

@subsection Configuration
@noindent
@cindex zftp function system, configuration
@cindex zftp function system, styles
@cindex styles in zftp functions

@noindent
Various styles are available using the standard shell style mechanism,
described in
@ref{The zsh/zutil Module}. Briefly, the
command `@t{zstyle ':zftp:*'} @var{style} @var{value} ...'.
defines the @var{style} to have value @var{value}; more than one value may be
given, although that is not useful in the cases described here.  These
values will then be used throughout the zftp function system.  For more
precise control, the first argument, which gives a context in which the
style applies, can be modified to include a particular function, as for
example `@t{:zftp:zfget}': the style will then have the given value only
in the @t{zfget} function.  Values for the same style in different contexts
may be set; the most specific function will be used, where
strings are held to be more specific than patterns, and longer patterns and
shorter patterns.  Note that only the top level function name, as called by
the user, is used; calling of lower level functions is transparent to the
user.  Hence modifications to the title bar in @t{zftp_chpwd} use the
contexts @t{:zftp:zfopen}, @t{:zftp:zfcd}, etc., depending where it was
called from.  The following styles are understood:

@noindent
@table @asis
@kindex progress, zftp style
@item @t{progress}
Controls the way that @t{zftp_progress} reports on the progress of a
transfer.  If empty, unset, or `@t{none}', no progress report is made; if
`@t{bar}' a growing bar of inverse video is shown; if `@t{percent}' (or any
other string, though this may change in future), the percentage of the file
transferred is shown.  The bar meter requires that the width of the
terminal be available via the @t{$COLUMNS} parameter (normally this is set
automatically).  If the size of the file being transferred is not
available, @t{bar} and @t{percent} meters will simply show the number of
bytes transferred so far.

@noindent
When @t{zfinit} is run, if this style is not defined for the context
@t{:zftp:*}, it will be set to `bar'.

@kindex update, zftp style
@item @t{update}
Specifies the minimum time interval between updates of the progress meter
in seconds.  No update is made unless new data has been received, so the
actual time interval is limited only by @t{$ZFTP_TIMEOUT}.

@noindent
As described for @t{progress}, @t{zfinit} will force this to default to 1.

@kindex remote-glob, zftp style
@item @t{remote-glob}
If set to `1', `yes' or `true', filename generation (globbing) is
performed on the remote machine instead of by zsh itself; see below.

@kindex titlebar, zftp style
@item @t{titlebar}
If set to `1', `yes' or `true', @t{zftp_chpwd} will put the remote host and
remote directory into the titlebar of terminal emulators such as xterm or
sun-cmd that allow this.

@noindent
As described for @t{progress}, @t{zfinit} will force this to default to 1.

@kindex chpwd, zftp style
@item @t{chpwd}
If set to `1' `yes' or `true', @t{zftp_chpwd} will call the function
@t{chpwd} when a connection is closed.  This is useful if the remote host
details were put into the terminal title bar by @t{zftp_chpwd} and your
usual @t{chpwd} also modifies the title bar.

@noindent
When @t{zfinit} is run, it will determine whether @t{chpwd} exists and if
so it will set the default value for the style to 1 if none exists
already.

@end table

@noindent
Note that there is also an associative array @t{zfconfig} which contains
values used by the function system.  This should not be modified or
overwritten.

@noindent

@subsection Remote globbing
@noindent
@cindex zftp function system, remote globbing

@noindent
The commands for retrieving files usually perform filename generation
(globbing) on their arguments; this can be turned off by passing the option
@t{-G} to each of the commands.  Normally this operates by retrieving a
complete list of files for the directory in question, then matching these
locally against the pattern supplied.  This has the advantage that the full
range of zsh patterns (respecting the setting of the option
@t{EXTENDED_GLOB}) can be used.  However, it means that the directory part
of a filename will not be expanded and must be given exactly.  If the
remote server does not support the UNIX directory semantics, directory
handling is problematic and it is recommended that globbing only be used
within the current directory.  The list of files in the current directory,
if retrieved, will be cached, so that subsequent globs in the same
directory without an intervening @t{zfcd} are much faster.

@noindent
If the @t{remote-glob} style (see above) is set, globbing is instead
performed on the remote host: the server is asked for a list of matching
files.  This is highly dependent on how the server is implemented, though
typically UNIX servers will provide support for basic glob patterns.  This
may in some cases be faster, as it avoids retrieving the entire list of
directory contents.

@noindent

@subsection Automatic and temporary reopening
@noindent
@cindex zftp function system, automatic reopening

@noindent
As described for the @t{zfopen} command, a subsequent @t{zfopen} with no
parameters will reopen the connection to the last host (this includes
connections made with the @t{zfanon} command).  Opened in this fashion, the
connection starts in the default remote directory and will remain open
until explicitly closed.

@noindent
Automatic re-opening is also available.  If a connection is not currently
open and a command requiring a connection is given, the last connection is
implicitly reopened.  In this case the directory which was current when the
connection was closed again becomes the current directory (unless, of
course, the command given changes it).  Automatic reopening will also take
place if the connection was close by the remote server for whatever reason
(e.g. a timeout).  It is not available if the @t{-1} option to @t{zfopen}
or @t{zfanon} was used.

@noindent
Furthermore, if the command issued is a file transfer, the connection will
be closed after the transfer is finished, hence providing a one-shot mode
for transfers.  This does not apply to directory changing or listing
commands; for example a @t{zfdir} may reopen a connection but will leave it
open.  Also, automatic closure will only ever happen in the same command as
automatic opening, i.e a @t{zfdir} directly followed by a @t{zfget} will
never close the connection automatically.

@noindent
Information about the previous connection is given by the @t{zfstat}
function.  So, for example, if that reports:

@noindent
@example
Session:        default
Not connected.
Last session:   ftp.bar.com:/pub/textfiles
@end example

@noindent
then the command @t{zfget file.txt} will attempt to reopen a connection to
@t{ftp.bar.com}, retrieve the file @t{/pub/textfiles/file.txt}, and
immediately close the connection again.  On the other hand, @t{zfcd ..}
will open the connection in the directory @t{/pub} and leave it open.

@noindent
Note that all the above is local to each session; if you return to a
previous session, the connection for that session is the one which will be
reopened.

@noindent

@subsection Completion
@noindent

@noindent
Completion of local and remote files, directories, sessions and bookmarks
is supported.  The older, @t{compctl}-style completion is defined when
@t{zfinit} is called; support for the new widget-based completion system is
provided in the function @t{Completion/Zsh/Command/_zftp}, which should be
installed with the other functions of the completion system and hence
should automatically be available.
@c (avoiding a yodl bug)
@c Yodl file: Zsh/contrib.yo
@node User Contributions, , Zftp Function System, Top

@chapter User Contributions
@noindent
@cindex user contributions

@section Description
@noindent

@noindent
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.

@noindent
@menu
* Utilities::
* Prompt Themes::
* ZLE Functions::
* Other Functions::
@end menu

@noindent
@node Utilities, Prompt Themes, , User Contributions

@section Utilities
@noindent

@noindent

@subsection Accessing On-Line Help
@noindent
@cindex helpfiles utility

@noindent
The key sequence @t{ESC h} is normally bound by ZLE to execute the
@t{run-help} widget (see
@ref{Zsh Line Editor}).  This invokes the @t{run-help} command with the command word from the
current input line as its argument.  By default, @t{run-help} is an alias
for the @t{man} command, so this often fails when the command word is a
shell builtin or a user-defined function.  By redefining the @t{run-help}
alias, one can improve the on-line help provided by the shell.

@noindent
The @t{helpfiles} utility, found in the @t{Util} 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 @t{run-help} function, found in
@t{Functions/Misc}, searches for these helpfiles and performs several
other tests to produce the most complete help possible for the command.

@noindent
There may already be a directory of help files on your system; look in
@t{/usr/share/zsh} or @t{/usr/local/share/zsh} and subdirectories below
those, or ask your system administrator.

@noindent
To create your own help files with @t{helpfiles}, choose or create a
directory where the individual command help files will reside.  For
example, you might choose @t{~/zsh_help}.  If you unpacked the zsh
distribution in your home directory, you would use the commands:

@noindent
@example
mkdir ~/zsh_help
cd ~/zsh_help
man zshall | colcrt - | \ 
perl ~/zsh-4.0.7/Util/helpfiles
@end example

@noindent
@findex run-help, use of
Next, to use the @t{run-help} function, you need to add lines something
like the following to your @t{.zshrc} or equivalent startup file:

@noindent
@example
unalias run-help
autoload run-help
HELPDIR=~/zsh_help
@end example

@noindent
@vindex HELPDIR
The @t{HELPDIR} parameter tells @t{run-help} where to look for the help
files.  If your system already has a help file directory installed, set
@t{HELPDIR} to the path of that directory instead.

@noindent
Note that in order for `@t{autoload run-help}' to work, the @t{run-help}
file must be in one of the directories named in your @t{fpath} array (see
@ref{Parameters Used By The Shell}).  This should already be the case if you have a standard zsh
installation; if it is not, copy @t{Functions/Misc/run-help} to an
appropriate directory.

@noindent

@subsection Recompiling Functions
@noindent
@cindex functions, recompiling
@cindex zrecompile utility

@noindent
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 @t{zcompile} 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 @t{fpath}, zsh won't check whether
any of its source files has changed.

@noindent
The @t{zrecompile} autoloadable function, found in @t{Functions/Misc}, can
be used to keep function digests up to date.

@noindent
@table @asis
@findex zrecompile
@item @t{zrecompile} [ @t{-qt} ] [ @var{name} ... ]
@itemx @t{zrecompile} [ @t{-qt} ] @t{-p} @var{args} [ @t{-}@t{-} @var{args} ... ]
This tries to find @t{*.zwc} 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 @t{.zwc} file.

@noindent
In the first form, each @var{name} is the name of a compiled file or a
directory containing @t{*.zwc} files that should be checked.  If no
arguments are given, the directories and @t{*.zwc} files in @t{fpath} are
used.

@noindent
When @t{-t} 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 @t{-q} option quiets the chatty output
that describes what @t{zrecompile} is doing.

@noindent
Without the @t{-t} 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.

@noindent
If the @t{-p} option is given, the @var{args} are interpreted as one
or more sets of arguments for @t{zcompile}, separated by `@t{-}@t{-}'.
For example:

@noindent
@example
zrecompile -p \ 
           -R ~/.zshrc -- \ 
           -M ~/.zcompdump -- \ 
           ~/zsh/comp.zwc ~/zsh/Completion/*/_*
@end example

@noindent
This compiles @t{~/.zshrc} into @t{~/.zshrc.zwc} if that doesn't exist or
if it is older than @t{~/.zshrc}. The compiled file will be marked for
reading instead of mapping. The same is done for @t{~/.zcompdump} and
@t{~/.zcompdump.zwc}, but this compiled file is marked for mapping. The
last line re-creates the file @t{~/zsh/comp.zwc} if any of the files
matching the given pattern is newer than it.

@noindent
Without the @t{-p} option, @t{zrecompile} does not create function digests
that do not already exist, nor does it add new functions to the digest.

@end table

@noindent
The following shell loop is an example of a method for creating function
digests for all functions in your @t{fpath}, assuming that you have write
permission to the directories:

@noindent
@example
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
@end example

@noindent
The @t{-U} and @t{-z} options are appropriate for functions in the default
zsh installation @t{fpath}; you may need to use different options for your
personal function directories.

@noindent
Once the digests have been created and your @t{fpath} modified to refer to
them, you can keep them up to date by running @t{zrecompile} with no
arguments.

@noindent

@subsection Keyboard Definition
@noindent
@cindex keyboard definition

@noindent
@findex zkbd
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 @t{zkbd} utility,
found in Functions/Misc, can help you quickly create key bindings for your
configuration.

@noindent
Run @t{zkbd} either as an autoloaded function, or as a shell script:

@noindent
@example
zsh -f ~/zsh-4.0.7/Functions/Misc/zkbd
@end example

@noindent
When you run @t{zkbd}, 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; @t{zkbd} warns you if it finds anything out of the
ordinary, such as a Delete key that sends neither @t{^H} nor @t{^?}.

@noindent
The keystrokes read by @t{zkbd} are recorded as a definition for an
associative array named @t{key}, written to a file in the subdirectory
@t{.zkbd} within either your @t{HOME} or @t{ZDOTDIR} directory.  The name
of the file is composed from the @t{TERM}, @t{VENDOR} and @t{OSTYPE}
parameters, joined by hyphens.

@noindent
You may read this file into your @t{.zshrc} or another startup file with
the "source" or "." commands, then reference the @t{key} parameter in
bindkey commands, like this:

@noindent
@example
source $@{ZDOTDIR:-$HOME@}/.zkbd/$TERM-$VENDOR-$OSTYPE
[[ -n $@{key[Left]@} ]] && bindkey "$@{key[Left]@}" backward-char
[[ -n $@{key[Right]@} ]] && bindkey "$@{key[Right]@}" forward-char
# etc.
@end example

@noindent
Note that in order for `@t{autoload zkbd}' to work, the @t{zkdb} file must
be in one of the directories named in your @t{fpath} array (see
@ref{Parameters Used By The Shell}).  This should already be the case if you have a standard zsh
installation; if it is not, copy @t{Functions/Misc/zkbd} to an
appropriate directory.

@noindent

@subsection Dumping Shell State
@noindent
@cindex reporter utility

@noindent
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
@ref{Mailing Lists}), but sometimes one of the zsh developers will need to recreate your
environment in order to track the problem down.

@noindent
The script named @t{reporter}, found in the @t{Util} directory of the
distribution, is provided for this purpose.  (It is also possible to
@t{autoload reporter}, but @t{reporter} is not installed in @t{fpath}
by default.)  This script outputs a detailed dump of the shell state,
in the form of another script that can be read with `@t{zsh -f}' to
recreate that state.

@noindent
To use @t{reporter}, read the script into your shell with the `@t{.}'
command and redirect the output into a file:

@noindent
@example
. ~/zsh-4.0.7/Util/reporter > zsh.report
@end example

@noindent
You should check the @t{zsh.report} file for any sensitive information
such as passwords and delete them by hand before sending the script to the
developers.  Also, as the output can be voluminous, it's best to wait for
the developers to ask for this information before sending it.

@noindent
You can also use @t{reporter} 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 @t{aliases}, @t{options}, and
@t{zstyles} states may be useful because they include only changes from
the defaults.  The @t{bindings} state may be useful if you have created
any of your own keymaps, because @t{reporter} arranges to dump the keymap
creation commands as well as the bindings for every keymap.

@noindent
As is usual with automated tools, if you create a startup file with
@t{reporter}, you should edit the results to remove unnecessary commands.
Note that if you're using the new completion system, you should @emph{not}
dump the @t{functions} state to your startup files with @t{reporter}; use
the @t{compdump} function instead (see
@ref{Completion System}).

@noindent
@table @asis
@item @t{reporter} [ @var{state} ... ]
@findex reporter
Print to standard output the indicated subset of the current shell state.
The @var{state} arguments may be one or more of:

@noindent
@table @asis
@item @t{all}
Output everything listed below.
@item @t{aliases}
Output alias definitions.
@item @t{bindings}
Output ZLE key maps and bindings.
@item @t{completion}
Output old-style @t{compctl} commands.
New completion is covered by @t{functions} and @t{zstyles}.
@item @t{functions}
Output autoloads and function definitions.
@item @t{limits}
Output @t{limit} commands.
@item @t{options}
Output @t{setopt} commands.
@item @t{styles}
Same as @t{zstyles}.
@item @t{variables}
Output shell parameter assignments, plus @t{export}
commands for any environment variables.
@item @t{zstyles}
Output @t{zstyle} commands.
@end table

@noindent
If the @var{state} is omitted, @t{all} is assumed.


@noindent
With the exception of `@t{all}', every @var{state} can be abbreviated by
any prefix, even a single letter; thus @t{a} is the same as @t{aliases},
@t{z} is the same as @t{zstyles}, etc.
@end table

@noindent
@node Prompt Themes, ZLE Functions, Utilities, User Contributions

@section Prompt Themes
@noindent

@noindent

@subsection Installation
@noindent

@noindent
You should make sure all the functions from the @t{Functions/Prompts}
directory of the source distribution are available; they all begin with
the string `@t{prompt_}' except for the special function`@t{promptinit}'.
You also need the `@t{colors}' function from @t{Functions/Misc}.  All of
these functions may already have been installed on your system; if not,
you will need to find them and copy them.  The directory should appear as
one of the elements of the @t{fpath} array (this should already be the
case if they were installed), and at least the function @t{promptinit}
should be autoloaded; it will autoload the rest.  Finally, to initialize
the use of the system you need to call the @t{promptinit} function.  The
following code in your @t{.zshrc} will arrange for this; assume the
functions are stored in the directory @t{~/myfns}:

@noindent
@example
fpath=(~/myfns $fpath)
autoload -U promptinit
promptinit
@end example

@noindent

@subsection Theme Selection
@noindent

@noindent
Use the @t{prompt} command to select your preferred theme.  This command
may be added to your @t{.zshrc} following the call to @t{promptinit} in
order to start zsh with a theme already selected.

@noindent
@table @asis
@item @t{prompt} [ @t{-c} | @t{-l} ]
@itemx @t{prompt} [ @t{-p} | @t{-h} ] [ @var{theme} ... ]
@itemx @t{prompt} [ @t{-s} ] @var{theme} [ @var{arg} ... ]
Set or examine the prompt theme.  With no options and a @var{theme}
argument, the theme with that name is set as the current theme.  The
available themes are determined at run time; use the @t{-l} option to see
a list.  The special @var{theme} `@t{random}' selects at random one of the
available themes and sets your prompt to that.

@noindent
In some cases the @var{theme} may be modified by one or more arguments,
which should be given after the theme name.  See the help for each theme
for descriptions of these arguments.

@noindent
Options are:

@noindent
@table @asis
@item @t{-c}
Show the currently selected theme and its parameters, if any.
@item @t{-l}
List all available prompt themes.
@item @t{-p}
Preview the theme named by @var{theme}, or all themes if no
@var{theme} is given.
@item @t{-h}
Show help for the theme named by @var{theme}, or for the
@t{prompt} function if no @var{theme} is given.
@item @t{-s}
Set @var{theme} as the current theme and save state.
@end table

@item @t{prompt_}@var{theme}@t{_setup}
Each available @var{theme} has a setup function which is called by the
@t{prompt} function to install that theme.  This function may define
other functions as necessary to maintain the prompt, including functions
used to preview the prompt or provide help for its use.  You should not
normally call a theme's setup function directly.

@end table

@noindent
@node ZLE Functions, Other Functions, Prompt Themes, User Contributions

@section ZLE Functions
@noindent

@noindent

@subsection Widgets
@noindent

@noindent
These functions all implement user-defined ZLE widgets (see
@ref{Zsh Line Editor}) which can be bound to keystrokes in interactive shells.  To use them,
your @t{.zshrc} should contain lines of the form

@noindent
@example
autoload @var{function}
zle -N @var{function}
@end example

@noindent
followed by an appropriate @t{bindkey} command to associate the function
with a key sequence.  Suggested bindings are described below.

@noindent
@table @asis
@tindex bash-forward-word
@tindex bash-backward-word
@tindex bash-kill-word
@tindex bash-backward-kill-word
@tindex bash-transpose-words
@tindex bash-up-case-word
@tindex bash-down-case-word
@item @t{bash-forward-word}, @t{bash-backward-word}
@itemx @t{bash-kill-word}, @t{bash-backward-kill-word}
@itemx @t{bash-up-case-word}, @t{bash-down-case-word}
@itemx @t{bash-transpose-words}
These work similarly to the corresponding builtin zle functions without the
`@t{bash-}' prefix, but a word is considered to consist of alphanumeric
characters only.  If you wish to replace your existing bindings with these
four widgets, the following is sufficient:

@noindent
@example
for widget in kill-word backward-kill-word \ 
forward-word backward-word \ 
up-case-word down-case-word \ 
transpose-words; do 
  autoload bash-$widget 
  zle -N $widget bash-$widget
done
@end example

@tindex cycle-completion-positions
@item @t{cycle-completion-positions}
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.

@noindent
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.

@tindex edit-command-line
@item @t{edit-command-line}
Edit the command line using your visual editor, as in @t{ksh}.

@noindent
@example
bindkey -M vicmd v edit-command-line
@end example

@tindex history-beginning-search-backward-end
@tindex history-beginning-search-forward-end
@item @t{history-search-end}
This function implements the widgets
@t{history-beginning-search-backward-end} and
@t{history-beginning-search-forward-end}.  These commands work by first
calling the corresponding builtin widget (see
@ref{History Control}) and then moving the cursor to the end of the line.  The original cursor
position is remembered and restored before calling the builtin widget a
second time, so that the same search is repeated to look farther through
the history.

@noindent
Although you @t{autoload} only one function, the commands to use it are
slightly different because it implements two widgets.

@noindent
@example
zle -N history-beginning-search-backward-end \ 
       history-search-end
zle -N history-beginning-search-forward-end \ 
       history-search-end
bindkey '\e^P' history-beginning-search-backward-end
bindkey '\e^N' history-beginning-search-forward-end
@end example

@tindex incarg
@vindex incarg, use of
@item @t{incarg}
Typing the keystrokes for this widget with the cursor placed on or to the
left of an integer causes that integer to be incremented by one.  With a
numeric prefix argument, the number is incremented by the amount of the
argument (decremented if the prefix argument is negative).  The shell
parameter @t{incarg} may be set to change the default increment something
other than one.

@noindent
@example
bindkey '^X+' incarg
@end example

@tindex incremental-complete-word
@item @t{incremental-complete-word}
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 @t{^H} or @t{DEL}.  Pressing return
accepts the completion so far and returns you to normal editing (that is,
the command line is @emph{not} immediately executed).  You can hit @t{TAB} to
do normal completion, @t{^G} to abort back to the state when you started,
and @t{^D} to list the matches.

@noindent
This works only with the new function based completion system.

@noindent
@example
bindkey '^Xi' incremental-complete-word
@end example

@tindex insert-files
@item @t{insert-files}
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.

@noindent
@example
bindkey '^Xf' insert-files
@end example

@tindex predict-on
@tindex predict-off
@item @t{predict-on}
This set of functions implements predictive typing using history search.
After @t{predict-on}, typing characters causes the editor to look backward
in the history for the first line beginning with what you have typed so
far.  After @t{predict-off}, editing returns to normal for the line found.
In fact, you often don't even need to use @t{predict-off}, because if the
line doesn't match something in the history, adding a key performs
standard completion, and then inserts itself if no completions were found.
However, editing in the middle of a line is liable to confuse prediction;
see the @t{toggle} style below.

@noindent
With the function based completion system (which is needed for this), you
should be able to type @t{TAB} at almost any point to advance the cursor
to the next @value{dsbq}interesting@value{dsq} 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.

@noindent
The first time @t{predict-on} is used, it creates several additional
widget functions:

@noindent
@table @asis
@item @t{delete-backward-and-predict}
Replaces the @t{backward-delete-char}
widget.  You do not need to bind this yourself.
@item @t{insert-and-predict}
Implements predictive typing by replacing the
@t{self-insert} widget.  You do not need to bind this yourself.
@item @t{predict-off}
Turns off predictive typing.
@end table

@noindent
Although you @t{autoload} only the @t{predict-on} function, it is
necessary to create a keybinding for @t{predict-off} as well.

@noindent
@example
zle -N predict-on
zle -N predict-off
bindkey '^X^Z' predict-on
bindkey '^Z' predict-off
@end example

@findex smart-insert-last-word
@item @t{smart-insert-last-word}
This function may replace the @t{insert-last-word} widget, like so:

@noindent
@example
zle -N insert-last-word smart-insert-last-word
@end example

@noindent
With a numeric prefix, it behaves like @t{insert-last-word}, except that
words in comments are ignored when @t{INTERACTIVE_COMMENTS} is set.

@noindent
Otherwise, the rightmost @value{dsbq}interesting@value{dsq} word from the previous command is
found and inserted.  The default definition of @value{dsbq}interesting@value{dsq} is that the
word contains at least one alphabetic character, slash, or backslash.
This definition may be overridden by use of the @t{match} style.  The
context used to look up the style is the widget name, so usually the
context is @t{:insert-last-word}.  However, you can bind this function to
different widgets to use different patterns:

@noindent
@example
zle -N insert-last-assignment smart-insert-last-word
zstyle :insert-last-assignment match '[[:alpha:]][][[:alnum:]]#=*'
bindkey '\e=' insert-last-assignment
@end example

@end table

@noindent

@subsection Styles
@noindent

@noindent
The behavior of several of the above widgets can be controlled by the use
of the @t{zstyle} mechanism.  In particular, widgets that interact with
the completion system pass along their context to any completions that
they invoke.

@noindent
@table @asis
@kindex break-keys, widget style
@item @t{break-keys}
This style is used by the @t{incremental-complete-word} 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
@t{incremental-complete-word}, this style is looked up using the
context `@t{:incremental}'.

@kindex completer, completion style
@item @t{completer}
The @t{incremental-complete-word} and @t{insert-and-predict} 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:

@noindent
@example
zstyle ':completion:*' completer \ 
        _complete _correct _approximate
zstyle ':completion:incremental:*' completer \ 
        _complete _correct
zstyle ':completion:predict:*' completer \ 
        _complete
@end example

@noindent
It is a good idea to restrict the completers used in prediction, because
they may be automatically invoked as you type.  The @t{_list} and
@t{_menu} completers should never be used with prediction.  The
@t{_approximate}, @t{_correct}, @t{_expand}, and @t{_match} 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.

@kindex cursor, completion style
@item @t{cursor}
The @t{insert-and-predict} widget uses this style, in the context
`@t{:predict}', to decide where to place the cursor after completion has
been tried.  Values are:

@noindent
@table @asis
@item @t{complete}
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 `@t{key}'.

@item @t{key}
The cursor is left
after the @var{n}th occurrence of the character just inserted, where
@var{n} is the number of times that character appeared in the word
before completion was attempted.  In short, this has the effect of
leaving the cursor after the character just typed even if the
completion code found out that no other characters need to be inserted 
at that position.

@end table

@noindent
Any other value for this style unconditionally leaves the cursor at the
position where the completion code left it.

@kindex list, widget style
@item @t{list}
When using the @t{incremental-complete-word} widget, this style says
if the matches should be listed on every key press (if they fit on the 
screen).  Use the context prefix `@t{:completion:incremental}'.

@noindent
The @t{insert-and-predict} 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 @t{always}.  In this
case the context is `@t{:predict}' (@emph{not} `@t{:completion:predict}').

@kindex match, widget style
@item @t{match}
This style is used by @t{smart-insert-last-word} to provide a pattern
(using full @t{EXTENDED_GLOB} syntax) that matches an interesting word.
The context is the name of the widget to which @t{smart-insert-last-word}
is bound (see above).  The default behavior of @t{smart-insert-last-word}
is equivalent to:

@noindent
@example
zstyle :insert-last-word match '*[[:alpha:]/\\]*'
@end example

@noindent
However, you might want to include words that contain spaces:

@noindent
@example
zstyle :insert-last-word match '*[[:alpha:][:space:]/\\]*'
@end example

@noindent
Or include numbers as long as the word is at least two characters long:

@noindent
@example
zstyle :insert-last-word match '*([[:digit:]]?|[[:alpha:]/\\])*'
@end example

@noindent
The above example causes redirections like "2>" to be included.

@kindex prompt, widget style
@item @t{prompt}
The @t{incremental-complete-word} 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 @t{PS1} and other prompt parameters:

@noindent
@table @asis
@item @t{%c}
Replaced by the name of the completer function that generated the
matches (without the leading underscore).

@item @t{%l}
When the @t{list} style is set,
replaced by `@t{...}' if the list of matches is too long to fit on the
screen and with an empty string otherwise.  If the @t{list} style is
`false' or not set, `@t{%l}' is always removed.

@item @t{%n}
Replaced by the number of matches generated.

@item @t{%s}
Replaced by `@t{-no match-}', `@t{-no prefix-}', or an empty string
if there is no completion matching the word on the line, if the
matches have no common prefix different from the word on the line, or
if there is such a common prefix, respectively.

@item @t{%u}
Replaced by the unambiguous part of all matches, if there
is any, and if it is different from the word on the line.

@end table

@noindent
Like `@t{break-keys}', this uses the `@t{:incremental}' context.

@kindex stop-keys, widget style
@item @t{stop-keys}
This style is used by the @t{incremental-complete-word} widget.  Its value
is treated similarly to the one for the @t{break-keys} style (and uses 
the same context: `@t{:incremental}').  However, in
this case all keys matching the pattern given as its value will stop
incremental completion and will then execute their usual function.

@kindex toggle, widget style
@item @t{toggle}
This boolean style is used by @t{predict-on} and its related widgets in
the context `@t{:predict}'.  If set to one of the standard `true' values,
predictive typing is automatically toggled off in situations where it is
unlikely to be useful, such as when editing a multi-line buffer or after
moving into the middle of a line and then deleting a character.  The
default is to leave prediction turned on until an explicit call to
@t{predict-off}.

@kindex verbose, widget style
@item @t{verbose}
This boolean style is used by @t{predict-on} and its related widgets in
the context `@t{:predict}'.  If set to one of the standard `true' values,
these widgets display a message below the prompt when the predictive state
is toggled.  This is most useful in combination with the @t{toggle} style.
The default does not display these messages.

@end table

@noindent
@node Other Functions, , ZLE Functions, User Contributions

@section Other Functions
@noindent

@noindent
There are a large number of helpful functions in the @t{Functions/Misc}
directory of the zsh distribution.  Most are very simple and do not
require documentation here, but a few are worthy of special mention.

@noindent

@subsection Descriptions
@noindent

@noindent
@table @asis
@findex colors
@item @t{colors}
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 (@ref{Prompt Themes}).  You seldom should need to run
@t{colors} more than once.

@noindent
The eight base colors are: black, red, green, yellow, blue, magenta, cyan,
and white.  Each of these has codes for foreground and background.  In
addition there are eight intensity attributes: bold, faint, standout,
underline, blink, reverse, and conceal.  Finally, there are six codes used
to negate attributes: none (reset all attributes to the defaults), normal
(neither bold nor faint), no-standout, no-underline, no-blink, and
no-reverse.

@noindent
Some terminals do not support all combinations of colors and intensities.

@noindent
The associative arrays are:

@noindent
@table @asis
@item color
@itemx colour
Map all the color names to their integer codes, and integer codes to the
color names.  The eight base names map to the foreground color codes, as
do names prefixed with `@t{fg-}', such as `@t{fg-red}'.  Names prefixed
with `@t{bg-}', such as `@t{bg-blue}', refer to the background codes.  The
reverse mapping from code to color yields base name for foreground codes
and the @t{bg-} form for backgrounds.

@noindent
Although it is a misnomer to call them `colors', these arrays also map the
other fourteen attributes from names to codes and codes to names.

@item fg
@itemx fg_bold
@itemx fg_no_bold
Map the eight basic color names to ANSI terminal escape sequences that set
the corresponding foreground text properties.  The @t{fg} sequences change
the color without changing the eight intensity attributes.

@item bg
@itemx bg_bold
@itemx bg_no_bold
Map the eight basic color names to ANSI terminal escape sequences that set
the corresponding background properties.  The @t{bg} sequences change the
color without changing the eight intensity attributes.

@end table

@noindent
In addition, the scalar parameters @t{reset_color} and @t{bold_color} are
set to the ANSI terminal escapes that turn off all attributes and turn on
bold intensity, respectively.

@findex fned
@item @t{fned} @var{name}
Same as @t{zed -f}.  This function does not appear in the zsh
distribution, but can be created by linking @t{zed} to the name @t{fned}
in some directory in your @t{fpath}.

@findex is-at-least
@item @t{is-at-least} @var{needed} [ @var{present} ]
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 @var{present} string is not
provided, @t{$ZSH_VERSION} 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.

@noindent
This is useful in startup files to set options and other state that are
not available in all versions of zsh.

@noindent
@example
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 "You can't use is-at-least here."
@end example

@findex nslookup
@item @t{nslookup} [ @var{arg} ... ]
This wrapper function for the @t{nslookup} command requires the
@t{zsh/zpty} module (see
@ref{The zsh/zpty Module}).  It behaves exactly like the standard @t{nslookup}
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 `@t{:completion:nslookup}'.

@noindent
See also the @t{pager}, @t{prompt} and @t{rprompt} styles below.

@item @t{run-help}
See `Accessing On-Line Help'
(@ref{Utilities}).

@findex zed
@item @t{zed} [ @t{-f} ] @var{name}
This function uses the ZLE editor to edit a file or function.  It rebinds
the return key to insert a line break, and adds bindings for `@t{^X^W}' in
the @t{emacs} keymap and `@t{ZZ}' in the @t{vicmd} keymap to accept (and
therefore write, in the case of a file) the edited file or function.
Keybindings are otherwise the standard ones; completion is available, and
styles may be set with the context prefix `@t{:completion:zed}'.

@noindent
Only one @var{name} argument is recognized (additional arguments are
ignored).  If the @t{-f} option is given, the name is taken to be that of
a function; if the function is marked for autoloading, @t{zed} searches
for it in the @t{fpath} and loads it.  Note that functions edited this way
are installed into the current shell, but @emph{not} written back to the
autoload file.

@noindent
Without @t{-f}, @var{name} is the path name of the file to edit, which need
not exist; it is created on write, if necessary.

@findex zcp
@findex zln
@item @t{zcp} [ @t{-finqQvwW} ] @var{srcpat} @var{dest}
@itemx @t{zln} [ @t{-finqQsvwW} ] @var{srcpat} @var{dest}
Same as @t{zmv -C} and @t{zmv -L}, respectively.  These functions do not
appear in the zsh distribution, but can be created by linking @t{zmv} to
the names @t{zcp} and @t{zln} in some directory in your @t{fpath}.

@item @t{zkbd}
See `Keyboard Definition'
(@ref{Utilities}).

@findex zmv
@item @t{zmv} [ @t{-finqQsvwW} ] [ -C | -L | -M | -p @var{program} ] [ -o @var{optstring} ] @var{srcpat} @var{dest} 
Move (usually, rename) files matching the pattern @var{srcpat} to
corresponding files having names of the form given by @var{dest}, where
@var{srcpat} contains parentheses surrounding patterns which will be
replaced in turn by $1, $2, ... in @var{dest}.  For example,

@noindent
@example
zmv '(*).lis' '$1.txt'
@end example

@noindent
renames `@t{foo.lis}' to `@t{foo.txt}', `@t{my.old.stuff.lis}' to
`@t{my.old.stuff.txt}', and so on.

@noindent
The pattern is always treated as an @t{EXTENDED_GLOB} 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 @t{-f}
was not given) causes the entire function to abort without doing anything.

@noindent
Options:

@noindent
@table @asis
@item @t{-f}
Force overwriting of destination files.  Not currently
passed down to the @t{mv}/@t{cp}/@t{ln} command due to vagaries of
implementations (but you can use @t{-o-f} to do that).
@item @t{-i}
Interactive: show each line to be executed and ask the user
whether to execute it.  `Y' or `y' will execute it, anything else will
skip it.  Note that you just need to type one character.
@item @t{-n}
No execution: print what would happen, but don't do it.
@item @t{-q}
Turn bare glob qualifiers off: now assumed by default, so
this has no effect.
@item @t{-Q}
Force bare glob qualifiers on.  Don't turn this on unless
you are actually using glob qualifiers in a pattern.
@item @t{-s}
Symbolic, passed down to @t{ln}; only works with @t{-L}.
@item @t{-v}
Verbose: print each command as it's being executed.
@item @t{-w}
Pick out wildcard parts of the pattern, as described above,
and implicitly add parentheses for referring to them.
@item @t{-W}
Just like @t{-w}, with the addition of turning wildcards in
the replacement pattern into sequential $@{1@} .. $@{N@} references.
@item @t{-C}
@itemx @t{-L}
@itemx @t{-M}
Force @t{cp}, @t{ln} or @t{mv}, respectively, regardless of
the name of the function.
@item @t{-p} @var{program}
Call @var{program} instead of @t{cp}, @t{ln} or
@t{mv}.  Whatever it does, it should at least understand the form
@example
@var{program} @t{-}@t{-} @var{oldname} @var{newname}
@end example
where @var{oldname} and @var{newname} are filenames generated by @t{zmv}.
@item @t{-o} @var{optstring}
The @var{optstring} is split into words and
passed down verbatim to the @t{cp}, @t{ln} or @t{mv} command called to
perform the work.  It should probably begin with a `@t{-}'.
@end table

@noindent
For more complete examples and other implementation details, see the
@t{zmv} source file, usually located in one of the directories named in
your @t{fpath}, or in @t{Functions/Misc/zmv} in the zsh distribution.

@item @t{zrecompile}
See `Recompiling Functions'
(@ref{Utilities}).

@findex zstyle+
@item @t{zstyle+} @var{context} @var{style} @var{value} [ + @var{subcontext} @var{style} @var{value} ... ]
This makes defining styles a bit simpler by using a single `@t{+}' as a
special token that allows you to append a context name to the previously
used context name.  Like this:

@noindent
@example
zstyle+ ':foo:bar' style1 value1 \ 
      + ':baz'     style2 value2 \ 
      + ':frob'    style3 value3
@end example

@noindent
This defines `style1' with `value1' for the context @t{:foo:bar} as usual,
but it also defines `style2' with `value2' for the context
@t{:foo:bar:baz} and `style3' with `value3' for @t{:foo:bar:frob}.  Any
@var{subcontext} may be the empty string to re-use the first context
unchanged.

@end table

@noindent

@subsection Styles
@noindent

@noindent
@table @asis
@kindex insert-tab, completion style
@item @t{insert-tab}
The @t{zed} function @emph{sets} this style in context `@t{:completion:zed:*}'
to turn off completion when @t{TAB} is typed at the beginning of a line.
You may override this by setting your own value for this context and style.

@kindex pager, nslookup style
@item @t{pager}
The @t{nslookup} function looks up this style in the context
`@t{:nslookup}' to determine the program used to display output that does
not fit on a single screen.

@kindex prompt, nslookup style
@kindex rprompt, nslookup style
@item @t{prompt}
@itemx @t{rprompt}
The @t{nslookup} function looks up this style in the context
`@t{:nslookup}' to set the prompt and the right-side prompt, respectively.
The usual expansions for the @t{PS1} and @t{RPS1} parameters may be used
(see
@ref{Prompt Expansion}).

@end table
@c (avoiding a yodl bug)
@c (avoiding a yodl bug)
@c (avoiding a yodl bug)
@c Yodl file: Zsh/index.yo
@node Concept Index, Variables Index, Top, Top
@page
@unnumbered Concept Index

@printindex cp

@noindent
@node Variables Index, Options Index, Concept Index, Top
@page
@unnumbered Variables Index

@printindex vr

@noindent
@node Options Index, Functions Index, Variables Index, Top
@page
@unnumbered Options Index

@printindex pg

@noindent
@node Functions Index, Editor Functions Index, Options Index, Top
@page
@unnumbered Functions Index

@printindex fn

@noindent
@node Editor Functions Index, Style and Tag Index, Functions Index, Top
@page
@unnumbered Editor Functions Index

@printindex tp

@noindent
@node Style and Tag Index, , Editor Functions Index, Top
@page
@unnumbered Style and Tag Index

@printindex ky
@c (avoiding a yodl bug)

@contents
@bye
