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  re‐
23       defining  the run-help alias, one can improve the on-line help provided
24       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.9/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 ex‐
100              ample:
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 di‐
116              gests 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.9/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  hy‐
168       phens.
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 an‐
197       other 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.9/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  de‐
214       faults.   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 re‐
219       porter, 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 au‐
258              tomatically 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 ex‐
272              ecuted in the given context.  Functions are invoked in the order
273              they were added.
274
275              If  the  option -L is given, the current values for the hook ar‐
276              rays are listed with typeset.
277
278              If the option -d is given, the function is removed from the  ar‐
279              ray 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 de‐
291              scribed 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 -f "nolast" -- "$@"
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 ar‐
318              ray.
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 en‐
343       tries in files it is maintained across sessions and  (by  default)  be‐
344       tween  terminal emulators in the current session.  Duplicates are auto‐
345       matically removed, so that the list reflects the single most recent use
346       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 re‐
368       cently changed-to directory.  1 is the immediately preceding directory;
369       the  current  directory  is remembered but is not offered as a destina‐
370       tion.  Note that if you have multiple windows open 1 may refer to a di‐
371       rectory  changed  to  in  another  window; you can avoid this by having
372       per-terminal files for storing  directory  as  described  for  the  re‐
373       cent-dirs-file style below.
374
375       If  you  set the recent-dirs-default style described below cdr will be‐
376       have 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  di‐
391       rectory  is shown; this style is on by default so no action is required
392       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); di‐
410              rectories  are  in  unabbreviated  form  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 ex‐
416              tended glob pattern; the pattern needs to be quoted from immedi‐
417              ate  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 in‐
425              stead 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 ':ch‐
431       pwd:*' in case the meaning of the context is extended  in  future,  for
432       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 ef‐
499              fect  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  re‐
533                     cent  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 re‐
537                     cent  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 al‐
549                     ways 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 chpwd_re‐
587       cent_dirs for more details.
588

ABBREVIATED DYNAMIC REFERENCES TO DIRECTORIES

590       The dynamic directory naming system is described in the subsection  Dy‐
591       namic  named  directories  of  the  section  Filename Expansion in zsh‐
592       expn(1).  In this, a reference to ~[...]  is  expanded  by  a  function
593       found by the 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 ab‐
602       breviations 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 di‐
606              rectory 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 ar‐
613              eas 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_directory_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 op‐
644       tional suffix with a slash followed by a colon and the name of a  vari‐
645       able  in the same format to give the next component.  (The slash before
646       the colon is to disambiguate the case where a colon is  needed  in  the
647       path  for  a drive.  There is otherwise no syntax for escaping this, so
648       path components whose names start with a colon are not  supported.)   A
649       special component :default: specifies a variable in the form /:var (the
650       path section is ignored and so is usually empty) that will be used  for
651       the next component if no variable is given for the path.  Variables re‐
652       ferred 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  be‐
676       ing 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  di‐
704       rectory should be sufficient to indicate the problem.
705
706   Complete example
707       Here is a full fictitious but usable autoloadable definition of the ex‐
708       ample function defined by the code  above.   So  ~[gs:p:s]  expands  to
709       /scratch/$USER/git/myscratchproject/top/srcdir  (with  $USER  also  ex‐
710       panded).
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 ex‐
758       ample.
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  en‐
949              able  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  get-re‐
991              vision  style  needs to be set and the use-simple style needs to
992              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 non-de‐
1034              fault installation directories.  Assume,  git  is  installed  in
1035              /usr/bin but your sysadmin installed a newer version in /usr/lo‐
1036              cal/bin. Instead of changing the order of your $PATH  parameter,
1037              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, hg, and git backends. In the case
1065              of hg it will invoke the external hexdump program to  parse  the
1066              binary  dirstate cache file; this method will not return the lo‐
1067              cal revision 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  vi‐
1073              tal).  For git, the hash value of the currently checked out com‐
1074              mit is available via the %i expansion. With hg, the local  revi‐
1075              sion  number and the corresponding global hash are available via
1076              %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, hg, and git 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 ac‐
1180              tionformats.
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 /foo/bar/re‐
1190              poXY/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 the
1213              quilt series' patch-format string.   The  set-patch-format  hook
1214              and 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.  For  hg, the branch name can include a topic
1221              name.
1222       %r     The current revision number or the hgrevformat style for hg.
1223
1224       In hgrevformat these replacements are done:
1225
1226       %r     The current local revision number.
1227       %h     The current global revision identifier.
1228
1229       In patch-format and nopatch-format these replacements are done:
1230
1231       %p     The name of the top-most applied patch; may be overridden by the
1232              applied-string hook.
1233       %u     The  number of unapplied patches; may be overridden by the unap‐
1234              plied-string hook.
1235       %n     The number of applied patches.
1236       %c     The number of unapplied patches.
1237       %a     The number of all patches (%a = %n + %c).
1238       %g     The names of active mq guards (hg backend).
1239       %G     The number of active mq guards (hg backend).
1240
1241       Not all VCS backends have to support all replacements. For  nvcsformats
1242       no replacements are performed at all, it is just a string.
1243
1244   Oddities
1245       If you want to use the %b (bold off) prompt expansion in formats, which
1246       expands %b itself, use %%b. That will cause the vcs_info  expansion  to
1247       replace  %%b with %b, so that zsh's prompt expansion mechanism can han‐
1248       dle it. Similarly, to hand down %b from branchformat, use %%%%b.  Sorry
1249       for  this inconvenience, but it cannot be easily avoided. Luckily we do
1250       not clash with a lot of prompt expansions and this  only  needs  to  be
1251       done for those.
1252
1253       When   one   of   the   gen-applied-string,  gen-unapplied-string,  and
1254       set-patch-format    hooks    is    defined,     applying     %-escaping
1255       (`foo=${foo//'%'/%%}') to the interpolated values for use in the prompt
1256       is the responsibility of those hooks (jointly); when neither  of  those
1257       hooks  is defined, vcs_info handles escaping by itself.  We regret this
1258       coupling, but it was required for backwards compatibility.
1259
1260   Quilt Support
1261       Quilt is not a version control system, therefore  this  is  not  imple‐
1262       mented  as a backend. It can help keeping track of a series of patches.
1263       People use it to keep a set of changes they want to use on top of soft‐
1264       ware  packages  (which  is  tightly  integrated  into the package build
1265       process - the Debian project does this for a large number of packages).
1266       Quilt  can  also  help  individual  developers  keep track of their own
1267       patches on top of real version control systems.
1268
1269       The vcs_info integration tries to support both ways of using  quilt  by
1270       having  two  slightly  different  modes  of operation: `addon' mode and
1271       `standalone' mode).
1272
1273       Quilt integration is off by default; to enable it,  set  the  use-quilt
1274       style, and add %Q to your formats or actionformats style:
1275              zstyle ':vcs_info:*' use-quilt true
1276
1277       Styles    looked    up    from   the   Quilt   support   code   include
1278       `.quilt-quilt-mode' in  the  vcs-string  part  of  the  context,  where
1279       quilt-mode     is     either    addon    or    standalone.     Example:
1280       :vcs_info:git.quilt-addon:default:repo-root-name.
1281
1282       For `addon' mode to become active vcs_info must have already detected a
1283       real  version  control system controlling the directory. If that is the
1284       case, a directory that holds quilt's patches needs to  be  found.  That
1285       directory is configurable via the `QUILT_PATCHES' environment variable.
1286       If that  variable  exists  its  value  is  used,  otherwise  the  value
1287       `patches'  is assumed. The value from $QUILT_PATCHES can be overwritten
1288       using the `quilt-patch-dir' style. (Note: you can use vcs_info to  keep
1289       the  value  of  $QUILT_PATCHES  correct all the time via the post-quilt
1290       hook).
1291
1292       When the directory in question is found, quilt is assumed to be active.
1293       To  gather  more  information,  vcs_info  looks  for a directory called
1294       `.pc'; Quilt uses that directory to track its current  state.  If  this
1295       directory  does  not  exist we know that quilt has not done anything to
1296       the working directory (read: no patches have been applied yet).
1297
1298       If patches are applied, vcs_info will try to find  out  which.  If  you
1299       want to know which patches of a series are not yet applied, you need to
1300       activate the get-unapplied style in the appropriate context.
1301
1302       vcs_info allows for very detailed control over how the gathered  infor‐
1303       mation  is  presented (see the Configuration and Hooks in vcs_info sec‐
1304       tions), all of which are documented below. Note there are a  number  of
1305       other patch tracking systems that work on top of a certain version con‐
1306       trol system (like stgit for git, or mq for hg); the  configuration  for
1307       systems  like  that  are generally configured the same way as the quilt
1308       support.
1309
1310       If the quilt support is working in `addon' mode, the produced string is
1311       available  as a simple format replacement (%Q to be precise), which can
1312       be used in formats and actionformats; see below for details).
1313
1314       If, on the other hand, the support  code  is  working  in  `standalone'
1315       mode,  vcs_info will pretend as if quilt were an actual version control
1316       system. That means that the version control  system  identifier  (which
1317       otherwise  would  be  something  like  `svn'  or  `cvs') will be set to
1318       `-quilt-'. This has implications on the used style context  where  this
1319       identifier is the second element. vcs_info will have filled in a proper
1320       value for the "repository's" root directory and the  string  containing
1321       the information about quilt's state will be available as the `misc' re‐
1322       placement (and %Q for compatibility with `addon' mode).
1323
1324       What is left to discuss is how `standalone' mode is detected.  The  de‐
1325       tection  itself  is  a series of searches for directories. You can have
1326       this detection enabled all the time in every directory that is not oth‐
1327       erwise  under  version control. If you know there is only a limited set
1328       of trees where you would like vcs_info to try and  look  for  Quilt  in
1329       `standalone'  mode to minimise the amount of searching on every call to
1330       vcs_info, there are a number of ways to do that:
1331
1332       Essentially, `standalone' mode  detection  is  controlled  by  a  style
1333       called  `quilt-standalone'. It is a string style and its value can have
1334       different effects. The simplest values are: `always' to  run  detection
1335       every  time  vcs_info is run, and `never' to turn the detection off en‐
1336       tirely.
1337
1338       If the value of quilt-standalone is something else, it  is  interpreted
1339       differently. If the value is the name of a scalar variable the value of
1340       that variable is checked and that  value  is  used  in  the  same  `al‐
1341       ways'/`never' way as described above.
1342
1343       If  the value of quilt-standalone is an array, the elements of that ar‐
1344       ray are used as directory names under which you want the  detection  to
1345       be active.
1346
1347       If  quilt-standalone is an associative array, the keys are taken as di‐
1348       rectory names under which you want the detection to be active, but only
1349       if the corresponding value is the string `true'.
1350
1351       Last,  but not least, if the value of quilt-standalone is the name of a
1352       function, the function is called without arguments and the return value
1353       decides whether detection should be active. A `0' return value is true;
1354       a non-zero return value is interpreted as false.
1355
1356       Note, if there is both a  function  and  a  variable  by  the  name  of
1357       quilt-standalone, the function will take precedence.
1358
1359   Function Descriptions (Public API)
1360       vcs_info [user-context]
1361              The main function, that runs all backends and assembles all data
1362              into ${vcs_info_msg_*_}. This is the function you want  to  call
1363              from  precmd  if  you  want to include up-to-date information in
1364              your prompt (see Variable Description below).  If an argument is
1365              given,  that  string  will  be  used  instead  of default in the
1366              user-context field of the style context.
1367
1368       vcs_info_hookadd
1369              Statically registers a number of functions to a given hook.  The
1370              hook  needs to be given as the first argument; what follows is a
1371              list of hook-function names to register to the hook. The  `+vi-'
1372              prefix  needs  to  be left out here. See Hooks in vcs_info below
1373              for details.
1374
1375       vcs_info_hookdel
1376              Remove hook-functions from a given hook. The hook  needs  to  be
1377              given  as  the first non-option argument; what follows is a list
1378              of hook-function names to un-register from the hook. If `-a'  is
1379              used as the first argument, all occurrences of the functions are
1380              unregistered. Otherwise only the last occurrence is removed  (if
1381              a  function was registered to a hook more than once). The `+vi-'
1382              prefix needs to be left out here.  See Hooks in  vcs_info  below
1383              for details.
1384
1385       vcs_info_lastmsg
1386              Outputs  the  current  values of ${vcs_info_msg_*_}.  Takes into
1387              account  the  value   of   the   use-prompt-escapes   style   in
1388              ':vcs_info:formats:command:-all-'.  It  also only prints max-ex‐
1389              ports values.
1390
1391       vcs_info_printsys [user-context]
1392              Prints a list of all supported version control  systems.  Useful
1393              to find out possible contexts (and which of them are enabled) or
1394              values for the disable style.
1395
1396       vcs_info_setsys
1397              Initializes vcs_info's internal list of available backends. With
1398              this function, you can add support for new VCSs without restart‐
1399              ing the shell.
1400
1401       All functions named VCS_INFO_* are for internal use only.
1402
1403   Variable Description
1404       ${vcs_info_msg_N_} (Note the trailing underscore)
1405              Where N is an integer, e.g.,  vcs_info_msg_0_.  These  variables
1406              are  the storage for the informational message the last vcs_info
1407              call has assembled. These are strongly connected to the formats,
1408              actionformats  and  nvcsformats  styles  described  above. Those
1409              styles are lists. The first member of that  list  gets  expanded
1410              into  ${vcs_info_msg_0_}, the second into ${vcs_info_msg_1_} and
1411              the Nth into ${vcs_info_msg_N-1_}. (See  the  max-exports  style
1412              above.)
1413
1414       All variables named VCS_INFO_* are for internal use only.
1415
1416   Hooks in vcs_info
1417       Hooks are places in vcs_info where you can run your own code. That code
1418       can communicate with the code that called it and through  that,  change
1419       the system's behaviour.
1420
1421       For configuration, hooks change the style context:
1422              :vcs_info:vcs-string+hook-name:user-context:repo-root-name
1423
1424       To  register  functions  to  a hook, you need to list them in the hooks
1425       style in the appropriate context.
1426
1427       Example:
1428              zstyle ':vcs_info:*+foo:*' hooks bar baz
1429
1430       This registers functions to the hook `foo' for all backends.  In  order
1431       to   avoid  namespace  problems,  all  registered  function  names  are
1432       prepended by a `+vi-', so the actual functions  called  for  the  `foo'
1433       hook are `+vi-bar' and `+vi-baz'.
1434
1435       If  you  would  like to register a function to a hook regardless of the
1436       current context, you may use the vcs_info_hookadd function. To remove a
1437       function that was added like that, the vcs_info_hookdel function can be
1438       used.
1439
1440       If something seems weird, you can enable the `debug' boolean  style  in
1441       the  proper  context and the hook-calling code will print what it tried
1442       to execute and whether the function in question existed.
1443
1444       When you register more than one function to a hook, all  functions  are
1445       executed one after another until one function returns non-zero or until
1446       all functions have been called. Context-sensitive  hook  functions  are
1447       executed   before   statically  registered  ones  (the  ones  added  by
1448       vcs_info_hookadd).
1449
1450       You  may  pass  data  between  functions  via  an  associative   array,
1451       user_data.  For example:
1452              +vi-git-myfirsthook(){
1453                  user_data[myval]=$myval
1454              }
1455              +vi-git-mysecondhook(){
1456                  # do something with ${user_data[myval]}
1457              }
1458
1459       There are a number of variables that are special in hook contexts:
1460
1461       ret    The  return  value  that  the  hooks  system  will return to the
1462              caller. The default is an integer `zero'. If and how  a  changed
1463              ret  value  changes  the  execution of the caller depends on the
1464              specific hook. See the hook documentation below for details.
1465
1466       hook_com
1467              An associated array which is used for  bidirectional  communica‐
1468              tion  from the caller to hook functions. The used keys depend on
1469              the specific hook.
1470
1471       context
1472              The active context of the hook. Functions that  wish  to  change
1473              this variable should make it local scope first.
1474
1475       vcs    The current VCS after it was detected. The same values as in the
1476              enable/disable style are used. Available  in  all  hooks  except
1477              start-up.
1478
1479       Finally, the full list of currently available hooks:
1480
1481       start-up
1482              Called after starting vcs_info but before the VCS in this direc‐
1483              tory is determined. It can be used to deactivate vcs_info tempo‐
1484              rarily  if  necessary. When ret is set to 1, vcs_info aborts and
1485              does nothing; when set to 2, vcs_info sets up everything  as  if
1486              no version control were active and exits.
1487
1488       pre-get-data
1489              Same as start-up but after the VCS was detected.
1490
1491       gen-hg-bookmark-string
1492              Called in the Mercurial backend when a bookmark string is gener‐
1493              ated; the get-revision and get-bookmarks styles must be true.
1494
1495              This hook  gets  the  names  of  the  Mercurial  bookmarks  that
1496              vcs_info collected from `hg'.
1497
1498              If a bookmark is active, the key ${hook_com[hg-active-bookmark]}
1499              is set to its name.  The key is otherwise unset.
1500
1501              When setting ret to non-zero, the string in  ${hook_com[hg-book‐
1502              mark-string]}  will  be used in the %m escape in formats and ac‐
1503              tionformats and will be available in the global backend_misc ar‐
1504              ray as ${backend_misc[bookmarks]}.
1505
1506       gen-applied-string
1507              Called in the git (with stgit or during rebase or merge), and hg
1508              (with mq) backends and in quilt support when the  applied-string
1509              is  generated;  the use-quilt zstyle must be true for quilt (the
1510              mq and stgit backends are active by default).
1511
1512              The arguments to this hook describe applied patches in the oppo‐
1513              site  order, which means that the first argument is the top-most
1514              patch and so forth.
1515
1516              When the patches' log messages can be extracted, those  are  em‐
1517              bedded  within  each argument after a space, so each argument is
1518              of the form `patch-name first line of the  log  message',  where
1519              patch-name  contains  no whitespace. The mq backend passes argu‐
1520              ments of the form `patch name', with possible  embedded  spaces,
1521              but without extracting the patch's log message.
1522
1523              When  setting  ret  to  non-zero,  the  string in ${hook_com[ap‐
1524              plied-string]} will be available as %p in the  patch-format  and
1525              nopatch-format   styles.    This   hook   is,  in  concert  with
1526              set-patch-format, responsible for %-escaping that value for  use
1527              in the prompt.  (See the Oddities section.)
1528
1529              The   quilt   backend   passes   to   this   hook   the   inputs
1530              ${hook_com[quilt-patches-dir]} and, if it has  been  determined,
1531              ${hook_com[quilt-pc-dir]}.
1532
1533       gen-unapplied-string
1534              Called  in  the  git (with stgit or during rebase), and hg (with
1535              mq) backend and in quilt support when  the  unapplied-string  is
1536              generated; the get-unapplied style must be true.
1537
1538              This hook gets the names of all unapplied patches which vcs_info
1539              in order, which means that  the  first  argument  is  the  patch
1540              next-in-line to be applied and so forth.
1541
1542              The format of each argument is as for gen-applied-string, above.
1543
1544              When  setting  ret  to  non-zero, the string in ${hook_com[unap‐
1545              plied-string]} will be available as %u in the  patch-format  and
1546              nopatch-format   styles.    This   hook   is,  in  concert  with
1547              set-patch-format, responsible for %-escaping that value for  use
1548              in the prompt.  (See the Oddities section.)
1549
1550              The   quilt   backend   passes   to   this   hook   the   inputs
1551              ${hook_com[quilt-patches-dir]} and, if it has  been  determined,
1552              ${hook_com[quilt-pc-dir]}.
1553
1554       gen-mqguards-string
1555              Called  in  the  hg backend when guards-string is generated; the
1556              get-mq style must be true (default).
1557
1558              This hook gets the names of any active mq guards.
1559
1560              When    setting    ret    to    non-zero,    the    string    in
1561              ${hook_com[guards-string]}  will be used in the %g escape in the
1562              patch-format and nopatch-format styles.
1563
1564       no-vcs This hooks is called when no  version  control  system  was  de‐
1565              tected.
1566
1567              The `hook_com' parameter is not used.
1568
1569       post-backend
1570              Called  as  soon as the backend has finished collecting informa‐
1571              tion.
1572
1573              The `hook_com' keys available are as for the set-message hook.
1574
1575       post-quilt
1576              Called after the quilt support is done. The  following  informa‐
1577              tion  is  passed  as arguments to the hook: 1. the quilt-support
1578              mode (`addon' or `standalone'); 2. the directory  that  contains
1579              the patch series; 3. the directory that holds quilt's status in‐
1580              formation (the `.pc' directory) or the string "-nopc-"  if  that
1581              directory wasn't found.
1582
1583              The `hook_com' parameter is not used.
1584
1585       set-branch-format
1586              Called  before  `branchformat'  is set. The only argument to the
1587              hook is the format that is configured at this point.
1588
1589              The `hook_com' keys  considered  are  `branch'  and  `revision'.
1590              They  are  set  to the values figured out so far by vcs_info and
1591              any change will be used directly when the actual replacement  is
1592              done.
1593
1594              If  ret  is set to non-zero, the string in ${hook_com[branch-re‐
1595              place]} will be used unchanged as the `%b'  replacement  in  the
1596              variables set by vcs_info.
1597
1598       set-hgrev-format
1599              Called  before  a `hgrevformat' is set. The only argument to the
1600              hook is the format that is configured at this point.
1601
1602              The `hook_com' keys considered are `hash' and `localrev'.   They
1603              are  set  to  the  values figured out so far by vcs_info and any
1604              change will be used directly  when  the  actual  replacement  is
1605              done.
1606
1607              If  ret  is  set  to  non-zero, the string in ${hook_com[rev-re‐
1608              place]} will be used unchanged as the `%i'  replacement  in  the
1609              variables set by vcs_info.
1610
1611       pre-addon-quilt
1612              This  hook is used when vcs_info's quilt functionality is active
1613              in "addon" mode (quilt used on top of  a  real  version  control
1614              system).  It is activated right before any quilt specific action
1615              is taken.
1616
1617              Setting the `ret' variable in this  hook  to  a  non-zero  value
1618              avoids any quilt specific actions from being run at all.
1619
1620       set-patch-format
1621              This  hook is used to control some of the possible expansions in
1622              patch-format and nopatch-format styles with patch queue  systems
1623              such as quilt, mqueue and the like.
1624
1625              This hook is used in the git, hg and quilt backends.
1626
1627              The hook allows the control of the %p (${hook_com[applied]}) and
1628              %u (${hook_com[unapplied]}) expansion in all backends  that  use
1629              the    hook.    With    the    mercurial    backend,    the   %g
1630              (${hook_com[guards]}) expansion is controllable in  addition  to
1631              that.
1632
1633              If  ret  is  set to non-zero, the string in ${hook_com[patch-re‐
1634              place]} will be used unchanged instead  of  an  expanded  format
1635              from patch-format or nopatch-format.
1636
1637              This  hook is, in concert with the gen-applied-string or gen-un‐
1638              applied-string hooks if they are defined, responsible for  %-es‐
1639              caping the final patch-format value for use in the prompt.  (See
1640              the Oddities section.)
1641
1642              The   quilt   backend   passes   to   this   hook   the   inputs
1643              ${hook_com[quilt-patches-dir]}  and,  if it has been determined,
1644              ${hook_com[quilt-pc-dir]}.
1645
1646       set-message
1647              Called each time before a `vcs_info_msg_N_' message is set.   It
1648              takes  two  arguments;  the  first  being the `N' in the message
1649              variable name, the second is the currently configured formats or
1650              actionformats.
1651
1652              There  are a number of `hook_com' keys, that are used here: `ac‐
1653              tion', `branch', `base', `base-name', `subdir',  `staged',  `un‐
1654              staged',  `revision',  `misc',  `vcs'  and one `miscN' entry for
1655              each backend-specific data field (N starting at zero). They  are
1656              set  to the values figured out so far by vcs_info and any change
1657              will be used directly when the actual replacement is done.
1658
1659              Since this hook is triggered multiple times (once for each  con‐
1660              figured  formats  or actionformats), each of the `hook_com' keys
1661              mentioned above (except for the miscN entries)  has  an  `_orig'
1662              counterpart,  so  even if you changed a value to your liking you
1663              can still get the original value in the next run.  Changing  the
1664              `_orig' values is probably not a good idea.
1665
1666              If  ret  is  set to non-zero, the string in ${hook_com[message]}
1667              will be used unchanged as the message by vcs_info.
1668
1669       If all of this sounds rather confusing, take a  look  at  the  Examples
1670       section  below  and  also in the Misc/vcs_info-examples file in the Zsh
1671       source.  They contain some explanatory code.
1672
1673   Examples
1674       Don't use vcs_info at all (even though it's in your prompt):
1675              zstyle ':vcs_info:*' enable NONE
1676
1677       Disable the backends for bzr and svk:
1678              zstyle ':vcs_info:*' disable bzr svk
1679
1680       Disable everything but bzr and svk:
1681              zstyle ':vcs_info:*' enable bzr svk
1682
1683       Provide a special formats for git:
1684              zstyle ':vcs_info:git:*' formats       ' GIT, BABY! [%b]'
1685              zstyle ':vcs_info:git:*' actionformats ' GIT ACTION! [%b|%a]'
1686
1687       All %x expansion in  all  sorts  of  formats  (formats,  actionformats,
1688       branchformat,  you  name  it) are done using the `zformat' builtin from
1689       the `zsh/zutil' module. That means you can do everything with these  %x
1690       items  what zformat supports. In particular, if you want something that
1691       is really long to have a fixed  width,  like  a  hash  in  a  mercurial
1692       branchformat, you can do this: %12.12i. That'll shrink the 40 character
1693       hash to its 12 leading characters. The form  is  actually  `%min.maxx'.
1694       More  is  possible.   See the section `The zsh/zutil Module' in zshmod‐
1695       ules(1) for details.
1696
1697       Use the quicker bzr backend
1698              zstyle ':vcs_info:bzr:*' use-simple true
1699
1700       If   you   do   use   use-simple,   please   report    if    it    does
1701       `the-right-thing[tm]'.
1702
1703       Display the revision number in yellow for bzr and svn:
1704              zstyle ':vcs_info:(svn|bzr):*' \
1705                     branchformat '%b%%F{yellow}:%r'
1706
1707       The doubled percent sign is explained in the Oddities section.
1708
1709       Alternatively, one can use the raw colour codes directly:
1710
1711              zstyle ':vcs_info:(svn|bzr):*' \
1712                     branchformat '%b%{'${fg[yellow]}'%}:%r'
1713
1714       Normally  when  a  variable  is  interpolated into a format string, the
1715       variable needs to be %-escaped. In this example we skipped that because
1716       we assume the value of ${fg[yellow]} doesn't contain any % signs.
1717
1718       Make sure you enclose the color codes in %{...%} if you want to use the
1719       string provided by vcs_info in prompts.
1720
1721       Here is how to print the  VCS  information  as  a  command  (not  in  a
1722       prompt):
1723              vcsi() { vcs_info interactive; vcs_info_lastmsg }
1724
1725       This  way,  you  can  even  define  different  formats  for  output via
1726       vcs_info_lastmsg in the ':vcs_info:*:interactive:*' namespace.
1727
1728       Now as promised, some code that uses hooks: say, you'd like to  replace
1729       the string `svn' by `subversion' in vcs_info's %s formats replacement.
1730
1731       First,  we  will  tell  vcs_info to call a function when populating the
1732       message variables with the gathered information:
1733              zstyle ':vcs_info:*+set-message:*' hooks svn2subversion
1734
1735       Nothing happens. Which is reasonable, since we didn't define the actual
1736       function  yet.  To see what the hooks subsystem is trying to do, enable
1737       the `debug' style:
1738              zstyle ':vcs_info:*+*:*' debug true
1739
1740       That should give you an idea what is going on. Specifically, the  func‐
1741       tion  that we are looking for is `+vi-svn2subversion'. Note, the `+vi-'
1742       prefix. So, everything is in order, just as documented.  When  you  are
1743       done checking out the debugging output, disable it again:
1744              zstyle ':vcs_info:*+*:*' debug false
1745
1746       Now, let's define the function:
1747              function +vi-svn2subversion() {
1748                  [[ ${hook_com[vcs_orig]} == svn ]] && hook_com[vcs]=subversion
1749              }
1750
1751       Simple enough. And it could have even been simpler, if only we had reg‐
1752       istered our function in a less generic context. If we do it only in the
1753       `svn' backend's context, we don't need to test which the active backend
1754       is:
1755              zstyle ':vcs_info:svn+set-message:*' hooks svn2subversion
1756              function +vi-svn2subversion() {
1757                  hook_com[vcs]=subversion
1758              }
1759
1760       And finally a little more elaborate example, that uses a hook to create
1761       a customised bookmark string for the hg backend.
1762
1763       Again, we start off by registering a function:
1764              zstyle ':vcs_info:hg+gen-hg-bookmark-string:*' hooks hgbookmarks
1765
1766       And then we define the `+vi-hgbookmarks' function:
1767              function +vi-hgbookmarks() {
1768                  # The default is to connect all bookmark names by
1769                  # commas. This mixes things up a little.
1770                  # Imagine, there's one type of bookmarks that is
1771                  # special to you. Say, because it's *your* work.
1772                  # Those bookmarks look always like this: "sh/*"
1773                  # (because your initials are sh, for example).
1774                  # This makes the bookmarks string use only those
1775                  # bookmarks. If there's more than one, it
1776                  # concatenates them using commas.
1777                  # The bookmarks returned by `hg' are available in
1778                  # the function's positional parameters.
1779                  local s="${(Mj:,:)@:#sh/*}"
1780                  # Now, the communication with the code that calls
1781                  # the hook functions is done via the hook_com[]
1782                  # hash. The key at which the `gen-hg-bookmark-string'
1783                  # hook looks is `hg-bookmark-string'. So:
1784                  hook_com[hg-bookmark-string]=$s
1785                  # And to signal that we want to use the string we
1786                  # just generated, set the special variable `ret' to
1787                  # something other than the default zero:
1788                  ret=1
1789                  return 0
1790              }
1791
1792       Some longer examples and code snippets which might be useful are avail‐
1793       able in the examples file located at Misc/vcs_info-examples in the  Zsh
1794       source directory.
1795
1796       This concludes our guided tour through zsh's vcs_info.
1797

PROMPT THEMES

1799   Installation
1800       You  should  make sure all the functions from the Functions/Prompts di‐
1801       rectory of the source distribution are available; they all  begin  with
1802       the string `prompt_' except for the special function `promptinit'.  You
1803       also  need  the  `colors'  and  `add-zsh-hook'  functions  from   Func‐
1804       tions/Misc.   All these functions may already be installed on your sys‐
1805       tem; if not, you will need to find them and copy them.   The  directory
1806       should  appear  as  one of the elements of the fpath array (this should
1807       already be the case if they were installed), and at least the  function
1808       promptinit  should  be autoloaded; it will autoload the rest.  Finally,
1809       to initialize the use of the system you need  to  call  the  promptinit
1810       function.  The following code in your .zshrc will arrange for this; as‐
1811       sume the functions are stored in the directory ~/myfns:
1812
1813              fpath=(~/myfns $fpath)
1814              autoload -U promptinit
1815              promptinit
1816
1817   Theme Selection
1818       Use the prompt command to select your preferred  theme.   This  command
1819       may  be  added to your .zshrc following the call to promptinit in order
1820       to start zsh with a theme already selected.
1821
1822       prompt [ -c | -l ]
1823       prompt [ -p | -h ] [ theme ... ]
1824       prompt [ -s ] theme [ arg ... ]
1825              Set or examine the prompt theme.  With no options  and  a  theme
1826              argument,  the theme with that name is set as the current theme.
1827              The available themes are determined at run time; use the -l  op‐
1828              tion  to see a list.  The special theme `random' selects at ran‐
1829              dom one of the available themes and sets your prompt to that.
1830
1831              In some cases the theme may be modified by  one  or  more  argu‐
1832              ments, which should be given after the theme name.  See the help
1833              for each theme for descriptions of these arguments.
1834
1835              Options are:
1836
1837              -c     Show the currently selected theme and its parameters,  if
1838                     any.
1839              -l     List all available prompt themes.
1840              -p     Preview  the  theme  named  by theme, or all themes if no
1841                     theme is given.
1842              -h     Show help for the theme named by theme, or for the prompt
1843                     function if no theme is given.
1844              -s     Set theme as the current theme and save state.
1845
1846       prompt_theme_setup
1847              Each available theme has a setup function which is called by the
1848              prompt function to install that theme.  This function may define
1849              other  functions  as necessary to maintain the prompt, including
1850              functions used to preview the prompt or  provide  help  for  its
1851              use.   You should not normally call a theme's setup function di‐
1852              rectly.
1853
1854   Utility Themes
1855       prompt off
1856              The theme `off' sets all the prompt variables to minimal  values
1857              with no special effects.
1858
1859       prompt default
1860              The  theme `default' sets all prompt variables to the same state
1861              as if an interactive zsh  was  started  with  no  initialization
1862              files.
1863
1864       prompt restore
1865              The  special  theme `restore' erases all theme settings and sets
1866              prompt variables to  their  state  before  the  first  time  the
1867              `prompt'  function was run, provided each theme has properly de‐
1868              fined its cleanup (see below).
1869
1870              Note that you can undo `prompt off' and  `prompt  default'  with
1871              `prompt restore', but a second restore does not undo the first.
1872
1873   Writing Themes
1874       The  first  step  for adding your own theme is to choose a name for it,
1875       and create a file `prompt_name_setup' in a  directory  in  your  fpath,
1876       such  as ~/myfns in the example above.  The file should at minimum con‐
1877       tain assignments for the prompt variables that  your  theme  wishes  to
1878       modify.   By  convention,  themes use PS1, PS2, RPS1, etc., rather than
1879       the longer PROMPT and RPROMPT.
1880
1881       The file is autoloaded as a function in the current shell  context,  so
1882       it  may contain any necessary commands to customize your theme, includ‐
1883       ing defining additional functions.  To make some complex tasks  easier,
1884       your setup function may also do any of the following:
1885
1886       Assign prompt_opts
1887              The array prompt_opts may be assigned any of "bang", "cr", "per‐
1888              cent", "sp", and/or "subst" as values.   The  corresponding  se‐
1889              topts (promptbang, etc.) are turned on, all other prompt-related
1890              options are turned off.  The prompt_opts array preserves setopts
1891              even beyond the scope of localoptions, should your function need
1892              that.
1893
1894       Modify hooks
1895              Use of add-zsh-hook and add-zle-hook-widget is recommended  (see
1896              the  Manipulating Hook Functions section above).  All hooks that
1897              follow the naming pattern  prompt_theme_hook  are  automatically
1898              removed when the prompt theme changes or is disabled.
1899
1900       Declare cleanup
1901              If  your  function makes any other changes that should be undone
1902              when the theme is disabled, your setup function may call
1903
1904                     prompt_cleanup command
1905
1906              where command should be suitably quoted.  If your theme is  ever
1907              disabled  or replaced by another, command is executed with eval.
1908              You may declare more than one such cleanup hook.
1909
1910       Define preview
1911              Define or autoload a function prompt_name_preview to  display  a
1912              simulated version of your prompt.  A simple default previewer is
1913              defined by promptinit for themes that do not define  their  own.
1914              This preview function is called by `prompt -p'.
1915
1916       Provide help
1917              Define  or autoload a function prompt_name_help to display docu‐
1918              mentation or help text for your theme.  This  help  function  is
1919              called by `prompt -h'.
1920

ZLE FUNCTIONS

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

EXCEPTION HANDLING

3253       Two functions are provided to enable zsh to provide exception  handling
3254       in a form that should be familiar from other languages.
3255
3256       throw exception
3257              The  function  throw throws the named exception.  The name is an
3258              arbitrary string and is only used by the throw and  catch  func‐
3259              tions.   An exception is for the most part treated the same as a
3260              shell error, i.e. an unhandled exception will cause the shell to
3261              abort  all  processing  in a function or script and to return to
3262              the top level in an interactive shell.
3263
3264       catch exception-pattern
3265              The function catch returns  status  zero  if  an  exception  was
3266              thrown and the pattern exception-pattern matches its name.  Oth‐
3267              erwise it returns status 1.   exception-pattern  is  a  standard
3268              shell  pattern,  respecting  the  current  setting  of  the  EX‐
3269              TENDED_GLOB option.  An alias catch is also defined  to  prevent
3270              the  argument  to  the function from matching filenames, so pat‐
3271              terns may be used unquoted.  Note that  as  exceptions  are  not
3272              fundamentally  different  from other shell errors it is possible
3273              to catch shell errors by using an empty string as the  exception
3274              name.   The shell variable CAUGHT is set by catch to the name of
3275              the exception caught.  It is possible to rethrow an exception by
3276              calling  the  throw  function  again  once an exception has been
3277              caught.
3278
3279       The functions are designed to be used together  with  the  always  con‐
3280       struct  described  in  zshmisc(1).  This is important as only this con‐
3281       struct provides the required support for exceptions.  A typical example
3282       is as follows.
3283
3284              {
3285                # "try" block
3286                # ... nested code here calls "throw MyExcept"
3287              } always {
3288                # "always" block
3289                if catch MyExcept; then
3290                  print "Caught exception MyExcept"
3291                elif catch ''; then
3292                  print "Caught a shell error.  Propagating..."
3293                  throw ''
3294                fi
3295                # Other exceptions are not handled but may be caught further
3296                # up the call stack.
3297              }
3298
3299       If  all  exceptions  should  be  caught,  the  following idiom might be
3300       preferable.
3301
3302              {
3303                # ... nested code here throws an exception
3304              } always {
3305                if catch *; then
3306                  case $CAUGHT in
3307                    (MyExcept)
3308                    print "Caught my own exception"
3309                    ;;
3310                    (*)
3311                    print "Caught some other exception"
3312                    ;;
3313                  esac
3314                fi
3315              }
3316
3317       In common with exception handling in other languages, the exception may
3318       be  thrown by code deeply nested inside the `try' block.  However, note
3319       that it must be thrown inside the current  shell,  not  in  a  subshell
3320       forked  for  a pipeline, parenthesised current-shell construct, or some
3321       form of command or process substitution.
3322
3323       The system internally uses the shell variable EXCEPTION to  record  the
3324       name  of  the exception between throwing and catching.  One drawback of
3325       this scheme is that if the exception is not handled the variable EXCEP‐
3326       TION  remains  set  and may be incorrectly recognised as the name of an
3327       exception if a shell error subsequently occurs.  Adding unset EXCEPTION
3328       at  the  start  of  the outermost layer of any code that uses exception
3329       handling will eliminate this problem.
3330

MIME FUNCTIONS

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

MATHEMATICAL FUNCTIONS

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

USER CONFIGURATION FUNCTIONS

3942       The  zsh/newuser  module  comes  with  a function to aid in configuring
3943       shell options for new users.  If the module is installed, this function
3944       can  also be run by hand.  It is available even if the module's default
3945       behaviour, namely running the function for a new user logging in  with‐
3946       out startup files, is inhibited.
3947
3948       zsh-newuser-install [ -f ]
3949              The  function  presents  the  user with various options for cus‐
3950              tomizing their initialization scripts.  Currently only  ~/.zshrc
3951              is  handled.   $ZDOTDIR/.zshrc  is used instead if the parameter
3952              ZDOTDIR is set; this provides a way for the user to configure  a
3953              file without altering an existing .zshrc.
3954
3955              By default the function exits immediately if it finds any of the
3956              files .zshenv, .zprofile, .zshrc, or .zlogin in the  appropriate
3957              directory.   The  option  -f  is  required in order to force the
3958              function to continue.  Note this may happen even if  .zshrc  it‐
3959              self does not exist.
3960
3961              As  currently  configured, the function will exit immediately if
3962              the user has root privileges; this behaviour cannot be  overrid‐
3963              den.
3964
3965              Once  activated,  the  function's  behaviour  is  supposed to be
3966              self-explanatory.  Menus are present allowing the user to  alter
3967              the  value  of options and parameters.  Suggestions for improve‐
3968              ments are always welcome.
3969
3970              When the script exits, the user is given the opportunity to save
3971              the  new  file  or  not; changes are not irreversible until this
3972              point.  However, the script is careful to  restrict  changes  to
3973              the file only to a group marked by the lines `# Lines configured
3974              by zsh-newuser-install'  and  `#  End  of  lines  configured  by
3975              zsh-newuser-install'.  In addition, the old version of .zshrc is
3976              saved to a file with the suffix .zni appended.
3977
3978              If the function edits an existing .zshrc, it is up to  the  user
3979              to  ensure that the changes made will take effect.  For example,
3980              if control usually returns early from the  existing  .zshrc  the
3981              lines  will  not be executed; or a later initialization file may
3982              override options or parameters, and so on.  The function  itself
3983              does not attempt to detect any such conflicts.
3984

OTHER FUNCTIONS

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