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

NAME

6       zshcontrib - user contributions to zsh
7

DESCRIPTION

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

UTILITIES

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

REMEMBERING RECENT DIRECTORIES

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

ABBREVIATED DYNAMIC REFERENCES TO DIRECTORIES

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

GATHERING INFORMATION FROM VERSION CONTROL SYSTEMS

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

PROMPT THEMES

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

ZLE FUNCTIONS

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

EXCEPTION HANDLING

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

MIME FUNCTIONS

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

MATHEMATICAL FUNCTIONS

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

USER CONFIGURATION FUNCTIONS

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

OTHER FUNCTIONS

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