1ZSHCONTRIB(1)               General Commands Manual              ZSHCONTRIB(1)
2
3
4

NAME

6       zshcontrib - user contributions to zsh
7

DESCRIPTION

9       The  Zsh  source distribution includes a number of items contributed by
10       the user community.  These are not inherently a part of the shell,  and
11       some may not be available in every zsh installation.  The most signifi‐
12       cant of these are documented here.  For documentation on other contrib‐
13       uted  items  such as shell functions, look for comments in the function
14       source files.
15

UTILITIES

17   Accessing On-Line Help
18       The key sequence ESC h is normally bound by ZLE to execute the run-help
19       widget  (see  zshzle(1)).   This  invokes the run-help command with the
20       command word from the current input line as its argument.  By  default,
21       run-help  is an alias for the man command, so this often fails when the
22       command word is  a  shell  builtin  or  a  user-defined  function.   By
23       redefining  the  run-help  alias, one can improve the on-line help pro‐
24       vided by the shell.
25
26       The helpfiles utility, found in the Util directory of the distribution,
27       is a Perl program that can be used to process the zsh manual to produce
28       a separate help file for each shell builtin and for  many  other  shell
29       features  as  well.  The autoloadable run-help function, found in Func‐
30       tions/Misc, searches for these helpfiles  and  performs  several  other
31       tests to produce the most complete help possible for the command.
32
33       Help files are installed by default to a subdirectory of /usr/share/zsh
34       or /usr/local/share/zsh.
35
36       To create your own help files with helpfiles, choose or create a direc‐
37       tory where the individual command help files will reside.  For example,
38       you might choose ~/zsh_help.  If you unpacked the zsh  distribution  in
39       your home directory, you would use the commands:
40
41              mkdir ~/zsh_help
42              perl ~/zsh-5.8/Util/helpfiles ~/zsh_help
43
44       The  HELPDIR parameter tells run-help where to look for the help files.
45       When unset, it uses the default installation path.  To use your own set
46       of  help files, set this to the appropriate path in one of your startup
47       files:
48
49              HELPDIR=~/zsh_help
50
51       To use the run-help function, you need to add lines something like  the
52       following to your .zshrc or equivalent startup file:
53
54              unalias run-help
55              autoload run-help
56
57       Note  that  in order for `autoload run-help' to work, the run-help file
58       must be in one of the directories named in your fpath array  (see  zsh‐
59       param(1)).   This should already be the case if you have a standard zsh
60       installation; if it is not, copy Functions/Misc/run-help to  an  appro‐
61       priate directory.
62
63   Recompiling Functions
64       If  you frequently edit your zsh functions, or periodically update your
65       zsh installation to track the latest developments, you  may  find  that
66       function  digests compiled with the zcompile builtin are frequently out
67       of date with respect to the function source files.  This is not usually
68       a  problem, because zsh always looks for the newest file when loading a
69       function, but it may cause slower shell startup and  function  loading.
70       Also,  if  a digest file is explicitly used as an element of fpath, zsh
71       won't check whether any of its source files has changed.
72
73       The zrecompile autoloadable function, found in Functions/Misc,  can  be
74       used to keep function digests up to date.
75
76       zrecompile [ -qt ] [ name ... ]
77       zrecompile [ -qt ] -p arg ... [ -- arg ... ]
78              This tries to find *.zwc files and automatically re-compile them
79              if at least one of the original files is newer than the compiled
80              file.  This works only if the names stored in the compiled files
81              are full paths or are relative to the  directory  that  contains
82              the .zwc file.
83
84              In the first form, each name is the name of a compiled file or a
85              directory containing *.zwc files that should be checked.  If  no
86              arguments  are  given,  the directories and *.zwc files in fpath
87              are used.
88
89              When -t is given, no compilation is performed, but a return sta‐
90              tus  of  zero  (true)  is set if there are files that need to be
91              re-compiled and non-zero (false) otherwise.  The -q option  qui‐
92              ets the chatty output that describes what zrecompile is doing.
93
94              Without  the  -t  option, the return status is zero if all files
95              that needed re-compilation could be  compiled  and  non-zero  if
96              compilation for at least one of the files failed.
97
98              If  the  -p  option is given, the args are interpreted as one or
99              more sets of arguments for zcompile,  separated  by  `--'.   For
100              example:
101
102                     zrecompile -p \
103                                -R ~/.zshrc -- \
104                                -M ~/.zcompdump -- \
105                                ~/zsh/comp.zwc ~/zsh/Completion/*/_*
106
107              This  compiles  ~/.zshrc into ~/.zshrc.zwc if that doesn't exist
108              or if it is older than  ~/.zshrc.  The  compiled  file  will  be
109              marked  for  reading  instead  of  mapping. The same is done for
110              ~/.zcompdump and ~/.zcompdump.zwc, but  this  compiled  file  is
111              marked   for   mapping.   The  last  line  re-creates  the  file
112              ~/zsh/comp.zwc if any of the files matching the given pattern is
113              newer than it.
114
115              Without  the  -p  option,  zrecompile  does  not create function
116              digests that do not already exist, nor does it add new functions
117              to the digest.
118
119       The  following  shell loop is an example of a method for creating func‐
120       tion digests for all functions in your fpath, assuming  that  you  have
121       write permission to the directories:
122
123              for ((i=1; i <= $#fpath; ++i)); do
124                dir=$fpath[i]
125                zwc=${dir:t}.zwc
126                if [[ $dir == (.|..) || $dir == (.|..)/* ]]; then
127                  continue
128                fi
129                files=($dir/*(N-.))
130                if [[ -w $dir:h && -n $files ]]; then
131                  files=(${${(M)files%/*/*}#/})
132                  if ( cd $dir:h &&
133                       zrecompile -p -U -z $zwc $files ); then
134                    fpath[i]=$fpath[i].zwc
135                  fi
136                fi
137              done
138
139       The  -U and -z options are appropriate for functions in the default zsh
140       installation fpath; you may need to use different options for your per‐
141       sonal function directories.
142
143       Once  the digests have been created and your fpath modified to refer to
144       them, you can keep them up to date by running zrecompile with no  argu‐
145       ments.
146
147   Keyboard Definition
148       The  large  number of possible combinations of keyboards, workstations,
149       terminals, emulators, and window systems makes it impossible for zsh to
150       have  built-in  key  bindings  for  every situation.  The zkbd utility,
151       found in Functions/Misc, can help you quickly create key  bindings  for
152       your configuration.
153
154       Run zkbd either as an autoloaded function, or as a shell script:
155
156              zsh -f ~/zsh-5.8/Functions/Misc/zkbd
157
158       When  you  run  zkbd, it first asks you to enter your terminal type; if
159       the default it offers is correct, just press return.  It then asks  you
160       to  press  a  number  of different keys to determine characteristics of
161       your keyboard and terminal; zkbd warns you if it finds anything out  of
162       the ordinary, such as a Delete key that sends neither ^H nor ^?.
163
164       The  keystrokes  read by zkbd are recorded as a definition for an asso‐
165       ciative array named key, written to a file in  the  subdirectory  .zkbd
166       within  either your HOME or ZDOTDIR directory.  The name of the file is
167       composed from  the  TERM,  VENDOR  and  OSTYPE  parameters,  joined  by
168       hyphens.
169
170       You  may  read  this file into your .zshrc or another startup file with
171       the `source' or `.' commands, then reference the key parameter in bind‐
172       key commands, like this:
173
174              source ${ZDOTDIR:-$HOME}/.zkbd/$TERM-$VENDOR-$OSTYPE
175              [[ -n ${key[Left]} ]] && bindkey "${key[Left]}" backward-char
176              [[ -n ${key[Right]} ]] && bindkey "${key[Right]}" forward-char
177              # etc.
178
179       Note  that  in order for `autoload zkbd' to work, the zkdb file must be
180       in one of the directories named in your fpath array (see  zshparam(1)).
181       This  should  already  be the case if you have a standard zsh installa‐
182       tion; if it is not, copy Functions/Misc/zkbd to an  appropriate  direc‐
183       tory.
184
185   Dumping Shell State
186       Occasionally  you  may encounter what appears to be a bug in the shell,
187       particularly if you are using a beta version of zsh  or  a  development
188       release.  Usually it is sufficient to send a description of the problem
189       to one of the zsh mailing lists (see zsh(1)), but sometimes one of  the
190       zsh developers will need to recreate your environment in order to track
191       the problem down.
192
193       The script named reporter, found in the Util directory of the distribu‐
194       tion,  is  provided for this purpose.  (It is also possible to autoload
195       reporter, but reporter is not installed in  fpath  by  default.)   This
196       script  outputs  a  detailed  dump  of  the shell state, in the form of
197       another script that can be read with `zsh -f' to recreate that state.
198
199       To use reporter, read the script into your shell with the  `.'  command
200       and redirect the output into a file:
201
202              . ~/zsh-5.8/Util/reporter > zsh.report
203
204       You should check the zsh.report file for any sensitive information such
205       as passwords and delete them by hand before sending the script  to  the
206       developers.   Also,  as the output can be voluminous, it's best to wait
207       for the developers to ask for this information before sending it.
208
209       You can also use reporter to dump only a subset  of  the  shell  state.
210       This is sometimes useful for creating startup files for the first time.
211       Most of the output from reporter is far more detailed than  usually  is
212       necessary  for  a  startup  file, but the aliases, options, and zstyles
213       states may be  useful  because  they  include  only  changes  from  the
214       defaults.   The bindings state may be useful if you have created any of
215       your own keymaps, because reporter arranges to dump the keymap creation
216       commands as well as the bindings for every keymap.
217
218       As  is  usual  with  automated tools, if you create a startup file with
219       reporter, you should edit the results to remove  unnecessary  commands.
220       Note  that  if  you're  using the new completion system, you should not
221       dump the functions state to your startup files with reporter;  use  the
222       compdump function instead (see zshcompsys(1)).
223
224       reporter [ state ... ]
225              Print  to  standard  output  the indicated subset of the current
226              shell state.  The state arguments may be one or more of:
227
228              all    Output everything listed below.
229              aliases
230                     Output alias definitions.
231              bindings
232                     Output ZLE key maps and bindings.
233              completion
234                     Output old-style compctl  commands.   New  completion  is
235                     covered by functions and zstyles.
236              functions
237                     Output autoloads and function definitions.
238              limits Output limit commands.
239              options
240                     Output setopt commands.
241              styles Same as zstyles.
242              variables
243                     Output  shell parameter assignments, plus export commands
244                     for any environment variables.
245              zstyles
246                     Output zstyle commands.
247
248              If the state is omitted, all is assumed.
249
250       With the exception of `all', every state can be abbreviated by any pre‐
251       fix, even a single letter; thus a is the same as aliases, z is the same
252       as zstyles, etc.
253
254   Manipulating Hook Functions
255       add-zsh-hook [ -L | -dD ] [ -Uzk ] hook function
256              Several functions are special to the shell, as described in  the
257              section  SPECIAL  FUNCTIONS,  see  zshmisc(1),  in that they are
258              automatically called at specific points during shell  execution.
259              Each has an associated array consisting of names of functions to
260              be called at the same point; these  are  so-called  `hook  func‐
261              tions'.   The  shell function add-zsh-hook provides a simple way
262              of adding or removing functions from the array.
263
264              hook is one of chpwd, periodic, precmd, preexec,  zshaddhistory,
265              zshexit,  or  zsh_directory_name, the special functions in ques‐
266              tion.  Note that zsh_directory_name is called in a different way
267              from  the  other  functions,  but  may still be manipulated as a
268              hook.
269
270              function is name of an ordinary shell function.  If  no  options
271              are  given  this  will  be added to the array of functions to be
272              executed in the given context.  Functions  are  invoked  in  the
273              order they were added.
274
275              If  the  option  -L  is  given,  the current values for the hook
276              arrays are listed with typeset.
277
278              If the option -d is given, the  function  is  removed  from  the
279              array of functions to be executed.
280
281              If  the option -D is given, the function is treated as a pattern
282              and any matching names of functions are removed from  the  array
283              of functions to be executed.
284
285              The  options  -U,  -z and -k are passed as arguments to autoload
286              for function.  For functions contributed with zsh,  the  options
287              -Uz are appropriate.
288
289       add-zle-hook-widget [ -L | -dD ] [ -Uzk ] hook widgetname
290              Several  widget  names  are  special  to  the  line  editor,  as
291              described in the section Special Widgets, see zshzle(1), in that
292              they are automatically called at specific points during editing.
293              Unlike function hooks, these do not use a  predefined  array  of
294              other  names  to  call  at  the  same  point; the shell function
295              add-zle-hook-widget maintains a similar array and  arranges  for
296              the special widget to invoke those additional widgets.
297
298              hook  is  one  of isearch-exit, isearch-update, line-pre-redraw,
299              line-init, line-finish, history-line-set, or keymap-select, cor‐
300              responding to each of the special widgets zle-isearch-exit, etc.
301              The special widget names are also accepted as the hook argument.
302
303              widgetname is the name of a ZLE widget.  If no options are given
304              this is added to the array of widgets to be invoked in the given
305              hook context.  Widgets are invoked in the order they were added,
306              with
307                     zle widgetname -Nw -- "$@"
308
309              Note  that this means that the `WIDGET' special parameter tracks
310              the widgetname when the widget function is called,  rather  than
311              tracking the name of the corresponding special hook widget.
312
313              If  the  option  -d is given, the widgetname is removed from the
314              array of widgets to be executed.
315
316              If the option -D is given, the widgetname is treated as  a  pat‐
317              tern  and  any  matching  names  of widgets are removed from the
318              array.
319
320              If widgetname does not name an existing widget when added to the
321              array, it is assumed that a shell function also named widgetname
322              is meant to provide the implementation of the widget.  This name
323              is  therefore marked for autoloading, and the options -U, -z and
324              -k are passed as arguments to  autoload  as  with  add-zsh-hook.
325              The widget is also created with `zle -N widgetname' to cause the
326              corresponding function to be loaded the first time the  hook  is
327              called.
328
329              The arrays of widgetname are currently maintained in zstyle con‐
330              texts, one for each hook context, with a style of `widgets'.  If
331              the  -L  option  is  given,  this  set  of styles is listed with
332              `zstyle -L'.  This implementation may change,  and  the  special
333              widgets   that   refer   to  the  styles  are  created  only  if
334              add-zle-hook-widget is called to add at least one widget, so  if
335              this  function  is  used for any hooks, then all hooks should be
336              managed only via this function.
337

REMEMBERING RECENT DIRECTORIES

339       The function cdr allows you to change the working directory to a previ‐
340       ous working directory from a list maintained automatically.  It is sim‐
341       ilar in concept to the directory stack controlled by  the  pushd,  popd
342       and  dirs  builtins,  but  is  more  configurable, and as it stores all
343       entries in files it is maintained  across  sessions  and  (by  default)
344       between  terminal  emulators  in  the  current session.  Duplicates are
345       automatically removed, so that the list reflects the single most recent
346       use of each directory.
347
348       Note that the pushd directory stack is not actually modified or used by
349       cdr unless you configure it to do so as described in the  configuration
350       section below.
351
352   Installation
353       The  system works by means of a hook function that is called every time
354       the directory changes.  To install the system,  autoload  the  required
355       functions and use the add-zsh-hook function described above:
356
357              autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
358              add-zsh-hook chpwd chpwd_recent_dirs
359
360       Now  every time you change directly interactively, no matter which com‐
361       mand you use, the directory to which you change will be  remembered  in
362       most-recent-first order.
363
364   Use
365       All direct user interaction is via the cdr function.
366
367       The  argument  to  cdr  is  a  number  N  corresponding to the Nth most
368       recently changed-to directory.  1 is the immediately  preceding  direc‐
369       tory;  the current directory is remembered but is not offered as a des‐
370       tination.  Note that if you have multiple windows open 1 may refer to a
371       directory  changed  to  in another window; you can avoid this by having
372       per-terminal  files  for  storing  directory  as  described   for   the
373       recent-dirs-file style below.
374
375       If  you  set  the  recent-dirs-default  style  described below cdr will
376       behave the same as cd if given a non-numeric argument, or more than one
377       argument.   The  recent directory list is updated just the same however
378       you change directory.
379
380       If the argument is omitted, 1 is assumed.  This is similar  to  pushd's
381       behaviour of swapping the two most recent directories on the stack.
382
383       Completion  for  the  argument to cdr is available if compinit has been
384       run; menu selection is recommended, using:
385
386              zstyle ':completion:*:*:cdr:*:*' menu selection
387
388       to allow you to cycle through recent directories;  the  order  is  pre‐
389       served,  so  the  first  choice is the most recent directory before the
390       current one.  The verbose style  is  also  recommended  to  ensure  the
391       directory  is  shown;  this  style  is  on  by  default so no action is
392       required unless you have changed it.
393
394   Options
395       The behaviour of cdr may be modified by the following options.
396
397       -l     lists the numbers and the corresponding directories in  abbrevi‐
398              ated  form  (i.e.  with ~ substitution reapplied), one per line.
399              The directories here are not quoted (this would only be an issue
400              if  a  directory name contained a newline).  This is used by the
401              completion system.
402
403       -r     sets the variable reply  to  the  current  set  of  directories.
404              Nothing is printed and the directory is not changed.
405
406       -e     allows  you  to edit the list of directories, one per line.  The
407              list can be edited to any extent you like; no sanity checking is
408              performed.   Completion  is  available.  No quoting is necessary
409              (except for newlines, where I have in  any  case  no  sympathy);
410              directories  are  in  unabbreviated from and contain an absolute
411              path, i.e. they start with /.  Usually the first entry should be
412              left as the current directory.
413
414       -p 'pattern'
415              Prunes  any  items  in  the  directory list that match the given
416              extended glob pattern; the pattern needs to be quoted from imme‐
417              diate  expansion  on  the  command line.  The pattern is matched
418              against each completely expanded file name in the list; the full
419              string  must  match, so wildcards at the end (e.g. '*removeme*')
420              are needed to remove entries with a given substring.
421
422              If output is to a terminal, then the function will print the new
423              list  after  pruning  and  prompt  for confirmation by the user.
424              This output and confirmation step can be  skipped  by  using  -P
425              instead of -p.
426
427   Configuration
428       Configuration is by means of the styles mechanism that should be famil‐
429       iar from completion; if not, see the description of the zstyle  command
430       in  see  zshmodules(1).   The  context  for  setting  styles  should be
431       ':chpwd:*' in case the meaning of the context is  extended  in  future,
432       for example:
433
434              zstyle ':chpwd:*' recent-dirs-max 0
435
436       sets  the  value  of  the  recent-dirs-max style to 0.  In practice the
437       style name is specific enough that a context of '*' should be fine.
438
439       An exception is recent-dirs-insert, which is used  exclusively  by  the
440       completion  system  and  so  has  the  usual  completion system context
441       (':completion:*' if nothing more specific is needed), though again  '*'
442       should be fine in practice.
443
444       recent-dirs-default
445              If  true, and the command is expecting a recent directory index,
446              and either there is more than one argument or  the  argument  is
447              not an integer, then fall through to "cd".  This allows the lazy
448              to use only one  command  for  directory  changing.   Completion
449              recognises  this, too; see recent-dirs-insert for how to control
450              completion when this option is in use.
451
452       recent-dirs-file
453              The file where the list of directories is saved.  The default is
454              ${ZDOTDIR:-$HOME}/.chpwd-recent-dirs,  i.e. this is in your home
455              directory unless you have set  the  variable  ZDOTDIR  to  point
456              somewhere  else.   Directory  names  are  saved in $'...' quoted
457              form, so each line in the file can be supplied directly  to  the
458              shell as an argument.
459
460              The  value  of  this  style  may be an array.  In this case, the
461              first file in the list will always be used for  saving  directo‐
462              ries while any other files are left untouched.  When reading the
463              recent directory list, if there are fewer than the maximum  num‐
464              ber of entries in the first file, the contents of later files in
465              the array will be appended with duplicates removed from the list
466              shown.   The  contents of the two files are not sorted together,
467              i.e. all the entries in the first file  are  shown  first.   The
468              special  value  + can appear in the list to indicate the default
469              file should be read at that point.  This allows effects like the
470              following:
471
472                     zstyle ':chpwd:*' recent-dirs-file \
473                     ~/.chpwd-recent-dirs-${TTY##*/} +
474
475              Recent  directories  are  read from a file numbered according to
476              the terminal.  If there are insufficient  entries  the  list  is
477              supplemented from the default file.
478
479              It  is  possible  to use zstyle -e to make the directory config‐
480              urable at run time:
481
482                     zstyle -e ':chpwd:*' recent-dirs-file pick-recent-dirs-file
483                     pick-recent-dirs-file() {
484                       if [[ $PWD = ~/text/writing(|/*) ]]; then
485                         reply=(~/.chpwd-recent-dirs-writing)
486                       else
487                         reply=(+)
488                       fi
489                     }
490
491              In this example, if the current directory is ~/text/writing or a
492              directory  under  it,  then use a special file for saving recent
493              directories, else use the default.
494
495       recent-dirs-insert
496              Used by completion.  If recent-dirs-default is true,  then  set‐
497              ting  this  to true causes the actual directory, rather than its
498              index, to be inserted on the command line;  this  has  the  same
499              effect  as  using the corresponding index, but makes the history
500              clearer and the line easier to edit.  With this setting, if part
501              of  an  argument  was already typed, normal directory completion
502              rather than recent directory completion is done; this is because
503              recent  directory  completion  is expected to be done by cycling
504              through entries menu fashion.
505
506              If the value of the style is always, then only  recent  directo‐
507              ries  will  be  completed; in that case, use the cd command when
508              you want to complete other directories.
509
510              If the value is  fallback,  recent  directories  will  be  tried
511              first,  then  normal directory completion is performed if recent
512              directory completion failed to find a match.
513
514              Finally, if the value is both then both sets of completions  are
515              presented;  the  usual  tag mechanism can be used to distinguish
516              results, with recent directories tagged  as  recent-dirs.   Note
517              that the recent directories inserted are abbreviated with direc‐
518              tory names where appropriate.
519
520       recent-dirs-max
521              The maximum number of directories to save to the file.  If  this
522              is  zero  or  negative  there is no maximum.  The default is 20.
523              Note this includes the current directory, which  isn't  offered,
524              so  the highest number of directories you will be offered is one
525              less than the maximum.
526
527       recent-dirs-prune
528              This style is an array determining what directories  should  (or
529              should  not) be added to the recent list.  Elements of the array
530              can include:
531
532              parent Prune  parents  (more  accurately,  ancestors)  from  the
533                     recent  list.   If present, changing directly down by any
534                     number of directories causes the current directory to  be
535                     overwritten.    For   example,   changing  from  ~pws  to
536                     ~pws/some/other/dir causes ~pws not to  be  left  on  the
537                     recent  directory  stack.   This  only  applies to direct
538                     changes to descendant directories; earlier directories on
539                     the  list  are  not  pruned.   For example, changing from
540                     ~pws/yet/another to ~pws/some/other/dir  does  not  cause
541                     ~pws to be pruned.
542
543              pattern:pattern
544                     Gives  a  zsh  pattern for directories that should not be
545                     added to the recent list (if not  already  there).   This
546                     element  can  be repeated to add different patterns.  For
547                     example, 'pattern:/tmp(|/*)' stops /tmp  or  its  descen‐
548                     dants  from  being  added.   The  EXTENDED_GLOB option is
549                     always turned on for these patterns.
550
551       recent-dirs-pushd
552              If set to true, cdr will use pushd instead of cd to  change  the
553              directory, so the directory is saved on the directory stack.  As
554              the directory stack is completely  separate  from  the  list  of
555              files saved by the mechanism used in this file there is no obvi‐
556              ous reason to do this.
557
558   Use with dynamic directory naming
559       It is possible to refer to recent directories using the dynamic  direc‐
560       tory  name syntax by using the supplied function zsh_directory_name_cdr
561       a hook:
562
563              autoload -Uz add-zsh-hook
564              add-zsh-hook -Uz zsh_directory_name zsh_directory_name_cdr
565
566       When this is done, ~[1] will refer to the most recent  directory  other
567       than $PWD, and so on.  Completion after ~[...  also works.
568
569   Details of directory handling
570       This  section  is for the curious or confused; most users will not need
571       to know this information.
572
573       Recent directories are saved to a file immediately and hence  are  pre‐
574       served across sessions.  Note currently no file locking is applied: the
575       list is updated immediately on interactive commands  and  nowhere  else
576       (unlike history), and it is assumed you are only going to change direc‐
577       tory in one window at once.  This is not safe on shared  accounts,  but
578       in  any case the system has limited utility when someone else is chang‐
579       ing to a different set of directories behind your back.
580
581       To make this a little safer, only directory changes instituted from the
582       command  line,  either  directly  or  indirectly through shell function
583       calls (but not through subshells, evals,  traps,  completion  functions
584       and  the like) are saved.  Shell functions should use cd -q or pushd -q
585       to avoid side effects if the change to the directory is to be invisible
586       at   the   command   line.    See   the   contents   of   the  function
587       chpwd_recent_dirs for more details.
588

ABBREVIATED DYNAMIC REFERENCES TO DIRECTORIES

590       The dynamic directory naming system  is  described  in  the  subsection
591       Dynamic named directories of the section Filename Expansion in expn(1).
592       In this, a reference to ~[...] is expanded by a function found  by  the
593       hooks mechanism.
594
595       The  contributed  function zsh_directory_name_generic provides a system
596       allowing the user to refer to directories with only a limited amount of
597       new  code.  It supports all three of the standard interfaces for direc‐
598       tory naming: converting from a name to a directory, converting  in  the
599       reverse direction to find a short name, and completion of names.
600
601       The  main  feature  of  this  function is a path-like syntax, combining
602       abbreviations at multiple levels separated  by  ":".   As  an  example,
603       ~[g:p:s] might specify:
604       g      The top level directory for your git area.  This first component
605              has to match, or the function  will  return  indicating  another
606              directory name hook function should be tried.
607
608       p      The name of a project within your git area.
609
610       s      The  source  area  within that project.  This allows you to col‐
611              lapse references to long hierarchies to  a  very  compact  form,
612              particularly  if  the  hierarchies  are similar across different
613              areas of the disk.
614
615       Name components may be completed: if a description is shown at the  top
616       of the list of completions, it includes the path to which previous com‐
617       ponents expand, while the  description  for  an  individual  completion
618       shows  the  path  segment it would add.  No additional configuration is
619       needed for this as the completion system is aware of the dynamic direc‐
620       tory name mechanism.
621
622   Usage
623       To  use the function, first define a wrapper function for your specific
624       case.  We'll assume it's to be autoloaded.  This can have any name  but
625       we'll  refer to it as zdn_mywrapper.  This wrapper function will define
626       various variables and then call this function with the  same  arguments
627       that the wrapper function gets.  This configuration is described below.
628
629       Then arrange for the wrapper to be run as a zsh_directory_name hook:
630
631              autoload -Uz add-zsh-hook zsh_diretory_name_generic zdn_mywrapper
632              add-zsh-hook -U zsh_directory_name zdn_mywrapper
633
634   Configuration
635       The  wrapper  function should define a local associative array zdn_top.
636       Alternatively, this can be set with a style called mapping.   The  con‐
637       text for the style is :zdn:wrapper-name where wrapper-name is the func‐
638       tion calling zsh_directory_name_generic; for example:
639
640              zstyle :zdn:zdn_mywrapper: mapping zdn_mywrapper_top
641
642       The keys in this associative array correspond to the first component of
643       the  name.   The  values  are  matching  directories.  They may have an
644       optional suffix with a slash followed by a colon  and  the  name  of  a
645       variable  in  the  same  format to give the next component.  (The slash
646       before the colon is to disambiguate the case where a colon is needed in
647       the  path for a drive.  There is otherwise no syntax for escaping this,
648       so path components whose names start with a colon are  not  supported.)
649       A  special  component  :default: specifies a variable in the form /:var
650       (the path section is ignored and so is usually empty) that will be used
651       for the next component if no variable is given for the path.  Variables
652       referred to within zdn_top have the same format as zdn_top itself,  but
653       contain relative paths.
654
655       For example,
656
657              local -A zdn_top=(
658                g   ~/git
659                ga  ~/alternate/git
660                gs  /scratch/$USER/git/:second2
661                :default: /:second1
662              )
663
664       This specifies the behaviour of a directory referred to as ~[g:...]  or
665       ~[ga:...] or ~[gs:...].  Later path components are  optional;  in  that
666       case   ~[g]   expands   to   ~/git,   and   so   on.    gs  expands  to
667       /scratch/$USER/git and uses the associative array second2 to match  the
668       second  component;  g and ga use the associative array second1 to match
669       the second component.
670
671       When expanding a name to a directory, if the first component is  not  g
672       or  ga or gs, it is not an error; the function simply returns 1 so that
673       a later hook function can be tried.  However, matching the first compo‐
674       nent  commits  the function, so if a later component does not match, an
675       error is printed (though this still does  not  stop  later  hooks  from
676       being executed).
677
678       For  components  after the first, a relative path is expected, but note
679       that multiple levels may still appear.  Here is an example of second1:
680
681              local -A second1=(
682                p   myproject
683                s   somproject
684                os  otherproject/subproject/:third
685              )
686
687       The path as found from zdn_top is extended with the matching directory,
688       so ~[g:p] becomes ~/git/myproject.  The slash between is added automat‐
689       ically (it's not possible to have a later component modify the name  of
690       a directory already matched).  Only os specifies a variable for a third
691       component, and there's no :default:, so it's an error  to  use  a  name
692       like  ~[g:p:x] or ~[ga:s:y] because there's nowhere to look up the x or
693       y.
694
695       The associative arrays need to be visible  within  this  function;  the
696       generic function therefore uses internal variable names beginning _zdn_
697       in order to avoid clashes.  Note that the variable reply  needs  to  be
698       passed  back  to the shell, so should not be local in the calling func‐
699       tion.
700
701       The function does not test whether directories assembled  by  component
702       actually  exist; this allows the system to work across automounted file
703       systems.  The error from the  command  trying  to  use  a  non-existent
704       directory should be sufficient to indicate the problem.
705
706   Complete example
707       Here  is  a  full  fictitious but usable autoloadable definition of the
708       example function defined by the code above.  So  ~[gs:p:s]  expands  to
709       /scratch/$USER/git/myscratchproject/top/srcdir    (with    $USER   also
710       expanded).
711
712              local -A zdn_top=(
713                g   ~/git
714                ga  ~/alternate/git
715                gs  /scratch/$USER/git/:second2
716                :default: /:second1
717              )
718
719              local -A second1=(
720                p   myproject
721                s   somproject
722                os  otherproject/subproject/:third
723              )
724
725              local -A second2=(
726                p   myscratchproject
727                s   somescratchproject
728              )
729
730              local -A third=(
731                s   top/srcdir
732                d   top/documentation
733              )
734
735              # autoload not needed if you did this at initialisation...
736              autoload -Uz zsh_directory_name_generic
737              zsh_directory_name_generic "$@
738
739       It is also possible to use global associative arrays,  suitably  named,
740       and  set the style for the context of your wrapper function to refer to
741       this.  Then your set up code would contain the following:
742
743              typeset -A zdn_mywrapper_top=(...)
744              # ... and so on for other associative arrays ...
745              zstyle ':zdn:zdn_mywrapper:' mapping zdn_mywrapper_top
746              autoload -Uz add-zsh-hook zsh_directory_name_generic zdn_mywrapper
747              add-zsh-hook -U zsh_directory_name zdn_mywrapper
748
749       and the function zdn_mywrapper would contain only the following:
750
751              zsh_directory_name_generic "$@"
752

GATHERING INFORMATION FROM VERSION CONTROL SYSTEMS

754       In a lot of cases, it is nice  to  automatically  retrieve  information
755       from version control systems (VCSs), such as subversion, CVS or git, to
756       be able to provide it to the user; possibly in the  user's  prompt.  So
757       that  you  can  instantly  tell  which branch you are currently on, for
758       example.
759
760       In order to do that, you may use the vcs_info function.
761
762       The following VCSs are supported, showing the abbreviated name by which
763       they are referred to within the system:
764       Bazaar (bzr)
765              https://bazaar.canonical.com/
766       Codeville (cdv)
767              http://freecode.com/projects/codeville/
768       Concurrent Versioning System (cvs)
769              https://www.nongnu.org/cvs/
770       Darcs (darcs)
771              http://darcs.net/
772       Fossil (fossil)
773              https://fossil-scm.org/
774       Git (git)
775              https://git-scm.com/
776       GNU arch (tla)
777              https://www.gnu.org/software/gnu-arch/
778       Mercurial (hg)
779              https://www.mercurial-scm.org/
780       Monotone (mtn)
781              https://monotone.ca/
782       Perforce (p4)
783              https://www.perforce.com/
784       Subversion (svn)
785              https://subversion.apache.org/
786       SVK (svk)
787              https://svk.bestpractical.com/
788
789       There   is   also   support  for  the  patch  management  system  quilt
790       (https://savannah.nongnu.org/projects/quilt). See Quilt  Support  below
791       for details.
792
793       To load vcs_info:
794
795              autoload -Uz vcs_info
796
797       It  can be used in any existing prompt, because it does not require any
798       specific $psvar entries to be available.
799
800   Quickstart
801       To get this feature working quickly (including colors), you can do  the
802       following (assuming, you loaded vcs_info properly - see above):
803
804              zstyle ':vcs_info:*' actionformats \
805                  '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f '
806              zstyle ':vcs_info:*' formats       \
807                  '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{5}]%f '
808              zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r'
809              precmd () { vcs_info }
810              PS1='%F{5}[%F{2}%n%F{5}] %F{3}%3~ ${vcs_info_msg_0_}%f%# '
811
812       Obviously,  the last two lines are there for demonstration. You need to
813       call vcs_info from your precmd function. Once that is done you  need  a
814       single quoted '${vcs_info_msg_0_}' in your prompt.
815
816       To  be  able  to  use '${vcs_info_msg_0_}' directly in your prompt like
817       this, you will need to have the PROMPT_SUBST option enabled.
818
819       Now call the vcs_info_printsys utility from the command line:
820
821              % vcs_info_printsys
822              ## list of supported version control backends:
823              ## disabled systems are prefixed by a hash sign (#)
824              bzr
825              cdv
826              cvs
827              darcs
828              fossil
829              git
830              hg
831              mtn
832              p4
833              svk
834              svn
835              tla
836              ## flavours (cannot be used in the enable or disable styles; they
837              ## are enabled and disabled with their master [git-svn -> git])
838              ## they *can* be used in contexts: ':vcs_info:git-svn:*'.
839              git-p4
840              git-svn
841              hg-git
842              hg-hgsubversion
843              hg-hgsvn
844
845       You may not want all of these because there is no point in running  the
846       code  to  detect  systems you do not use.  So there is a way to disable
847       some backends altogether:
848
849              zstyle ':vcs_info:*' disable bzr cdv darcs mtn svk tla
850
851       You may also pick a few from that list and enable only those:
852
853              zstyle ':vcs_info:*' enable git cvs svn
854
855       If you rerun vcs_info_printsys after one of these  commands,  you  will
856       see  the  backends  listed in the disable style (or backends not in the
857       enable style - if you used that) marked as disabled  by  a  hash  sign.
858       That  means  the  detection  of these systems is skipped completely. No
859       wasted time there.
860
861   Configuration
862       The vcs_info feature can be configured via zstyle.
863
864       First, the context in which we are working:
865              :vcs_info:vcs-string:user-context:repo-root-name
866
867       vcs-string
868              is one of: git, git-svn, git-p4,  hg,  hg-git,  hg-hgsubversion,
869              hg-hgsvn,  darcs,  bzr, cdv, mtn, svn, cvs, svk, tla, p4 or fos‐
870              sil.  This is followed by `.quilt-quilt-mode' in Quilt mode (see
871              Quilt  Support  for details) and by `+hook-name' while hooks are
872              active (see Hooks in vcs_info for details).
873
874              Currently, hooks in quilt mode don't add the `.quilt-quilt-mode'
875              information.  This may change in the future.
876
877       user-context
878              is  a  freely configurable string, assignable by the user as the
879              first argument to vcs_info (see its description below).
880
881       repo-root-name
882              is the name of a repository in which you want a style to  match.
883              So,  if  you  want a setting specific to /usr/src/zsh, with that
884              being a CVS checkout, you can set repo-root-name to zsh to  make
885              it so.
886
887       There  are  three  special  values  for  vcs-string: The first is named
888       -init-, that is in effect as long as there was  no  decision  what  VCS
889       backend  to use. The second is -preinit-; it is used before vcs_info is
890       run, when initializing the data exporting variables. The third  special
891       value is formats and is used by the vcs_info_lastmsg for looking up its
892       styles.
893
894       The initial value of repo-root-name is -all- and it  is  replaced  with
895       the actual name, as soon as it is known. Only use this part of the con‐
896       text for defining the formats, actionformats or branchformat styles, as
897       it  is  guaranteed  that  repo-root-name  is set up correctly for these
898       only. For all other styles, just use '*' instead.
899
900       There are two pre-defined values for user-context:
901       default
902              the one used if none is specified
903       command
904              used by vcs_info_lastmsg to lookup its styles
905
906       You can of course use ':vcs_info:*' to match all VCSs in all  user-con‐
907       texts at once.
908
909       This is a description of all styles that are looked up.
910
911       formats
912              A list of formats, used when actionformats is not used (which is
913              most of the time).
914
915       actionformats
916              A list of formats, used if there is a special action going on in
917              your  current  repository; like an interactive rebase or a merge
918              conflict.
919
920       branchformat
921              Some backends replace %b in the formats and actionformats styles
922              above,  not only by a branch name but also by a revision number.
923              This style lets you modify how that string should look.
924
925       nvcsformats
926              These "formats" are set when we didn't detect a version  control
927              system  for the current directory or vcs_info was disabled. This
928              is useful if you want vcs_info to completely take over the  gen‐
929              eration   of   your   prompt.   You   would  do  something  like
930              PS1='${vcs_info_msg_0_}' to accomplish that.
931
932       hgrevformat
933              hg uses both a hash and a revision number to  reference  a  spe‐
934              cific  changeset in a repository. With this style you can format
935              the revision string (see  branchformat)  to  include  either  or
936              both. It's only useful when get-revision is true. Note, the full
937              40-character revision id is not available (except when using the
938              use-simple  option)  because  executing  hg  more  than once per
939              prompt is too slow; you may customize this behavior using hooks.
940
941       max-exports
942              Defines the maximum number of vcs_info_msg_*_ variables vcs_info
943              will set.
944
945       enable A  list  of backends you want to use. Checked in the -init- con‐
946              text. If this list contains an item called NONE  no  backend  is
947              used  at all and vcs_info will do nothing. If this list contains
948              ALL, vcs_info will use all known  backends.  Only  with  ALL  in
949              enable  will the disable style have any effect. ALL and NONE are
950              case insensitive.
951
952       disable
953              A list of VCSs you don't want vcs_info to test for  repositories
954              (checked  in  the -init- context, too). Only used if enable con‐
955              tains ALL.
956
957       disable-patterns
958              A list of patterns that are checked against $PWD. If  a  pattern
959              matches, vcs_info will be disabled. This style is checked in the
960              :vcs_info:-init-:*:-all- context.
961
962              Say, ~/.zsh is a directory under version control, in  which  you
963              do not want vcs_info to be active, do:
964                     zstyle ':vcs_info:*' disable-patterns "${(b)HOME}/.zsh(|/*)"
965
966       use-quilt
967              If  enabled,  the  quilt support code is active in `addon' mode.
968              See Quilt Support for details.
969
970       quilt-standalone
971              If enabled, `standalone' mode detection is attempted if  no  VCS
972              is active in a given directory. See Quilt Support for details.
973
974       quilt-patch-dir
975              Overwrite  the value of the $QUILT_PATCHES environment variable.
976              See Quilt Support for details.
977
978       quiltcommand
979              When quilt itself is called in quilt support, the value of  this
980              style is used as the command name.
981
982       check-for-changes
983              If  enabled,  this  style causes the %c and %u format escapes to
984              show when the working directory  has  uncommitted  changes.  The
985              strings  displayed  by  these  escapes can be controlled via the
986              stagedstr and unstagedstr styles. The only  backends  that  cur‐
987              rently  support this option are git, hg, and bzr (the latter two
988              only support unstaged).
989
990              For this  style  to  be  evaluated  with  the  hg  backend,  the
991              get-revision  style  needs  to  be  set and the use-simple style
992              needs to be unset. The latter is the default; the former is not.
993
994              With the bzr backend,  lightweight  checkouts  only  honor  this
995              style if the use-server style is set.
996
997              Note, the actions taken if this style is enabled are potentially
998              expensive (read: they may be slow, depending on how big the cur‐
999              rent repository is).  Therefore, it is disabled by default.
1000
1001       check-for-staged-changes
1002              This  style  is  like check-for-changes, but it never checks the
1003              worktree files, only the metadata in the  .${vcs}  dir.   There‐
1004              fore, this style initializes only the %c escape (with stagedstr)
1005              but  not  the  %u   escape.    This   style   is   faster   than
1006              check-for-changes.
1007
1008              In  the git backend, this style checks for changes in the index.
1009              Other backends do not currently implement this style.
1010
1011              This style is disabled by default.
1012
1013       stagedstr
1014              This string will be used in the %c escape if  there  are  staged
1015              changes in the repository.
1016
1017       unstagedstr
1018              This  string will be used in the %u escape if there are unstaged
1019              changes in the repository.
1020
1021       command
1022              This style causes vcs_info to use the  supplied  string  as  the
1023              command  to  use as the VCS's binary. Note, that setting this in
1024              ':vcs_info:*' is not a good idea.
1025
1026              If the value of this style is empty (which is the default),  the
1027              used  binary name is the name of the backend in use (e.g. svn is
1028              used in an svn repository).
1029
1030              The repo-root-name part in the context  is  always  the  default
1031              -all- when this style is looked up.
1032
1033              For  example,  this  style  can  be  used  to  use binaries from
1034              non-default installation directories. Assume, git  is  installed
1035              in  /usr/bin  but  your  sysadmin  installed  a newer version in
1036              /usr/local/bin. Instead of changing  the  order  of  your  $PATH
1037              parameter, you can do this:
1038                     zstyle ':vcs_info:git:*:-all-' command /usr/local/bin/git
1039
1040       use-server
1041              This is used by the Perforce backend (p4) to decide if it should
1042              contact the Perforce server to find out if a directory  is  man‐
1043              aged  by Perforce.  This is the only reliable way of doing this,
1044              but runs the risk of a delay if the server name cannot be found.
1045              If  the server (more specifically, the host:port pair describing
1046              the server) cannot be contacted, its name is put into the  asso‐
1047              ciative  array  vcs_info_p4_dead_servers  and  is  not contacted
1048              again during the session until it is removed by hand.  If you do
1049              not  set  this  style, the p4 backend is only usable if you have
1050              set the environment variable P4CONFIG to a file  name  and  have
1051              corresponding  files  in  the  root directories of each Perforce
1052              client.  See comments in  the  function  VCS_INFO_detect_p4  for
1053              more detail.
1054
1055              The  Bazaar  backend  (bzr)  uses  this to permit contacting the
1056              server about lightweight checkouts,  see  the  check-for-changes
1057              style.
1058
1059       use-simple
1060              If  there  are  two different ways of gathering information, you
1061              can select the simpler one by setting this style  to  true;  the
1062              default is to use the not-that-simple code, which is potentially
1063              a lot slower but might be more accurate in all  possible  cases.
1064              This style is used by the bzr and hg backends. In the case of hg
1065              it will invoke the external hexdump program to parse the  binary
1066              dirstate cache file; this method will not return the local revi‐
1067              sion number.
1068
1069       get-revision
1070              If set to true, vcs_info goes the extra mile to figure  out  the
1071              revision  of a repository's work tree (currently for the git and
1072              hg backends, where  this  kind  of  information  is  not  always
1073              vital).  For  git,  the  hash value of the currently checked out
1074              commit is available via the %i expansion.  With  hg,  the  local
1075              revision  number and the corresponding global hash are available
1076              via %i.
1077
1078       get-mq If set to true, the hg backend will look for a  Mercurial  Queue
1079              (mq) patch directory. Information will be available via the `%m'
1080              replacement.
1081
1082       get-bookmarks
1083              If set to true, the hg backend will try to get a list of current
1084              bookmarks. They will be available via the `%m' replacement.
1085
1086              The  default  is to generate a comma-separated list of all book‐
1087              mark names that refer to the currently checked out revision.  If
1088              a  bookmark  is  active,  its  name  is suffixed an asterisk and
1089              placed first in the list.
1090
1091       use-prompt-escapes
1092              Determines if we assume that the assembled string from  vcs_info
1093              includes prompt escapes. (Used by vcs_info_lastmsg.)
1094
1095       debug  Enable  debugging  output  to track possible problems. Currently
1096              this style is only used by vcs_info's hooks system.
1097
1098       hooks  A list style that defines  hook-function  names.  See  Hooks  in
1099              vcs_info below for details.
1100
1101       patch-format
1102       nopatch-format
1103              This  pair of styles format the patch information used by the %m
1104              expando in formats and actionformats for the git  and  hg  back‐
1105              ends.   The  value  is subject to certain %-expansions described
1106              below.  The expanded value is made available in the global back‐
1107              end_misc   array   as   ${backend_misc[patches]}   (also   if  a
1108              set-patch-format hook is used).
1109
1110       get-unapplied
1111              This boolean style controls whether a backend should attempt  to
1112              gather  a  list of unapplied patches (for example with Mercurial
1113              Queue patches).
1114
1115              Used by the quilt and hg backends.
1116
1117       The default values for these styles in all contexts are:
1118
1119       formats
1120              " (%s)-[%b]%u%c-"
1121       actionformats
1122              " (%s)-[%b|%a]%u%c-"
1123       branchformat
1124              "%b:%r" (for bzr, svn, svk and hg)
1125       nvcsformats
1126              ""
1127       hgrevformat
1128              "%r:%h"
1129       max-exports
1130              2
1131       enable ALL
1132       disable
1133              (empty list)
1134       disable-patterns
1135              (empty list)
1136       check-for-changes
1137              false
1138       check-for-staged-changes
1139              false
1140       stagedstr
1141              (string: "S")
1142       unstagedstr
1143              (string: "U")
1144       command
1145              (empty string)
1146       use-server
1147              false
1148       use-simple
1149              false
1150       get-revision
1151              false
1152       get-mq true
1153       get-bookmarks
1154              false
1155       use-prompt-escapes
1156              true
1157       debug  false
1158       hooks  (empty list)
1159       use-quilt
1160              false
1161       quilt-standalone
1162              false
1163       quilt-patch-dir
1164              empty - use $QUILT_PATCHES
1165       quiltcommand
1166              quilt
1167       patch-format
1168              backend dependent
1169       nopatch-format
1170              backend dependent
1171       get-unapplied
1172              false
1173
1174       In normal formats and  actionformats  the  following  replacements  are
1175       done:
1176
1177       %s     The VCS in use (git, hg, svn, etc.).
1178       %b     Information about the current branch.
1179       %a     An  identifier  that  describes  the action. Only makes sense in
1180              actionformats.
1181       %i     The current revision number or identifier. For hg the  hgrevfor‐
1182              mat style may be used to customize the output.
1183       %c     The  string from the stagedstr style if there are staged changes
1184              in the repository.
1185       %u     The string from the unstagedstr  style  if  there  are  unstaged
1186              changes in the repository.
1187       %R     The base directory of the repository.
1188       %r     The repository name. If %R is /foo/bar/repoXY, %r is repoXY.
1189       %S     A    subdirectory    within    a    repository.   If   $PWD   is
1190              /foo/bar/repoXY/beer/tasty, %S is beer/tasty.
1191       %m     A "misc" replacement. It is at the discretion of the backend  to
1192              decide what this replacement expands to.
1193
1194              The hg and git backends use this expando to display patch infor‐
1195              mation.  hg sources patch information from  the  mq  extensions;
1196              git  from in-progress rebase and cherry-pick operations and from
1197              the stgit extension.  The patch-format and nopatch-format styles
1198              control  the generated string.  The former is used when at least
1199              one patch from the patch queue has been applied, and the  latter
1200              otherwise.
1201
1202              The hg backend displays bookmark information in this expando (in
1203              addition to mq information).  See the get-mq  and  get-bookmarks
1204              styles.   Both  of these styles may be enabled at the same time.
1205              If both are enabled, both resulting strings will be shown  sepa‐
1206              rated by a semicolon (that cannot currently be customized).
1207
1208              The  quilt  `standalone'  backend  sets this expando to the same
1209              value as the %Q expando.
1210
1211       %Q     Quilt series information.  When quilt is used (either in `addon'
1212              mode or as a `standalone' backend), this expando is set to quilt
1213              series' patch-format  string.   The  set-patch-format  hook  and
1214              nopatch-format style are honoured.
1215
1216              See Quilt Support below for details.
1217
1218       In branchformat these replacements are done:
1219
1220       %b     The branch name.
1221       %r     The current revision number or the hgrevformat style for hg.
1222
1223       In hgrevformat these replacements are done:
1224
1225       %r     The current local revision number.
1226       %h     The current global revision identifier.
1227
1228       In patch-format and nopatch-format these replacements are done:
1229
1230       %p     The name of the top-most applied patch; may be overridden by the
1231              applied-string hook.
1232       %u     The number of unapplied patches; may be overridden by the  unap‐
1233              plied-string hook.
1234       %n     The number of applied patches.
1235       %c     The number of unapplied patches.
1236       %a     The number of all patches (%a = %n + %c).
1237       %g     The names of active mq guards (hg backend).
1238       %G     The number of active mq guards (hg backend).
1239
1240       Not  all VCS backends have to support all replacements. For nvcsformats
1241       no replacements are performed at all, it is just a string.
1242
1243   Oddities
1244       If you want to use the %b (bold off) prompt expansion in formats, which
1245       expands  %b  itself, use %%b. That will cause the vcs_info expansion to
1246       replace %%b with %b, so that zsh's prompt expansion mechanism can  han‐
1247       dle  it. Similarly, to hand down %b from branchformat, use %%%%b. Sorry
1248       for this inconvenience, but it cannot be easily avoided. Luckily we  do
1249       not  clash  with  a  lot of prompt expansions and this only needs to be
1250       done for those.
1251
1252       When  one  of   the   gen-applied-string,   gen-unapplied-string,   and
1253       set-patch-format     hooks     is    defined,    applying    %-escaping
1254       (`foo=${foo//'%'/%%}') to the interpolated values for use in the prompt
1255       is  the  responsibility of those hooks (jointly); when neither of those
1256       hooks is defined, vcs_info handles escaping by itself.  We regret  this
1257       coupling, but it was required for backwards compatibility.
1258
1259   Quilt Support
1260       Quilt  is  not  a  version control system, therefore this is not imple‐
1261       mented as a backend. It can help keeping track of a series of  patches.
1262       People use it to keep a set of changes they want to use on top of soft‐
1263       ware packages (which is  tightly  integrated  into  the  package  build
1264       process - the Debian project does this for a large number of packages).
1265       Quilt can also help individual  developers  keep  track  of  their  own
1266       patches on top of real version control systems.
1267
1268       The  vcs_info  integration tries to support both ways of using quilt by
1269       having two slightly different modes  of  operation:  `addon'  mode  and
1270       `standalone' mode).
1271
1272       Quilt  integration  is  off by default; to enable it, set the use-quilt
1273       style, and add %Q to your formats or actionformats style:
1274              zstyle ':vcs_info:*' use-quilt true
1275
1276       Styles   looked   up   from   the   Quilt    support    code    include
1277       `.quilt-quilt-mode'  in  the  vcs-string  part  of  the  context, where
1278       quilt-mode    is    either    addon    or     standalone.      Example:
1279       :vcs_info:git.quilt-addon:default:repo-root-name.
1280
1281       For `addon' mode to become active vcs_info must have already detected a
1282       real version control system controlling the directory. If that  is  the
1283       case,  a  directory  that holds quilt's patches needs to be found. That
1284       directory is configurable via the `QUILT_PATCHES' environment variable.
1285       If  that  variable  exists  its  value  is  used,  otherwise  the value
1286       `patches' is assumed. The value from $QUILT_PATCHES can be  overwritten
1287       using  the  `quilt-patches'  style. (Note: you can use vcs_info to keep
1288       the value of $QUILT_PATCHES correct all the  time  via  the  post-quilt
1289       hook).
1290
1291       When the directory in question is found, quilt is assumed to be active.
1292       To gather more information,  vcs_info  looks  for  a  directory  called
1293       `.pc';  Quilt  uses  that directory to track its current state. If this
1294       directory does not exist we know that quilt has not  done  anything  to
1295       the working directory (read: no patches have been applied yet).
1296
1297       If  patches  are  applied,  vcs_info will try to find out which. If you
1298       want to know which patches of a series are not yet applied, you need to
1299       activate the get-unapplied style in the appropriate context.
1300
1301       vcs_info  allows for very detailed control over how the gathered infor‐
1302       mation is presented (see the Configuration and Hooks in  vcs_info  sec‐
1303       tions),  all  of which are documented below. Note there are a number of
1304       other patch tracking systems that work on top of a certain version con‐
1305       trol  system  (like stgit for git, or mq for hg); the configuration for
1306       systems like that are generally configured the same way  as  the  quilt
1307       support.
1308
1309       If the quilt support is working in `addon' mode, the produced string is
1310       available as a simple format replacement (%Q to be precise), which  can
1311       be used in formats and actionformats; see below for details).
1312
1313       If,  on  the  other  hand,  the support code is working in `standalone'
1314       mode, vcs_info will pretend as if quilt were an actual version  control
1315       system.  That  means  that the version control system identifier (which
1316       otherwise would be something like  `svn'  or  `cvs')  will  be  set  to
1317       `-quilt-'.  This  has implications on the used style context where this
1318       identifier is the second element. vcs_info will have filled in a proper
1319       value  for  the "repository's" root directory and the string containing
1320       the information about quilt's state will be  available  as  the  `misc'
1321       replacement (and %Q for compatibility with `addon' mode).
1322
1323       What  is  left  to  discuss  is  how `standalone' mode is detected. The
1324       detection itself is a series of searches for directories. You can  have
1325       this detection enabled all the time in every directory that is not oth‐
1326       erwise under version control. If you know there is only a  limited  set
1327       of  trees  where  you  would like vcs_info to try and look for Quilt in
1328       `standalone' mode to minimise the amount of searching on every call  to
1329       vcs_info, there are a number of ways to do that:
1330
1331       Essentially,  `standalone'  mode  detection  is  controlled  by a style
1332       called `quilt-standalone'. It is a string style and its value can  have
1333       different  effects.  The simplest values are: `always' to run detection
1334       every time vcs_info is run, and  `never'  to  turn  the  detection  off
1335       entirely.
1336
1337       If  the  value of quilt-standalone is something else, it is interpreted
1338       differently. If the value is the name of a scalar variable the value of
1339       that   variable  is  checked  and  that  value  is  used  in  the  same
1340       `always'/`never' way as described above.
1341
1342       If the value of quilt-standalone is an  array,  the  elements  of  that
1343       array are used as directory names under which you want the detection to
1344       be active.
1345
1346       If quilt-standalone is an associative array,  the  keys  are  taken  as
1347       directory  names  under  which you want the detection to be active, but
1348       only if the corresponding value is the string `true'.
1349
1350       Last, but not least, if the value of quilt-standalone is the name of  a
1351       function, the function is called without arguments and the return value
1352       decides whether detection should be active. A `0' return value is true;
1353       a non-zero return value is interpreted as false.
1354
1355       Note,  if  there  is  both  a  function  and  a variable by the name of
1356       quilt-standalone, the function will take precedence.
1357
1358   Function Descriptions (Public API)
1359       vcs_info [user-context]
1360              The main function, that runs all backends and assembles all data
1361              into  ${vcs_info_msg_*_}.  This is the function you want to call
1362              from precmd if you want to  include  up-to-date  information  in
1363              your prompt (see Variable Description below).  If an argument is
1364              given, that string will  be  used  instead  of  default  in  the
1365              user-context field of the style context.
1366
1367       vcs_info_hookadd
1368              Statically  registers a number of functions to a given hook. The
1369              hook needs to be given as the first argument; what follows is  a
1370              list  of hook-function names to register to the hook. The `+vi-'
1371              prefix needs to be left out here. See Hooks  in  vcs_info  below
1372              for details.
1373
1374       vcs_info_hookdel
1375              Remove  hook-functions  from  a given hook. The hook needs to be
1376              given as the first non-option argument; what follows is  a  list
1377              of  hook-function names to un-register from the hook. If `-a' is
1378              used as the first argument, all occurrences of the functions are
1379              unregistered.  Otherwise only the last occurrence is removed (if
1380              a function was registered to a hook more than once). The  `+vi-'
1381              prefix  needs  to be left out here.  See Hooks in vcs_info below
1382              for details.
1383
1384       vcs_info_lastmsg
1385              Outputs the last ${vcs_info_msg_*_} value.  Takes  into  account
1386              the  value  of  the  use-prompt-escapes style in ':vcs_info:for‐
1387              mats:command:-all-'. It also only prints max-exports values.
1388
1389       vcs_info_printsys [user-context]
1390              Prints a list of all supported version control  systems.  Useful
1391              to find out possible contexts (and which of them are enabled) or
1392              values for the disable style.
1393
1394       vcs_info_setsys
1395              Initializes vcs_info's internal list of available backends. With
1396              this function, you can add support for new VCSs without restart‐
1397              ing the shell.
1398
1399       All functions named VCS_INFO_* are for internal use only.
1400
1401   Variable Description
1402       ${vcs_info_msg_N_} (Note the trailing underscore)
1403              Where N is an integer, e.g.,  vcs_info_msg_0_.  These  variables
1404              are  the storage for the informational message the last vcs_info
1405              call has assembled. These are strongly connected to the formats,
1406              actionformats  and  nvcsformats  styles  described  above. Those
1407              styles are lists. The first member of that  list  gets  expanded
1408              into  ${vcs_info_msg_0_}, the second into ${vcs_info_msg_1_} and
1409              the Nth into ${vcs_info_msg_N-1_}. (See  the  max-exports  style
1410              above.)
1411
1412       All variables named VCS_INFO_* are for internal use only.
1413
1414   Hooks in vcs_info
1415       Hooks are places in vcs_info where you can run your own code. That code
1416       can communicate with the code that called it and through  that,  change
1417       the system's behaviour.
1418
1419       For configuration, hooks change the style context:
1420              :vcs_info:vcs-string+hook-name:user-context:repo-root-name
1421
1422       To  register  functions  to  a hook, you need to list them in the hooks
1423       style in the appropriate context.
1424
1425       Example:
1426              zstyle ':vcs_info:*+foo:*' hooks bar baz
1427
1428       This registers functions to the hook `foo' for all backends.  In  order
1429       to   avoid  namespace  problems,  all  registered  function  names  are
1430       prepended by a `+vi-', so the actual functions  called  for  the  `foo'
1431       hook are `+vi-bar' and `+vi-baz'.
1432
1433       If  you  would  like to register a function to a hook regardless of the
1434       current context, you may use the vcs_info_hookadd function. To remove a
1435       function that was added like that, the vcs_info_hookdel function can be
1436       used.
1437
1438       If something seems weird, you can enable the `debug' boolean  style  in
1439       the  proper  context and the hook-calling code will print what it tried
1440       to execute and whether the function in question existed.
1441
1442       When you register more than one function to a hook, all  functions  are
1443       executed one after another until one function returns non-zero or until
1444       all functions have been called. Context-sensitive  hook  functions  are
1445       executed   before   statically  registered  ones  (the  ones  added  by
1446       vcs_info_hookadd).
1447
1448       You  may  pass  data  between  functions  via  an  associative   array,
1449       user_data.  For example:
1450              +vi-git-myfirsthook(){
1451                  user_data[myval]=$myval
1452              }
1453              +vi-git-mysecondhook(){
1454                  # do something with ${user_data[myval]}
1455              }
1456
1457       There are a number of variables that are special in hook contexts:
1458
1459       ret    The  return value that the hooks system will return to the call‐
1460              er. The default is an integer `zero'. If and how a  changed  ret
1461              value  changes  the  execution of the caller depends on the spe‐
1462              cific hook. See the hook documentation below for details.
1463
1464       hook_com
1465              An associated array which is used for  bidirectional  communica‐
1466              tion  from the caller to hook functions. The used keys depend on
1467              the specific hook.
1468
1469       context
1470              The active context of the hook. Functions that  wish  to  change
1471              this variable should make it local scope first.
1472
1473       vcs    The current VCS after it was detected. The same values as in the
1474              enable/disable style are used. Available  in  all  hooks  except
1475              start-up.
1476
1477       Finally, the full list of currently available hooks:
1478
1479       start-up
1480              Called after starting vcs_info but before the VCS in this direc‐
1481              tory is determined. It can be used to deactivate vcs_info tempo‐
1482              rarily  if  necessary. When ret is set to 1, vcs_info aborts and
1483              does nothing; when set to 2, vcs_info sets up everything  as  if
1484              no version control were active and exits.
1485
1486       pre-get-data
1487              Same as start-up but after the VCS was detected.
1488
1489       gen-hg-bookmark-string
1490              Called in the Mercurial backend when a bookmark string is gener‐
1491              ated; the get-revision and get-bookmarks styles must be true.
1492
1493              This hook  gets  the  names  of  the  Mercurial  bookmarks  that
1494              vcs_info collected from `hg'.
1495
1496              If a bookmark is active, the key ${hook_com[hg-active-bookmark]}
1497              is set to its name.  The key is otherwise unset.
1498
1499              When setting ret to non-zero, the string in  ${hook_com[hg-book‐
1500              mark-string]}  will  be  used  in  the  %m escape in formats and
1501              actionformats and will be available in the  global  backend_misc
1502              array as ${backend_misc[bookmarks]}.
1503
1504       gen-applied-string
1505              Called in the git (with stgit or during rebase or merge), and hg
1506              (with mq) backends and in quilt support when the  applied-string
1507              is  generated;  the use-quilt zstyle must be true for quilt (the
1508              mq and stgit backends are active by default).
1509
1510              This hook gets the names of all applied patches  which  vcs_info
1511              collected  so  far  in  the opposite order, which means that the
1512              first argument is the top-most patch and so forth.
1513
1514              When    setting    ret    to    non-zero,    the    string    in
1515              ${hook_com[applied-string]}  will  be  available  as  %p  in the
1516              patch-format and nopatch-format styles.  This hook is,  in  con‐
1517              cert  with  set-patch-format,  responsible  for  %-escaping that
1518              value for use in the prompt.  (See the Oddities section.)
1519
1520       gen-unapplied-string
1521              Called in the git (with stgit or during rebase),  and  hg  (with
1522              mq)  backend  and  in quilt support when the unapplied-string is
1523              generated; the get-unapplied style must be true.
1524
1525              This hook gets the names of all unapplied patches which vcs_info
1526              collected  so  far in order, which means that the first argument
1527              is the patch next-in-line to be applied and so forth.
1528
1529              When setting ret to non-zero,  the  string  in  ${hook_com[unap‐
1530              plied-string]}  will  be available as %u in the patch-format and
1531              nopatch-format  styles.   This  hook   is,   in   concert   with
1532              set-patch-format,  responsible for %-escaping that value for use
1533              in the prompt.  (See the Oddities section.)
1534
1535       gen-mqguards-string
1536              Called in the hg backend when guards-string  is  generated;  the
1537              get-mq style must be true (default).
1538
1539              This hook gets the names of any active mq guards.
1540
1541              When    setting    ret    to    non-zero,    the    string    in
1542              ${hook_com[guards-string]} will be used in the %g escape in  the
1543              patch-format and nopatch-format styles.
1544
1545       no-vcs This  hooks  is  called  when  no  version  control  system  was
1546              detected.
1547
1548              The `hook_com' parameter is not used.
1549
1550       post-backend
1551              Called as soon as the backend has finished  collecting  informa‐
1552              tion.
1553
1554              The `hook_com' keys available are as for the set-message hook.
1555
1556       post-quilt
1557              Called  after  the quilt support is done. The following informa‐
1558              tion is passed as arguments to the hook:  1.  the  quilt-support
1559              mode  (`addon'  or `standalone'); 2. the directory that contains
1560              the patch series; 3. the directory  that  holds  quilt's  status
1561              information (the `.pc' directory) or the string "-nopc-" if that
1562              directory wasn't found.
1563
1564              The `hook_com' parameter is not used.
1565
1566       set-branch-format
1567              Called before `branchformat' is set. The only  argument  to  the
1568              hook is the format that is configured at this point.
1569
1570              The  `hook_com'  keys  considered  are  `branch' and `revision'.
1571              They are set to the values figured out so far  by  vcs_info  and
1572              any  change will be used directly when the actual replacement is
1573              done.
1574
1575              If    ret    is    set    to    non-zero,    the    string    in
1576              ${hook_com[branch-replace]}  will  be used unchanged as the `%b'
1577              replacement in the variables set by vcs_info.
1578
1579       set-hgrev-format
1580              Called before a `hgrevformat' is set. The only argument  to  the
1581              hook is the format that is configured at this point.
1582
1583              The  `hook_com' keys considered are `hash' and `localrev'.  They
1584              are set to the values figured out so far  by  vcs_info  and  any
1585              change  will  be  used  directly  when the actual replacement is
1586              done.
1587
1588              If    ret    is    set    to    non-zero,    the    string    in
1589              ${hook_com[rev-replace]}  will  be  used  unchanged  as the `%i'
1590              replacement in the variables set by vcs_info.
1591
1592       pre-addon-quilt
1593              This hook is used when vcs_info's quilt functionality is  active
1594              in  "addon"  mode  (quilt  used on top of a real version control
1595              system). It is activated right before any quilt specific  action
1596              is taken.
1597
1598              Setting  the  `ret'  variable  in  this hook to a non-zero value
1599              avoids any quilt specific actions from being run at all.
1600
1601       set-patch-format
1602              This hook is used to control some of the possible expansions  in
1603              patch-format  and nopatch-format styles with patch queue systems
1604              such as quilt, mqueue and the like.
1605
1606              This hook is used in the git, hg and quilt backends.
1607
1608              The hook allows the control of the %p (${hook_com[applied]}) and
1609              %u  (${hook_com[unapplied]})  expansion in all backends that use
1610              the   hook.    With    the    mercurial    backend,    the    %g
1611              (${hook_com[guards]})  expansion  is controllable in addition to
1612              that.
1613
1614              If    ret    is    set    to    non-zero,    the    string    in
1615              ${hook_com[patch-replace]}  will be used unchanged instead of an
1616              expanded format from patch-format or nopatch-format.
1617
1618              This  hook  is,  in  concert  with  the  gen-applied-string   or
1619              gen-unapplied-string  hooks if they are defined, responsible for
1620              %-escaping the final patch-format value for use in  the  prompt.
1621              (See the Oddities section.)
1622
1623       set-message
1624              Called  each time before a `vcs_info_msg_N_' message is set.  It
1625              takes two arguments; the first being  the  `N'  in  the  message
1626              variable name, the second is the currently configured formats or
1627              actionformats.
1628
1629              There are a number of  `hook_com'  keys,  that  are  used  here:
1630              `action',  `branch',  `base',  `base-name',  `subdir', `staged',
1631              `unstaged', `revision', `misc', `vcs' and one `miscN' entry  for
1632              each  backend-specific data field (N starting at zero). They are
1633              set to the values figured out so far by vcs_info and any  change
1634              will be used directly when the actual replacement is done.
1635
1636              Since  this hook is triggered multiple times (once for each con‐
1637              figured formats or actionformats), each of the  `hook_com'  keys
1638              mentioned  above  (except  for the miscN entries) has an `_orig'
1639              counterpart, so even if you changed a value to your  liking  you
1640              can  still  get the original value in the next run. Changing the
1641              `_orig' values is probably not a good idea.
1642
1643              If ret is set to non-zero, the  string  in  ${hook_com[message]}
1644              will be used unchanged as the message by vcs_info.
1645
1646       If  all  of  this  sounds rather confusing, take a look at the Examples
1647       section below and also in the Misc/vcs_info-examples file  in  the  Zsh
1648       source.  They contain some explanatory code.
1649
1650   Examples
1651       Don't use vcs_info at all (even though it's in your prompt):
1652              zstyle ':vcs_info:*' enable NONE
1653
1654       Disable the backends for bzr and svk:
1655              zstyle ':vcs_info:*' disable bzr svk
1656
1657       Disable everything but bzr and svk:
1658              zstyle ':vcs_info:*' enable bzr svk
1659
1660       Provide a special formats for git:
1661              zstyle ':vcs_info:git:*' formats       ' GIT, BABY! [%b]'
1662              zstyle ':vcs_info:git:*' actionformats ' GIT ACTION! [%b|%a]'
1663
1664       All  %x  expansion  in  all  sorts  of formats (formats, actionformats,
1665       branchformat, you name it) are done using the  `zformat'  builtin  from
1666       the  `zsh/zutil' module. That means you can do everything with these %x
1667       items what zformat supports. In particular, if you want something  that
1668       is  really  long  to  have  a  fixed  width, like a hash in a mercurial
1669       branchformat, you can do this: %12.12i. That'll shrink the 40 character
1670       hash  to  its  12 leading characters. The form is actually `%min.maxx'.
1671       More is possible.  See the section `The zsh/zutil  Module'  in  zshmod‐
1672       ules(1) for details.
1673
1674       Use the quicker bzr backend
1675              zstyle ':vcs_info:bzr:*' use-simple true
1676
1677       If    you    do    use   use-simple,   please   report   if   it   does
1678       `the-right-thing[tm]'.
1679
1680       Display the revision number in yellow for bzr and svn:
1681              zstyle ':vcs_info:(svn|bzr):*' \
1682                     branchformat '%b%{'${fg[yellow]}'%}:%r'
1683
1684       If you want colors, make sure you enclose the color codes in %{...%} if
1685       you want to use the string provided by vcs_info in prompts.
1686
1687       Here  is  how  to  print  the  VCS  information  as a command (not in a
1688       prompt):
1689              alias vcsi='vcs_info command; vcs_info_lastmsg'
1690
1691       This way,  you  can  even  define  different  formats  for  output  via
1692       vcs_info_lastmsg in the ':vcs_info:*:command:*' namespace.
1693
1694       Now  as promised, some code that uses hooks: say, you'd like to replace
1695       the string `svn' by `subversion' in vcs_info's %s formats replacement.
1696
1697       First, we will tell vcs_info to call a  function  when  populating  the
1698       message variables with the gathered information:
1699              zstyle ':vcs_info:*+set-message:*' hooks svn2subversion
1700
1701       Nothing happens. Which is reasonable, since we didn't define the actual
1702       function yet. To see what the hooks subsystem is trying to  do,  enable
1703       the `debug' style:
1704              zstyle ':vcs_info:*+*:*' debug true
1705
1706       That  should give you an idea what is going on. Specifically, the func‐
1707       tion that we are looking for is `+vi-svn2subversion'. Note, the  `+vi-'
1708       prefix.  So,  everything  is in order, just as documented. When you are
1709       done checking out the debugging output, disable it again:
1710              zstyle ':vcs_info:*+*:*' debug false
1711
1712       Now, let's define the function:
1713              function +vi-svn2subversion() {
1714                  [[ ${hook_com[vcs_orig]} == svn ]] && hook_com[vcs]=subversion
1715              }
1716
1717       Simple enough. And it could have even been simpler, if only we had reg‐
1718       istered our function in a less generic context. If we do it only in the
1719       `svn' backend's context, we don't need to test which the active backend
1720       is:
1721              zstyle ':vcs_info:svn+set-message:*' hooks svn2subversion
1722              function +vi-svn2subversion() {
1723                  hook_com[vcs]=subversion
1724              }
1725
1726       And finally a little more elaborate example, that uses a hook to create
1727       a customised bookmark string for the hg backend.
1728
1729       Again, we start off by registering a function:
1730              zstyle ':vcs_info:hg+gen-hg-bookmark-string:*' hooks hgbookmarks
1731
1732       And then we define the `+vi-hgbookmarks' function:
1733              function +vi-hgbookmarks() {
1734                  # The default is to connect all bookmark names by
1735                  # commas. This mixes things up a little.
1736                  # Imagine, there's one type of bookmarks that is
1737                  # special to you. Say, because it's *your* work.
1738                  # Those bookmarks look always like this: "sh/*"
1739                  # (because your initials are sh, for example).
1740                  # This makes the bookmarks string use only those
1741                  # bookmarks. If there's more than one, it
1742                  # concatenates them using commas.
1743                  # The bookmarks returned by `hg' are available in
1744                  # the function's positional parameters.
1745                  local s="${(Mj:,:)@:#sh/*}"
1746                  # Now, the communication with the code that calls
1747                  # the hook functions is done via the hook_com[]
1748                  # hash. The key at which the `gen-hg-bookmark-string'
1749                  # hook looks is `hg-bookmark-string'. So:
1750                  hook_com[hg-bookmark-string]=$s
1751                  # And to signal that we want to use the string we
1752                  # just generated, set the special variable `ret' to
1753                  # something other than the default zero:
1754                  ret=1
1755                  return 0
1756              }
1757
1758       Some longer examples and code snippets which might be useful are avail‐
1759       able  in the examples file located at Misc/vcs_info-examples in the Zsh
1760       source directory.
1761
1762       This concludes our guided tour through zsh's vcs_info.
1763

PROMPT THEMES

1765   Installation
1766       You should make sure  all  the  functions  from  the  Functions/Prompts
1767       directory of the source distribution are available; they all begin with
1768       the string `prompt_' except for the special function`promptinit'.   You
1769       also   need  the  `colors'  and  `add-zsh-hook'  functions  from  Func‐
1770       tions/Misc.  All these functions may already be installed on your  sys‐
1771       tem;  if  not, you will need to find them and copy them.  The directory
1772       should appear as one of the elements of the fpath  array  (this  should
1773       already  be the case if they were installed), and at least the function
1774       promptinit should be autoloaded; it will autoload the  rest.   Finally,
1775       to  initialize  the  use  of the system you need to call the promptinit
1776       function.  The following code in your .zshrc  will  arrange  for  this;
1777       assume the functions are stored in the directory ~/myfns:
1778
1779              fpath=(~/myfns $fpath)
1780              autoload -U promptinit
1781              promptinit
1782
1783   Theme Selection
1784       Use  the  prompt  command to select your preferred theme.  This command
1785       may be added to your .zshrc following the call to promptinit  in  order
1786       to start zsh with a theme already selected.
1787
1788       prompt [ -c | -l ]
1789       prompt [ -p | -h ] [ theme ... ]
1790       prompt [ -s ] theme [ arg ... ]
1791              Set  or  examine  the prompt theme.  With no options and a theme
1792              argument, the theme with that name is set as the current  theme.
1793              The  available  themes  are  determined  at run time; use the -l
1794              option to see a list.  The special  theme  `random'  selects  at
1795              random one of the available themes and sets your prompt to that.
1796
1797              In  some  cases  the  theme may be modified by one or more argu‐
1798              ments, which should be given after the theme name.  See the help
1799              for each theme for descriptions of these arguments.
1800
1801              Options are:
1802
1803              -c     Show  the currently selected theme and its parameters, if
1804                     any.
1805              -l     List all available prompt themes.
1806              -p     Preview the theme named by theme, or  all  themes  if  no
1807                     theme is given.
1808              -h     Show help for the theme named by theme, or for the prompt
1809                     function if no theme is given.
1810              -s     Set theme as the current theme and save state.
1811
1812       prompt_theme_setup
1813              Each available theme has a setup function which is called by the
1814              prompt function to install that theme.  This function may define
1815              other functions as necessary to maintain the  prompt,  including
1816              functions  used  to  preview  the prompt or provide help for its
1817              use.  You should not normally  call  a  theme's  setup  function
1818              directly.
1819
1820   Utility Themes
1821       prompt off
1822              The  theme `off' sets all the prompt variables to minimal values
1823              with no special effects.
1824
1825       prompt default
1826              The theme `default' sets all prompt variables to the same  state
1827              as  if  an  interactive  zsh  was started with no initialization
1828              files.
1829
1830       prompt restore
1831              The special theme `restore' erases all theme settings  and  sets
1832              prompt  variables  to  their  state  before  the  first time the
1833              `prompt' function was run,  provided  each  theme  has  properly
1834              defined its cleanup (see below).
1835
1836              Note  that  you  can undo `prompt off' and `prompt default' with
1837              `prompt restore', but a second restore does not undo the first.
1838
1839   Writing Themes
1840       The first step for adding your own theme is to choose a  name  for  it,
1841       and  create  a  file  `prompt_name_setup' in a directory in your fpath,
1842       such as ~/myfns in the example above.  The file should at minimum  con‐
1843       tain  assignments  for  the  prompt variables that your theme wishes to
1844       modify.  By convention, themes use PS1, PS2, RPS1,  etc.,  rather  than
1845       the longer PROMPT and RPROMPT.
1846
1847       The  file  is autoloaded as a function in the current shell context, so
1848       it may contain any necessary commands to customize your theme,  includ‐
1849       ing  defining additional functions.  To make some complex tasks easier,
1850       your setup function may also do any of the following:
1851
1852       Assign prompt_opts
1853              The array prompt_opts may be assigned any of "bang", "cr", "per‐
1854              cent",  "sp",  and/or  "subst"  as  values.   The  corresponding
1855              setopts  (promptbang,   etc.)   are   turned   on,   all   other
1856              prompt-related  options  are  turned off.  The prompt_opts array
1857              preserves setopts even beyond the scope of localoptions,  should
1858              your function need that.
1859
1860       Modify precmd and preexec
1861              Use  of  add-zsh-hook  is  recommended.   The precmd and preexec
1862              hooks are automatically adjusted if the prompt theme changes  or
1863              is disabled.
1864
1865       Declare cleanup
1866              If  your  function makes any other changes that should be undone
1867              when the theme is disabled, your setup function may call
1868              prompt_cleanup command
1869       where command should be suitably quoted.  If your theme  is  ever  dis‐
1870       abled  or  replaced by another, command is executed with eval.  You may
1871       declare more than one such cleanup hook.
1872
1873       Define preview
1874              Define or autoload a function prompt_name_preview to  display  a
1875              simulated version of your prompt.  A simple default previewer is
1876              defined by promptinit for themes that do not define  their  own.
1877              This preview function is called by `prompt -p'.
1878
1879       Provide help
1880              Define  or autoload a function prompt_name_help to display docu‐
1881              mentation or help text for your theme.  This  help  function  is
1882              called by `prompt -h'.
1883

ZLE FUNCTIONS

1885   Widgets
1886       These  functions all implement user-defined ZLE widgets (see zshzle(1))
1887       which can be bound to keystrokes in interactive shells.  To  use  them,
1888       your .zshrc should contain lines of the form
1889
1890              autoload function
1891              zle -N function
1892
1893       followed  by  an  appropriate bindkey command to associate the function
1894       with a key sequence.  Suggested bindings are described below.
1895
1896       bash-style word functions
1897              If you are looking for functions to implement  moving  over  and
1898              editing  words  in  the  manner of bash, where only alphanumeric
1899              characters are considered word characters, you can use the func‐
1900              tions  described  in  the next section.  The following is suffi‐
1901              cient:
1902
1903                     autoload -U select-word-style
1904                     select-word-style bash
1905
1906       forward-word-match, backward-word-match
1907       kill-word-match, backward-kill-word-match
1908       transpose-words-match, capitalize-word-match
1909       up-case-word-match, down-case-word-match
1910       delete-whole-word-match, select-word-match
1911       select-word-style, match-word-context, match-words-by-style
1912              The first eight `-match' functions are drop-in replacements  for
1913              the  builtin widgets without the suffix.  By default they behave
1914              in a similar way.  However, by the use of styles and  the  func‐
1915              tion  select-word-style,  the  way  words  are  matched  can  be
1916              altered. select-word-match is intended to  be  used  as  a  text
1917              object  in  vi mode but with custom word styles. For comparison,
1918              the widgets described in zshzle(1) under Text Objects use  fixed
1919              definitions of words, compatible with the vim editor.
1920
1921              The  simplest  way  of  configuring  the  functions  is  to  use
1922              select-word-style, which can either be called as a normal  func‐
1923              tion with the appropriate argument, or invoked as a user-defined
1924              widget that will prompt for the  first  character  of  the  word
1925              style to be used.  The first time it is invoked, the first eight
1926              -match functions will automatically  replace  the  builtin  ver‐
1927              sions, so they do not need to be loaded explicitly.
1928
1929              The  word styles available are as follows.  Only the first char‐
1930              acter is examined.
1931
1932              bash   Word characters are alphanumeric characters only.
1933
1934              normal As  in  normal  shell  operation:   word  characters  are
1935                     alphanumeric  characters  plus  any characters present in
1936                     the string given by the parameter $WORDCHARS.
1937
1938              shell  Words are  complete  shell  command  arguments,  possibly
1939                     including  complete quoted strings, or any tokens special
1940                     to the shell.
1941
1942              whitespace
1943                     Words are any set of characters delimited by whitespace.
1944
1945              default
1946                     Restore the default settings; this is usually the same as
1947                     `normal'.
1948
1949              All but `default' can be input as an upper case character, which
1950              has the same effect but with subword  matching  turned  on.   In
1951              this  case,  words  with  upper case characters are treated spe‐
1952              cially: each separate run of upper case characters, or an  upper
1953              case  character  followed  by any number of other characters, is
1954              considered a word.  The style subword-range can supply an alter‐
1955              native  character range to the default `[:upper:]'; the value of
1956              the style is treated as the contents of a `[...]' pattern  (note
1957              that  the outer brackets should not be supplied, only those sur‐
1958              rounding named ranges).
1959
1960              More control can  be  obtained  using  the  zstyle  command,  as
1961              described in zshmodules(1).  Each style is looked up in the con‐
1962              text :zle:widget where widget is the name  of  the  user-defined
1963              widget,  not the name of the function implementing it, so in the
1964              case of the definitions supplied by select-word-style the appro‐
1965              priate  contexts are :zle:forward-word, and so on.  The function
1966              select-word-style itself always defines styles for  the  context
1967              `:zle:*'  which can be overridden by more specific (longer) pat‐
1968              terns as well as explicit contexts.
1969
1970              The style word-style specifies the rules to use.  This may  have
1971              the following values.
1972
1973              normal Use  the  standard  shell  rules,  i.e. alphanumerics and
1974                     $WORDCHARS, unless overridden by the styles word-chars or
1975                     word-class.
1976
1977              specified
1978                     Similar to normal, but only the specified characters, and
1979                     not also alphanumerics, are considered word characters.
1980
1981              unspecified
1982                     The negation of  specified.   The  given  characters  are
1983                     those which will not be considered part of a word.
1984
1985              shell  Words  are obtained by using the syntactic rules for gen‐
1986                     erating shell command arguments.   In  addition,  special
1987                     tokens which are never command arguments such as `()' are
1988                     also treated as words.
1989
1990              whitespace
1991                     Words are whitespace-delimited strings of characters.
1992
1993              The first three of those rules usually use $WORDCHARS,  but  the
1994              value   in   the  parameter  can  be  overridden  by  the  style
1995              word-chars, which works in exactly the same way  as  $WORDCHARS.
1996              In addition, the style word-class uses character class syntax to
1997              group characters and takes precedence over  word-chars  if  both
1998              are  set.  The word-class style does not include the surrounding
1999              brackets of the character class; for example, `-:[:alnum:]' is a
2000              valid  word-class  to include all alphanumerics plus the charac‐
2001              ters `-' and `:'.  Be careful including  `]',  `^'  and  `-'  as
2002              these are special inside character classes.
2003
2004              word-style  may  also  have  `-subword' appended to its value to
2005              turn on subword matching, as described above.
2006
2007              The style skip-chars is mostly useful  for  transpose-words  and
2008              similar  functions.   If  set,  it  gives  a count of characters
2009              starting at the cursor position which  will  not  be  considered
2010              part  of  the  word and are treated as space, regardless of what
2011              they actually are.  For example, if
2012
2013                     zstyle ':zle:transpose-words' skip-chars 1
2014
2015              has been set, and transpose-words-match is called with the  cur‐
2016              sor  on the X of fooXbar, where X can be any character, then the
2017              resulting expression is barXfoo.
2018
2019              Finer grained control can  be  obtained  by  setting  the  style
2020              word-context  to  an  array  of  pairs of entries.  Each pair of
2021              entries consists of a pattern and a subcontext.  The shell argu‐
2022              ment  the  cursor  is on is matched against each pattern in turn
2023              until one matches; if it does, the  context  is  extended  by  a
2024              colon  and  the corresponding subcontext.  Note that the test is
2025              made against the original word on the line, with no stripping of
2026              quotes.   Special  handling  is  done between words: the current
2027              context is examined and if it contains the  string  between  the
2028              word is set to a single space; else if it is contains the string
2029              back, the word before the cursor is considered,  else  the  word
2030              after cursor is considered. Some examples are given below.
2031
2032              The  style  skip-whitespace-first  is  only  used  with the for‐
2033              ward-word widget.  If it is set to true, then forward-word skips
2034              any  non-word-characters,  followed  by any non-word-characters:
2035              this is similar to the behaviour of other  word-orientated  wid‐
2036              gets,  and  also  that used by other editors, however it differs
2037              from the standard zsh behaviour.  When  using  select-word-style
2038              the  widget  is  set  in  the context :zle:* to true if the word
2039              style is bash and false otherwise.  It may be overridden by set‐
2040              ting it in the more specific context :zle:forward-word*.
2041
2042              It  is  possible  to  create  widgets with specific behaviour by
2043              defining a new widget implemented  by  the  appropriate  generic
2044              function,  then  setting a style for the context of the specific
2045              widget.  For example,  the  following  defines  a  widget  back‐
2046              ward-kill-space-word using backward-kill-word-match, the generic
2047              widget implementing backward-kill-word  behaviour,  and  ensures
2048              that the new widget always implements space-delimited behaviour.
2049
2050                     zle -N backward-kill-space-word backward-kill-word-match
2051                     zstyle :zle:backward-kill-space-word word-style space
2052
2053              The widget backward-kill-space-word can now be bound to a key.
2054
2055              Here  are  some  further examples of use of the styles, actually
2056              taken from the simplified interface in select-word-style:
2057
2058                     zstyle ':zle:*' word-style standard
2059                     zstyle ':zle:*' word-chars ''
2060
2061              Implements bash-style word handling for all widgets,  i.e.  only
2062              alphanumerics  are  word  characters;  equivalent to setting the
2063              parameter WORDCHARS empty for the given context.
2064
2065                     style ':zle:*kill*' word-style space
2066
2067              Uses space-delimited words for widgets with the word  `kill'  in
2068              the  name.   Neither  of the styles word-chars nor word-class is
2069              used in this case.
2070
2071              Here are some examples of  use  of  the  word-context  style  to
2072              extend the context.
2073
2074                     zstyle ':zle:*' word-context \
2075                            "*/*" filename "[[:space:]]" whitespace
2076                     zstyle ':zle:transpose-words:whitespace' word-style shell
2077                     zstyle ':zle:transpose-words:filename' word-style normal
2078                     zstyle ':zle:transpose-words:filename' word-chars ''
2079
2080              This  provides  two  different  ways  of  using  transpose-words
2081              depending on whether the cursor is on whitespace  between  words
2082              or  on a filename, here any word containing a /.  On whitespace,
2083              complete arguments as defined by standard shell  rules  will  be
2084              transposed.   In  a  filename, only alphanumerics will be trans‐
2085              posed.  Elsewhere, words will be transposed  using  the  default
2086              style for :zle:transpose-words.
2087
2088              The  word  matching  and  all the handling of zstyle settings is
2089              actually implemented by the function match-words-by-style.  This
2090              can  be  used  to  create new user-defined widgets.  The calling
2091              function should set the local parameter curcontext to  :zle:wid‐
2092              get,   create   the   local  parameter  matched_words  and  call
2093              match-words-by-style   with   no    arguments.     On    return,
2094              matched_words will be set to an array with the elements: (1) the
2095              start of the line  (2)  the  word  before  the  cursor  (3)  any
2096              non-word  characters  between  that  word and the cursor (4) any
2097              non-word character at the cursor  position  plus  any  remaining
2098              non-word  characters before the next word, including all charac‐
2099              ters specified by the skip-chars style, (5) the word at or  fol‐
2100              lowing  the  cursor  (6)  any non-word characters following that
2101              word (7) the remainder of the line.  Any of the elements may  be
2102              an  empty  string;  the calling function should test for this to
2103              decide whether it can perform its function.
2104
2105              If the variable  matched_words  is  defined  by  the  caller  to
2106              match-words-by-style   as   an   associative   array  (local  -A
2107              matched_words), then the seven  values  given  above  should  be
2108              retrieved  from  it as elements named start, word-before-cursor,
2109              ws-before-cursor,      ws-after-cursor,       word-after-cursor,
2110              ws-after-word,  and  end.  In addition the element is-word-start
2111              is 1 if the cursor is on the start of a word or subword,  or  on
2112              white space before it (the cases can be distinguished by testing
2113              the ws-after-cursor element) and 0 otherwise.  This form is rec‐
2114              ommended for future compatibility.
2115
2116              It   is   possible   to   pass   options   with   arguments   to
2117              match-words-by-style to override the use of styles.  The options
2118              are:
2119              -w     word-style
2120              -s     skip-chars
2121              -c     word-class
2122              -C     word-chars
2123              -r     subword-range
2124
2125              For  example,  match-words-by-style -w shell -c 0 may be used to
2126              extract the command argument around the cursor.
2127
2128              The  word-context  style  is   implemented   by   the   function
2129              match-word-context.   This  should not usually need to be called
2130              directly.
2131
2132       bracketed-paste-magic
2133              The bracketed-paste widget (see subsection Miscellaneous in zsh‐
2134              zle(1))  inserts  pasted  text  literally into the editor buffer
2135              rather than interpret it as keystrokes.  This disables some com‐
2136              mon  usages where the self-insert widget is replaced in order to
2137              accomplish some extra processing.  An example is the contributed
2138              url-quote-magic widget described below.
2139
2140              The  bracketed-paste-magic  widget  is  meant  to replace brack‐
2141              eted-paste with a  wrapper  that  re-enables  these  self-insert
2142              actions,  and  other  actions as selected by zstyles.  Therefore
2143              this widget is installed with
2144
2145                     autoload -Uz bracketed-paste-magic
2146                     zle -N bracketed-paste bracketed-paste-magic
2147
2148              Other   than   enabling   some   widget    processing,    brack‐
2149              eted-paste-magic attempts to replicate bracketed-paste as faith‐
2150              fully as possible.
2151
2152              The following zstyles may be set to control processing of pasted
2153              text.    All   are   looked   up   in   the   context   `:brack‐
2154              eted-paste-magic'.
2155
2156              active-widgets
2157                     A list of patterns matching widget names that  should  be
2158                     activated  during the paste.  All other key sequences are
2159                     processed as self-insert-unmeta.  The default is `self-*'
2160                     so  any  user-defined  widgets named with that prefix are
2161                     active along with the builtin self-insert.
2162
2163                     If this style is not set (explicitly deleted) or  set  to
2164                     an empty value, no widgets are active and the pasted text
2165                     is inserted literally.   If  the  value  includes  `unde‐
2166                     fined-key',  any unknown sequences are discarded from the
2167                     pasted text.
2168
2169              inactive-keys
2170                     The inverse of active-widgets, a list  of  key  sequences
2171                     that  always use self-insert-unmeta even when bound to an
2172                     active widget.  Note that this is a list of  literal  key
2173                     sequences, not patterns.
2174
2175              paste-init
2176                     A  list  of function names, called in widget context (but
2177                     not as widgets).  The functions are called in order until
2178                     one  of  them  returns  a non-zero status.  The parameter
2179                     `PASTED' contains the initial state of the  pasted  text.
2180                     All other ZLE parameters such as `BUFFER' have their nor‐
2181                     mal values and side-effects, and full history  is  avail‐
2182                     able,  so for example paste-init functions may move words
2183                     from BUFFER into PASTED to make those  words  visible  to
2184                     the active-widgets.
2185
2186                     A  non-zero  return  from  a paste-init function does not
2187                     prevent the paste itself from proceeding.
2188
2189                     Loading     bracketed-paste-magic      defines      back‐
2190                     ward-extend-paste,   a   helper   function   for  use  in
2191                     paste-init.
2192
2193                            zstyle :bracketed-paste-magic paste-init \
2194                                   backward-extend-paste
2195
2196                     When a paste would insert into the middle of  a  word  or
2197                     append  text  to  a  word  already  on  the  line,  back‐
2198                     ward-extend-paste moves  the  prefix  from  LBUFFER  into
2199                     PASTED  so  that  the active-widgets see the full word so
2200                     far.  This may be useful with url-quote-magic.
2201
2202              paste-finish
2203                     Another list of function names called in order until  one
2204                     returns  non-zero.   These functions are called after the
2205                     pasted text has been processed by the active-widgets, but
2206                     before it is inserted into `BUFFER'.  ZLE parameters have
2207                     their normal values and side-effects.
2208
2209                     A non-zero return from a paste-finish function  does  not
2210                     prevent the paste itself from proceeding.
2211
2212                     Loading bracketed-paste-magic also defines quote-paste, a
2213                     helper function for use in paste-finish.
2214
2215                            zstyle :bracketed-paste-magic paste-finish \
2216                                   quote-paste
2217                            zstyle :bracketed-paste-magic:finish quote-style \
2218                                   qqq
2219
2220                     When the pasted text  is  inserted  into  BUFFER,  it  is
2221                     quoted  per  the quote-style value.  To forcibly turn off
2222                     the built-in numeric prefix quoting  of  bracketed-paste,
2223                     use:
2224
2225                            zstyle :bracketed-paste-magic:finish quote-style \
2226                                   none
2227
2228              Important:  During active-widgets processing of the paste (after
2229              paste-init and before paste-finish),  BUFFER  starts  empty  and
2230              history  is  restricted,  so  cursor motions, etc., may not pass
2231              outside of the pasted content.  Text assigned to BUFFER  by  the
2232              active widgets is copied back into PASTED before paste-finish.
2233
2234       copy-earlier-word
2235              This  widget  works  like  a combination of insert-last-word and
2236              copy-prev-shell-word.   Repeated  invocations  of   the   widget
2237              retrieve  earlier  words  on  the relevant history line.  With a
2238              numeric argument N, insert the Nth word from the history line; N
2239              may be negative to count from the end of the line.
2240
2241              If insert-last-word has been used to retrieve the last word on a
2242              previous history line, repeated invocations  will  replace  that
2243              word with earlier words from the same line.
2244
2245              Otherwise,  the  widget  applies  to words on the line currently
2246              being edited.  The widget style  can  be  set  to  the  name  of
2247              another  widget  that  should be called to retrieve words.  This
2248              widget must accept the same three arguments as insert-last-word.
2249
2250       cycle-completion-positions
2251              After inserting an unambiguous string into the command line, the
2252              new  function  based  completion  system may know about multiple
2253              places in this string where characters  are  missing  or  differ
2254              from  at  least one of the possible matches.  It will then place
2255              the cursor on the position it considers to be the most interest‐
2256              ing one, i.e. the one where one can disambiguate between as many
2257              matches as possible with as little typing as possible.
2258
2259              This widget allows the cursor to be easily moved  to  the  other
2260              interesting  spots.   It  can  be  invoked  repeatedly  to cycle
2261              between all positions reported by the completion system.
2262
2263       delete-whole-word-match
2264              This is another function which works like the  -match  functions
2265              described  immediately  above,  i.e.  using styles to decide the
2266              word boundaries.  However, it  is  not  a  replacement  for  any
2267              existing function.
2268
2269              The  basic  behaviour  is  to delete the word around the cursor.
2270              There is no numeric argument  handling;  only  the  single  word
2271              around  the  cursor  is  considered.  If the widget contains the
2272              string kill, the removed text will be placed  in  the  cutbuffer
2273              for   future   yanking.    This  can  be  obtained  by  defining
2274              kill-whole-word-match as follows:
2275
2276                     zle -N kill-whole-word-match delete-whole-word-match
2277
2278              and then binding the widget kill-whole-word-match.
2279
2280       up-line-or-beginning-search, down-line-or-beginning-search
2281              These   widgets   are   similar   to   the   builtin   functions
2282              up-line-or-search  and  down-line-or-search:   if in a multiline
2283              buffer they move up or down within the  buffer,  otherwise  they
2284              search  for  a  history  line  matching the start of the current
2285              line.  In this case, however,  they  search  for  a  line  which
2286              matches  the  current line up to the current cursor position, in
2287              the manner of  history-beginning-search-backward  and  -forward,
2288              rather than the first word on the line.
2289
2290       edit-command-line
2291              Edit the command line using your visual editor, as in ksh.
2292
2293                     bindkey -M vicmd v edit-command-line
2294
2295       expand-absolute-path
2296              Expand  the  file  name  under  the  cursor to an absolute path,
2297              resolving symbolic links.  Where possible, the initial path seg‐
2298              ment  is  turned into a named directory or reference to a user's
2299              home directory.
2300
2301       history-search-end
2302              This   function   implements    the    widgets    history-begin‐
2303              ning-search-backward-end    and    history-beginning-search-for‐
2304              ward-end.  These commands work by first calling the  correspond‐
2305              ing builtin widget (see `History Control' in zshzle(1)) and then
2306              moving the cursor to the end of the line.  The  original  cursor
2307              position  is  remembered and restored before calling the builtin
2308              widget a second time, so that the same  search  is  repeated  to
2309              look farther through the history.
2310
2311              Although  you autoload only one function, the commands to use it
2312              are slightly different because it implements two widgets.
2313
2314                     zle -N history-beginning-search-backward-end \
2315                            history-search-end
2316                     zle -N history-beginning-search-forward-end \
2317                            history-search-end
2318                     bindkey '\e^P' history-beginning-search-backward-end
2319                     bindkey '\e^N' history-beginning-search-forward-end
2320
2321       history-beginning-search-menu
2322              This function implements yet another form of history  searching.
2323              The text before the cursor is used to select lines from the his‐
2324              tory, as for history-beginning-search-backward except  that  all
2325              matches  are  shown  in a numbered menu.  Typing the appropriate
2326              digits inserts the full history line.  Note that leading  zeroes
2327              must  be  typed (they are only shown when necessary for removing
2328              ambiguity).  The entire history is searched; there  is  no  dis‐
2329              tinction between forwards and backwards.
2330
2331              With a numeric argument, the search is not anchored to the start
2332              of the line; the string typed by the use may appear anywhere  in
2333              the line in the history.
2334
2335              If  the  widget  name contains `-end' the cursor is moved to the
2336              end of the line inserted.  If the widget name contains  `-space'
2337              any  space  in  the  text typed is treated as a wildcard and can
2338              match anything (hence a leading space is equivalent to giving  a
2339              numeric argument).  Both forms can be combined, for example:
2340
2341                     zle -N history-beginning-search-menu-space-end \
2342                            history-beginning-search-menu
2343
2344       history-pattern-search
2345              The  function  history-pattern-search  implements  widgets which
2346              prompt for a pattern with which to search the history  backwards
2347              or  forwards.   The  pattern is in the usual zsh format, however
2348              the first character may be ^ to anchor the search to  the  start
2349              of  the  line,  and  the  last  character may be $ to anchor the
2350              search to the end of the line.  If the search was  not  anchored
2351              to  the  end of the line the cursor is positioned just after the
2352              pattern found.
2353
2354              The commands to create bindable widgets are similar to those  in
2355              the example immediately above:
2356
2357                     autoload -U history-pattern-search
2358                     zle -N history-pattern-search-backward history-pattern-search
2359                     zle -N history-pattern-search-forward history-pattern-search
2360
2361       incarg Typing  the keystrokes for this widget with the cursor placed on
2362              or to the left of an integer causes that integer  to  be  incre‐
2363              mented  by  one.   With a numeric argument, the number is incre‐
2364              mented by the amount of the argument (decremented if the numeric
2365              argument is negative).  The shell parameter incarg may be set to
2366              change the default increment to something other than one.
2367
2368                     bindkey '^X+' incarg
2369
2370       incremental-complete-word
2371              This allows incremental completion of a  word.   After  starting
2372              this  command,  a  list of completion choices can be shown after
2373              every character you type, which you can delete with ^H  or  DEL.
2374              Pressing return accepts the completion so far and returns you to
2375              normal editing (that is, the command  line  is  not  immediately
2376              executed).  You can hit TAB to do normal completion, ^G to abort
2377              back to the state when you started, and ^D to list the matches.
2378
2379              This works only with the new function based completion system.
2380
2381                     bindkey '^Xi' incremental-complete-word
2382
2383       insert-composed-char
2384              This function allows you to compose characters that don't appear
2385              on  the keyboard to be inserted into the command line.  The com‐
2386              mand is followed by two keys corresponding to  ASCII  characters
2387              (there is no prompt).  For accented characters, the two keys are
2388              a base character followed by a code for the  accent,  while  for
2389              other  special  characters  the  two  characters together form a
2390              mnemonic for the character to be  inserted.   The  two-character
2391              codes  are  a subset of those given by RFC 1345 (see for example
2392              http://www.faqs.org/rfcs/rfc1345.html).
2393
2394              The function may optionally be followed by up to two  characters
2395              which  replace  one or both of the characters read from the key‐
2396              board; if both characters are supplied, no input is  read.   For
2397              example,  insert-composed-char a: can be used within a widget to
2398              insert an a with umlaut into the command  line.   This  has  the
2399              advantages  over use of a literal character that it is more por‐
2400              table.
2401
2402              For best results zsh should have been  built  with  support  for
2403              multibyte  characters (configured with --enable-multibyte); how‐
2404              ever, the function works for the  limited  range  of  characters
2405              available in single-byte character sets such as ISO-8859-1.
2406
2407              The  character  is  converted  into the local representation and
2408              inserted into the command line at  the  cursor  position.   (The
2409              conversion  is  done within the shell, using whatever facilities
2410              the C library provides.)  With a numeric argument, the character
2411              and its code are previewed in the status line
2412
2413              The  function may be run outside zle in which case it prints the
2414              character (together with a newline) to standard  output.   Input
2415              is still read from keystrokes.
2416
2417              See insert-unicode-char for an alternative way of inserting Uni‐
2418              code characters using their hexadecimal character number.
2419
2420              The set of accented characters is reasonably complete up to Uni‐
2421              code  character  U+0180,  the set of special characters less so.
2422              However, it is very sporadic from that point.  Adding new  char‐
2423              acters is easy, however; see the function define-composed-chars.
2424              Please send any additions to zsh-workers@zsh.org.
2425
2426              The codes for the second character when used to accent the first
2427              are  as  follows.   Note that not every character can take every
2428              accent.
2429              !      Grave.
2430              '      Acute.
2431              >      Circumflex.
2432              ?      Tilde.  (This is not ~ as RFC 1345 does not  assume  that
2433                     character is present on the keyboard.)
2434              -      Macron.  (A horizontal bar over the base character.)
2435              (      Breve.  (A shallow dish shape over the base character.)
2436              .      Dot above the base character, or in the case of i no dot,
2437                     or in the case of L and l a centered dot.
2438              :      Diaeresis (Umlaut).
2439              c      Cedilla.
2440              _      Underline, however  there  are  currently  no  underlined
2441                     characters.
2442              /      Stroke through the base character.
2443              "      Double acute (only supported on a few letters).
2444              ;      Ogonek.   (A  little  forward  facing  hook at the bottom
2445                     right of the character.)
2446              <      Caron.  (A little v over the letter.)
2447              0      Circle over the base character.
2448              2      Hook over the base character.
2449              9      Horn over the base character.
2450
2451              The most common characters from the Arabic, Cyrillic, Greek  and
2452              Hebrew  alphabets are available; consult RFC 1345 for the appro‐
2453              priate sequences.  In addition, a set of two letter codes not in
2454              RFC  1345  are  available for the double-width characters corre‐
2455              sponding to ASCII characters from !  to ~ (0x21 to 0x7e) by pre‐
2456              ceding  the  character with ^, for example ^A for a double-width
2457              A.
2458
2459              The following other two-character sequences are understood.
2460
2461              ASCII characters
2462                     These are already present on most keyboards:
2463              <(     Left square bracket
2464              //     Backslash (solidus)
2465              )>     Right square bracket
2466              (!     Left brace (curly bracket)
2467              !!     Vertical bar (pipe symbol)
2468              !)     Right brace (curly bracket)
2469              '?     Tilde
2470
2471              Special letters
2472                     Characters found in various variants of the Latin  alpha‐
2473                     bet:
2474              ss     Eszett (scharfes S)
2475              D-, d- Eth
2476              TH, th Thorn
2477              kk     Kra
2478              'n     'n
2479              NG, ng Ng
2480              OI, oi Oi
2481              yr     yr
2482              ED     ezh
2483
2484              Currency symbols
2485              Ct     Cent
2486              Pd     Pound sterling (also lira and others)
2487              Cu     Currency
2488              Ye     Yen
2489              Eu     Euro (N.B. not in RFC 1345)
2490
2491              Punctuation characters
2492                     References to "right" quotes indicate the shape (like a 9
2493                     rather than 6) rather than their grammatical  use.   (For
2494                     example,  a "right" low double quote is used to open quo‐
2495                     tations in German.)
2496              !I     Inverted exclamation mark
2497              BB     Broken vertical bar
2498              SE     Section
2499              Co     Copyright
2500              -a     Spanish feminine ordinal indicator
2501              <<     Left guillemet
2502              --     Soft hyphen
2503              Rg     Registered trade mark
2504              PI     Pilcrow (paragraph)
2505              -o     Spanish masculine ordinal indicator
2506              >>     Right guillemet
2507              ?I     Inverted question mark
2508              -1     Hyphen
2509              -N     En dash
2510              -M     Em dash
2511              -3     Horizontal bar
2512              :3     Vertical ellipsis
2513              .3     Horizontal midline ellipsis
2514              !2     Double vertical line
2515              =2     Double low line
2516              '6     Left single quote
2517              '9     Right single quote
2518              .9     "Right" low quote
2519              9'     Reversed "right" quote
2520              "6     Left double quote
2521              "9     Right double quote
2522              :9     "Right" low double quote
2523              9"     Reversed "right" double quote
2524              /-     Dagger
2525              /=     Double dagger
2526
2527              Mathematical symbols
2528              DG     Degree
2529              -2, +-, -+
2530                     - sign, +/- sign, -/+ sign
2531              2S     Superscript 2
2532              3S     Superscript 3
2533              1S     Superscript 1
2534              My     Micro
2535              .M     Middle dot
2536              14     Quarter
2537              12     Half
2538              34     Three quarters
2539              *X     Multiplication
2540              -:     Division
2541              %0     Per mille
2542              FA, TE, /0
2543                     For all, there exists, empty set
2544              dP, DE, NB
2545                     Partial derivative, delta (increment), del (nabla)
2546              (-, -) Element of, contains
2547              *P, +Z Product, sum
2548              *-, Ob, Sb
2549                     Asterisk, ring, bullet
2550              RT, 0(, 00
2551                     Root sign, proportional to, infinity
2552
2553              Other symbols
2554              cS, cH, cD, cC
2555                     Card suits: spades, hearts, diamonds, clubs
2556              Md, M8, M2, Mb, Mx, MX
2557                     Musical notation: crotchet (quarter note), quaver (eighth
2558                     note),  semiquavers (sixteenth notes), flag sign, natural
2559                     sign, sharp sign
2560              Fm, Ml Female, male
2561
2562              Accents on their own
2563              '>     Circumflex (same as caret, ^)
2564              '!     Grave (same as backtick, `)
2565              ',     Cedilla
2566              ':     Diaeresis (Umlaut)
2567              'm     Macron
2568              ''     Acute
2569
2570       insert-files
2571              This function allows you  type  a  file  pattern,  and  see  the
2572              results of the expansion at each step.  When you hit return, all
2573              expansions are inserted into the command line.
2574
2575                     bindkey '^Xf' insert-files
2576
2577       insert-unicode-char
2578              When first executed, the user inputs a set of  hexadecimal  dig‐
2579              its.   This  is  terminated  with  another  call  to insert-uni‐
2580              code-char.  The digits are then turned  into  the  corresponding
2581              Unicode  character.  For example, if the widget is bound to ^XU,
2582              the character sequence `^XU 4 c ^XU' inserts L (Unicode U+004c).
2583
2584              See insert-composed-char for a way of inserting characters using
2585              a two-character mnemonic.
2586
2587
2588       narrow-to-region [ -p pre ] [ -P post ]
2589                        [  -S statepm | -R statepm | [ -l lbufvar ] [ -r rbuf‐
2590       var ] ]
2591                        [ -n ] [ start end ]
2592       narrow-to-region-invisible
2593              Narrow the editable portion of the buffer to the region  between
2594              the  cursor  and  the  mark,  which may be in either order.  The
2595              region may not be empty.
2596
2597              narrow-to-region may be used as a widget or called as a function
2598              from  a  user-defined  widget;  by default, the text outside the
2599              editable area remains visible.  A  recursive-edit  is  performed
2600              and  the  original  widening  status  is then restored.  Various
2601              options and arguments are available when it is called as a func‐
2602              tion.
2603
2604              The  options  -p  pretext and -P posttext may be used to replace
2605              the text before and after the display for the  duration  of  the
2606              function; either or both may be an empty string.
2607
2608              If the option -n is also given, pretext or posttext will only be
2609              inserted if there is text before or  after  the  region  respec‐
2610              tively which will be made invisible.
2611
2612              Two numeric arguments may be given which will be used instead of
2613              the cursor and mark positions.
2614
2615              The option -S statepm is used to narrow according to  the  other
2616              options  while  saving  the original state in the parameter with
2617              name statepm, while the option -R statepm is used to restore the
2618              state  from  the  parameter;  note in both cases the name of the
2619              parameter is required.  In the second case,  other  options  and
2620              arguments  are  irrelevant.  When this method is used, no recur‐
2621              sive-edit is performed; the  calling  widget  should  call  this
2622              function with the option -S, perform its own editing on the com‐
2623              mand line or pass control to the user via `zle  recursive-edit',
2624              then  call  this  function  with  the  option  -R.  The argument
2625              statepm must be a  suitable  name  for  an  ordinary  parameter,
2626              except  that  parameters  beginning  with  the  prefix _ntr_ are
2627              reserved for use within narrow-to-region.  Typically the parame‐
2628              ter will be local to the calling function.
2629
2630              The  options  -l  lbufvar  and -r rbufvar may be used to specify
2631              parameters where the widget will store the resulting  text  from
2632              the  operation.   The parameter lbufvar will contain LBUFFER and
2633              rbufvar will contain RBUFFER.  Neither of these two options  may
2634              be used with -S or -R.
2635
2636              narrow-to-region-invisible  is  a simple widget which calls nar‐
2637              row-to-region with arguments which replace any text outside  the
2638              region with `...'.  It does not take any arguments.
2639
2640              The  display  is  restored (and the widget returns) upon any zle
2641              command which would usually cause the line  to  be  accepted  or
2642              aborted.  Hence an additional such command is required to accept
2643              or abort the current line.
2644
2645              The return status of both  widgets  is  zero  if  the  line  was
2646              accepted, else non-zero.
2647
2648              Here is a trivial example of a widget using this feature.
2649                     local state
2650                     narrow-to-region -p $'Editing restricted region\n' \
2651                       -P '' -S state
2652                     zle recursive-edit
2653                     narrow-to-region -R state
2654
2655       predict-on
2656              This set of functions implements predictive typing using history
2657              search.  After predict-on, typing characters causes  the  editor
2658              to  look  backward  in  the history for the first line beginning
2659              with what you have typed so  far.   After  predict-off,  editing
2660              returns  to normal for the line found.  In fact, you often don't
2661              even need to use predict-off, because if the line doesn't  match
2662              something in the history, adding a key performs standard comple‐
2663              tion, and then inserts itself  if  no  completions  were  found.
2664              However,  editing  in  the middle of a line is liable to confuse
2665              prediction; see the toggle style below.
2666
2667              With the function based completion system (which is  needed  for
2668              this),  you  should  be  able to type TAB at almost any point to
2669              advance the cursor to the next ``interesting''  character  posi‐
2670              tion  (usually  the end of the current word, but sometimes some‐
2671              where in the middle of the word).  And of course as soon as  the
2672              entire  line is what you want, you can accept with return, with‐
2673              out needing to move the cursor to the end first.
2674
2675              The first time predict-on is used, it creates several additional
2676              widget functions:
2677
2678              delete-backward-and-predict
2679                     Replaces  the  backward-delete-char  widget.   You do not
2680                     need to bind this yourself.
2681              insert-and-predict
2682                     Implements predictive typing by replacing the self-insert
2683                     widget.  You do not need to bind this yourself.
2684              predict-off
2685                     Turns off predictive typing.
2686
2687              Although you autoload only the predict-on function, it is neces‐
2688              sary to create a keybinding for predict-off as well.
2689
2690                     zle -N predict-on
2691                     zle -N predict-off
2692                     bindkey '^X^Z' predict-on
2693                     bindkey '^Z' predict-off
2694
2695       read-from-minibuffer
2696              This is most useful when called as a function from inside a wid‐
2697              get,  but  will work correctly as a widget in its own right.  It
2698              prompts for a value below the current command line; a value  may
2699              be  input  using  all  of  the  standard zle operations (and not
2700              merely the restricted set available when executing, for example,
2701              execute-named-cmd).   The  value is then returned to the calling
2702              function in the parameter $REPLY and the editing buffer restored
2703              to  its  previous  state.  If the read was aborted by a keyboard
2704              break (typically ^G), the function returns status 1  and  $REPLY
2705              is not set.
2706
2707              If  one  argument  is  supplied to the function it is taken as a
2708              prompt, otherwise `? ' is used.  If two arguments are  supplied,
2709              they  are the prompt and the initial value of $LBUFFER, and if a
2710              third argument is given it is the  initial  value  of  $RBUFFER.
2711              This  provides  a  default  value and starting cursor placement.
2712              Upon return the entire buffer is the value of $REPLY.
2713
2714              One option is available: `-k num' specifies that num  characters
2715              are  to be read instead of a whole line.  The line editor is not
2716              invoked recursively in this case, so depending on  the  terminal
2717              settings  the  input may not be visible, and only the input keys
2718              are placed in $REPLY, not the entire buffer.  Note  that  unlike
2719              the read builtin num must be given; there is no default.
2720
2721              The  name  is  a  slight  misnomer,  as  in fact the shell's own
2722              minibuffer is not used.  Hence it is still possible to call exe‐
2723              cuted-named-cmd and similar functions while reading a value.
2724
2725       replace-argument, replace-argument-edit
2726              The  function  replace-argument can be used to replace a command
2727              line argument in the current command line  or,  if  the  current
2728              command  line  is  empty, in the last command line executed (the
2729              new command line is not executed).  Arguments are  as  delimited
2730              by standard shell syntax,
2731
2732              If  a  numeric argument is given, that specifies the argument to
2733              be replaced.  0 means the command name, as in history expansion.
2734              A negative numeric argument counts backward from the last word.
2735
2736              If  no  numeric  argument  is  given,  the  current  argument is
2737              replaced; this is the last argument if the previous history line
2738              is being used.
2739
2740              The function prompts for a replacement argument.
2741
2742              If  the  widget contains the string edit, for example is defined
2743              as
2744
2745                     zle -N replace-argument-edit replace-argument
2746
2747              then the function presents the current value of the argument for
2748              editing,  otherwise  the  editing  buffer for the replacement is
2749              initially empty.
2750
2751       replace-string, replace-pattern
2752       replace-string-again, replace-pattern-again
2753              The  function  replace-string  implements  three  widgets.    If
2754              defined  under the same name as the function, it prompts for two
2755              strings; the first (source) string will be replaced by the  sec‐
2756              ond everywhere it occurs in the line editing buffer.
2757
2758              If  the  widget name contains the word `pattern', for example by
2759              defining the widget using the command  `zle  -N  replace-pattern
2760              replace-string',  then  the matching is performed using zsh pat‐
2761              terns.  All zsh extended globbing patterns can be  used  in  the
2762              source  string; note that unlike filename generation the pattern
2763              does not need to match an entire word, nor  do  glob  qualifiers
2764              have  any  effect.  In addition, the replacement string can con‐
2765              tain parameter or command substitutions.  Furthermore, a `&'  in
2766              the  replacement string will be replaced with the matched source
2767              string, and a backquoted digit `\N' will be replaced by the  Nth
2768              parenthesised  expression  matched.  The form `\{N}' may be used
2769              to protect the digit from following digits.
2770
2771              If the widget instead contains the word `regex'  (or  `regexp'),
2772              then  the  matching  is  performed  using  regular  expressions,
2773              respecting the setting of  the  option  RE_MATCH_PCRE  (see  the
2774              description  of the function regexp-replace below).  The special
2775              replacement facilities described above for pattern matching  are
2776              available.
2777
2778              By default the previous source or replacement string will not be
2779              offered for editing.  However, this feature can be activated  by
2780              setting  the style edit-previous in the context :zle:widget (for
2781              example, :zle:replace-string) to true.  In addition, a  positive
2782              numeric  argument  forces  the  previous values to be offered, a
2783              negative or zero argument forces them not to be.
2784
2785              The function replace-string-again can be used to repeat the pre‐
2786              vious    replacement;   no   prompting   is   done.    As   with
2787              replace-string, if the name of  the  widget  contains  the  word
2788              `pattern'  or `regex', pattern or regular expression matching is
2789              performed, else a literal string  replacement.   Note  that  the
2790              previous  source  and replacement text are the same whether pat‐
2791              tern, regular expression or string matching is used.
2792
2793              In addition, replace-string shows the previous replacement above
2794              the prompt, so long as there was one during the current session;
2795              if the source string is empty, that replacement will be repeated
2796              without the widget prompting for a replacement string.
2797
2798              For example, starting from the line:
2799
2800                     print This line contains fan and fond
2801
2802              and  invoking replace-pattern with the source string `f(?)n' and
2803              the replacement string `c\1r' produces the not very useful line:
2804
2805                     print This line contains car and cord
2806
2807              The range of the replacement string can be limited by using  the
2808              narrow-to-region-invisible  widget.   One limitation of the cur‐
2809              rent version is that undo will  cycle  through  changes  to  the
2810              replacement  and  source  strings before undoing the replacement
2811              itself.
2812
2813       send-invisible
2814              This is similar to read-from-minibuffer in that it may be called
2815              as  a  function  from  a  widget  or as a widget of its own, and
2816              interactively reads input from the keyboard.  However, the input
2817              being  typed  is  concealed  and  a string of asterisks (`*') is
2818              shown instead.  The value is saved in the  parameter  $INVISIBLE
2819              to  which a reference is inserted into the editing buffer at the
2820              restored cursor position.  If the read was aborted by a keyboard
2821              break  (typically  ^G)  or  another  escape from editing such as
2822              push-line, $INVISIBLE is set to empty and the original buffer is
2823              restored unchanged.
2824
2825              If  one  argument  is  supplied to the function it is taken as a
2826              prompt, otherwise `Non-echoed text: ' is used (as in emacs).  If
2827              a  second and third argument are supplied they are used to begin
2828              and end the reference to $INVISIBLE that is  inserted  into  the
2829              buffer.   The  default  is  to open with ${, then INVISIBLE, and
2830              close with }, but many other effects are possible.
2831
2832       smart-insert-last-word
2833              This function may replace the insert-last-word widget, like so:
2834
2835                     zle -N insert-last-word smart-insert-last-word
2836
2837              With a numeric argument, or when passed command  line  arguments
2838              in a call from another widget, it behaves like insert-last-word,
2839              except that words in comments are ignored when  INTERACTIVE_COM‐
2840              MENTS is set.
2841
2842              Otherwise,  the rightmost ``interesting'' word from the previous
2843              command is  found  and  inserted.   The  default  definition  of
2844              ``interesting''  is  that  the word contains at least one alpha‐
2845              betic character, slash, or backslash.  This  definition  may  be
2846              overridden  by use of the match style.  The context used to look
2847              up the style is the widget  name,  so  usually  the  context  is
2848              :insert-last-word.   However, you can bind this function to dif‐
2849              ferent widgets to use different patterns:
2850
2851                     zle -N insert-last-assignment smart-insert-last-word
2852                     zstyle :insert-last-assignment match '[[:alpha:]][][[:alnum:]]#=*'
2853                     bindkey '\e=' insert-last-assignment
2854
2855              If no interesting word is found and the auto-previous  style  is
2856              set  to  a  true  value, the search continues upward through the
2857              history.  When auto-previous is unset or  false  (the  default),
2858              the widget must be invoked repeatedly in order to search earlier
2859              history lines.
2860
2861       transpose-lines
2862              Only useful with a multi-line editing buffer; the lines here are
2863              lines  within  the  current on-screen buffer, not history lines.
2864              The effect is similar to the function of the same name in Emacs.
2865
2866              Transpose the current line with the previous line and  move  the
2867              cursor to the start of the next line.  Repeating this (which can
2868              be done by providing a positive numeric argument) has the effect
2869              of moving the line above the cursor down by a number of lines.
2870
2871              With  a  negative numeric argument, requires two lines above the
2872              cursor.  These two lines are transposed and the cursor moved  to
2873              the  start  of the previous line.  Using a numeric argument less
2874              than -1 has the effect of moving the line above the cursor up by
2875              minus that number of lines.
2876
2877       url-quote-magic
2878              This  widget replaces the built-in self-insert to make it easier
2879              to type URLs as command line arguments.  As you type, the  input
2880              character  is  analyzed and, if it may need quoting, the current
2881              word is checked for a URI scheme.  If one is found and the  cur‐
2882              rent  word  is  not  already  in quotes, a backslash is inserted
2883              before the input character.
2884
2885              Styles to control quoting behavior:
2886
2887              url-metas
2888                     This   style   is    looked    up    in    the    context
2889                     `:url-quote-magic:scheme'  (where  scheme  is that of the
2890                     current URL, e.g. "ftp").  The value is a string  listing
2891                     the  characters  to be treated as globbing metacharacters
2892                     when appearing in a URL using that scheme.   The  default
2893                     is to quote all zsh extended globbing characters, exclud‐
2894                     ing '<' and '>' but including braces (as in brace  expan‐
2895                     sion).  See also url-seps.
2896
2897              url-seps
2898                     Like  url-metas, but lists characters that should be con‐
2899                     sidered command separators, redirections, history  refer‐
2900                     ences,  etc.  The default is to quote the standard set of
2901                     shell separators, excluding those that overlap  with  the
2902                     extended  globbing  characters, but including '<' and '>'
2903                     and the first character of $histchars.
2904
2905              url-globbers
2906                     This   style   is    looked    up    in    the    context
2907                     `:url-quote-magic'.   The  values  form a list of command
2908                     names that are expected to do their own globbing  on  the
2909                     URL  string.   This  implies that they are aliased to use
2910                     the `noglob' modifier.  When the first word on  the  line
2911                     matches  one  of the values and the URL refers to a local
2912                     file (see url-local-schema), only the url-seps characters
2913                     are  quoted;  the url-metas are left alone, allowing them
2914                     to affect command-line  parsing,  completion,  etc.   The
2915                     default  values  are  a  literal  `noglob' plus (when the
2916                     zsh/parameter module is available) any  commands  aliased
2917                     to   the   helper  function  `urlglobber'  or  its  alias
2918                     `globurl'.
2919
2920              url-local-schema
2921                     This style is always looked up in the context  `:urlglob‐
2922                     ber',  even though it is used by both url-quote-magic and
2923                     urlglobber.  The values form a list of  URI  schema  that
2924                     should  be  treated  as referring to local files by their
2925                     real local path names, as  opposed  to  files  which  are
2926                     specified relative to a web-server-defined document root.
2927                     The defaults are "ftp" and "file".
2928
2929              url-other-schema
2930                     Like url-local-schema, but lists  all  other  URI  schema
2931                     upon which urlglobber and url-quote-magic should act.  If
2932                     the URI on the  command  line  does  not  have  a  scheme
2933                     appearing  either in this list or in url-local-schema, it
2934                     is not magically quoted.  The default values are  "http",
2935                     "https",  and "ftp".  When a scheme appears both here and
2936                     in url-local-schema, it is quoted  differently  depending
2937                     on whether the command name appears in url-globbers.
2938
2939              Loading url-quote-magic also defines a helper function `urlglob‐
2940              ber' and aliases `globurl' to `noglob urlglobber'.   This  func‐
2941              tion  takes  a  local  URL  apart, attempts to pattern-match the
2942              local file portion of the URL path, and then  puts  the  results
2943              back into URL format again.
2944
2945       vi-pipe
2946              This  function  reads  a  movement command from the keyboard and
2947              then prompts for an external command. The  part  of  the  buffer
2948              covered  by  the  movement  is piped to the external command and
2949              then replaced by the command's output. If the  movement  command
2950              is bound to vi-pipe, the current line is used.
2951
2952              The function serves as an example for reading a vi movement com‐
2953              mand from within a user-defined widget.
2954
2955       which-command
2956              This function is a drop-in replacement for  the  builtin  widget
2957              which-command.   It has enhanced behaviour, in that it correctly
2958              detects whether or not the command word needs to be expanded  as
2959              an  alias; if so, it continues tracing the command word from the
2960              expanded alias until it reaches the command that  will  be  exe‐
2961              cuted.
2962
2963              The  style whence is available in the context :zle:$WIDGET; this
2964              may be set to an array to give the command and options that will
2965              be  used  to investigate the command word found.  The default is
2966              whence -c.
2967
2968       zcalc-auto-insert
2969              This  function  is  useful  together  with  the  zcalc  function
2970              described  in  the section Mathematical Functions.  It should be
2971              bound to a key representing a binary operator such as `+',  `-',
2972              `*'  or  `/'.   When  running in zcalc, if the key occurs at the
2973              start of the line or immediately following an open  parenthesis,
2974              the text "ans " is inserted before the representation of the key
2975              itself.  This allows easy use of the answer  from  the  previous
2976              calculation in the current line.  The text to be inserted before
2977              the symbol  typed  can  be  modified  by  setting  the  variable
2978              ZCALC_AUTO_INSERT_PREFIX.
2979
2980              Hence,  for  example, typing `+12' followed by return adds 12 to
2981              the previous result.
2982
2983              If zcalc is in RPN mode (-r option) the effect of  this  binding
2984              is  automatically  suppressed  as  operators alone on a line are
2985              meaningful.
2986
2987              When not in zcalc, the key simply inserts the symbol itself.
2988
2989   Utility Functions
2990       These functions are useful in constructing  widgets.   They  should  be
2991       loaded  with  `autoload  -U  function'  and  called  as  indicated from
2992       user-defined widgets.
2993
2994       split-shell-arguments
2995              This function splits the line currently being edited into  shell
2996              arguments  and  whitespace.   The  result is stored in the array
2997              reply.  The array contains all the parts of the line  in  order,
2998              starting with any whitespace before the first argument, and fin‐
2999              ishing with any whitespace after the last argument.   Hence  (so
3000              long as the option KSH_ARRAYS is not set) whitespace is given by
3001              odd indices in the array and arguments by  even  indices.   Note
3002              that  no  stripping  of quotes is done; joining together all the
3003              elements of reply in order is guaranteed to produce the original
3004              line.
3005
3006              The  parameter  REPLY  is  set to the index of the word in reply
3007              which contains the character after the cursor, where  the  first
3008              element  has  index 1.  The parameter REPLY2 is set to the index
3009              of the character under the cursor in that word, where the  first
3010              character has index 1.
3011
3012              Hence  reply,  REPLY  and REPLY2 should all be made local to the
3013              enclosing function.
3014
3015              See the function modify-current-argument, described  below,  for
3016              an example of how to call this function.
3017
3018       modify-current-argument [ expr-using-$ARG | func ]
3019              This  function provides a simple method of allowing user-defined
3020              widgets to modify the command line argument under the cursor (or
3021              immediately  to  the left of the cursor if the cursor is between
3022              arguments).
3023
3024              The argument can be an expression which when evaluated  operates
3025              on the shell parameter ARG, which will have been set to the com‐
3026              mand line argument under the cursor.  The expression  should  be
3027              suitably quoted to prevent it being evaluated too early.
3028
3029              Alternatively,  if the argument does not contain the string ARG,
3030              it is assumed to be a shell function, to which the current  com‐
3031              mand line argument is passed as the only argument.  The function
3032              should set the variable REPLY to the new value for  the  command
3033              line argument.  If the function returns non-zero status, so does
3034              the calling function.
3035
3036              For example, a user-defined widget containing the following code
3037              converts  the  characters  in the argument under the cursor into
3038              all upper case:
3039
3040                     modify-current-argument '${(U)ARG}'
3041
3042              The following strips any quoting from the current word  (whether
3043              backslashes  or  one  of  the styles of quotes), and replaces it
3044              with single quoting throughout:
3045
3046                     modify-current-argument '${(qq)${(Q)ARG}}'
3047
3048              The following performs directory expansion on the  command  line
3049              argument and replaces it by the absolute path:
3050
3051                     expand-dir() {
3052                       REPLY=${~1}
3053                       REPLY=${REPLY:a}
3054                     }
3055                     modify-current-argument expand-dir
3056
3057              In  practice  the  function  expand-dir  would  probably  not be
3058              defined  within  the  widget  where  modify-current-argument  is
3059              called.
3060
3061   Styles
3062       The  behavior  of several of the above widgets can be controlled by the
3063       use of the zstyle mechanism.  In particular, widgets that interact with
3064       the  completion system pass along their context to any completions that
3065       they invoke.
3066
3067       break-keys
3068              This style is used by the incremental-complete-word widget.  Its
3069              value  should  be  a pattern, and all keys matching this pattern
3070              will cause the widget to stop incremental completion without the
3071              key  having any further effect. Like all styles used directly by
3072              incremental-complete-word, this style is  looked  up  using  the
3073              context `:incremental'.
3074
3075       completer
3076              The incremental-complete-word and insert-and-predict widgets set
3077              up their top-level context name before calling completion.  This
3078              allows  one  to define different sets of completer functions for
3079              normal completion and for these widgets.  For  example,  to  use
3080              completion,  approximation and correction for normal completion,
3081              completion and correction for incremental  completion  and  only
3082              completion for prediction one could use:
3083
3084                     zstyle ':completion:*' completer \
3085                             _complete _correct _approximate
3086                     zstyle ':completion:incremental:*' completer \
3087                             _complete _correct
3088                     zstyle ':completion:predict:*' completer \
3089                             _complete
3090
3091              It is a good idea to restrict the completers used in prediction,
3092              because they may be automatically  invoked  as  you  type.   The
3093              _list and _menu completers should never be used with prediction.
3094              The _approximate, _correct, _expand, and _match  completers  may
3095              be  used,  but be aware that they may change characters anywhere
3096              in the word behind the cursor, so you need  to  watch  carefully
3097              that the result is what you intended.
3098
3099       cursor The  insert-and-predict  widget  uses this style, in the context
3100              `:predict', to decide where to place the cursor after completion
3101              has been tried.  Values are:
3102
3103              complete
3104                     The cursor is left where it was when completion finished,
3105                     but only if it is after a character equal to the one just
3106                     inserted  by the user.  If it is after another character,
3107                     this value is the same as `key'.
3108
3109              key    The cursor is left after the nth occurrence of the  char‐
3110                     acter  just inserted, where n is the number of times that
3111                     character appeared in  the  word  before  completion  was
3112                     attempted.   In short, this has the effect of leaving the
3113                     cursor after the character just typed even if the comple‐
3114                     tion  code  found out that no other characters need to be
3115                     inserted at that position.
3116
3117              Any other value for this style unconditionally leaves the cursor
3118              at the position where the completion code left it.
3119
3120       list   When using the incremental-complete-word widget, this style says
3121              if the matches should be listed on every key press (if they  fit
3122              on  the  screen).  Use the context prefix `:completion:incremen‐
3123              tal'.
3124
3125              The insert-and-predict widget uses this style to decide  if  the
3126              completion  should  be  shown even if there is only one possible
3127              completion.  This is done if the value  of  this  style  is  the
3128              string  always.   In  this  case  the context is `:predict' (not
3129              `:completion:predict').
3130
3131       match  This style is used by smart-insert-last-word to provide  a  pat‐
3132              tern (using full EXTENDED_GLOB syntax) that matches an interest‐
3133              ing word.  The context is  the  name  of  the  widget  to  which
3134              smart-insert-last-word is bound (see above).  The default behav‐
3135              ior of smart-insert-last-word is equivalent to:
3136
3137                     zstyle :insert-last-word match '*[[:alpha:]/\\]*'
3138
3139              However, you might want to include words that contain spaces:
3140
3141                     zstyle :insert-last-word match '*[[:alpha:][:space:]/\\]*'
3142
3143              Or include numbers as long as the word is at least  two  charac‐
3144              ters long:
3145
3146                     zstyle :insert-last-word match '*([[:digit:]]?|[[:alpha:]/\\])*'
3147
3148              The above example causes redirections like "2>" to be included.
3149
3150       prompt The  incremental-complete-word  widget  shows  the value of this
3151              style in the status line  during  incremental  completion.   The
3152              string  value may contain any of the following substrings in the
3153              manner of the PS1 and other prompt parameters:
3154
3155              %c     Replaced by the name of the completer function that  gen‐
3156                     erated the matches (without the leading underscore).
3157
3158              %l     When the list style is set, replaced by `...' if the list
3159                     of matches is too long to fit on the screen and  with  an
3160                     empty  string otherwise.  If the list style is `false' or
3161                     not set, `%l' is always removed.
3162
3163              %n     Replaced by the number of matches generated.
3164
3165              %s     Replaced by `-no match-',  `-no  prefix-',  or  an  empty
3166                     string if there is no completion matching the word on the
3167                     line, if the matches have no common prefix different from
3168                     the  word  on the line, or if there is such a common pre‐
3169                     fix, respectively.
3170
3171              %u     Replaced by the unambiguous part of all matches, if there
3172                     is any, and if it is different from the word on the line.
3173
3174              Like `break-keys', this uses the `:incremental' context.
3175
3176       stop-keys
3177              This style is used by the incremental-complete-word widget.  Its
3178              value is treated similarly to the one for the  break-keys  style
3179              (and  uses  the same context: `:incremental').  However, in this
3180              case all keys matching the pattern given as its value will  stop
3181              incremental  completion  and will then execute their usual func‐
3182              tion.
3183
3184       toggle This boolean style is used by predict-on and its related widgets
3185              in the context `:predict'.  If set to one of the standard `true'
3186              values, predictive typing is automatically toggled off in situa‐
3187              tions  where it is unlikely to be useful, such as when editing a
3188              multi-line buffer or after moving into the middle of a line  and
3189              then  deleting  a character.  The default is to leave prediction
3190              turned on until an explicit call to predict-off.
3191
3192       verbose
3193              This boolean style is used by predict-on and its related widgets
3194              in the context `:predict'.  If set to one of the standard `true'
3195              values, these widgets display a message below  the  prompt  when
3196              the  predictive state is toggled.  This is most useful in combi‐
3197              nation with the toggle style.   The  default  does  not  display
3198              these messages.
3199
3200       widget This style is similar to the command style: For widget functions
3201              that use zle to call other widgets, this style can sometimes  be
3202              used  to  override  the widget which is called.  The context for
3203              this style is the name of the calling widget (not  the  name  of
3204              the  calling function, because one function may be bound to mul‐
3205              tiple widget names).
3206
3207                     zstyle :copy-earlier-word widget smart-insert-last-word
3208
3209              Check the documentation for the calling widget  or  function  to
3210              determine whether the widget style is used.
3211

EXCEPTION HANDLING

3213       Two  functions are provided to enable zsh to provide exception handling
3214       in a form that should be familiar from other languages.
3215
3216       throw exception
3217              The function throw throws the named exception.  The name  is  an
3218              arbitrary  string  and is only used by the throw and catch func‐
3219              tions.  An exception is for the most part treated the same as  a
3220              shell error, i.e. an unhandled exception will cause the shell to
3221              abort all processing in a function or script and  to  return  to
3222              the top level in an interactive shell.
3223
3224       catch exception-pattern
3225              The  function  catch  returns  status  zero  if an exception was
3226              thrown and the pattern exception-pattern matches its name.  Oth‐
3227              erwise  it  returns  status  1.  exception-pattern is a standard
3228              shell  pattern,  respecting   the   current   setting   of   the
3229              EXTENDED_GLOB option.  An alias catch is also defined to prevent
3230              the argument to the function from matching  filenames,  so  pat‐
3231              terns  may  be  used  unquoted.  Note that as exceptions are not
3232              fundamentally different from other shell errors it  is  possible
3233              to  catch shell errors by using an empty string as the exception
3234              name.  The shell variable CAUGHT is set by catch to the name  of
3235              the exception caught.  It is possible to rethrow an exception by
3236              calling the throw function again  once  an  exception  has  been
3237              caught.
3238
3239       The  functions  are  designed  to be used together with the always con‐
3240       struct described in zshmisc(1).  This is important as  only  this  con‐
3241       struct provides the required support for exceptions.  A typical example
3242       is as follows.
3243
3244              {
3245                # "try" block
3246                # ... nested code here calls "throw MyExcept"
3247              } always {
3248                # "always" block
3249                if catch MyExcept; then
3250                  print "Caught exception MyExcept"
3251                elif catch ''; then
3252                  print "Caught a shell error.  Propagating..."
3253                  throw ''
3254                fi
3255                # Other exceptions are not handled but may be caught further
3256                # up the call stack.
3257              }
3258
3259       If all exceptions should  be  caught,  the  following  idiom  might  be
3260       preferable.
3261
3262              {
3263                # ... nested code here throws an exception
3264              } always {
3265                if catch *; then
3266                  case $CAUGHT in
3267                    (MyExcept)
3268                    print "Caught my own exception"
3269                    ;;
3270                    (*)
3271                    print "Caught some other exception"
3272                    ;;
3273                  esac
3274                fi
3275              }
3276
3277       In common with exception handling in other languages, the exception may
3278       be thrown by code deeply nested inside the `try' block.  However,  note
3279       that  it  must  be  thrown  inside the current shell, not in a subshell
3280       forked for a pipeline, parenthesised current-shell construct,  or  some
3281       form of command or process substitution.
3282
3283       The  system  internally uses the shell variable EXCEPTION to record the
3284       name of the exception between throwing and catching.  One  drawback  of
3285       this scheme is that if the exception is not handled the variable EXCEP‐
3286       TION remains set and may be incorrectly recognised as the  name  of  an
3287       exception if a shell error subsequently occurs.  Adding unset EXCEPTION
3288       at the start of the outermost layer of any  code  that  uses  exception
3289       handling will eliminate this problem.
3290

MIME FUNCTIONS

3292       Three  functions  are available to provide handling of files recognised
3293       by extension, for example to dispatch a file text.ps when executed as a
3294       command to an appropriate viewer.
3295
3296       zsh-mime-setup [ -fv ] [ -l [ suffix ... ] ]
3297       zsh-mime-handler [ -l ] command argument ...
3298              These   two   functions   use   the   files   ~/.mime.types  and
3299              /etc/mime.types, which associate types and extensions,  as  well
3300              as  ~/.mailcap and /etc/mailcap files, which associate types and
3301              the programs that handle them.  These are provided on many  sys‐
3302              tems with the Multimedia Internet Mail Extensions.
3303
3304              To  enable  the  system,  the  function zsh-mime-setup should be
3305              autoloaded and run.  This allows files  with  extensions  to  be
3306              treated  as  executable; such files be completed by the function
3307              completion system.  The  function  zsh-mime-handler  should  not
3308              need to be called by the user.
3309
3310              The  system  works by setting up suffix aliases with `alias -s'.
3311              Suffix aliases already installed by the user will not  be  over‐
3312              written.
3313
3314              For  suffixes  defined  in  lower case, upper case variants will
3315              also automatically be handled (e.g. PDF is automatically handled
3316              if handling for the suffix pdf is defined), but not vice versa.
3317
3318              Repeated  calls  to  zsh-mime-setup do not override the existing
3319              mapping between suffixes and executable files unless the  option
3320              -f  is given.  Note, however, that this does not override exist‐
3321              ing suffix aliases assigned to handlers other than zsh-mime-han‐
3322              dler.
3323
3324              Calling  zsh-mime-setup  with  the  option -l lists the existing
3325              mappings without altering them.  Suffixes  to  list  (which  may
3326              contain  pattern characters that should be quoted from immediate
3327              interpretation on the command line) may be given  as  additional
3328              arguments, otherwise all suffixes are listed.
3329
3330              Calling  zsh-mime-setup with the option -v causes verbose output
3331              to be shown during the setup operation.
3332
3333              The system respects the mailcap flags  needsterminal  and  copi‐
3334              ousoutput, see mailcap(4).
3335
3336              The  functions  use the following styles, which are defined with
3337              the zstyle builtin command (see zshmodules(1)).  They should  be
3338              defined  before  zsh-mime-setup  is  run.  The contexts used all
3339              start with :mime:, with additional components in some cases.  It
3340              is  recommended  that a trailing * (suitably quoted) be appended
3341              to style patterns in case the  system  is  extended  in  future.
3342              Some examples are given below.
3343
3344              For  files  that have multiple suffixes, e.g. .pdf.gz, where the
3345              context includes the suffix it will be looked up  starting  with
3346              the  longest  possible  suffix  until  a  match for the style is
3347              found.  For example, if .pdf.gz produces a match  for  the  han‐
3348              dler,  that  will be used; otherwise the handler for .gz will be
3349              used.  Note that, owing to the way suffix aliases  work,  it  is
3350              always  required that there be a handler for the shortest possi‐
3351              ble suffix, so in this example .pdf.gz can only  be  handled  if
3352              .gz  is  also  handled (though not necessarily in the same way).
3353              Alternatively, if no handling for .gz on its own is needed, sim‐
3354              ply adding the command
3355
3356                     alias -s gz=zsh-mime-handler
3357
3358              to  the  initialisation code is sufficient; .gz will not be han‐
3359              dled on its own, but may be in combination with other suffixes.
3360
3361              current-shell
3362                     If this boolean style is true, the  mailcap  handler  for
3363                     the  context  in  question  is run using the eval builtin
3364                     instead of by starting a new sh process.   This  is  more
3365                     efficient, but may not work in the occasional cases where
3366                     the mailcap handler uses strict POSIX syntax.
3367
3368              disown If this boolean style is true, mailcap  handlers  started
3369                     in  the  background will be disowned, i.e. not subject to
3370                     job control  within  the  parent  shell.   Such  handlers
3371                     nearly  always  produce  their  own  windows, so the only
3372                     likely harmful side effect of setting the style  is  that
3373                     it becomes harder to kill jobs from within the shell.
3374
3375              execute-as-is
3376                     This style gives a list of patterns to be matched against
3377                     files passed for execution with a  handler  program.   If
3378                     the  file matches the pattern, the entire command line is
3379                     executed in its current form, with no handler.   This  is
3380                     useful  for  files which might have suffixes but nonethe‐
3381                     less be executable in their own right.  If the  style  is
3382                     not  set, the pattern *(*) *(/) is used; hence executable
3383                     files are executed directly and not passed to a  handler,
3384                     and  the option AUTO_CD may be used to change to directo‐
3385                     ries that happen to have MIME suffixes.
3386
3387              execute-never
3388                     This style is useful in combination  with  execute-as-is.
3389                     It  is  set to an array of patterns corresponding to full
3390                     paths to files that  should  never  be  treated  as  exe‐
3391                     cutable,  even  if  the  file  passed to the MIME handler
3392                     matches execute-as-is.  This is useful for  file  systems
3393                     that don't handle execute permission or that contain exe‐
3394                     cutables from another operating system.  For example,  if
3395                     /mnt/windows is a Windows mount, then
3396
3397                            zstyle ':mime:*' execute-never '/mnt/windows/*'
3398
3399                     will  ensure  that  any  files found in that area will be
3400                     executed as MIME types even if they are  executable.   As
3401                     this  example  shows,  the  complete file name is matched
3402                     against the pattern,  regardless  of  how  the  file  was
3403                     passed  to  the  handler.  The file is resolved to a full
3404                     path using the :P modifier described  in  the  subsection
3405                     Modifiers  in  zshexpn(1); this means that symbolic links
3406                     are resolved where possible, so  that  links  into  other
3407                     file systems behave in the correct fashion.
3408
3409              file-path
3410                     Used  if the style find-file-in-path is true for the same
3411                     context.  Set to an array of directories  that  are  used
3412                     for  searching for the file to be handled; the default is
3413                     the command path given by  the  special  parameter  path.
3414                     The  shell option PATH_DIRS is respected; if that is set,
3415                     the appropriate path will be searched even if the name of
3416                     the  file to be handled as it appears on the command line
3417                     contains a `/'.  The full context is  :mime:.suffix:,  as
3418                     described for the style handler.
3419
3420              find-file-in-path
3421                     If  set, allows files whose names do not contain absolute
3422                     paths to be searched for in the command path or the  path
3423                     specified  by  the  file-path  style.  If the file is not
3424                     found in the path, it is looked for locally  (whether  or
3425                     not  the  current directory is in the path); if it is not
3426                     found locally, the handler will  abort  unless  the  han‐
3427                     dle-nonexistent  style  is  set.  Files found in the path
3428                     are tested as described for the style execute-as-is.  The
3429                     full  context  is  :mime:.suffix:,  as  described for the
3430                     style handler.
3431
3432              flags  Defines flags to go with a handler; the context is as for
3433                     the  handler style, and the format is as for the flags in
3434                     mailcap.
3435
3436              handle-nonexistent
3437                     By default, arguments that don't correspond to files  are
3438                     not  passed  to  the  MIME handler in order to prevent it
3439                     from intercepting commands found in the path that  happen
3440                     to  have  suffixes.  This style may be set to an array of
3441                     extended glob patterns for arguments that will be  passed
3442                     to  the  handler  even if they don't exist.  If it is not
3443                     explicitly  set  it  defaults  to  [[:alpha:]]#:/*  which
3444                     allows  URLs to be passed to the MIME handler even though
3445                     they don't exist in that format in the file system.   The
3446                     full  context  is  :mime:.suffix:,  as  described for the
3447                     style handler.
3448
3449              handler
3450                     Specifies a handler for a suffix; the suffix is given  by
3451                     the context as :mime:.suffix:, and the format of the han‐
3452                     dler is exactly that in mailcap.  Note in particular  the
3453                     `.'  and  trailing  colon  to distinguish this use of the
3454                     context.  This overrides any  handler  specified  by  the
3455                     mailcap  files.   If the handler requires a terminal, the
3456                     flags style should be set to include the word needstermi‐
3457                     nal,  or if the output is to be displayed through a pager
3458                     (but not if the handler is itself  a  pager),  it  should
3459                     include copiousoutput.
3460
3461              mailcap
3462                     A   list  of  files  in  the  format  of  ~/.mailcap  and
3463                     /etc/mailcap to  be  read  during  setup,  replacing  the
3464                     default list which consists of those two files.  The con‐
3465                     text is :mime:.  A + in the list will be replaced by  the
3466                     default files.
3467
3468              mailcap-priorities
3469                     This  style  is  used to resolve multiple mailcap entries
3470                     for the same MIME type.  It consists of an array  of  the
3471                     following  elements,  in  descending  order  of priority;
3472                     later entries will be used if earlier entries are  unable
3473                     to  resolve  the  entries being compared.  If none of the
3474                     tests resolve the entries, the first entry encountered is
3475                     retained.
3476
3477                     files  The  order of files (entries in the mailcap style)
3478                            read.  Earlier files are  preferred.   (Note  this
3479                            does not resolve entries in the same file.)
3480
3481                     priority
3482                            The  priority  flag  from  the mailcap entry.  The
3483                            priority is an  integer  from  0  to  9  with  the
3484                            default value being 5.
3485
3486                     flags  The test given by the mailcap-prio-flags option is
3487                            used to resolve entries.
3488
3489                     place  Later entries are preferred; as  the  entries  are
3490                            strictly ordered, this test always succeeds.
3491
3492                     Note that as this style is handled during initialisation,
3493                     the context is always :mime:, with no  discrimination  by
3494                     suffix.
3495
3496              mailcap-prio-flags
3497                     This  style is used when the keyword flags is encountered
3498                     in the list of tests specified by the  mailcap-priorities
3499                     style.   It  should be set to a list of patterns, each of
3500                     which is tested against the flags specified in the  mail‐
3501                     cap  entry (in other words, the sets of assignments found
3502                     with some entries in the mailcap file).  Earlier patterns
3503                     in the list are preferred to later ones, and matched pat‐
3504                     terns are preferred to unmatched ones.
3505
3506              mime-types
3507                     A list of  files  in  the  format  of  ~/.mime.types  and
3508                     /etc/mime.types  to  be  read during setup, replacing the
3509                     default list which consists of those two files.  The con‐
3510                     text  is :mime:.  A + in the list will be replaced by the
3511                     default files.
3512
3513              never-background
3514                     If this boolean style is set, the handler for  the  given
3515                     context  is  always  run  in  the foreground, even if the
3516                     flags provided in the mailcap entry suggest it  need  not
3517                     be (for example, it doesn't require a terminal).
3518
3519              pager  If  set, will be used instead of $PAGER or more to handle
3520                     suffixes where the copiousoutput flag is set.   The  con‐
3521                     text  is as for handler, i.e. :mime:.suffix: for handling
3522                     a file with the given suffix.
3523
3524              Examples:
3525
3526                     zstyle ':mime:*' mailcap ~/.mailcap /usr/local/etc/mailcap
3527                     zstyle ':mime:.txt:' handler less %s
3528                     zstyle ':mime:.txt:' flags needsterminal
3529
3530              When zsh-mime-setup is subsequently run, it will look for  mail‐
3531              cap  entries  in the two files given.  Files of suffix .txt will
3532              be handled by running `less file.txt'.  The  flag  needsterminal
3533              is  set  to show that this program must run attached to a termi‐
3534              nal.
3535
3536              As there are several steps to dispatching a command, the follow‐
3537              ing  should be checked if attempting to execute a file by exten‐
3538              sion .ext does not have the expected effect.
3539
3540              The command `alias -s ext'  should  show  `ps=zsh-mime-handler'.
3541              If  it  shows  something  else, another suffix alias was already
3542              installed and was not overwritten.  If it shows nothing, no han‐
3543              dler  was installed:  this is most likely because no handler was
3544              found in the .mime.types and mailcap combination for .ext files.
3545              In   that   case,   appropriate  handling  should  be  added  to
3546              ~/.mime.types and mailcap.
3547
3548              If the extension is handled by zsh-mime-handler but the file  is
3549              not opened correctly, either the handler defined for the type is
3550              incorrect, or the flags associated with it are  in  appropriate.
3551              Running  zsh-mime-setup  -l  will show the handler and, if there
3552              are any, the flags.  A %s in the handler is replaced by the file
3553              (suitably  quoted if necessary).  Check that the handler program
3554              listed lists and can be run in the way shown.  Also  check  that
3555              the  flags needsterminal or copiousoutput are set if the handler
3556              needs to be run under a terminal; the second flag is used if the
3557              output  should  be  sent  to  a pager.  An example of a suitable
3558              mailcap entry for such a program is:
3559
3560                     text/html; /usr/bin/lynx '%s'; needsterminal
3561
3562              Running `zsh-mime-handler -l command line'  prints  the  command
3563              line  that would be executed, simplified to remove the effect of
3564              any flags, and quoted so that the output can be run  as  a  com‐
3565              plete  zsh  command line.  This is used by the completion system
3566              to decide how to complete after a file handled by  zsh-mime-set‐
3567              up.
3568
3569       pick-web-browser
3570              This  function is separate from the two MIME functions described
3571              above and can be assigned directly to a suffix:
3572
3573                     autoload -U pick-web-browser
3574                     alias -s html=pick-web-browser
3575
3576              It is provided as an intelligent front end  to  dispatch  a  web
3577              browser.   It may be run as either a function or a shell script.
3578              The status 255 is returned if no browser could be started.
3579
3580              Various  styles  are  available  to  customize  the  choice   of
3581              browsers:
3582
3583              browser-style
3584                     The  value of the style is an array giving preferences in
3585                     decreasing order for the type of  browser  to  use.   The
3586                     values of elements may be
3587
3588                     running
3589                            Use  a GUI browser that is already running when an
3590                            X  Window  display  is  available.   The  browsers
3591                            listed  in the x-browsers style are tried in order
3592                            until one is found; if it is,  the  file  will  be
3593                            displayed in that browser, so the user may need to
3594                            check whether it  has  appeared.   If  no  running
3595                            browser  is  found,  one is not started.  Browsers
3596                            other  than  Firefox,  Opera  and  Konqueror   are
3597                            assumed to understand the Mozilla syntax for open‐
3598                            ing a URL remotely.
3599
3600                     x      Start a new GUI browser when an X  Window  display
3601                            is  available.  Search for the availability of one
3602                            of the browsers listed in the x-browsers style and
3603                            start  the  first  one that is found.  No check is
3604                            made for an already running browser.
3605
3606                     tty    Start a terminal-based browser.   Search  for  the
3607                            availability  of one of the browsers listed in the
3608                            tty-browsers style and start the first one that is
3609                            found.
3610
3611                     If  the  style  is  not  set the default running x tty is
3612                     used.
3613
3614              x-browsers
3615                     An array in decreasing order of preference of browsers to
3616                     use  when  running  under the X Window System.  The array
3617                     consists of the command name under  which  to  start  the
3618                     browser.  They are looked up in the context :mime: (which
3619                     may be extended in future, so  appending  `*'  is  recom‐
3620                     mended).  For example,
3621
3622                            zstyle ':mime:*' x-browsers opera konqueror firefox
3623
3624                     specifies  that  pick-web-browser should first look for a
3625                     running instance of Opera, Konqueror or Firefox, in  that
3626                     order,  and  if  it  fails  to find any should attempt to
3627                     start Opera.  The default  is  firefox  mozilla  netscape
3628                     opera konqueror.
3629
3630              tty-browsers
3631                     An  array  similar  to  x-browsers,  except that it gives
3632                     browsers to use when no X Window  display  is  available.
3633                     The default is elinks links lynx.
3634
3635              command
3636                     If  it is set this style is used to pick the command used
3637                     to  open  a  page  for  a  browser.    The   context   is
3638                     :mime:browser:new:$browser:  to  start  a  new browser or
3639                     :mime:browser:running:$browser:  to  open  a  URL  in   a
3640                     browser  already  running on the current X display, where
3641                     $browser is  the  value  matched  in  the  x-browsers  or
3642                     tty-browsers  style.   The  escape  sequence  %b  in  the
3643                     style's value will be replaced by the browser,  while  %u
3644                     will  be  replaced  by the URL.  If the style is not set,
3645                     the default for all new instances is equivalent to %b  %u
3646                     and  the  defaults for using running browsers are equiva‐
3647                     lent to the values kfmclient openURL  %u  for  Konqueror,
3648                     firefox  -new-tab  %u  for Firefox, opera -newpage %u for
3649                     Opera, and %b -remote "openUrl(%u)" for all others.
3650

MATHEMATICAL FUNCTIONS

3652       zcalc [ -erf ] [ expression ... ]
3653              A reasonably powerful calculator based on zsh's arithmetic eval‐
3654              uation  facility.   The syntax is similar to that of formulae in
3655              most programming languages; see the section `Arithmetic  Evalua‐
3656              tion' in zshmisc(1) for details.
3657
3658              Non-programmers  should  note that, as in many other programming
3659              languages, expressions involving  only  integers  (whether  con‐
3660              stants  without  a  `.',  variables containing such constants as
3661              strings, or variables declared to be integers)  are  by  default
3662              evaluated using integer arithmetic, which is not how an ordinary
3663              desk calculator operates.  To force  floating  point  operation,
3664              pass the option -f; see further notes below.
3665
3666              If  the  file  ~/.zcalcrc  exists  it will be sourced inside the
3667              function once it is set up and  about  to  process  the  command
3668              line.  This can be used, for example, to set shell options; emu‐
3669              late -L zsh and setopt extendedglob are in effect at this point.
3670              Any failure to source the file if it exists is treated as fatal.
3671              As with other initialisation files, the  directory  $ZDOTDIR  is
3672              used instead of $HOME if it is set.
3673
3674              The  mathematical  library  zsh/mathfunc will be loaded if it is
3675              available; see the section `The zsh/mathfunc Module' in  zshmod‐
3676              ules(1).   The mathematical functions correspond to the raw sys‐
3677              tem libraries, so trigonometric functions  are  evaluated  using
3678              radians, and so on.
3679
3680              Each line typed is evaluated as an expression.  The prompt shows
3681              a number, which corresponds to a positional parameter where  the
3682              result  of  that calculation is stored.  For example, the result
3683              of the calculation on the line preceded by `4> ' is available as
3684              $4.   The  last value calculated is available as ans.  Full com‐
3685              mand line editing, including the history  of  previous  calcula‐
3686              tions,   is   available;  the  history  is  saved  in  the  file
3687              ~/.zcalc_history.  To exit, enter a blank line or type  `:q'  on
3688              its own (`q' is allowed for historical compatibility).
3689
3690              A  line  ending  with  a single backslash is treated in the same
3691              fashion as it is in command  line  editing:   the  backslash  is
3692              removed, the function prompts for more input (the prompt is pre‐
3693              ceded by `...' to indicate this), and  the  lines  are  combined
3694              into  one to get the final result.  In addition, if the input so
3695              far contains more open than close parentheses zcalc will  prompt
3696              for more input.
3697
3698              If  arguments  are  given to zcalc on start up, they are used to
3699              prime the first few positional parameters.  A visual  indication
3700              of this is given when the calculator starts.
3701
3702              The  constants  PI (3.14159...) and E (2.71828...) are provided.
3703              Parameter assignment is possible, but note that  all  parameters
3704              will  be put into the global namespace unless the :local special
3705              command is used.  The function  creates  local  variables  whose
3706              names  start  with _, so users should avoid doing so.  The vari‐
3707              ables ans (the last answer) and stack (the stack  in  RPN  mode)
3708              may  be  referred to directly; stack is an array but elements of
3709              it are  numeric.   Various  other  special  variables  are  used
3710              locally  with  their  standard meaning, for example compcontext,
3711              match, mbegin, mend, psvar.
3712
3713              The output  base  can  be  initialised  by  passing  the  option
3714              `-#base',  for  example  `zcalc  -#16'  (the  `#' may have to be
3715              quoted, depending on the globbing options set).
3716
3717              If the option `-e' is set, the function runs  non-interactively:
3718              the  arguments  are treated as expressions to be evaluated as if
3719              entered interactively line by line.
3720
3721              If the option `-f' is set, all numbers are treated  as  floating
3722              point,  hence for example the expression `3/4' evaluates to 0.75
3723              rather than 0.  Options must appear in separate words.
3724
3725              If the option `-r' is set, RPN (Reverse Polish Notation) mode is
3726              entered.  This has various additional properties:
3727              Stack  Evaluated  values are maintained in a stack; this is con‐
3728                     tained in an array named stack with the most recent value
3729                     in ${stack[1]}.
3730
3731              Operators and functions
3732                     If  the line entered matches an operator (+, -, *, /, **,
3733                     ^, | or &) or a function  supplied  by  the  zsh/mathfunc
3734                     library,  the bottom element or elements of the stack are
3735                     popped to use as the argument or arguments.   The  higher
3736                     elements  of  stack  (least  recent)  are used as earlier
3737                     arguments.  The result is then pushed into ${stack[1]}.
3738
3739              Expressions
3740                     Other expressions are evaluated  normally,  printed,  and
3741                     added  to the stack as numeric values.  The syntax within
3742                     expressions on a single line is normal  shell  arithmetic
3743                     (not RPN).
3744
3745              Stack listing
3746                     If  an  integer follows the option -r with no space, then
3747                     on every evaluation that  many  elements  of  the  stack,
3748                     where  available,  are  printed  instead of just the most
3749                     recent result.   Hence,  for  example,  zcalc  -r4  shows
3750                     $stack[4] to $stack[1] each time results are printed.
3751
3752              Duplication: =
3753                     The  pseudo-operator  = causes the most recent element of
3754                     the stack to be duplicated onto the stack.
3755
3756              pop    The pseudo-function pop causes the most recent element of
3757                     the  stack  to  be popped.  A `>' on its own has the same
3758                     effect.
3759
3760              >ident The expression > followed (with  no  space)  by  a  shell
3761                     identifier causes the most recent element of the stack to
3762                     be popped and assigned to the variable  with  that  name.
3763                     The variable is local to the zcalc function.
3764
3765              <ident The  expression  <  followed  (with  no space) by a shell
3766                     identifier causes the value of  the  variable  with  that
3767                     name  to be pushed onto the stack.  ident may be an inte‐
3768                     ger, in which case the previous result with  that  number
3769                     (as  shown  before the > in the standard zcalc prompt) is
3770                     put on the stack.
3771
3772              Exchange: xy
3773                     The pseudo-function xy causes the most  recent  two  ele‐
3774                     ments  of  the  stack to be exchanged.  `<>' has the same
3775                     effect.
3776
3777              The prompt is configurable via the parameter ZCALCPROMPT,  which
3778              undergoes  standard  prompt expansion.  The index of the current
3779              entry is stored locally in the first element of the array psvar,
3780              which  can  be referred to in ZCALCPROMPT as `%1v'.  The default
3781              prompt is `%1v> '.
3782
3783              The variable ZCALC_ACTIVE is set within the function and can  be
3784              tested  by nested functions; it has the value rpn if RPN mode is
3785              active, else 1.
3786
3787              A few special commands are available; these are introduced by  a
3788              colon.  For backward compatibility, the colon may be omitted for
3789              certain commands.  Completion is available if compinit has  been
3790              run.
3791
3792              The  output  precision  may be specified within zcalc by special
3793              commands familiar from many calculators.
3794              :norm  The default output format.  It corresponds to the  printf
3795                     %g  specification.  Typically this shows six decimal dig‐
3796                     its.
3797
3798              :sci digits
3799                     Scientific notation, corresponding to the printf %g  out‐
3800                     put format with the precision given by digits.  This pro‐
3801                     duces either fixed point or exponential notation  depend‐
3802                     ing on the value output.
3803
3804              :fix digits
3805                     Fixed point notation, corresponding to the printf %f out‐
3806                     put format with the precision given by digits.
3807
3808              :eng digits
3809                     Exponential notation, corresponding to the printf %E out‐
3810                     put format with the precision given by digits.
3811
3812              :raw   Raw  output:  this is the default form of the output from
3813                     a math evaluation.  This may show more precision than the
3814                     number actually possesses.
3815
3816              Other special commands:
3817              :!line...
3818                     Execute  line...  as  a  normal shell command line.  Note
3819                     that it is executed in the context of the function,  i.e.
3820                     with local variables.  Space is optional after :!.
3821
3822              :local arg ...
3823                     Declare variables local to the function.  Other variables
3824                     may be used, too, but they will be taken from or put into
3825                     the global scope.
3826
3827              :function name [ body ]
3828                     Define  a  mathematical function or (with no body) delete
3829                     it.  :function may be abbreviated to :func or simply  :f.
3830                     The name may contain the same characters as a shell func‐
3831                     tion name.  The function is defined  using  zmathfuncdef,
3832                     see below.
3833
3834                     Note  that  zcalc  takes  care of all quoting.  Hence for
3835                     example:
3836
3837                            :f cube $1 * $1 * $1
3838
3839                     defines a function to cube the sole argument.   Functions
3840                     so  defined,  or indeed any functions defined directly or
3841                     indirectly using functions -M, are available  to  execute
3842                     by  typing  only  the  name on the line in RPN mode; this
3843                     pops the appropriate number of arguments off the stack to
3844                     pass  to  the function, i.e. 1 in the case of the example
3845                     cube function.  If there are optional arguments only  the
3846                     mandatory arguments are supplied by this means.
3847
3848              [#base]
3849                     This  is  not  a  special  command, rather part of normal
3850                     arithmetic syntax; however, when this form appears  on  a
3851                     line  by  itself the default output radix is set to base.
3852                     Use, for example, `[#16]' to display  hexadecimal  output
3853                     preceded  by  an indication of the base, or `[##16]' just
3854                     to display the raw number in the given base.  Bases them‐
3855                     selves  are  always  specified in decimal. `[#]' restores
3856                     the normal output format.  Note that  setting  an  output
3857                     base  suppresses  floating  point  output;  use  `[#]' to
3858                     return to normal operation.
3859
3860              $var   Print out the value of var literally; does not affect the
3861                     calculation.   To  use the value of var, omit the leading
3862                     `$'.
3863
3864              See the comments in the function for a few extra tips.
3865
3866       min(arg, ...)
3867       max(arg, ...)
3868       sum(arg, ...)
3869       zmathfunc
3870              The function zmathfunc defines the three mathematical  functions
3871              min,  max,  and sum.  The functions min and max take one or more
3872              arguments.  The function  sum  takes  zero  or  more  arguments.
3873              Arguments can be of different types (ints and floats).
3874
3875              Not  to  be  confused with the zsh/mathfunc module, described in
3876              the section `The zsh/mathfunc Module' in zshmodules(1).
3877
3878       zmathfuncdef [ mathfunc [ body ] ]
3879              A convenient front end to functions -M.
3880
3881              With two arguments, define a mathematical function  named  math‐
3882              func  which  can  be  used in any form of arithmetic evaluation.
3883              body is a mathematical expression to implement the function.  It
3884              may  contain  references  to position parameters $1, $2, ...  to
3885              refer to mandatory parameters and ${1:-defvalue} ...   to  refer
3886              to  optional  parameters.   Note that the forms must be strictly
3887              adhered to for the function to calculate the correct  number  of
3888              arguments.  The implementation is held in a shell function named
3889              zsh_math_func_mathfunc; usually the user will not need to  refer
3890              to  the  shell  function directly.  Any existing function of the
3891              same name is silently replaced.
3892
3893              With one argument, remove the mathematical function mathfunc  as
3894              well as the shell function implementation.
3895
3896              With  no  arguments, list all mathfunc functions in a form suit‐
3897              able for restoring the definition.  The functions have not  nec‐
3898              essarily been defined by zmathfuncdef.
3899

USER CONFIGURATION FUNCTIONS

3901       The  zsh/newuser  module  comes  with  a function to aid in configuring
3902       shell options for new users.  If the module is installed, this function
3903       can  also be run by hand.  It is available even if the module's default
3904       behaviour, namely running the function for a new user logging in  with‐
3905       out startup files, is inhibited.
3906
3907       zsh-newuser-install [ -f ]
3908              The  function  presents  the  user with various options for cus‐
3909              tomizing their initialization scripts.  Currently only  ~/.zshrc
3910              is  handled.   $ZDOTDIR/.zshrc  is used instead if the parameter
3911              ZDOTDIR is set; this provides a way for the user to configure  a
3912              file without altering an existing .zshrc.
3913
3914              By default the function exits immediately if it finds any of the
3915              files .zshenv, .zprofile, .zshrc, or .zlogin in the  appropriate
3916              directory.   The  option  -f  is  required in order to force the
3917              function to continue.  Note  this  may  happen  even  if  .zshrc
3918              itself does not exist.
3919
3920              As  currently  configured, the function will exit immediately if
3921              the user has root privileges; this behaviour cannot be  overrid‐
3922              den.
3923
3924              Once  activated,  the  function's  behaviour  is  supposed to be
3925              self-explanatory.  Menus are present allowing the user to  alter
3926              the  value  of options and parameters.  Suggestions for improve‐
3927              ments are always welcome.
3928
3929              When the script exits, the user is given the opportunity to save
3930              the  new  file  or  not; changes are not irreversible until this
3931              point.  However, the script is careful to  restrict  changes  to
3932              the file only to a group marked by the lines `# Lines configured
3933              by zsh-newuser-install'  and  `#  End  of  lines  configured  by
3934              zsh-newuser-install'.  In addition, the old version of .zshrc is
3935              saved to a file with the suffix .zni appended.
3936
3937              If the function edits an existing .zshrc, it is up to  the  user
3938              to  ensure that the changes made will take effect.  For example,
3939              if control usually returns early from the  existing  .zshrc  the
3940              lines  will  not be executed; or a later initialization file may
3941              override options or parameters, and so on.  The function  itself
3942              does not attempt to detect any such conflicts.
3943

OTHER FUNCTIONS

3945       There  are  a  large  number of helpful functions in the Functions/Misc
3946       directory of the zsh distribution.  Most are very  simple  and  do  not
3947       require documentation here, but a few are worthy of special mention.
3948
3949   Descriptions
3950       colors This  function  initializes  several  associative  arrays to map
3951              color names to (and from) the ANSI standard eight-color terminal
3952              codes.   These  are used by the prompt theme system (see above).
3953              You seldom should need to run colors more than once.
3954
3955              The eight base colors are:  black,  red,  green,  yellow,  blue,
3956              magenta,  cyan,  and  white.   Each of these has codes for fore‐
3957              ground and background.  In addition there  are  seven  intensity
3958              attributes:  bold,  faint,  standout, underline, blink, reverse,
3959              and conceal.  Finally, there are  seven  codes  used  to  negate
3960              attributes:  none (reset all attributes to the defaults), normal
3961              (neither bold nor faint), no-standout,  no-underline,  no-blink,
3962              no-reverse, and no-conceal.
3963
3964              Some  terminals  do  not  support all combinations of colors and
3965              intensities.
3966
3967              The associative arrays are:
3968
3969              color
3970              colour Map all the color names to their integer codes, and inte‐
3971                     ger  codes  to the color names.  The eight base names map
3972                     to the foreground color codes, as do names prefixed  with
3973                     `fg-', such as `fg-red'.  Names prefixed with `bg-', such
3974                     as `bg-blue', refer to the background codes.  The reverse
3975                     mapping  from  code  to  color yields base name for fore‐
3976                     ground codes and the bg- form for backgrounds.
3977
3978                     Although it is a misnomer to call  them  `colors',  these
3979                     arrays  also map the other fourteen attributes from names
3980                     to codes and codes to names.
3981
3982              fg
3983              fg_bold
3984              fg_no_bold
3985                     Map the eight basic color names to ANSI  terminal  escape
3986                     sequences  that  set  the  corresponding  foreground text
3987                     properties.  The fg sequences change  the  color  without
3988                     changing the eight intensity attributes.
3989
3990              bg
3991              bg_bold
3992              bg_no_bold
3993                     Map  the  eight basic color names to ANSI terminal escape
3994                     sequences that set the corresponding  background  proper‐
3995                     ties.  The bg sequences change the color without changing
3996                     the eight intensity attributes.
3997
3998              In addition, the scalar parameters  reset_color  and  bold_color
3999              are  set  to  the  ANSI  terminal  escapes  that  turn  off  all
4000              attributes and turn on bold intensity, respectively.
4001
4002       fned [ -x num ] name
4003              Same as zed -f.  This function does not appear in the  zsh  dis‐
4004              tribution, but can be created by linking zed to the name fned in
4005              some directory in your fpath.
4006
4007       is-at-least needed [ present ]
4008              Perform a greater-than-or-equal-to  comparison  of  two  strings
4009              having  the format of a zsh version number; that is, a string of
4010              numbers and text with segments separated by dots or dashes.   If
4011              the  present string is not provided, $ZSH_VERSION is used.  Seg‐
4012              ments are paired left-to-right in the two strings  with  leading
4013              non-number parts ignored.  If one string has fewer segments than
4014              the other, the missing segments are considered zero.
4015
4016              This is useful in startup files to set options and  other  state
4017              that are not available in all versions of zsh.
4018
4019                     is-at-least 3.1.6-15 && setopt NO_GLOBAL_RCS
4020                     is-at-least 3.1.0 && setopt HIST_REDUCE_BLANKS
4021                     is-at-least 2.6-17 || print "You can't use is-at-least here."
4022
4023       nslookup [ arg ... ]
4024              This  wrapper  function  for  the  nslookup command requires the
4025              zsh/zpty module (see zshmodules(1)).  It  behaves  exactly  like
4026              the  standard  nslookup  except  that  it  provides customizable
4027              prompts  (including  a  right-side  prompt)  and  completion  of
4028              nslookup  commands,  host  names,  etc.  (if  you  use the func‐
4029              tion-based completion system).  Completion  styles  may  be  set
4030              with the context prefix `:completion:nslookup'.
4031
4032              See also the pager, prompt and rprompt styles below.
4033
4034       regexp-replace var regexp replace
4035              Use  regular  expressions to perform a global search and replace
4036              operation on a variable.  POSIX extended regular expressions are
4037              used,  unless  the  option  RE_MATCH_PCRE has been set, in which
4038              case Perl-compatible regular expressions are used (this requires
4039              the shell to be linked against the pcre library).
4040
4041              var  is  the  name  of  the variable containing the string to be
4042              matched.  The variable will be modified directly  by  the  func‐
4043              tion.   The  variables  MATCH, MBEGIN, MEND, match, mbegin, mend
4044              should be avoided as these are used by  the  regular  expression
4045              code.
4046
4047              regexp is the regular expression to match against the string.
4048
4049              replace  is  the  replacement text.  This can contain parameter,
4050              command and arithmetic expressions which will be  replaced:   in
4051              particular,  a  reference to $MATCH will be replaced by the text
4052              matched by the pattern.
4053
4054              The return status is 0 if at least one match was performed, else
4055              1.
4056
4057       run-help cmd
4058              This function is designed to be invoked by the run-help ZLE wid‐
4059              get, in place of the  default  alias.   See  `Accessing  On-Line
4060              Help' above for setup instructions.
4061
4062              In  the  discussion which follows, if cmd is a file system path,
4063              it is first reduced to its rightmost component (the file name).
4064
4065              Help is first sought by looking for a  file  named  cmd  in  the
4066              directory  named by the HELPDIR parameter.  If no file is found,
4067              an assistant function, alias, or command named  run-help-cmd  is
4068              sought.   If  found,  the assistant is executed with the rest of
4069              the current command line (everything after the command name cmd)
4070              as its arguments.  When neither file nor assistant is found, the
4071              external command `man cmd' is run.
4072
4073              An example assistant for the "ssh" command:
4074
4075                     run-help-ssh() {
4076                         emulate -LR zsh
4077                         local -a args
4078                         # Delete the "-l username" option
4079                         zparseopts -D -E -a args l:
4080                         # Delete other options, leaving: host command
4081                         args=(${@:#-*})
4082                         if [[ ${#args} -lt 2 ]]; then
4083                             man ssh
4084                         else
4085                             run-help $args[2]
4086                         fi
4087                     }
4088
4089              Several of these assistants are provided in  the  Functions/Misc
4090              directory.   These  must  be autoloaded, or placed as executable
4091              scripts in your search path, in order to be found  and  used  by
4092              run-help.
4093
4094              run-help-git
4095              run-help-ip
4096              run-help-openssl
4097              run-help-p4
4098              run-help-sudo
4099              run-help-svk
4100              run-help-svn
4101                     Assistant  functions  for the git, ip, openssl, p4, sudo,
4102                     svk, and svn, commands.
4103
4104       tetris Zsh was once accused of not being as complete as Emacs,  because
4105              it  lacked  a  Tetris game.  This function was written to refute
4106              this vicious slander.
4107
4108              This function must be used as a ZLE widget:
4109
4110                     autoload -U tetris
4111                     zle -N tetris
4112                     bindkey keys tetris
4113
4114              To start a game, execute the widget by typing the  keys.   What‐
4115              ever  command  line you were editing disappears temporarily, and
4116              your keymap is also temporarily replaced by the  Tetris  control
4117              keys.   The  previous editor state is restored when you quit the
4118              game (by pressing `q') or when you lose.
4119
4120              If you quit in the middle of a game, the next invocation of  the
4121              tetris widget will continue where you left off.  If you lost, it
4122              will start a new game.
4123
4124       tetriscurses
4125              This is a port of the above to zcurses.  The input  handling  is
4126              improved a bit so that moving a block sideways doesn't automati‐
4127              cally advance a timestep, and the  graphics  use  unicode  block
4128              graphics.
4129
4130              This  version  does not save the game state between invocations,
4131              and is not invoked as a widget, but rather as:
4132
4133                     autoload -U tetriscurses
4134                     tetriscurses
4135
4136       zargs [ option ... -- ] [ input ... ] [ -- command [ arg ... ] ]
4137              This function has a similar purpose to GNU  xargs.   Instead  of
4138              reading  lines  of  arguments  from the standard input, it takes
4139              them from the command line.  This is useful because  zsh,  espe‐
4140              cially with recursive glob operators, often can construct a com‐
4141              mand line for a shell  function  that  is  longer  than  can  be
4142              accepted by an external command.
4143
4144              The  option list represents options of the zargs command itself,
4145              which are the same as those of xargs.  The  input  list  is  the
4146              collection  of  strings (often file names) that become the argu‐
4147              ments of the command, analogous to the standard input of  xargs.
4148              Finally,  the  arg  list  consists  of  those arguments (usually
4149              options) that are passed to the command each time it runs.   The
4150              arg  list precedes the elements from the input list in each run.
4151              If no command is provided, then no arg list may be provided, and
4152              in  that event the default command is `print' with arguments `-r
4153              --'.
4154
4155              For example, to get a long ls listing of  all  non-hidden  plain
4156              files in the current directory or its subdirectories:
4157
4158                     autoload -U zargs
4159                     zargs -- **/*(.) -- ls -ld --
4160
4161              The first and third occurrences of `--' are used to mark the end
4162              of options for zargs and ls respectively to guard against  file‐
4163              names  starting  with  `-', while the second is used to separate
4164              the list of files from the command to run (`ls -ld --').
4165
4166              The first `--' would also be needed if there was  a  chance  the
4167              list might be empty as in:
4168
4169                     zargs -r -- ./*.back(#qN) -- rm -f
4170
4171              In  the event that the string `--' is or may be an input, the -e
4172              option may be used to change  the  end-of-inputs  marker.   Note
4173              that  this does not change the end-of-options marker.  For exam‐
4174              ple, to use `..' as the marker:
4175
4176                     zargs -e.. -- **/*(.) .. ls -ld --
4177
4178              This is a good choice in that example because no plain file  can
4179              be  named  `..',  but the best end-marker depends on the circum‐
4180              stances.
4181
4182              The options -i, -I, -l, -L, and -n differ  slightly  from  their
4183              usage in xargs.  There are no input lines for zargs to count, so
4184              -l and -L count through the input list, and -n counts the number
4185              of  arguments passed to each execution of command, including any
4186              arg list.  Also, any time -i or -I is used, each input  is  pro‐
4187              cessed separately as if by `-L 1'.
4188
4189              For  details  of the other zargs options, see xargs(1) (but note
4190              the difference in function between zargs and xargs) or run zargs
4191              with the --help option.
4192
4193       zed [ -f [ -x num ] ] name
4194       zed -b This function uses the ZLE editor to edit a file or function.
4195
4196              Only  one  name argument is allowed.  If the -f option is given,
4197              the name is taken to be that of a function; if the  function  is
4198              marked  for  autoloading,  zed  searches for it in the fpath and
4199              loads it.  Note that functions edited  this  way  are  installed
4200              into  the  current  shell,  but not written back to the autoload
4201              file.  In this case the -x option specifies  that  leading  tabs
4202              indenting  the  function according to syntax should be converted
4203              into the given number of spaces; `-x 2' is consistent  with  the
4204              layout of functions distributed with the shell.
4205
4206              Without  -f,  name  is  the path name of the file to edit, which
4207              need not exist; it is created on write, if necessary.
4208
4209              While editing, the function sets the main keymap to zed and  the
4210              vi  command  keymap to zed-vicmd.  These will be copied from the
4211              existing main and vicmd keymaps if they do not exist  the  first
4212              time  zed is run.  They can be used to provide special key bind‐
4213              ings used only in zed.
4214
4215              If it creates the keymap, zed rebinds the return key to insert a
4216              line  break and `^X^W' to accept the edit in the zed keymap, and
4217              binds `ZZ' to accept the edit in the zed-vicmd keymap.
4218
4219              The bindings alone can be installed by running `zed  -b'.   This
4220              is  suitable  for  putting  into  a startup file.  Note that, if
4221              rerun, this  will  overwrite  the  existing  zed  and  zed-vicmd
4222              keymaps.
4223
4224              Completion  is available, and styles may be set with the context
4225              prefix `:completion:zed'.
4226
4227              A zle widget zed-set-file-name is available.  This can be called
4228              by  name  from  within  zed using `\ex zed-set-file-name' (note,
4229              however, that because of zed's rebindings you will have to  type
4230              ^j  at  the end instead of the return key), or can be bound to a
4231              key in either of the zed or zed-vicmd keymaps after `zed -b' has
4232              been  run.  When the widget is called, it prompts for a new name
4233              for the file being edited.  When zed  exits  the  file  will  be
4234              written  under  that  name  and  the  original file will be left
4235              alone.  The widget has no effect with `zed -f'.
4236
4237              While zed-set-file-name is running, zed uses the keymap zed-nor‐
4238              mal-keymap,  which  is  linked from the main keymap in effect at
4239              the time zed initialised its bindings.  (This  is  to  make  the
4240              return  key  operate  normally.)  The result is that if the main
4241              keymap has been changed, the widget won't notice.  This is not a
4242              concern for most users.
4243
4244       zcp [ -finqQvwW ] srcpat dest
4245       zln [ -finqQsvwW ] srcpat dest
4246              Same as zmv -C and zmv -L, respectively.  These functions do not
4247              appear in the zsh distribution, but can be  created  by  linking
4248              zmv to the names zcp and zln in some directory in your fpath.
4249
4250       zkbd   See `Keyboard Definition' above.
4251
4252
4253       zmv [ -finqQsvwW ] [ -C | -L | -M | -{p|P} program ] [ -o optstring ]
4254           srcpat dest
4255              Move (usually, rename) files matching the pattern srcpat to cor‐
4256              responding files having names of the form given by  dest,  where
4257              srcpat  contains  parentheses surrounding patterns which will be
4258              replaced in turn by $1, $2, ... in dest.  For example,
4259
4260                     zmv '(*).lis' '$1.txt'
4261
4262              renames   `foo.lis'   to   `foo.txt',   `my.old.stuff.lis'    to
4263              `my.old.stuff.txt', and so on.
4264
4265              The  pattern is always treated as an EXTENDED_GLOB pattern.  Any
4266              file whose name is not changed by  the  substitution  is  simply
4267              ignored.  Any error (a substitution resulted in an empty string,
4268              two substitutions gave the same result, the destination  was  an
4269              existing  regular  file  and -f was not given) causes the entire
4270              function to abort without doing anything.
4271
4272              In addition to pattern  replacement,  the  variable  $f  can  be
4273              referrred  to  in the second (replacement) argument.  This makes
4274              it possible to use variable substitution to alter the  argument;
4275              see examples below.
4276
4277              Options:
4278
4279              -f     Force  overwriting  of  destination files.  Not currently
4280                     passed down to the mv/cp/ln command due  to  vagaries  of
4281                     implementations (but you can use -o-f to do that).
4282              -i     Interactive:  show  each  line to be executed and ask the
4283                     user whether to execute it.  `Y' or `y' will execute  it,
4284                     anything  else  will skip it.  Note that you just need to
4285                     type one character.
4286              -n     No execution: print what would happen, but don't do it.
4287              -q     Turn bare glob qualifiers off: now assumed by default, so
4288                     this has no effect.
4289              -Q     Force bare glob qualifiers on.  Don't turn this on unless
4290                     you are actually using glob qualifiers in a pattern.
4291              -s     Symbolic, passed down to ln; only works with -L.
4292              -v     Verbose: print each command as it's being executed.
4293              -w     Pick out wildcard parts  of  the  pattern,  as  described
4294                     above,  and  implicitly  add parentheses for referring to
4295                     them.
4296              -W     Just like -w, with the addition of turning  wildcards  in
4297                     the replacement pattern into sequential ${1} .. ${N} ref‐
4298                     erences.
4299              -C
4300              -L
4301              -M     Force cp, ln or mv, respectively, regardless of the  name
4302                     of the function.
4303              -p program
4304                     Call  program instead of cp, ln or mv.  Whatever it does,
4305                     it should at least understand the form `program  --  old‐
4306                     name  newname'  where  oldname  and newname are filenames
4307                     generated by zmv.  program will be split into  words,  so
4308                     might  be e.g. the name of an archive tool plus a copy or
4309                     rename subcommand.
4310              -P program
4311                     As -p program, except that program does not accept a fol‐
4312                     lowing  --  to indicate the end of options.  In this case
4313                     filenames must already be in a sane form for the  program
4314                     in question.
4315              -o optstring
4316                     The  optstring is split into words and passed down verba‐
4317                     tim to the cp, ln or mv command  called  to  perform  the
4318                     work.  It should probably begin with a `-'.
4319
4320              Further examples:
4321
4322                     zmv -v '(* *)' '${1// /_}'
4323
4324              For any file in the current directory with at least one space in
4325              the name, replace every space by an underscore and  display  the
4326              commands executed.
4327
4328                     zmv -v '* *' '${f// /_}'
4329
4330              This  does exactly the same by referring to the file name stored
4331              in $f.
4332
4333              For more complete examples and other implementation details, see
4334              the  zmv  source file, usually located in one of the directories
4335              named in your fpath, or in Functions/Misc/zmv in the zsh distri‐
4336              bution.
4337
4338       zrecompile
4339              See `Recompiling Functions' above.
4340
4341       zstyle+ context style value [ + subcontext style value ... ]
4342              This  makes  defining styles a bit simpler by using a single `+'
4343              as a special token that allows you to append a context  name  to
4344              the previously used context name.  Like this:
4345
4346                     zstyle+ ':foo:bar' style1 value1 \
4347                            +':baz'     style2 value2 \
4348                            +':frob'    style3 value3
4349
4350              This  defines  style1  with  value1  for the context :foo:bar as
4351              usual, but it also defines style2 with value2  for  the  context
4352              :foo:bar:baz and style3 with value3 for :foo:bar:frob.  Any sub‐
4353              context may be the empty string  to  re-use  the  first  context
4354              unchanged.
4355
4356   Styles
4357       insert-tab
4358              The  zed function sets this style in context `:completion:zed:*'
4359              to turn off completion when TAB is typed at the beginning  of  a
4360              line.   You may override this by setting your own value for this
4361              context and style.
4362
4363       pager  The nslookup  function  looks  up  this  style  in  the  context
4364              `:nslookup' to determine the program used to display output that
4365              does not fit on a single screen.
4366
4367       prompt
4368       rprompt
4369              The nslookup  function  looks  up  this  style  in  the  context
4370              `:nslookup' to set the prompt and the right-side prompt, respec‐
4371              tively.  The usual expansions for the PS1  and  RPS1  parameters
4372              may be used (see EXPANSION OF PROMPT SEQUENCES in zshmisc(1)).
4373
4374
4375
4376zsh 5.8                        February 14, 2020                 ZSHCONTRIB(1)
Impressum