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.5.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.5.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.5.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              http://bazaar.canonical.com/
766       Codeville (cdv)
767              http://freecode.com/projects/codeville/
768       Concurrent Versioning System (cvs)
769              http://www.nongnu.org/cvs/
770       Darcs (darcs)
771              http://darcs.net/
772       Fossil (fossil)
773              http://fossil-scm.org/
774       Git (git)
775              http://git-scm.com/
776       GNU arch (tla)
777              http://www.gnu.org/software/gnu-arch/
778       Mercurial (hg)
779              http://mercurial.selenic.com/
780       Monotone (mtn)
781              http://monotone.ca/
782       Perforce (p4)
783              http://www.perforce.com/
784       Subversion (svn)
785              http://subversion.apache.org/
786       SVK (svk)
787              http://svk.bestpractical.com/
788
789       There   is   also   support  for  the  patch  management  system  quilt
790       (http://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  the  opposite order, which mean that the
1525              first argument is the patch next-in-line to be  applied  and  so
1526              forth.
1527
1528              When  setting  ret  to  non-zero, the string in ${hook_com[unap‐
1529              plied-string]} will be available as %u in the  patch-format  and
1530              nopatch-format   styles.    This   hook   is,  in  concert  with
1531              set-patch-format, responsible for %-escaping that value for  use
1532              in the prompt.  (See the Oddities section.)
1533
1534       gen-mqguards-string
1535              Called  in  the  hg backend when guards-string is generated; the
1536              get-mq style must be true (default).
1537
1538              This hook gets the names of any active mq guards.
1539
1540              When    setting    ret    to    non-zero,    the    string    in
1541              ${hook_com[guards-string]}  will be used in the %g escape in the
1542              patch-format and nopatch-format styles.
1543
1544       no-vcs This  hooks  is  called  when  no  version  control  system  was
1545              detected.
1546
1547              The `hook_com' parameter is not used.
1548
1549       post-backend
1550              Called  as  soon as the backend has finished collecting informa‐
1551              tion.
1552
1553              The `hook_com' keys available are as for the set-message hook.
1554
1555       post-quilt
1556              Called after the quilt support is done. The  following  informa‐
1557              tion  is  passed  as arguments to the hook: 1. the quilt-support
1558              mode (`addon' or `standalone'); 2. the directory  that  contains
1559              the  patch  series;  3.  the directory that holds quilt's status
1560              information (the `.pc' directory) or the string "-nopc-" if that
1561              directory wasn't found.
1562
1563              The `hook_com' parameter is not used.
1564
1565       set-branch-format
1566              Called  before  `branchformat'  is set. The only argument to the
1567              hook is the format that is configured at this point.
1568
1569              The `hook_com' keys  considered  are  `branch'  and  `revision'.
1570              They  are  set  to the values figured out so far by vcs_info and
1571              any change will be used directly when the actual replacement  is
1572              done.
1573
1574              If    ret    is    set    to    non-zero,    the    string    in
1575              ${hook_com[branch-replace]} will be used unchanged as  the  `%b'
1576              replacement in the variables set by vcs_info.
1577
1578       set-hgrev-format
1579              Called  before  a `hgrevformat' is set. The only argument to the
1580              hook is the format that is configured at this point.
1581
1582              The `hook_com' keys considered are `hash' and `localrev'.   They
1583              are  set  to  the  values figured out so far by vcs_info and any
1584              change will be used directly  when  the  actual  replacement  is
1585              done.
1586
1587              If    ret    is    set    to    non-zero,    the    string    in
1588              ${hook_com[rev-replace]} will be  used  unchanged  as  the  `%i'
1589              replacement in the variables set by vcs_info.
1590
1591       pre-addon-quilt
1592              This  hook is used when vcs_info's quilt functionality is active
1593              in "addon" mode (quilt used on top of  a  real  version  control
1594              system).  It is activated right before any quilt specific action
1595              is taken.
1596
1597              Setting the `ret' variable in this  hook  to  a  non-zero  value
1598              avoids any quilt specific actions from being run at all.
1599
1600       set-patch-format
1601              This  hook is used to control some of the possible expansions in
1602              patch-format and nopatch-format styles with patch queue  systems
1603              such as quilt, mqueue and the like.
1604
1605              This hook is used in the git, hg and quilt backends.
1606
1607              The hook allows the control of the %p (${hook_com[applied]}) and
1608              %u (${hook_com[unapplied]}) expansion in all backends  that  use
1609              the    hook.    With    the    mercurial    backend,    the   %g
1610              (${hook_com[guards]}) expansion is controllable in  addition  to
1611              that.
1612
1613              If    ret    is    set    to    non-zero,    the    string    in
1614              ${hook_com[patch-replace]} will be used unchanged instead of  an
1615              expanded format from patch-format or nopatch-format.
1616
1617              This   hook  is,  in  concert  with  the  gen-applied-string  or
1618              gen-unapplied-string hooks if they are defined, responsible  for
1619              %-escaping  the  final patch-format value for use in the prompt.
1620              (See the Oddities section.)
1621
1622       set-message
1623              Called each time before a `vcs_info_msg_N_' message is set.   It
1624              takes  two  arguments;  the  first  being the `N' in the message
1625              variable name, the second is the currently configured formats or
1626              actionformats.
1627
1628              There  are  a  number  of  `hook_com'  keys, that are used here:
1629              `action', `branch',  `base',  `base-name',  `subdir',  `staged',
1630              `unstaged',  `revision', `misc', `vcs' and one `miscN' entry for
1631              each backend-specific data field (N starting at zero). They  are
1632              set  to the values figured out so far by vcs_info and any change
1633              will be used directly when the actual replacement is done.
1634
1635              Since this hook is triggered multiple times (once for each  con‐
1636              figured  formats  or actionformats), each of the `hook_com' keys
1637              mentioned above (except for the miscN entries)  has  an  `_orig'
1638              counterpart,  so  even if you changed a value to your liking you
1639              can still get the original value in the next run.  Changing  the
1640              `_orig' values is probably not a good idea.
1641
1642              If  ret  is  set to non-zero, the string in ${hook_com[message]}
1643              will be used unchanged as the message by vcs_info.
1644
1645       If all of this sounds rather confusing, take a  look  at  the  Examples
1646       section  below  and  also in the Misc/vcs_info-examples file in the Zsh
1647       source.  They contain some explanatory code.
1648
1649   Examples
1650       Don't use vcs_info at all (even though it's in your prompt):
1651              zstyle ':vcs_info:*' enable NONE
1652
1653       Disable the backends for bzr and svk:
1654              zstyle ':vcs_info:*' disable bzr svk
1655
1656       Disable everything but bzr and svk:
1657              zstyle ':vcs_info:*' enable bzr svk
1658
1659       Provide a special formats for git:
1660              zstyle ':vcs_info:git:*' formats       ' GIT, BABY! [%b]'
1661              zstyle ':vcs_info:git:*' actionformats ' GIT ACTION! [%b|%a]'
1662
1663       All %x expansion in  all  sorts  of  formats  (formats,  actionformats,
1664       branchformat,  you  name  it) are done using the `zformat' builtin from
1665       the `zsh/zutil' module. That means you can do everything with these  %x
1666       items  what zformat supports. In particular, if you want something that
1667       is really long to have a fixed  width,  like  a  hash  in  a  mercurial
1668       branchformat, you can do this: %12.12i. That'll shrink the 40 character
1669       hash to its 12 leading characters. The form  is  actually  `%min.maxx'.
1670       More  is  possible.   See the section `The zsh/zutil Module' in zshmod‐
1671       ules(1) for details.
1672
1673       Use the quicker bzr backend
1674              zstyle ':vcs_info:bzr:*' use-simple true
1675
1676       If   you   do   use   use-simple,   please   report    if    it    does
1677       `the-right-thing[tm]'.
1678
1679       Display the revision number in yellow for bzr and svn:
1680              zstyle ':vcs_info:(svn|bzr):*' \
1681                     branchformat '%b%{'${fg[yellow]}'%}:%r'
1682
1683       If you want colors, make sure you enclose the color codes in %{...%} if
1684       you want to use the string provided by vcs_info in prompts.
1685
1686       Here is how to print the  VCS  information  as  a  command  (not  in  a
1687       prompt):
1688              alias vcsi='vcs_info command; vcs_info_lastmsg'
1689
1690       This  way,  you  can  even  define  different  formats  for  output via
1691       vcs_info_lastmsg in the ':vcs_info:*:command:*' namespace.
1692
1693       Now as promised, some code that uses hooks: say, you'd like to  replace
1694       the string `svn' by `subversion' in vcs_info's %s formats replacement.
1695
1696       First,  we  will  tell  vcs_info to call a function when populating the
1697       message variables with the gathered information:
1698              zstyle ':vcs_info:*+set-message:*' hooks svn2subversion
1699
1700       Nothing happens. Which is reasonable, since we didn't define the actual
1701       function  yet.  To see what the hooks subsystem is trying to do, enable
1702       the `debug' style:
1703              zstyle ':vcs_info:*+*:*' debug true
1704
1705       That should give you an idea what is going on. Specifically, the  func‐
1706       tion  that we are looking for is `+vi-svn2subversion'. Note, the `+vi-'
1707       prefix. So, everything is in order, just as documented.  When  you  are
1708       done checking out the debugging output, disable it again:
1709              zstyle ':vcs_info:*+*:*' debug false
1710
1711       Now, let's define the function:
1712              function +vi-svn2subversion() {
1713                  [[ ${hook_com[vcs_orig]} == svn ]] && hook_com[vcs]=subversion
1714              }
1715
1716       Simple enough. And it could have even been simpler, if only we had reg‐
1717       istered our function in a less generic context. If we do it only in the
1718       `svn' backend's context, we don't need to test which the active backend
1719       is:
1720              zstyle ':vcs_info:svn+set-message:*' hooks svn2subversion
1721              function +vi-svn2subversion() {
1722                  hook_com[vcs]=subversion
1723              }
1724
1725       And finally a little more elaborate example, that uses a hook to create
1726       a customised bookmark string for the hg backend.
1727
1728       Again, we start off by registering a function:
1729              zstyle ':vcs_info:hg+gen-hg-bookmark-string:*' hooks hgbookmarks
1730
1731       And then we define the `+vi-hgbookmarks' function:
1732              function +vi-hgbookmarks() {
1733                  # The default is to connect all bookmark names by
1734                  # commas. This mixes things up a little.
1735                  # Imagine, there's one type of bookmarks that is
1736                  # special to you. Say, because it's *your* work.
1737                  # Those bookmarks look always like this: "sh/*"
1738                  # (because your initials are sh, for example).
1739                  # This makes the bookmarks string use only those
1740                  # bookmarks. If there's more than one, it
1741                  # concatenates them using commas.
1742                  # The bookmarks returned by `hg' are available in
1743                  # the function's positional parameters.
1744                  local s="${(Mj:,:)@:#sh/*}"
1745                  # Now, the communication with the code that calls
1746                  # the hook functions is done via the hook_com[]
1747                  # hash. The key at which the `gen-hg-bookmark-string'
1748                  # hook looks is `hg-bookmark-string'. So:
1749                  hook_com[hg-bookmark-string]=$s
1750                  # And to signal that we want to use the string we
1751                  # just generated, set the special variable `ret' to
1752                  # something other than the default zero:
1753                  ret=1
1754                  return 0
1755              }
1756
1757       Some longer examples and code snippets which might be useful are avail‐
1758       able in the examples file located at Misc/vcs_info-examples in the  Zsh
1759       source directory.
1760
1761       This concludes our guided tour through zsh's vcs_info.
1762

PROMPT THEMES

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

ZLE FUNCTIONS

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

EXCEPTION HANDLING

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

MIME FUNCTIONS

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

MATHEMATICAL FUNCTIONS

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

USER CONFIGURATION FUNCTIONS

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

OTHER FUNCTIONS

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