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

REMEMBERING RECENT DIRECTORIES

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

GATHERING INFORMATION FROM VERSION CONTROL SYSTEMS

521       In  a  lot  of  cases, it is nice to automatically retrieve information
522       from version control systems (VCSs), such as subversion, CVS or git, to
523       be  able  to  provide it to the user; possibly in the user's prompt. So
524       that you can instantly tell which branch  you  are  currently  on,  for
525       example.
526
527       In order to do that, you may use the vcs_info function.
528
529       The following VCSs are supported, showing the abbreviated name by which
530       they are referred to within the system:
531       Bazaar (bzr)
532              http://bazaar-vcs.org/
533       Codeville (cdv)
534              http://codeville.org/
535       Concurrent Versioning System (cvs)
536              http://www.nongnu.org/cvs/
537       Darcs (darcs)
538              http://darcs.net/
539       Fossil (fossil)
540              http://fossil-scm.org/
541       Git (git)
542              http://git-scm.com/
543       GNU arch (tla)
544              http://www.gnu.org/software/gnu-arch/
545       Mercurial (hg)
546              http://mercurial.selenic.com/
547       Monotone (mtn)
548              http://monotone.ca/
549       Perforce (p4)
550              http://www.perforce.com/
551       Subversion (svn)
552              http://subversion.tigris.org/
553       SVK (svk)
554              http://svk.bestpractical.com/
555
556       There  is  also  support  for  the  patch   management   system   quilt
557       (http://savannah.nongnu.org/projects/quilt).  See  Quilt  Support below
558       for details.
559
560       To load vcs_info:
561
562              autoload -Uz vcs_info
563
564       It can be used in any existing prompt, because it does not require  any
565       $psvar entries to be left available.
566
567   Quickstart
568       To  get this feature working quickly (including colors), you can do the
569       following (assuming, you loaded vcs_info properly - see above):
570
571              zstyle ':vcs_info:*' actionformats \
572                  '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f '
573              zstyle ':vcs_info:*' formats       \
574                  '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{5}]%f '
575              zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r'
576              precmd () { vcs_info }
577              PS1='%F{5}[%F{2}%n%F{5}] %F{3}%3~ ${vcs_info_msg_0_}%f%# '
578
579       Obviously, the last two lines are there for demonstration. You need  to
580       call  vcs_info  from your precmd function. Once that is done you need a
581       single quoted '${vcs_info_msg_0_}' in your prompt.
582
583       To be able to use '${vcs_info_msg_0_}' directly  in  your  prompt  like
584       this, you will need to have the PROMPT_SUBST option enabled.
585
586       Now call the vcs_info_printsys utility from the command line:
587
588              % vcs_info_printsys
589              ## list of supported version control backends:
590              ## disabled systems are prefixed by a hash sign (#)
591              bzr
592              cdv
593              cvs
594              darcs
595              fossil
596              git
597              hg
598              mtn
599              p4
600              svk
601              svn
602              tla
603              ## flavours (cannot be used in the enable or disable styles; they
604              ## are enabled and disabled with their master [git-svn -> git])
605              ## they *can* be used in contexts: ':vcs_info:git-svn:*'.
606              git-p4
607              git-svn
608              hg-git
609              hg-hgsubversion
610              hg-hgsvn
611
612       You  may not want all of these because there is no point in running the
613       code to detect systems you do not use.  So there is a  way  to  disable
614       some backends altogether:
615
616              zstyle ':vcs_info:*' disable bzr cdv darcs mtn svk tla
617
618       You may also pick a few from that list and enable only those:
619
620              zstyle ':vcs_info:*' enable git cvs svn
621
622       If  you  rerun  vcs_info_printsys after one of these commands, you will
623       see the backends listed in the disable style (or backends  not  in  the
624       enable  style  -  if  you used that) marked as disabled by a hash sign.
625       That means the detection of these systems  is  skipped  completely.  No
626       wasted time there.
627
628   Configuration
629       The vcs_info feature can be configured via zstyle.
630
631       First, the context in which we are working:
632              :vcs_info:vcs-string:user-context:repo-root-name
633
634       vcs-string
635              is  one  of:  git, git-svn, git-p4, hg, hg-git, hg-hgsubversion,
636              hg-hgsvn, darcs, bzr, cdv, mtn, svn, cvs, svk, tla, p4  or  fos‐
637              sil.  When hooks are active the hooks name is added after a `+'.
638              (See Hooks in vcs_info below.)
639
640       user-context
641              is a freely configurable string, assignable by the user  as  the
642              first argument to vcs_info (see its description below).
643
644       repo-root-name
645              is  the name of a repository in which you want a style to match.
646              So, if you want a setting specific to  /usr/src/zsh,  with  that
647              being  a CVS checkout, you can set repo-root-name to zsh to make
648              it so.
649
650       There are three special values  for  vcs-string:  The  first  is  named
651       -init-,  that  is  in  effect as long as there was no decision what VCS
652       backend to use. The second is -preinit-; it is used before vcs_info  is
653       run,  when initializing the data exporting variables. The third special
654       value is formats and is used by the vcs_info_lastmsg for looking up its
655       styles.
656
657       The  initial  value  of repo-root-name is -all- and it is replaced with
658       the actual name, as soon as it is known. Only use this part of the con‐
659       text for defining the formats, actionformats or branchformat styles, as
660       it is guaranteed that repo-root-name is  set  up  correctly  for  these
661       only. For all other styles, just use '*' instead.
662
663       There are two pre-defined values for user-context:
664       default
665              the one used if none is specified
666       command
667              used by vcs_info_lastmsg to lookup its styles
668
669       You  can of course use ':vcs_info:*' to match all VCSs in all user-con‐
670       texts at once.
671
672       This is a description of all styles that are looked up.
673
674       formats
675              A list of formats, used when actionformats is not used (which is
676              most of the time).
677
678       actionformats
679              A list of formats, used if there is a special action going on in
680              your current repository; like an interactive rebase or  a  merge
681              conflict.
682
683       branchformat
684              Some backends replace %b in the formats and actionformats styles
685              above, not only by a branch name but also by a revision  number.
686              This style lets you modify how that string should look.
687
688       nvcsformats
689              These  "formats"  are  exported  when we didn't detect a version
690              control system for the current directory or  vcs_info  was  dis‐
691              abled.  This  is  useful if you want vcs_info to completely take
692              over the generation of your prompt. You would do something  like
693              PS1='${vcs_info_msg_0_}' to accomplish that.
694
695       hgrevformat
696              hg  uses  both  a hash and a revision number to reference a spe‐
697              cific changeset in a repository. With this style you can  format
698              the  revision  string  (see  branchformat)  to include either or
699              both. It's only useful when get-revision is true. Note, the full
700              40-character revision id is not available (except when using the
701              use-simple option) because  executing  hg  more  than  once  per
702              prompt is too slow; you may customize this behavior using hooks.
703
704       max-exports
705              Defines the maximum number of vcs_info_msg_*_ variables vcs_info
706              will export.
707
708       enable A list of backends you want to use. Checked in the  -init-  con‐
709              text.  If  this  list contains an item called NONE no backend is
710              used at all and vcs_info will do nothing. If this list  contains
711              ALL,  vcs_info  will  use  all  known backends. Only with ALL in
712              enable will the disable style have any effect. ALL and NONE  are
713              case insensitive.
714
715       disable
716              A  list of VCSs you don't want vcs_info to test for repositories
717              (checked in the -init- context, too). Only used if  enable  con‐
718              tains ALL.
719
720       disable-patterns
721              A  list  of patterns that are checked against $PWD. If a pattern
722              matches, vcs_info will be disabled. This style is checked in the
723              :vcs_info:-init-:*:-all- context.
724
725              Say,  ~/.zsh  is a directory under version control, in which you
726              do not want vcs_info to be active, do:
727                     zstyle ':vcs_info:*' disable-patterns "$HOME/.zsh(|/*)"
728
729       use-quilt
730              If enabled, the quilt support code is active  in  `addon'  mode.
731              See Quilt Support for details.
732
733       quilt-standalone
734              If  enabled,  `standalone' mode detection is attempted if no VCS
735              is active in a given directory. See Quilt Support for details.
736
737       quilt-patch-dir
738              Overwrite the value of the $QUILT_PATCHES environment  variable.
739              See Quilt Support for details.
740
741       quiltcommand
742              When  quilt  itself is called in quilt support the value of this
743              style is used as the command name.
744
745       check-for-changes
746              If enabled, this style causes the %c and %u  format  escapes  to
747              show  when  the  working  directory has uncommitted changes. The
748              strings displayed by these escapes can  be  controlled  via  the
749              stagedstr  and  unstagedstr  styles. The only backends that cur‐
750              rently support this option are git  and  hg  (hg  only  supports
751              unstaged).
752
753              For  this  style  to  be  evaluated  with  the  hg  backend, the
754              get-revision style needs to be  set  and  the  use-simple  style
755              needs to be unset. The latter is the default; the former is not.
756
757              Note, the actions taken if this style is enabled are potentially
758              expensive (read: they may be slow, depending on how big the cur‐
759              rent repository is).  Therefore, it is disabled by default.
760
761       stagedstr
762              This  string  will  be used in the %c escape if there are staged
763              changes in the repository.
764
765       unstagedstr
766              This string will be used in the %u escape if there are  unstaged
767              changes in the repository.
768
769       command
770              This  style  causes  vcs_info  to use the supplied string as the
771              command to use as the VCS's binary. Note, that setting  this  in
772              ':vcs_info:*' is not a good idea.
773
774              If  the value of this style is empty (which is the default), the
775              used binary name is the name of the backend in use (e.g. svn  is
776              used in an svn repository).
777
778              The  repo-root-name  part  in  the context is always the default
779              -all- when this style is looked up.
780
781              For example, this  style  can  be  used  to  use  binaries  from
782              non-default  installation  directories. Assume, git is installed
783              in /usr/bin but your  sysadmin  installed  a  newer  version  in
784              /usr/bin/local.  Instead  of  changing  the  order of your $PATH
785              parameter, you can do this:
786                     zstyle ':vcs_info:git:*:-all-' command /usr/local/bin/git
787
788       use-server
789              This is used by the Perforce backend (p4) to decide if it should
790              contact  the  Perforce server to find out if a directory is man‐
791              aged by Perforce.  This is the only reliable way of doing  this,
792              but runs the risk of a delay if the server name cannot be found.
793              If the server (more specifically, the host:port pair  describing
794              the  server) cannot be contacted, its name is put into the asso‐
795              ciative array  vcs_info_p4_dead_servers  and  is  not  contacted
796              again during the session until it is removed by hand.  If you do
797              not set this style, the p4 backend is only usable  if  you  have
798              set  the  environment  variable P4CONFIG to a file name and have
799              corresponding files in the root  directories  of  each  Perforce
800              client.   See  comments  in  the function VCS_INFO_detect_p4 for
801              more detail.
802
803       use-simple
804              If there are two different ways of  gathering  information,  you
805              can  select  the  simpler one by setting this style to true; the
806              default is to use the not-that-simple code, which is potentially
807              a  lot  slower but might be more accurate in all possible cases.
808              This style is used by the bzr and hg backends. In the case of hg
809              it  will invoke the external hexdump program to parse the binary
810              dirstate cache file; this method will not return the local revi‐
811              sion number.
812
813       get-revision
814              If  set  to true, vcs_info goes the extra mile to figure out the
815              revision of a repository's work tree (currently for the git  and
816              hg  backends,  where  this  kind  of  information  is not always
817              vital). For git, the hash value of  the  currently  checked  out
818              commit  is  available  via  the %i expansion. With hg, the local
819              revision number and the corresponding global hash are  available
820              via %i.
821
822       get-mq If  set  to true, the hg backend will look for a Mercurial Queue
823              (mq) patch directory. Information will be available via the `%m'
824              replacement.
825
826       get-bookmarks
827              If set to true, the hg backend will try to get a list of current
828              bookmarks. They will be available via the `%m' replacement.
829
830       use-prompt-escapes
831              Determines if we assume that the assembled string from  vcs_info
832              includes prompt escapes. (Used by vcs_info_lastmsg.)
833
834       debug  Enable  debugging  output  to track possible problems. Currently
835              this style is only used by vcs_info's hooks system.
836
837       hooks  A list style that defines  hook-function  names.  See  Hooks  in
838              vcs_info below for details.
839
840       The default values for these styles in all contexts are:
841
842       formats
843              " (%s)-[%b]%u%c-"
844       actionformats
845              " (%s)-[%b|%a]%u%c-"
846       branchformat
847              "%b:%r" (for bzr, svn, svk and hg)
848       nvcsformats
849              ""
850       hgrevformat
851              "%r:%h"
852       max-exports
853              2
854       enable ALL
855       disable
856              (empty list)
857       disable-patterns
858              (empty list)
859       check-for-changes
860              false
861       stagedstr
862              (string: "S")
863       unstagedstr
864              (string: "U")
865       command
866              (empty string)
867       use-server
868              false
869       use-simple
870              false
871       get-revision
872              false
873       get-mq true
874       get-bookmarks
875              false
876       use-prompt-escapes
877              true
878       debug  false
879       hooks  (empty list)
880       use-quilt
881              false
882       quilt-standalone
883              false
884       quilt-patch-dir
885              empty - use $QUILT_PATCHES
886       quiltcommand
887              quilt
888
889       In  normal  formats  and  actionformats  the following replacements are
890       done:
891
892       %s     The VCS in use (git, hg, svn, etc.).
893       %b     Information about the current branch.
894       %a     An identifier that describes the action.  Only  makes  sense  in
895              actionformats.
896       %i     The  current revision number or identifier. For hg the hgrevfor‐
897              mat style may be used to customize the output.
898       %c     The string from the stagedstr style if there are staged  changes
899              in the repository.
900       %u     The  string  from  the  unstagedstr  style if there are unstaged
901              changes in the repository.
902       %R     The base directory of the repository.
903       %r     The repository name. If %R is /foo/bar/repoXY, %r is repoXY.
904       %S     A   subdirectory   within   a    repository.    If    $PWD    is
905              /foo/bar/repoXY/beer/tasty, %S is beer/tasty.
906       %m     A  "misc" replacement. It is at the discretion of the backend to
907              decide what this replacement expands to. It is currently used by
908              the hg and git backends to display patch information from the mq
909              and stgit extensions.
910
911       In branchformat these replacements are done:
912
913       %b     The branch name.
914       %r     The current revision number or the hgrevformat style for hg.
915
916       In hgrevformat these replacements are done:
917
918       %r     The current local revision number.
919       %h     The current global revision identifier.
920
921       In patch-format and nopatch-format these replacements are done:
922
923       %p     The name of the top-most applied patch (applied-string).
924       %u     The number of unapplied patches (unapplied-string).
925       %n     The number of applied patches.
926       %c     The number of unapplied patches.
927       %a     The number of all patches.
928       %g     The names of active mq guards (hg backend).
929       %G     The number of active mq guards (hg backend).
930
931       Not all VCS backends have to support all replacements. For  nvcsformats
932       no replacements are performed at all, it is just a string.
933
934   Oddities
935       If you want to use the %b (bold off) prompt expansion in formats, which
936       expands %b itself, use %%b. That will cause the vcs_info  expansion  to
937       replace  %%b with %b, so that zsh's prompt expansion mechanism can han‐
938       dle it. Similarly, to hand down %b from branchformat, use %%%%b.  Sorry
939       for  this inconvenience, but it cannot be easily avoided. Luckily we do
940       not clash with a lot of prompt expansions and this  only  needs  to  be
941       done for those.
942
943   Quilt Support
944       Quilt  is  not  a  version control system, therefore this is not imple‐
945       mented as a backend. It can help keeping track of a series of  patches.
946       People use it to keep a set of changes they want to use on top of soft‐
947       ware packages (which is  tightly  integrated  into  the  package  build
948       process - the Debian project does this for a large number of packages).
949       Quilt can also help individual  developers  keep  track  of  their  own
950       patches on top of real version control systems.
951
952       The  vcs_info  integration tries to support both ways of using quilt by
953       having two slightly different modes  of  operation:  `addon'  mode  and
954       `standalone' mode).
955
956       For `addon' mode to become active vcs_info must have already detected a
957       real version control system controlling the directory. If that  is  the
958       case,  a  directory  that holds quilt's patches needs to be found. That
959       directory is configurable via the `QUILT_PATCHES' environment variable.
960       If  that  variable  exists  its  value  is  used,  otherwise  the value
961       `patches' is assumed. The value from $QUILT_PATCHES can be  overwritten
962       using  the  `quilt-patches'  style. (Note: you can use vcs_info to keep
963       the value of $QUILT_PATCHES correct all the  time  via  the  post-quilt
964       hook).
965
966       When the directory in question is found, quilt is assumed to be active.
967       To gather more information,  vcs_info  looks  for  a  directory  called
968       `.pc';  Quilt  uses  that directory to track its current state. If this
969       directory does not exist we know that quilt has not  done  anything  to
970       the working directory (read: no patches have been applied yet).
971
972       If  patches  are  applied,  vcs_info will try to find out which. If you
973       want to know which patches of a series are not yet applied, you need to
974       activate the get-unapplied style in the appropriate context.
975
976       vcs_info  allows for very detailed control over how the gathered infor‐
977       mation is presented (see  the  below  sections,  Styles  and  Hooks  in
978       vcs_info),  all  of which are documented below. Note there are a number
979       of other patch tracking systems that work on top of a  certain  version
980       control  system  (like  stgit for git, or mq for hg); the configuration
981       for systems like that are generally configured  the  same  way  as  the
982       quilt support.
983
984       If the quilt support is working in `addon' mode, the produced string is
985       available as a simple format replacement (%Q to be precise), which  can
986       be used in formats and actionformats; see below for details).
987
988       If,  on  the  other  hand,  the support code is working in `standalone'
989       mode, vcs_info will pretend as if quilt were an actual version  control
990       system.  That  means  that the version control system identifier (which
991       otherwise would be something like  `svn'  or  `cvs')  will  be  set  to
992       `-quilt-'.  This  has implications on the used style context where this
993       identifier is the second element. vcs_info will have filled in a proper
994       value  for  the "repository's" root directory and the string containing
995       the information about quilt's state will be  available  as  the  `misc'
996       replacement (and %Q for compatibility with `addon' mode.
997
998       What  is  left  to  discuss  is  how `standalone' mode is detected. The
999       detection itself is a series of searches for directories. You can  have
1000       this detection enabled all the time in every directory that is not oth‐
1001       erwise under version control. If you know there is only a  limited  set
1002       of  trees  where  you  would like vcs_info to try and look for Quilt in
1003       `standalone' mode to minimise the amount of searching on every call  to
1004       vcs_info, there are a number of ways to do that:
1005
1006       Essentially,  `standalone'  mode  detection  is  controlled  by a style
1007       called `quilt-standalone'. It is a string style and its value can  have
1008       different  effects.  The simplest values are: `always' to run detection
1009       every time vcs_info is run, and  `never'  to  turn  the  detection  off
1010       entirely.
1011
1012       If  the  value of quilt-standalone is something else, it is interpreted
1013       differently. If the value is the name of a scalar variable the value of
1014       that   variable  is  checked  and  that  value  is  used  in  the  same
1015       `always'/`never' way as described above.
1016
1017       If the value of quilt-standalone is an  array,  the  elements  of  that
1018       array are used as directory names under which you want the detection to
1019       be active.
1020
1021       If quilt-standalone is an associative array,  the  keys  are  taken  as
1022       directory  names  under  which you want the detection to be active, but
1023       only if the corresponding value is the string `true'.
1024
1025       Last, but not least, if the value of quilt-standalone is the name of  a
1026       function, the function is called without arguments and the return value
1027       decides whether detection should be active. A `0' return value is true;
1028       a non-zero return value is interpreted as false.
1029
1030       Note,  if  there  is  both  a  function  and  a variable by the name of
1031       quilt-standalone, the function will take precedence.
1032
1033   Function Descriptions (Public API)
1034       vcs_info [user-context]
1035              The main function, that runs all backends and assembles all data
1036              into  ${vcs_info_msg_*_}.  This is the function you want to call
1037              from precmd if you want to  include  up-to-date  information  in
1038              your  prompt (see Variable description below). If an argument is
1039              given, that string will  be  used  instead  of  default  in  the
1040              user-context field of the style context.
1041
1042       vcs_info_hookadd
1043              Statically  registers a number of functions to a given hook. The
1044              hook needs to be given as the first argument; what follows is  a
1045              list  of hook-function names to register to the hook. The `+vi-'
1046              prefix needs to be left out here. See Hooks  in  vcs_info  below
1047              for details.
1048
1049       vcs_info_hookdel
1050              Remove  hook-functions  from  a given hook. The hook needs to be
1051              given as the first non-option argument; what follows is  a  list
1052              of  hook-function names to un-register from the hook. If `-a' is
1053              used as the first argument, all occurances of the functions  are
1054              unregistered. Otherwise only the last occurance is removed (if a
1055              function was registered to a hook more than once) .  The  `+vi-'
1056              prefix  needs  to  be left out here. See Hooks in vcs_info below
1057              for details.
1058
1059       vcs_info_lastmsg
1060              Outputs the last ${vcs_info_msg_*_} value.  Takes  into  account
1061              the  value  of  the  use-prompt-escapes style in ':vcs_info:for‐
1062              mats:command:-all-'. It also only prints max-exports values.
1063
1064       vcs_info_printsys [user-context]
1065              Prints a list of all supported version control  systems.  Useful
1066              to find out possible contexts (and which of them are enabled) or
1067              values for the disable style.
1068
1069       vcs_info_setsys
1070              Initializes vcs_info's internal list of available backends. With
1071              this function, you can add support for new VCSs without restart‐
1072              ing the shell.
1073
1074       All functions named VCS_INFO_* are for internal use only.
1075
1076   Variable Description
1077       ${vcs_info_msg_N_} (Note the trailing underscore)
1078              Where N is an integer, e.g.,  vcs_info_msg_0_.  These  variables
1079              are  the storage for the informational message the last vcs_info
1080              call has assembled. These are strongly connected to the formats,
1081              actionformats  and  nvcsformats  styles  described  above. Those
1082              styles are lists. The first member of that  list  gets  expanded
1083              into  ${vcs_info_msg_0_}, the second into ${vcs_info_msg_1_} and
1084              the Nth into ${vcs_info_msg_N-1_}. These parameters are exported
1085              into the environment. (See the max-exports style above.)
1086
1087       All variables named VCS_INFO_* are for internal use only.
1088
1089   Hooks in vcs_info
1090       Hooks are places in vcs_info where you can run your own code. That code
1091       can communicate with the code that called it and through  that,  change
1092       the system's behaviour.
1093
1094       For configuration, hooks change the style context:
1095              :vcs_info:vcs-string+hook-name:user-context:repo-root-name
1096
1097       To  register  functions  to  a hook, you need to list them in the hooks
1098       style in the appropriate context.
1099
1100       Example:
1101              zstyle ':vcs_info:*+foo:*' hooks bar baz
1102
1103       This registers functions to the hook `foo' for all backends.  In  order
1104       to   avoid  namespace  problems,  all  registered  function  names  are
1105       prepended by a `+vi-', so the actual functions  called  for  the  `foo'
1106       hook are `+vi-bar' and `+vi-baz'.
1107
1108       If  you  would  like to register a function to a hook regardless of the
1109       current context, you may use the vcs_info_hookadd function. To remove a
1110       function that was added like that, the vcs_info_hookdel function can be
1111       used.
1112
1113       If something seems weird, you can enable the `debug' boolean  style  in
1114       the  proper  context and the hook-calling code will print what it tried
1115       to execute and whether the function in question existed.
1116
1117       When you register more than one function to a hook, all  functions  are
1118       executed one after another until one function returns non-zero or until
1119       all functions have been called. Context-sensitive  hook  functions  are
1120       executed   before   statically  registered  ones  (the  ones  added  by
1121       vcs_info_hookadd).
1122
1123       You  may  pass  data  between  functions  via  an  associative   array,
1124       user_data.  For example:
1125              +vi-git-myfirsthook(){
1126                  user_data[myval]=$myval
1127              }
1128              +vi-git-mysecondhook(){
1129                  # do something with ${user_data[myval]}
1130              }
1131
1132       There are a number of variables that are special in hook contexts:
1133
1134       ret    The  return value that the hooks system will return to the call‐
1135              er. The default is an integer `zero'. If and how a  changed  ret
1136              value  changes  the  execution of the caller depends on the spe‐
1137              cific hook. See the hook documentation below for details.
1138
1139       hook_com
1140              An associated array which is used for  bidirectional  communica‐
1141              tion  from the caller to hook functions. The used keys depend on
1142              the specific hook.
1143
1144       context
1145              The active context of the hook. Functions that  wish  to  change
1146              this variable should make it local scope first.
1147
1148       vcs    The current VCS after it was detected. The same values as in the
1149              enable/disable style are used. Available  in  all  hooks  except
1150              start-up.
1151
1152       Finally, the full list of currently available hooks:
1153
1154       start-up
1155              Called after starting vcs_info but before the VCS in this direc‐
1156              tory is determined. It can be used to deactivate vcs_info tempo‐
1157              rarily  if  necessary. When ret is set to 1, vcs_info aborts and
1158              does nothing; when set to 2, vcs_info sets up everything  as  if
1159              no version control were active and exits.
1160
1161       pre-get-data
1162              Same as start-up but after the VCS was detected.
1163
1164       gen-hg-bookmark-string
1165              Called in the Mercurial backend when a bookmark string is gener‐
1166              ated; the get-revision and get-bookmarks styles must be true.
1167
1168              This hook  gets  the  names  of  the  Mercurial  bookmarks  that
1169              vcs_info collected from `hg'.
1170
1171              When  setting ret to non-zero, the string in ${hook_com[hg-book‐
1172              mark-string]} will be used in  the  %m  escape  in  formats  and
1173              actionformats  and  will  be availabe in the global backend_misc
1174              array as ${backend_misc[bookmarks]}.
1175
1176       gen-applied-string
1177              Called in the git (with stgit), and hg (with mq) backends and in
1178              quilt   support   when  the  applied-string  is  generated;  the
1179              use-quilt zstyle must be true for quilt (the mq and stgit  back‐
1180              ends are active by default).
1181
1182              This  hook  gets the names of all applied patches which vcs_info
1183              collected so far in the opposite order,  which  means  that  the
1184              first argument is the top-most patch and so forth.
1185
1186              When    setting    ret    to    non-zero,    the    string    in
1187              ${hook_com[applied-string]} will be used in  the  %m  escape  in
1188              formats  and  actionformats;  it will be available in the global
1189              backend_misc array as $backend_misc[patches]}; and  it  will  be
1190              available as %p in the patch-format and nopatch-format styles.
1191
1192       gen-unapplied-string
1193              Called  in the git (with stgit), and hg (with mq) backend and in
1194              quilt  support  when  the  unapplied-string  is  generated;  the
1195              get-unapplied style must be true.
1196
1197              This hook gets the names of all unapplied patches which vcs_info
1198              collected so far in the opposite  order,  which  mean  that  the
1199              first  argument  is  the patch next-in-line to be applied and so
1200              forth.
1201
1202              When setting ret to non-zero,  the  string  in  ${hook_com[unap‐
1203              plied-string]}  will  be available as %u in the patch-format and
1204              nopatch-format styles.
1205
1206       gen-mqguards-string
1207              Called in the hg backend when guards-string  is  generated;  the
1208              get-mq style must be true (default).
1209
1210              This hook gets the names of any active mq guards.
1211
1212              When    setting    ret    to    non-zero,    the    string    in
1213              ${hook_com[guards-string]} will be used in the %g escape in  the
1214              patch-format and nopatch-format styles.
1215
1216       no-vcs This  hooks  is  called  when  no  version  control  system  was
1217              detected.
1218
1219              The `hook_com' parameter is not used.
1220
1221       post-quilt
1222              Called after the quilt support is done. The  following  informa‐
1223              tion  is  passed  as arguments to the hook: 1. the quilt-support
1224              mode (`addon' or `standalone'); 2. the directory  that  contains
1225              the  patch  series;  3.  the directory that holds quilt's status
1226              information (the `.pc' directory) or the string "-nopc-" if that
1227              directory wasn't found.
1228
1229              The `hook_com' parameter is not used.
1230
1231       set-branch-format
1232              Called  before  `branchformat'  is set. The only argument to the
1233              hook is the format that is configured at this point.
1234
1235              The `hook_com' keys  considered  are  `branch'  and  `revision'.
1236              They  are  set  to the values figured out so far by vcs_info and
1237              any change will be used directly when the actual replacement  is
1238              done.
1239
1240              If    ret    is    set    to    non-zero,    the    string    in
1241              ${hook_com[branch-replace]} will be used unchanged as  the  `%b'
1242              replacement in the variables set by vcs_info.
1243
1244       set-hgrev-format
1245              Called  before  a `hgrevformat' is set. The only argument to the
1246              hook is the format that is configured at this point.
1247
1248              The `hook_com' keys considered are `hash' and `localrev'.   They
1249              are  set  to  the  values figured out so far by vcs_info and any
1250              change will be used directly  when  the  actual  replacement  is
1251              done.
1252
1253              If    ret    is    set    to    non-zero,    the    string    in
1254              ${hook_com[rev-replace]} will be  used  unchanged  as  the  `%i'
1255              replacement in the variables set by vcs_info.
1256
1257       set-message
1258              Called  each time before a `vcs_info_msg_N_' message is set.  It
1259              takes two arguments; the first being  the  `N'  in  the  message
1260              variable name, the second is the currently configured formats or
1261              actionformats.
1262
1263              There are a number of  `hook_com'  keys,  that  are  used  here:
1264              `action',  `branch',  `base',  `base-name',  `subdir', `staged',
1265              `unstaged', `revision', `misc', `vcs' and one `miscN' entry  for
1266              each  backend-specific data field (N starting at zero). They are
1267              set to the values figured out so far by vcs_info and any  change
1268              will be used directly when the actual replacement is done.
1269
1270              Since  this hook is triggered multiple times (once for each con‐
1271              figured formats or actionformats), each of the  `hook_com'  keys
1272              mentioned  above  (except  for the miscN entries) has an `_orig'
1273              counterpart, so even if you changed a value to your  liking  you
1274              can  still  get the original value in the next run. Changing the
1275              `_orig' values is probably not a good idea.
1276
1277              If ret is set to non-zero, the  string  in  ${hook_com[message]}
1278              will be used unchanged as the message by vcs_info.
1279
1280       If  all  of  this  sounds rather confusing, take a look at the Examples
1281       section below and also in the Misc/vcs_info-examples file  in  the  Zsh
1282       source.  They contain some explanatory code.
1283
1284   Examples
1285       Don't use vcs_info at all (even though it's in your prompt):
1286              zstyle ':vcs_info:*' enable NONE
1287
1288       Disable the backends for bzr and svk:
1289              zstyle ':vcs_info:*' disable bzr svk
1290
1291       Disable everything but bzr and svk:
1292              zstyle ':vcs_info:*' enable bzr svk
1293
1294       Provide a special formats for git:
1295              zstyle ':vcs_info:git:*' formats       ' GIT, BABY! [%b]'
1296              zstyle ':vcs_info:git:*' actionformats ' GIT ACTION! [%b|%a]'
1297
1298       All  %x  expansion in all sorts of formats ("formats", "actionformats",
1299       branchformat, you name it) are done using the  `zformat'  builtin  from
1300       the  `zsh/zutil' module. That means you can do everything with these %x
1301       items what zformat supports. In particular, if you want something  that
1302       is  really  long  to  have  a  fixed  width, like a hash in a mercurial
1303       branchformat, you can do this: %12.12i. That'll shrink the 40 character
1304       hash  to  its  12 leading characters. The form is actually `%min.maxx'.
1305       More is possible.  See the section `The zsh/zutil  Module'  in  zshmod‐
1306       ules(1) for details.
1307
1308       Use the quicker bzr backend
1309              zstyle ':vcs_info:bzr:*' use-simple true
1310
1311       If    you    do    use   use-simple,   please   report   if   it   does
1312       `the-right-thing[tm]'.
1313
1314       Display the revision number in yellow for bzr and svn:
1315              zstyle ':vcs_info:(svn|bzr):*' branchformat '%b%{'${fg[yellow]}'%}:%r'
1316
1317       If you want colors, make sure you enclose the color codes in %{...%} if
1318       you want to use the string provided by vcs_info in prompts.
1319
1320       Here  is  how  to  print  the  VCS  information  as a command (not in a
1321       prompt):
1322              alias vcsi='vcs_info command; vcs_info_lastmsg'
1323
1324       This way,  you  can  even  define  different  formats  for  output  via
1325       vcs_info_lastmsg in the ':vcs_info:*:command:*' namespace.
1326
1327       Now  as promised, some code that uses hooks: say, you'd like to replace
1328       the string `svn' by `subversion' in vcs_info's %s formats replacement.
1329
1330       First, we will tell vcs_info to call a  function  when  populating  the
1331       message variables with the gathered information:
1332              zstyle ':vcs_info:*+set-message:*' hooks svn2subversion
1333
1334       Nothing happens. Which is reasonable, since we didn't define the actual
1335       function yet. To see what the hooks subsystem is trying to  do,  enable
1336       the `debug' style:
1337              zstyle ':vcs_info:*+*:*' debug true
1338
1339       That  should give you an idea what is going on. Specifically, the func‐
1340       tion that we are looking for is `+vi-svn2subversion'. Note, the  `+vi-'
1341       prefix.  So,  everything  is in order, just as documented. When you are
1342       done checking out the debugging output, disable it again:
1343              zstyle ':vcs_info:*+*:*' debug false
1344
1345       Now, let's define the function:
1346              function +vi-svn2subversion() {
1347                  [[ ${hook_com[vcs_orig]} == svn ]] && hook_com[vcs]=subversion
1348              }
1349
1350       Simple enough. And it could have even been simpler, if only we had reg‐
1351       istered our function in a less generic context. If we do it only in the
1352       `svn' backend's context, we don't need to test which the active backend
1353       is:
1354              zstyle ':vcs_info:svn+set-message:*' hooks svn2subversion
1355              function +vi-svn2subversion() {
1356                  hook_com[vcs]=subversion
1357              }
1358
1359       And finally a little more elaborate example, that uses a hook to create
1360       a customised bookmark string for the hg backend.
1361
1362       Again, we start off by registering a function:
1363              zstyle ':vcs_info:hg+gen-hg-bookmark-string:*' hooks hgbookmarks
1364
1365       And then we define the `+vi-hgbookmarks function:
1366              function +vi-hgbookmarks() {
1367                  # The default is to connect all bookmark names by
1368                  # commas. This mixes things up a little.
1369                  # Imagine, there's one type of bookmarks that is
1370                  # special to you. Say, because it's *your* work.
1371                  # Those bookmarks look always like this: "sh/*"
1372                  # (because your initials are sh, for example).
1373                  # This makes the bookmarks string use only those
1374                  # bookmarks. If there's more than one, it
1375                  # concatenates them using commas.
1376                  local s i
1377                  # The bookmarks returned by `hg' are available in
1378                  # the functions positional parameters.
1379                  (( $# == 0 )) && return 0
1380                  for i in "$@"; do
1381                      if [[ $i == sh/* ]]; then
1382                          [[ -n $s ]] && s=$s,
1383                          s=${s}$i
1384                      fi
1385                  done
1386                  # Now, the communication with the code that calls
1387                  # the hook functions is done via the hook_com[]
1388                  # hash. The key, at which the `gen-hg-bookmark-string'
1389                  # hook looks at is `hg-bookmark-string'. So:
1390                  hook_com[hg-bookmark-string]=$s
1391                  # And to signal, that we want to use the sting we
1392                  # just generated, set the special variable `ret' to
1393                  # something other than the default zero:
1394                  ret=1
1395                  return 0
1396              }
1397
1398       Some longer examples and code snippets which might be useful are avail‐
1399       able  in the examples file located at Misc/vcs_info-examples in the Zsh
1400       source directory.
1401
1402       This concludes our guided tour through zsh's vcs_info.
1403

PROMPT THEMES

1405   Installation
1406       You should make sure  all  the  functions  from  the  Functions/Prompts
1407       directory of the source distribution are available; they all begin with
1408       the string `prompt_' except for the special function`promptinit'.   You
1409       also  need  the  `colors'  function  from Functions/Misc.  All of these
1410       functions may already have been installed on your system; if  not,  you
1411       will  need  to find them and copy them.  The directory should appear as
1412       one of the elements of the fpath array (this should already be the case
1413       if they were installed), and at least the function promptinit should be
1414       autoloaded; it will autoload the rest.  Finally, to initialize the  use
1415       of  the system you need to call the promptinit function.  The following
1416       code in your .zshrc will arrange for this;  assume  the  functions  are
1417       stored in the directory ~/myfns:
1418
1419              fpath=(~/myfns $fpath)
1420              autoload -U promptinit
1421              promptinit
1422
1423   Theme Selection
1424       Use  the  prompt  command to select your preferred theme.  This command
1425       may be added to your .zshrc following the call to promptinit  in  order
1426       to start zsh with a theme already selected.
1427
1428       prompt [ -c | -l ]
1429       prompt [ -p | -h ] [ theme ... ]
1430       prompt [ -s ] theme [ arg ... ]
1431              Set  or  examine  the prompt theme.  With no options and a theme
1432              argument, the theme with that name is set as the current  theme.
1433              The  available  themes  are  determined  at run time; use the -l
1434              option to see a list.  The special  theme  `random'  selects  at
1435              random one of the available themes and sets your prompt to that.
1436
1437              In  some  cases  the  theme may be modified by one or more argu‐
1438              ments, which should be given after the theme name.  See the help
1439              for each theme for descriptions of these arguments.
1440
1441              Options are:
1442
1443              -c     Show  the currently selected theme and its parameters, if
1444                     any.
1445              -l     List all available prompt themes.
1446              -p     Preview the theme named by theme, or  all  themes  if  no
1447                     theme is given.
1448              -h     Show help for the theme named by theme, or for the prompt
1449                     function if no theme is given.
1450              -s     Set theme as the current theme and save state.
1451
1452       prompt_theme_setup
1453              Each available theme has a setup function which is called by the
1454              prompt function to install that theme.  This function may define
1455              other functions as necessary to maintain the  prompt,  including
1456              functions  used  to  preview  the prompt or provide help for its
1457              use.  You should not normally  call  a  theme's  setup  function
1458              directly.
1459

ZLE FUNCTIONS

1461   Widgets
1462       These  functions all implement user-defined ZLE widgets (see zshzle(1))
1463       which can be bound to keystrokes in interactive shells.  To  use  them,
1464       your .zshrc should contain lines of the form
1465
1466              autoload function
1467              zle -N function
1468
1469       followed  by  an  appropriate bindkey command to associate the function
1470       with a key sequence.  Suggested bindings are described below.
1471
1472       bash-style word functions
1473              If you are looking for functions to implement  moving  over  and
1474              editing  words  in  the  manner of bash, where only alphanumeric
1475              characters are considered word characters, you can use the func‐
1476              tions  described  in  the next section.  The following is suffi‐
1477              cient:
1478
1479                     autoload -U select-word-style
1480                     select-word-style bash
1481
1482       forward-word-match, backward-word-match
1483       kill-word-match, backward-kill-word-match
1484       transpose-words-match, capitalize-word-match
1485       up-case-word-match, down-case-word-match
1486       select-word-style, match-word-context, match-words-by-style
1487              The eight `-match' functions are drop-in  replacements  for  the
1488              builtin widgets without the suffix.  By default they behave in a
1489              similar way.  However, by the use of  styles  and  the  function
1490              select-word-style, the way words are matched can be altered.
1491
1492              The  simplest  way  of  configuring  the  functions  is  to  use
1493              select-word-style, which can either be called as a normal  func‐
1494              tion with the appropriate argument, or invoked as a user-defined
1495              widget that will prompt for the  first  character  of  the  word
1496              style  to  be  used.   The  first  time it is invoked, the eight
1497              -match functions will automatically  replace  the  builtin  ver‐
1498              sions, so they do not need to be loaded explicitly.
1499
1500              The  word styles available are as follows.  Only the first char‐
1501              acter is examined.
1502
1503              bash   Word characters are alphanumeric characters only.
1504
1505              normal As  in  normal  shell  operation:   word  characters  are
1506                     alphanumeric  characters  plus  any characters present in
1507                     the string given by the parameter $WORDCHARS.
1508
1509              shell  Words are  complete  shell  command  arguments,  possibly
1510                     including  complete quoted strings, or any tokens special
1511                     to the shell.
1512
1513              whitespace
1514                     Words are any set of characters delimited by whitespace.
1515
1516              default
1517                     Restore the default settings; this is usually the same as
1518                     `normal'.
1519
1520              All but `default' can be input as an upper case character, which
1521              has the same effect but with subword  matching  turned  on.   In
1522              this  case,  words  with  upper case characters are treated spe‐
1523              cially: each separate run of upper case characters, or an  upper
1524              case  character  followed  by any number of other characters, is
1525              considered a word.  The style subword-range can supply an alter‐
1526              native  character range to the default `[:upper:]'; the value of
1527              the style is treated as the contents of a `[...]' pattern  (note
1528              that  the outer brackets should not be supplied, only those sur‐
1529              rounding named ranges).
1530
1531              More control can  be  obtained  using  the  zstyle  command,  as
1532              described in zshmodules(1).  Each style is looked up in the con‐
1533              text :zle:widget where widget is the name  of  the  user-defined
1534              widget,  not the name of the function implementing it, so in the
1535              case of the definitions supplied by select-word-style the appro‐
1536              priate  contexts are :zle:forward-word, and so on.  The function
1537              select-word-style itself always defines styles for  the  context
1538              `:zle:*'  which can be overridden by more specific (longer) pat‐
1539              terns as well as explicit contexts.
1540
1541              The style word-style specifies the rules to use.  This may  have
1542              the following values.
1543
1544              normal Use  the  standard  shell  rules,  i.e. alphanumerics and
1545                     $WORDCHARS, unless overridden by the styles word-chars or
1546                     word-class.
1547
1548              specified
1549                     Similar to normal, but only the specified characters, and
1550                     not also alphanumerics, are considered word characters.
1551
1552              unspecified
1553                     The negation of  specified.   The  given  characters  are
1554                     those which will not be considered part of a word.
1555
1556              shell  Words  are obtained by using the syntactic rules for gen‐
1557                     erating shell command arguments.   In  addition,  special
1558                     tokens which are never command arguments such as `()' are
1559                     also treated as words.
1560
1561              whitespace
1562                     Words are whitespace-delimited strings of characters.
1563
1564              The first three of those rules usually use $WORDCHARS,  but  the
1565              value   in   the  parameter  can  be  overridden  by  the  style
1566              word-chars, which works in exactly the same way  as  $WORDCHARS.
1567              In addition, the style word-class uses character class syntax to
1568              group characters and takes precedence over  word-chars  if  both
1569              are  set.  The word-class style does not include the surrounding
1570              brackets of the character class; for example, `-:[:alnum:]' is a
1571              valid  word-class  to include all alphanumerics plus the charac‐
1572              ters `-' and `:'.  Be careful including  `]',  `^'  and  `-'  as
1573              these are special inside character classes.
1574
1575              word-style  may  also  have  `-subword' appended to its value to
1576              turn on subword matching, as described above.
1577
1578              The style skip-chars is mostly useful  for  transpose-words  and
1579              similar  functions.   If  set,  it  gives  a count of characters
1580              starting at the cursor position which  will  not  be  considered
1581              part  of  the  word and are treated as space, regardless of what
1582              they actually are.  For example, if
1583
1584                     zstyle ':zle:transpose-words' skip-chars 1
1585
1586              has been set, and transpose-words-match is called with the  cur‐
1587              sor  on the X of fooXbar, where X can be any character, then the
1588              resulting expression is barXfoo.
1589
1590              Finer grained control can  be  obtained  by  setting  the  style
1591              word-context  to  an  array  of  pairs of entries.  Each pair of
1592              entries consists of a pattern and a subcontext.  The shell argu‐
1593              ment  the  cursor  is on is matched against each pattern in turn
1594              until one matches; if it does, the  context  is  extended  by  a
1595              colon  and  the corresponding subcontext.  Note that the test is
1596              made against the original word on the line, with no stripping of
1597              quotes.   Special  handling  is  done between words: the current
1598              context is examined and if it contains the string back, the word
1599              before  the  cursor is considered, else the word after cursor is
1600              considered. Some examples are given below.
1601
1602              The style skip-whitespace-first  is  only  used  with  the  for‐
1603              ward-word widget.  If it is set to true, then forward-word skips
1604              any non-word-characters, followed  by  any  non-word-characters:
1605              this  is  similar to the behaviour of other word-orientated wid‐
1606              gets, and also that used by other editors,  however  it  differs
1607              from  the  standard zsh behaviour.  When using select-word-style
1608              the widget is set in the context :zle:*  to  true  if  the  word
1609              style is bash and false otherwise.  It may be overridden by set‐
1610              ting it in the more specific context :zle:forward-word*.
1611
1612              Here are some examples of use of the styles, actually taken from
1613              the simplified interface in select-word-style:
1614
1615                     zstyle ':zle:*' word-style standard
1616                     zstyle ':zle:*' word-chars ''
1617
1618              Implements  bash-style  word handling for all widgets, i.e. only
1619              alphanumerics are word characters;  equivalent  to  setting  the
1620              parameter WORDCHARS empty for the given context.
1621
1622                     style ':zle:*kill*' word-style space
1623
1624              Uses  space-delimited  words for widgets with the word `kill' in
1625              the name.  Neither of the styles word-chars  nor  word-class  is
1626              used in this case.
1627
1628              Here  are  some  examples  of  use  of the word-context style to
1629              extend the context.
1630
1631                     zstyle ':zle:*' word-context "*/*" file "[[:space:]]" whitespace
1632                     zstyle ':zle:transpose-words:whitespace' word-style shell
1633                     zstyle ':zle:transpose-words:filename' word-style normal
1634                     zstyle ':zle:transpose-words:filename' word-chars ''
1635
1636              This  provides  two  different  ways  of  using  transpose-words
1637              depending  on  whether the cursor is on whitespace between words
1638              or on a filename, here any word containing a /.  On  whitespace,
1639              complete  arguments  as  defined by standard shell rules will be
1640              transposed.  In a filename, only alphanumerics  will  be  trans‐
1641              posed.   Elsewhere,  words  will be transposed using the default
1642              style for :zle:transpose-words.
1643
1644              The word matching and all the handling  of  zstyle  settings  is
1645              actually implemented by the function match-words-by-style.  This
1646              can be used to create new  user-defined  widgets.   The  calling
1647              function  should set the local parameter curcontext to :zle:wid‐
1648              get,  create  the  local  parameter   matched_words   and   call
1649              match-words-by-style    with    no    arguments.    On   return,
1650              matched_words will be set to an array with the elements: (1) the
1651              start  of  the  line  (2)  the  word  before  the cursor (3) any
1652              non-word characters between that word and  the  cursor  (4)  any
1653              non-word  character  at  the  cursor position plus any remaining
1654              non-word characters before the next word, including all  charac‐
1655              ters  specified by the skip-chars style, (5) the word at or fol‐
1656              lowing the cursor (6) any  non-word  characters  following  that
1657              word  (7) the remainder of the line.  Any of the elements may be
1658              an empty string; the calling function should test  for  this  to
1659              decide whether it can perform its function.
1660
1661              It   is   possible   to   pass   options   with   arguments   to
1662              match-words-by-style to override the use of styles.  The options
1663              are:
1664              -w     word-style
1665              -s     skip-chars
1666              -c     word-class
1667              -C     word-chars
1668              -r     subword-range
1669
1670              For  example,  match-words-by-style -w shell -c 0 may be used to
1671              extract the command argument around the cursor.
1672
1673              The  word-context  style  is   implemented   by   the   function
1674              match-word-context.   This  should not usually need to be called
1675              directly.
1676
1677       copy-earlier-word
1678              This widget works like a  combination  of  insert-last-word  and
1679              copy-prev-shell-word.    Repeated   invocations  of  the  widget
1680              retrieve earlier words on the relevant  history  line.   With  a
1681              numeric argument N, insert the Nth word from the history line; N
1682              may be negative to count from the end of the line.
1683
1684              If insert-last-word has been used to retrieve the last word on a
1685              previous  history  line,  repeated invocations will replace that
1686              word with earlier words from the same line.
1687
1688              Otherwise, the widget applies to words  on  the  line  currently
1689              being  edited.   The  widget  style  can  be  set to the name of
1690              another widget that should be called to  retrieve  words.   This
1691              widget must accept the same three arguments as insert-last-word.
1692
1693       cycle-completion-positions
1694              After inserting an unambiguous string into the command line, the
1695              new function based completion system  may  know  about  multiple
1696              places  in  this  string  where characters are missing or differ
1697              from at least one of the possible matches.  It will  then  place
1698              the cursor on the position it considers to be the most interest‐
1699              ing one, i.e. the one where one can disambiguate between as many
1700              matches as possible with as little typing as possible.
1701
1702              This  widget  allows  the cursor to be easily moved to the other
1703              interesting spots.   It  can  be  invoked  repeatedly  to  cycle
1704              between all positions reported by the completion system.
1705
1706       delete-whole-word-match
1707              This  is  another function which works like the -match functions
1708              described immediately above, i.e. using  styles  to  decide  the
1709              word  boundaries.   However,  it  is  not  a replacement for any
1710              existing function.
1711
1712              The basic behaviour is to delete the  word  around  the  cursor.
1713              There is no numeric prefix handling; only the single word around
1714              the cursor is considered.  If the  widget  contains  the  string
1715              kill,  the  removed  text  will  be  placed in the cutbuffer for
1716              future   yanking.    This   can   be   obtained   by    defining
1717              kill-whole-word-match as follows:
1718
1719                     zle -N kill-whole-word-match delete-whole-word-match
1720
1721              and then binding the widget kill-whole-word-match.
1722
1723       up-line-or-beginning-search, down-line-or-beginning-search
1724              These   widgets   are   similar   to   the   builtin   functions
1725              up-line-or-search and down-line-or-search:  if  in  a  multiline
1726              buffer  they  move  up or down within the buffer, otherwise they
1727              search for a history line matching  the  start  of  the  current
1728              line.   In  this  case,  however,  they  search for a line which
1729              matches the current line up to the current cursor  position,  in
1730              the  manner  of  history-beginning-search-backward and -forward,
1731              rather than the first word on the line.
1732
1733       edit-command-line
1734              Edit the command line using your visual editor, as in ksh.
1735
1736                     bindkey -M vicmd v edit-command-line
1737
1738       history-search-end
1739              This   function   implements    the    widgets    history-begin‐
1740              ning-search-backward-end    and    history-beginning-search-for‐
1741              ward-end.  These commands work by first calling the  correspond‐
1742              ing builtin widget (see `History Control' in zshzle(1)) and then
1743              moving the cursor to the end of the line.  The  original  cursor
1744              position  is  remembered and restored before calling the builtin
1745              widget a second time, so that the same  search  is  repeated  to
1746              look farther through the history.
1747
1748              Although  you autoload only one function, the commands to use it
1749              are slightly different because it implements two widgets.
1750
1751                     zle -N history-beginning-search-backward-end \
1752                            history-search-end
1753                     zle -N history-beginning-search-forward-end \
1754                            history-search-end
1755                     bindkey '\e^P' history-beginning-search-backward-end
1756                     bindkey '\e^N' history-beginning-search-forward-end
1757
1758       history-beginning-search-menu
1759              This function implements yet another form of history  searching.
1760              The text before the cursor is used to select lines from the his‐
1761              tory, as for history-beginning-search-backward except  that  all
1762              matches  are  shown  in a numbered menu.  Typing the appropriate
1763              digits inserts the full history line.  Note that leading  zeroes
1764              must  be  typed (they are only shown when necessary for removing
1765              ambiguity).  The entire history is searched; there  is  no  dis‐
1766              tinction between forwards and backwards.
1767
1768              With  a prefix argument, the search is not anchored to the start
1769              of the line; the string typed by the use may appear anywhere  in
1770              the line in the history.
1771
1772              If  the  widget  name contains `-end' the cursor is moved to the
1773              end of the line inserted.  If the widget name contains  `-space'
1774              any  space  in  the  text typed is treated as a wildcard and can
1775              match anything (hence a leading space is equivalent to giving  a
1776              prefix argument).  Both forms can be combined, for example:
1777
1778                     zle -N history-beginning-search-menu-space-end \
1779                            history-beginning-search-menu
1780
1781       history-pattern-search
1782              The  function  history-pattern-search  implements  widgets which
1783              prompt for a pattern with which to search the history  backwards
1784              or  forwards.   The  pattern is in the usual zsh format, however
1785              the first character may be ^ to anchor the search to  the  start
1786              of  the  line,  and  the  last  character may be $ to anchor the
1787              search to the end of the line.  If the search was  not  anchored
1788              to  the  end of the line the cursor is positioned just after the
1789              pattern found.
1790
1791              The commands to create bindable widgets are similar to those  in
1792              the example immediately above:
1793
1794                     autoload -U history-pattern-search
1795                     zle -N history-pattern-search-backward history-pattern-search
1796                     zle -N history-pattern-search-forward history-pattern-search
1797
1798       incarg Typing  the keystrokes for this widget with the cursor placed on
1799              or to the left of an integer causes that integer  to  be  incre‐
1800              mented  by  one.   With a numeric prefix argument, the number is
1801              incremented by the amount of the argument  (decremented  if  the
1802              prefix argument is negative).  The shell parameter incarg may be
1803              set to change the default increment to something other than one.
1804
1805                     bindkey '^X+' incarg
1806
1807       incremental-complete-word
1808              This allows incremental completion of a  word.   After  starting
1809              this  command,  a  list of completion choices can be shown after
1810              every character you type, which you can delete with ^H  or  DEL.
1811              Pressing return accepts the completion so far and returns you to
1812              normal editing (that is, the command  line  is  not  immediately
1813              executed).  You can hit TAB to do normal completion, ^G to abort
1814              back to the state when you started, and ^D to list the matches.
1815
1816              This works only with the new function based completion system.
1817
1818                     bindkey '^Xi' incremental-complete-word
1819
1820       insert-composed-char
1821              This function allows you to compose characters that don't appear
1822              on  the keyboard to be inserted into the command line.  The com‐
1823              mand is followed by two keys corresponding to  ASCII  characters
1824              (there is no prompt).  For accented characters, the two keys are
1825              a base character followed by a code for the  accent,  while  for
1826              other  special  characters  the  two  characters together form a
1827              mnemonic for the character to be  inserted.   The  two-character
1828              codes  are  a subset of those given by RFC 1345 (see for example
1829              http://www.faqs.org/rfcs/rfc1345.html).
1830
1831              The function may optionally be followed by up to two  characters
1832              which  replace  one or both of the characters read from the key‐
1833              board; if both characters are supplied, no input is  read.   For
1834              example,  insert-composed-char a: can be used within a widget to
1835              insert an a with umlaut into the command  line.   This  has  the
1836              advantages  over use of a literal character that it is more por‐
1837              table.
1838
1839              For best results zsh should have been  built  with  support  for
1840              multibyte  characters (configured with --enable-multibyte); how‐
1841              ever, the function works for the  limited  range  of  characters
1842              available in single-byte character sets such as ISO-8859-1.
1843
1844              The  character  is  converted  into the local representation and
1845              inserted into the command line at  the  cursor  position.   (The
1846              conversion  is  done within the shell, using whatever facilities
1847              the C library provides.)  With a numeric argument, the character
1848              and its code are previewed in the status line
1849
1850              The  function may be run outside zle in which case it prints the
1851              character (together with a newline) to standard  output.   Input
1852              is still read from keystrokes.
1853
1854              See insert-unicode-char for an alternative way of inserting Uni‐
1855              code characters using their hexadecimal character number.
1856
1857              The set of accented characters is reasonably complete up to Uni‐
1858              code  character  U+0180,  the set of special characters less so.
1859              However, it is very sporadic from that point.  Adding new  char‐
1860              acters is easy, however; see the function define-composed-chars.
1861              Please send any additions to zsh-workers@zsh.org.
1862
1863              The codes for the second character when used to accent the first
1864              are  as  follows.   Note that not every character can take every
1865              accent.
1866              !      Grave.
1867              '      Acute.
1868              >      Circumflex.
1869              ?      Tilde.  (This is not ~ as RFC 1345 does not  assume  that
1870                     character is present on the keyboard.)
1871              -      Macron.  (A horizontal bar over the base character.)
1872              (      Breve.  (A shallow dish shape over the base character.)
1873              .      Dot above the base character, or in the case of i no dot,
1874                     or in the case of L and l a centered dot.
1875              :      Diaeresis (Umlaut).
1876              c      Cedilla.
1877              _      Underline, however  there  are  currently  no  underlined
1878                     characters.
1879              /      Stroke through the base character.
1880              "      Double acute (only supported on a few letters).
1881              ;      Ogonek.   (A  little  forward  facing  hook at the bottom
1882                     right of the character.)
1883              <      Caron.  (A little v over the letter.)
1884              0      Circle over the base character.
1885              2      Hook over the base character.
1886              9      Horn over the base character.
1887
1888              The most common characters from the Arabic, Cyrillic, Greek  and
1889              Hebrew  alphabets are available; consult RFC 1345 for the appro‐
1890              priate sequences.  In addition, a set of two letter codes not in
1891              RFC  1345  are  available for the double-width characters corre‐
1892              sponding to ASCII characters from !  to ~ (0x21 to 0x7e) by pre‐
1893              ceding  the  character with ^, for example ^A for a double-width
1894              A.
1895
1896              The following other two-character sequences are understood.
1897
1898              ASCII characters
1899                     These are already present on most keyboards:
1900              <(     Left square bracket
1901              //     Backslash (solidus)
1902              )>     Right square bracket
1903              (!     Left brace (curly bracket)
1904              !!     Vertical bar (pipe symbol)
1905              !)     Right brace (curly bracket)
1906              '?     Tilde
1907
1908              Special letters
1909                     Characters found in various variants of the Latin  alpha‐
1910                     bet:
1911              ss     Eszett (scharfes S)
1912              D-, d- Eth
1913              TH, th Thorn
1914              kk     Kra
1915              'n     'n
1916              NG, ng Ng
1917              OI, oi Oi
1918              yr     yr
1919              ED     ezh
1920
1921              Currency symbols
1922              Ct     Cent
1923              Pd     Pound sterling (also lira and others)
1924              Cu     Currency
1925              Ye     Yen
1926              Eu     Euro (N.B. not in RFC 1345)
1927
1928              Punctuation characters
1929                     References to "right" quotes indicate the shape (like a 9
1930                     rather than 6) rather than their grammatical  use.   (For
1931                     example,  a "right" low double quote is used to open quo‐
1932                     tations in German.)
1933              !I     Inverted exclamation mark
1934              BB     Broken vertical bar
1935              SE     Section
1936              Co     Copyright
1937              -a     Spanish feminine ordinal indicator
1938              <<     Left guillemet
1939              --     Soft hyphen
1940              Rg     Registered trade mark
1941              PI     Pilcrow (paragraph)
1942              -o     Spanish masculine ordinal indicator
1943              >>     Right guillemet
1944              ?I     Inverted question mark
1945              -1     Hyphen
1946              -N     En dash
1947              -M     Em dash
1948              -3     Horizontal bar
1949              :3     Vertical ellipsis
1950              .3     Horizontal midline ellipsis
1951              !2     Double vertical line
1952              =2     Double low line
1953              '6     Left single quote
1954              '9     Right single quote
1955              .9     "Right" low quote
1956              9'     Reversed "right" quote
1957              "6     Left double quote
1958              "9     Right double quote
1959              :9     "Right" low double quote
1960              9"     Reversed "right" double quote
1961              /-     Dagger
1962              /=     Double dagger
1963
1964              Mathematical symbols
1965              DG     Degree
1966              -2, +-, -+
1967                     - sign, +/- sign, -/+ sign
1968              2S     Superscript 2
1969              3S     Superscript 3
1970              1S     Superscript 1
1971              My     Micro
1972              .M     Middle dot
1973              14     Quarter
1974              12     Half
1975              34     Three quarters
1976              *X     Multiplication
1977              -:     Division
1978              %0     Per mille
1979              FA, TE, /0
1980                     For all, there exists, empty set
1981              dP, DE, NB
1982                     Partial derivative, delta (increment), del (nabla)
1983              (-, -) Element of, contains
1984              *P, +Z Product, sum
1985              *-, Ob, Sb
1986                     Asterisk, ring, bullet
1987              RT, 0(, 00
1988                     Root sign, proportional to, infinity
1989
1990              Other symbols
1991              cS, cH, cD, cC
1992                     Card suits: spades, hearts, diamonds, clubs
1993              Md, M8, M2, Mb, Mx, MX
1994                     Musical notation: crotchet (quarter note), quaver (eighth
1995                     note),  semiquavers (sixteenth notes), flag sign, natural
1996                     sign, sharp sign
1997              Fm, Ml Female, male
1998
1999              Accents on their own
2000              '>     Circumflex (same as caret, ^)
2001              '!     Grave (same as backtick, `)
2002              ',     Cedilla
2003              ':     Diaeresis (Umlaut)
2004              'm     Macron
2005              ''     Acute
2006
2007       insert-files
2008              This function allows you  type  a  file  pattern,  and  see  the
2009              results of the expansion at each step.  When you hit return, all
2010              expansions are inserted into the command line.
2011
2012                     bindkey '^Xf' insert-files
2013
2014       insert-unicode-char
2015              When first executed, the user inputs a set of  hexadecimal  dig‐
2016              its.   This  is  terminated  with  another  call  to insert-uni‐
2017              code-char.  The digits are then turned  into  the  corresponding
2018              Unicode  character.  For example, if the widget is bound to ^XU,
2019              the character sequence `^XU 4 c ^XU' inserts L (Unicode U+004c).
2020
2021              See insert-composed-char for a way of inserting characters using
2022              a two-character mnemonic.
2023
2024       narrow-to-region [ -p pre ] [ -P post ]
2025           [ -S statepm | -R statepm ] [ -n ] [ start end ])
2026       narrow-to-region-invisible
2027              Narrow  the editable portion of the buffer to the region between
2028              the cursor and the mark, which may  be  in  either  order.   The
2029              region may not be empty.
2030
2031              narrow-to-region may be used as a widget or called as a function
2032              from a user-defined widget; by default,  the  text  outside  the
2033              editable  area  remains  visible.  A recursive-edit is performed
2034              and the original widening  status  is  then  restored.   Various
2035              options and arguments are available when it is called as a func‐
2036              tion.
2037
2038              The options -p pretext and -P posttext may be  used  to  replace
2039              the  text  before  and after the display for the duration of the
2040              function; either or both may be an empty string.
2041
2042              If the option -n is also given, pretext or posttext will only be
2043              inserted  if  there  is  text before or after the region respec‐
2044              tively which will be made invisible.
2045
2046              Two numeric arguments may be given which will be used instead of
2047              the cursor and mark positions.
2048
2049              The  option  -S statepm is used to narrow according to the other
2050              options while saving the original state in  the  parameter  with
2051              name statepm, while the option -R statepm is used to restore the
2052              state from the parameter; note in both cases  the  name  of  the
2053              parameter  is  required.   In the second case, other options and
2054              arguments are irrelevant.  When this method is used,  no  recur‐
2055              sive-edit  is  performed;  the  calling  widget should call this
2056              function with the option -S, perform its own editing on the com‐
2057              mand  line or pass control to the user via `zle recursive-edit',
2058              then call this  function  with  the  option  -R.   The  argument
2059              statepm  must  be  a  suitable  name  for an ordinary parameter,
2060              except that parameters  beginning  with  the  prefix  _ntr_  are
2061              reserved for use within narrow-to-region.  Typically the parame‐
2062              ter will be local to the calling function.
2063
2064              narrow-to-region-invisible is a simple widget which  calls  nar‐
2065              row-to-region  with arguments which replace any text outside the
2066              region with `...'.
2067
2068              The display is restored (and the widget returns)  upon  any  zle
2069              command  which  would  usually  cause the line to be accepted or
2070              aborted.  Hence an additional such command is required to accept
2071              or abort the current line.
2072
2073              The  return  status  of  both  widgets  is  zero if the line was
2074              accepted, else non-zero.
2075
2076              Here is a trivial example of a widget using this feature.
2077                     local state
2078                     narrow-to-region -p $'Editing restricted region\n' \
2079                       -P '' -S state
2080                     zle recursive-edit
2081                     narrow-to-region -R state
2082
2083       predict-on
2084              This set of functions implements predictive typing using history
2085              search.   After  predict-on, typing characters causes the editor
2086              to look backward in the history for  the  first  line  beginning
2087              with  what  you  have  typed so far.  After predict-off, editing
2088              returns to normal for the line found.  In fact, you often  don't
2089              even  need to use predict-off, because if the line doesn't match
2090              something in the history, adding a key performs standard comple‐
2091              tion,  and  then  inserts  itself  if no completions were found.
2092              However, editing in the middle of a line is  liable  to  confuse
2093              prediction; see the toggle style below.
2094
2095              With  the  function based completion system (which is needed for
2096              this), you should be able to type TAB at  almost  any  point  to
2097              advance  the  cursor to the next ``interesting'' character posi‐
2098              tion (usually the end of the current word, but  sometimes  some‐
2099              where  in the middle of the word).  And of course as soon as the
2100              entire line is what you want, you can accept with return,  with‐
2101              out needing to move the cursor to the end first.
2102
2103              The first time predict-on is used, it creates several additional
2104              widget functions:
2105
2106              delete-backward-and-predict
2107                     Replaces the backward-delete-char  widget.   You  do  not
2108                     need to bind this yourself.
2109              insert-and-predict
2110                     Implements predictive typing by replacing the self-insert
2111                     widget.  You do not need to bind this yourself.
2112              predict-off
2113                     Turns off predictive typing.
2114
2115              Although you autoload only the predict-on function, it is neces‐
2116              sary to create a keybinding for predict-off as well.
2117
2118                     zle -N predict-on
2119                     zle -N predict-off
2120                     bindkey '^X^Z' predict-on
2121                     bindkey '^Z' predict-off
2122
2123       read-from-minibuffer
2124              This is most useful when called as a function from inside a wid‐
2125              get, but will work correctly as a widget in its own  right.   It
2126              prompts  for a value below the current command line; a value may
2127              be input using all of  the  standard  zle  operations  (and  not
2128              merely the restricted set available when executing, for example,
2129              execute-named-cmd).  The value is then returned to  the  calling
2130              function in the parameter $REPLY and the editing buffer restored
2131              to its previous state.  If the read was aborted  by  a  keyboard
2132              break  (typically  ^G), the function returns status 1 and $REPLY
2133              is not set.
2134
2135              If one argument is supplied to the function it  is  taken  as  a
2136              prompt,  otherwise `? ' is used.  If two arguments are supplied,
2137              they are the prompt and the initial value of $LBUFFER, and if  a
2138              third  argument  is  given  it is the initial value of $RBUFFER.
2139              This provides a default value  and  starting  cursor  placement.
2140              Upon return the entire buffer is the value of $REPLY.
2141
2142              One  option is available: `-k num' specifies that num characters
2143              are to be read instead of a whole line.  The line editor is  not
2144              invoked  recursively  in this case, so depending on the terminal
2145              settings the input may not be visible, and only the  input  keys
2146              are  placed  in $REPLY, not the entire buffer.  Note that unlike
2147              the read builtin num must be given; there is no default.
2148
2149              The name is a slight  misnomer,  as  in  fact  the  shell's  own
2150              minibuffer is not used.  Hence it is still possible to call exe‐
2151              cuted-named-cmd and similar functions while reading a value.
2152
2153       replace-string, replace-pattern
2154       replace-string-again, replace-pattern-again
2155              The  function  replace-string  implements  three  widgets.    If
2156              defined  under the same name as the function, it prompts for two
2157              strings; the first (source) string will be replaced by the  sec‐
2158              ond everywhere it occurs in the line editing buffer.
2159
2160              If  the  widget name contains the word `pattern', for example by
2161              defining the widget using the command  `zle  -N  replace-pattern
2162              replace-string',  then  the matching is performed using zsh pat‐
2163              terns.  All zsh extended globbing patterns can be  used  in  the
2164              source  string; note that unlike filename generation the pattern
2165              does not need to match an entire word, nor  do  glob  qualifiers
2166              have  any  effect.  In addition, the replacement string can con‐
2167              tain parameter or command substitutions.  Furthermore, a `&'  in
2168              the  replacement string will be replaced with the matched source
2169              string, and a backquoted digit `\N' will be replaced by the  Nth
2170              parenthesised  expression  matched.  The form `\{N}' may be used
2171              to protect the digit from following digits.
2172
2173              If the widget instead contains the word `regex'  (or  `regexp'),
2174              then  the  matching  is  performed  using  regular  expressions,
2175              respecting the setting of  the  option  RE_MATCH_PCRE  (see  the
2176              description  of the function regexp-replace below).  The special
2177              replacement facilities described above for pattern matching  are
2178              available.
2179
2180              By default the previous source or replacement string will not be
2181              offered for editing.  However, this feature can be activated  by
2182              setting  the style edit-previous in the context :zle:widget (for
2183              example, :zle:replace-string) to true.  In addition, a  positive
2184              numeric  argument  forces  the  previous values to be offered, a
2185              negative or zero argument forces them not to be.
2186
2187              The function replace-string-again can be used to repeat the pre‐
2188              vious    replacement;   no   prompting   is   done.    As   with
2189              replace-string, if the name of  the  widget  contains  the  word
2190              `pattern'  or `regex', pattern or regular expression matching is
2191              performed, else a literal string  replacement.   Note  that  the
2192              previous  source  and replacement text are the same whether pat‐
2193              tern, regular expression or string matching is used.
2194
2195              In addition, replace-string shows the previous replacement above
2196              the prompt, so long as there was one during the current session;
2197              if the source string is empty, that replacement will be repeated
2198              without the widget prompting for a replacement string.
2199
2200              For example, starting from the line:
2201
2202                     print This line contains fan and fond
2203
2204              and  invoking replace-pattern with the source string `f(?)n' and
2205              the replacement string `c\1r' produces the not very useful line:
2206
2207                     print This line contains car and cord
2208
2209              The range of the replacement string can be limited by using  the
2210              narrow-to-region-invisible  widget.   One limitation of the cur‐
2211              rent version is that undo will  cycle  through  changes  to  the
2212              replacement  and  source  strings before undoing the replacement
2213              itself.
2214
2215       send-invisible
2216              This is similar to read-from-minibuffer in that it may be called
2217              as  a  function  from  a  widget  or as a widget of its own, and
2218              interactively reads input from the keyboard.  However, the input
2219              being  typed  is  concealed  and  a string of asterisks (`*') is
2220              shown instead.  The value is saved in the  parameter  $INVISIBLE
2221              to  which a reference is inserted into the editing buffer at the
2222              restored cursor position.  If the read was aborted by a keyboard
2223              break  (typically  ^G)  or  another  escape from editing such as
2224              push-line, $INVISIBLE is set to empty and the original buffer is
2225              restored unchanged.
2226
2227              If  one  argument  is  supplied to the function it is taken as a
2228              prompt, otherwise `Non-echoed text: ' is used (as in emacs).  If
2229              a  second and third argument are supplied they are used to begin
2230              and end the reference to $INVISIBLE that is  inserted  into  the
2231              buffer.   The  default  is  to open with ${, then INVISIBLE, and
2232              close with }, but many other effects are possible.
2233
2234       smart-insert-last-word
2235              This function may replace the insert-last-word widget, like so:
2236
2237                     zle -N insert-last-word smart-insert-last-word
2238
2239              With a numeric prefix, or when passed command line arguments  in
2240              a  call  from  another widget, it behaves like insert-last-word,
2241              except that words in comments are ignored when  INTERACTIVE_COM‐
2242              MENTS is set.
2243
2244              Otherwise,  the rightmost ``interesting'' word from the previous
2245              command is  found  and  inserted.   The  default  definition  of
2246              ``interesting''  is  that  the word contains at least one alpha‐
2247              betic character, slash, or backslash.  This  definition  may  be
2248              overridden  by use of the match style.  The context used to look
2249              up the style is the widget  name,  so  usually  the  context  is
2250              :insert-last-word.   However, you can bind this function to dif‐
2251              ferent widgets to use different patterns:
2252
2253                     zle -N insert-last-assignment smart-insert-last-word
2254                     zstyle :insert-last-assignment match '[[:alpha:]][][[:alnum:]]#=*'
2255                     bindkey '\e=' insert-last-assignment
2256
2257              If no interesting word is found and the auto-previous  style  is
2258              set  to  a  true  value, the search continues upward through the
2259              history.  When auto-previous is unset or  false  (the  default),
2260              the widget must be invoked repeatedly in order to search earlier
2261              history lines.
2262
2263       transpose-lines
2264              Only useful with a multi-line editing buffer; the lines here are
2265              lines  within  the  current on-screen buffer, not history lines.
2266              The effect is similar to the function of the same name in Emacs.
2267
2268              Transpose the current line with the previous line and  move  the
2269              cursor to the start of the next line.  Repeating this (which can
2270              be done by providing a positive numeric prefix argument) has the
2271              effect  of  moving the line above the cursor down by a number of
2272              lines.
2273
2274              With a negative numeric  prefix  argument,  requires  two  lines
2275              above the cursor.  These two lines are transposed and the cursor
2276              moved to the start of the previous line.  Using a numeric prefix
2277              less  than -1 has the effect of moving the line above the cursor
2278              up by minus that number of lines.
2279
2280       which-command
2281              This function is a drop-in replacement for  the  builtin  widget
2282              which-command.   It has enhanced behaviour, in that it correctly
2283              detects whether or not the command word needs to be expanded  as
2284              an  alias; if so, it continues tracing the command word from the
2285              expanded alias until it reaches the command that  will  be  exe‐
2286              cuted.
2287
2288              The  style whence is available in the context :zle:$WIDGET; this
2289              may be set to an array to give the command and options that will
2290              be  used  to investigate the command word found.  The default is
2291              whence -c.
2292
2293   Utility Functions
2294       These functions are useful in constructing  widgets.   They  should  be
2295       loaded  with  `autoload  -U  function'  and  called  as  indicated from
2296       user-defined widgets.
2297
2298       split-shell-arguments
2299              This function splits the line currently being edited into  shell
2300              arguments  and  whitespace.   The  result is stored in the array
2301              reply.  The array contains all the parts of the line  in  order,
2302              starting with any whitespace before the first argument, and fin‐
2303              ishing with any whitespace after the last argument.   Hence  (so
2304              long as the option KSH_ARRAYS is not set) whitespace is given by
2305              odd indices in the array and arguments by  even  indices.   Note
2306              that  no  stripping  of quotes is done; joining together all the
2307              elements of reply in order is guaranteed to produce the original
2308              line.
2309
2310              The  parameter  REPLY  is  set to the index of the word in reply
2311              which contains the character after the cursor, where  the  first
2312              element  has  index 1.  The parameter REPLY2 is set to the index
2313              of the character under the cursor in that word, where the  first
2314              character has index 1.
2315
2316              Hence  reply,  REPLY  and REPLY2 should all be made local to the
2317              enclosing function.
2318
2319              See the function modify-current-argument, described  below,  for
2320              an example of how to call this function.
2321
2322       modify-current-argument expr-using-$ARG
2323              This  function provides a simple method of allowing user-defined
2324              widgets to modify the command line argument under the cursor (or
2325              immediately  to  the left of the cursor if the cursor is between
2326              arguments).  The argument should be  an  expression  which  when
2327              evaluated  operates  on the shell parameter ARG, which will have
2328              been set to the command line argument  under  the  cursor.   The
2329              expression  should be suitably quoted to prevent it being evalu‐
2330              ated too early.
2331
2332              For example, a user-defined widget containing the following code
2333              converts  the  characters  in the argument under the cursor into
2334              all upper case:
2335
2336                     modify-current-argument '${(U)ARG}'
2337
2338              The following strips any quoting from the current word  (whether
2339              backslashes  or  one  of  the styles of quotes), and replaces it
2340              with single quoting throughout:
2341
2342                     modify-current-argument '${(qq)${(Q)ARG}}'
2343
2344   Styles
2345       The behavior of several of the above widgets can be controlled  by  the
2346       use of the zstyle mechanism.  In particular, widgets that interact with
2347       the completion system pass along their context to any completions  that
2348       they invoke.
2349
2350       break-keys
2351              This  style is used by the incremental-complete-word widget. Its
2352              value should be a pattern, and all keys  matching  this  pattern
2353              will cause the widget to stop incremental completion without the
2354              key having any further effect. Like all styles used directly  by
2355              incremental-complete-word,  this  style  is  looked up using the
2356              context `:incremental'.
2357
2358       completer
2359              The incremental-complete-word and insert-and-predict widgets set
2360              up their top-level context name before calling completion.  This
2361              allows one to define different sets of completer  functions  for
2362              normal  completion  and  for these widgets.  For example, to use
2363              completion, approximation and correction for normal  completion,
2364              completion  and  correction  for incremental completion and only
2365              completion for prediction one could use:
2366
2367                     zstyle ':completion:*' completer \
2368                             _complete _correct _approximate
2369                     zstyle ':completion:incremental:*' completer \
2370                             _complete _correct
2371                     zstyle ':completion:predict:*' completer \
2372                             _complete
2373
2374              It is a good idea to restrict the completers used in prediction,
2375              because  they  may  be  automatically  invoked as you type.  The
2376              _list and _menu completers should never be used with prediction.
2377              The  _approximate,  _correct, _expand, and _match completers may
2378              be used, but be aware that they may change  characters  anywhere
2379              in  the  word  behind the cursor, so you need to watch carefully
2380              that the result is what you intended.
2381
2382       cursor The insert-and-predict widget uses this style,  in  the  context
2383              `:predict', to decide where to place the cursor after completion
2384              has been tried.  Values are:
2385
2386              complete
2387                     The cursor is left where it was when completion finished,
2388                     but only if it is after a character equal to the one just
2389                     inserted by the user.  If it is after another  character,
2390                     this value is the same as `key'.
2391
2392              key    The  cursor is left after the nth occurrence of the char‐
2393                     acter just inserted, where n is the number of times  that
2394                     character  appeared  in  the  word  before completion was
2395                     attempted.  In short, this has the effect of leaving  the
2396                     cursor after the character just typed even if the comple‐
2397                     tion code found out that no other characters need  to  be
2398                     inserted at that position.
2399
2400              Any other value for this style unconditionally leaves the cursor
2401              at the position where the completion code left it.
2402
2403       list   When using the incremental-complete-word widget, this style says
2404              if  the matches should be listed on every key press (if they fit
2405              on the screen).  Use the context  prefix  `:completion:incremen‐
2406              tal'.
2407
2408              The  insert-and-predict  widget uses this style to decide if the
2409              completion should be shown even if there is  only  one  possible
2410              completion.   This  is  done  if  the value of this style is the
2411              string always.  In this case  the  context  is  `:predict'  (not
2412              `:completion:predict').
2413
2414       match  This  style  is used by smart-insert-last-word to provide a pat‐
2415              tern (using full EXTENDED_GLOB syntax) that matches an interest‐
2416              ing  word.   The  context  is  the  name  of the widget to which
2417              smart-insert-last-word is bound (see above).  The default behav‐
2418              ior of smart-insert-last-word is equivalent to:
2419
2420                     zstyle :insert-last-word match '*[[:alpha:]/\\]*'
2421
2422              However, you might want to include words that contain spaces:
2423
2424                     zstyle :insert-last-word match '*[[:alpha:][:space:]/\\]*'
2425
2426              Or  include  numbers as long as the word is at least two charac‐
2427              ters long:
2428
2429                     zstyle :insert-last-word match '*([[:digit:]]?|[[:alpha:]/\\])*'
2430
2431              The above example causes redirections like "2>" to be included.
2432
2433       prompt The incremental-complete-word widget shows  the  value  of  this
2434              style  in  the  status  line during incremental completion.  The
2435              string value may contain any of the following substrings in  the
2436              manner of the PS1 and other prompt parameters:
2437
2438              %c     Replaced  by the name of the completer function that gen‐
2439                     erated the matches (without the leading underscore).
2440
2441              %l     When the list style is set, replaced by `...' if the list
2442                     of  matches  is too long to fit on the screen and with an
2443                     empty string otherwise.  If the list style is `false'  or
2444                     not set, `%l' is always removed.
2445
2446              %n     Replaced by the number of matches generated.
2447
2448              %s     Replaced  by  `-no  match-',  `-no  prefix-', or an empty
2449                     string if there is no completion matching the word on the
2450                     line, if the matches have no common prefix different from
2451                     the word on the line, or if there is such a  common  pre‐
2452                     fix, respectively.
2453
2454              %u     Replaced by the unambiguous part of all matches, if there
2455                     is any, and if it is different from the word on the line.
2456
2457              Like `break-keys', this uses the `:incremental' context.
2458
2459       stop-keys
2460              This style is used by the incremental-complete-word widget.  Its
2461              value  is  treated similarly to the one for the break-keys style
2462              (and uses the same context: `:incremental').  However,  in  this
2463              case  all keys matching the pattern given as its value will stop
2464              incremental completion and will then execute their  usual  func‐
2465              tion.
2466
2467       toggle This boolean style is used by predict-on and its related widgets
2468              in the context `:predict'.  If set to one of the standard `true'
2469              values, predictive typing is automatically toggled off in situa‐
2470              tions where it is unlikely to be useful, such as when editing  a
2471              multi-line  buffer or after moving into the middle of a line and
2472              then deleting a character.  The default is to  leave  prediction
2473              turned on until an explicit call to predict-off.
2474
2475       verbose
2476              This boolean style is used by predict-on and its related widgets
2477              in the context `:predict'.  If set to one of the standard `true'
2478              values,  these  widgets  display a message below the prompt when
2479              the predictive state is toggled.  This is most useful in  combi‐
2480              nation  with  the  toggle  style.   The default does not display
2481              these messages.
2482
2483       widget This style is similar to the command style: For widget functions
2484              that  use zle to call other widgets, this style can sometimes be
2485              used to override the widget which is called.   The  context  for
2486              this  style  is  the name of the calling widget (not the name of
2487              the calling function, because one function may be bound to  mul‐
2488              tiple widget names).
2489
2490                     zstyle :copy-earlier-word widget smart-insert-last-word
2491
2492              Check  the  documentation  for the calling widget or function to
2493              determine whether the widget style is used.
2494

EXCEPTION HANDLING

2496       Two functions are provided to enable zsh to provide exception  handling
2497       in a form that should be familiar from other languages.
2498
2499       throw exception
2500              The  function  throw throws the named exception.  The name is an
2501              arbitrary string and is only used by the throw and  catch  func‐
2502              tions.   An exception is for the most part treated the same as a
2503              shell error, i.e. an unhandled exception will cause the shell to
2504              abort  all  processing  in a function or script and to return to
2505              the top level in an interactive shell.
2506
2507       catch exception-pattern
2508              The function catch returns  status  zero  if  an  exception  was
2509              thrown and the pattern exception-pattern matches its name.  Oth‐
2510              erwise it returns status 1.   exception-pattern  is  a  standard
2511              shell   pattern,   respecting   the   current   setting  of  the
2512              EXTENDED_GLOB option.  An alias catch is also defined to prevent
2513              the  argument  to  the function from matching filenames, so pat‐
2514              terns may be used unquoted.  Note that  as  exceptions  are  not
2515              fundamentally  different  from other shell errors it is possible
2516              to catch shell errors by using an empty string as the  exception
2517              name.   The shell variable CAUGHT is set by catch to the name of
2518              the exception caught.  It is possible to rethrow an exception by
2519              calling  the  throw  function  again  once an exception has been
2520              caught.
2521
2522       The functions are designed to be used together  with  the  always  con‐
2523       struct  described  in  zshmisc(1).  This is important as only this con‐
2524       struct provides the required support for exceptions.  A typical example
2525       is as follows.
2526
2527              {
2528                # "try" block
2529                # ... nested code here calls "throw MyExcept"
2530              } always {
2531                # "always" block
2532                if catch MyExcept; then
2533                  print "Caught exception MyExcept"
2534                elif catch ''; then
2535                  print "Caught a shell error.  Propagating..."
2536                  throw ''
2537                fi
2538                # Other exceptions are not handled but may be caught further
2539                # up the call stack.
2540              }
2541
2542       If  all  exceptions  should  be  caught,  the  following idiom might be
2543       preferable.
2544
2545              {
2546                # ... nested code here throws an exception
2547              } always {
2548                if catch *; then
2549                  case $CAUGHT in
2550                    (MyExcept)
2551                    print "Caught my own exception"
2552                    ;;
2553                    (*)
2554                    print "Caught some other exception"
2555                    ;;
2556                  esac
2557                fi
2558              }
2559
2560       In common with exception handling in other languages, the exception may
2561       be  thrown by code deeply nested inside the `try' block.  However, note
2562       that it must be thrown inside the current  shell,  not  in  a  subshell
2563       forked  for  a pipeline, parenthesised current-shell construct, or some
2564       form of command or process substitution.
2565
2566       The system internally uses the shell variable EXCEPTION to  record  the
2567       name  of  the exception between throwing and catching.  One drawback of
2568       this scheme is that if the exception is not handled the variable EXCEP‐
2569       TION  remains  set  and may be incorrectly recognised as the name of an
2570       exception if a shell error subsequently occurs.  Adding unset EXCEPTION
2571       at  the  start  of  the outermost layer of any code that uses exception
2572       handling will eliminate this problem.
2573

MIME FUNCTIONS

2575       Three functions are available to provide handling of  files  recognised
2576       by extension, for example to dispatch a file text.ps when executed as a
2577       command to an appropriate viewer.
2578
2579       zsh-mime-setup [ -fv ] [ -l [ suffix ... ] ]
2580       zsh-mime-handler [-l] command arguments ...
2581              These  two   functions   use   the   files   ~/.mime.types   and
2582              /etc/mime.types,  which  associate types and extensions, as well
2583              as ~/.mailcap and /etc/mailcap files, which associate types  and
2584              the  programs that handle them.  These are provided on many sys‐
2585              tems with the Multimedia Internet Mail Extensions.
2586
2587              To enable the system,  the  function  zsh-mime-setup  should  be
2588              autoloaded  and  run.   This  allows files with extensions to be
2589              treated as executable; such files be completed by  the  function
2590              completion  system.   The  function  zsh-mime-handler should not
2591              need to be called by the user.
2592
2593              The system works by setting up suffix aliases with  `alias  -s'.
2594              Suffix  aliases  already installed by the user will not be over‐
2595              written.
2596
2597              For suffixes defined in lower case,  upper  case  variants  will
2598              also automatically be handled (e.g. PDF is automatically handled
2599              if handling for the suffix pdf is defined), but not vice versa.
2600
2601              Repeated calls to zsh-mime-setup do not  override  the  existing
2602              mapping  between suffixes and executable files unless the option
2603              -f is given.  Note, however, that this does not override  exist‐
2604              ing suffix aliases assigned to handlers other than zsh-mime-han‐
2605              dler.
2606
2607              Calling zsh-mime-setup with the option  -l  lists  the  existing
2608              mappings  without  altering  them.   Suffixes to list (which may
2609              contain pattern characters that should be quoted from  immediate
2610              interpretation  on  the command line) may be given as additional
2611              arguments, otherwise all suffixes are listed.
2612
2613              Calling zsh-mime-setup with the option -v causes verbose  output
2614              to be shown during the setup operation.
2615
2616              The  system  respects  the mailcap flags needsterminal and copi‐
2617              ousoutput, see mailcap(4).
2618
2619              The functions use the following styles, which are  defined  with
2620              the  zstyle builtin command (see zshmodules(1)).  They should be
2621              defined before zsh-mime-setup is run.   The  contexts  used  all
2622              start with :mime:, with additional components in some cases.  It
2623              is recommended that a trailing * (suitably quoted)  be  appended
2624              to  style  patterns  in  case  the system is extended in future.
2625              Some examples are given below.
2626
2627              For files that have multiple suffixes, e.g. .pdf.gz,  where  the
2628              context  includes  the suffix it will be looked up starting with
2629              the longest possible suffix until  a  match  for  the  style  is
2630              found.   For  example,  if .pdf.gz produces a match for the han‐
2631              dler, that will be used; otherwise the handler for .gz  will  be
2632              used.   Note  that,  owing to the way suffix aliases work, it is
2633              always required that there be a handler for the shortest  possi‐
2634              ble  suffix,  so  in this example .pdf.gz can only be handled if
2635              .gz is also handled (though not necessarily in  the  same  way).
2636              Alternatively, if no handling for .gz on its own is needed, sim‐
2637              ply adding the command
2638
2639                     alias -s gz=zsh-mime-handler
2640
2641              to the initialisation code is sufficient; .gz will not  be  han‐
2642              dled on its own, but may be in combination with other suffixes.
2643
2644              current-shell
2645                     If  this  boolean  style is true, the mailcap handler for
2646                     the context in question is run  using  the  eval  builtin
2647                     instead  of  by  starting a new sh process.  This is more
2648                     efficient, but may not work in the occasional cases where
2649                     the mailcap handler uses strict POSIX syntax.
2650
2651              execute-as-is
2652                     This style gives a list of patterns to be matched against
2653                     files passed for execution with a  handler  program.   If
2654                     the  file matches the pattern, the entire command line is
2655                     executed in its current form, with no handler.   This  is
2656                     useful  for  files which might have suffixes but nonethe‐
2657                     less be executable in their own right.  If the  style  is
2658                     not  set, the pattern *(*) *(/) is used; hence executable
2659                     files are executed directly and not passed to a  handler,
2660                     and  the option AUTO_CD may be used to change to directo‐
2661                     ries that happen to have MIME suffixes.
2662
2663              file-path
2664                     Used if the style find-file-in-path is true for the  same
2665                     context.   Set  to  an array of directories that are used
2666                     for searching for the file to be handled; the default  is
2667                     the  command  path  given  by the special parameter path.
2668                     The shell option PATH_DIRS is respected; if that is  set,
2669                     the appropriate path will be searched even if the name of
2670                     the file to be handled as it appears on the command  line
2671                     contains  a  `/'.  The full context is :mime:.suffix:, as
2672                     described for the style handler.
2673
2674              find-file-in-path
2675                     If set, allows files whose names do not contain  absolute
2676                     paths  to be searched for in the command path or the path
2677                     specified by the file-path style.  If  the  file  is  not
2678                     found  in  the path, it is looked for locally (whether or
2679                     not the current directory is in the path); if it  is  not
2680                     found  locally,  the  handler  will abort unless the han‐
2681                     dle-nonexistent style is set.  Files found  in  the  path
2682                     are tested as described for the style execute-as-is.  The
2683                     full context is  :mime:.suffix:,  as  described  for  the
2684                     style handler.
2685
2686              flags  Defines flags to go with a handler; the context is as for
2687                     the handler style, and the format is as for the flags  in
2688                     mailcap.
2689
2690              handle-nonexistent
2691                     By  default, arguments that don't correspond to files are
2692                     not passed to the MIME handler in  order  to  prevent  it
2693                     from  intercepting commands found in the path that happen
2694                     to have suffixes.  This style may be set to an  array  of
2695                     extended  glob patterns for arguments that will be passed
2696                     to the handler even if they don't exist.  If  it  is  not
2697                     explicitly  set  it  defaults  to  [[:alpha:]]#:/*  which
2698                     allows URLs to be passed to the MIME handler even  though
2699                     they  don't exist in that format in the file system.  The
2700                     full context is  :mime:.suffix:,  as  described  for  the
2701                     style handler.
2702
2703              handler
2704                     Specifies  a handler for a suffix; the suffix is given by
2705                     the context as :mime:.suffix:, and the format of the han‐
2706                     dler  is exactly that in mailcap.  Note in particular the
2707                     `.' and trailing colon to distinguish  this  use  of  the
2708                     context.   This  overrides  any  handler specified by the
2709                     mailcap files.  If the handler requires a  terminal,  the
2710                     flags style should be set to include the word needstermi‐
2711                     nal, or if the output is to be displayed through a  pager
2712                     (but  not  if  the  handler is itself a pager), it should
2713                     include copiousoutput.
2714
2715              mailcap
2716                     A  list  of  files  in  the  format  of  ~/.mailcap   and
2717                     /etc/mailcap  to  be  read  during  setup,  replacing the
2718                     default list which consists of those two files.  The con‐
2719                     text  is :mime:.  A + in the list will be replaced by the
2720                     default files.
2721
2722              mailcap-priorities
2723                     This style is used to resolve  multiple  mailcap  entries
2724                     for  the  same MIME type.  It consists of an array of the
2725                     following elements,  in  descending  order  of  priority;
2726                     later  entries will be used if earlier entries are unable
2727                     to resolve the entries being compared.  If  none  of  the
2728                     tests resolve the entries, the first entry encountered is
2729                     retained.
2730
2731                     files  The order of files (entries in the mailcap  style)
2732                            read.   Earlier  files  are preferred.  (Note this
2733                            does not resolve entries in the same file.)
2734
2735                     priority
2736                            The priority flag from  the  mailcap  entry.   The
2737                            priority  is  an  integer  from  0  to  9 with the
2738                            default value being 5.
2739
2740                     flags  The test given by the mailcap-prio-flags option is
2741                            used to resolve entries.
2742
2743                     place  Later  entries  are  preferred; as the entries are
2744                            strictly ordered, this test always succeeds.
2745
2746                     Note that as this style is handled during initialisation,
2747                     the  context  is always :mime:, with no discrimination by
2748                     suffix.
2749
2750              mailcap-prio-flags
2751                     This style is used when the keyword flags is  encountered
2752                     in  the list of tests specified by the mailcap-priorities
2753                     style.  It should be set to a list of patterns,  each  of
2754                     which  is tested against the flags specified in the mail‐
2755                     cap entry (in other words, the sets of assignments  found
2756                     with some entries in the mailcap file).  Earlier patterns
2757                     in the list are preferred to later ones, and matched pat‐
2758                     terns are preferred to unmatched ones.
2759
2760              mime-types
2761                     A  list  of  files  in  the  format  of ~/.mime.types and
2762                     /etc/mime.types to be read during  setup,  replacing  the
2763                     default list which consists of those two files.  The con‐
2764                     text is :mime:.  A + in the list will be replaced by  the
2765                     default files.
2766
2767              never-background
2768                     If  this  boolean style is set, the handler for the given
2769                     context is always run in  the  foreground,  even  if  the
2770                     flags  provided  in the mailcap entry suggest it need not
2771                     be (for example, it doesn't require a terminal).
2772
2773              pager  If set, will be used instead of $PAGER or more to  handle
2774                     suffixes  where  the copiousoutput flag is set.  The con‐
2775                     text is as for handler, i.e. :mime:.suffix: for  handling
2776                     a file with the given suffix.
2777
2778              Examples:
2779
2780                     zstyle ':mime:*' mailcap ~/.mailcap /usr/local/etc/mailcap
2781                     zstyle ':mime:.txt:' handler less %s
2782                     zstyle ':mime:.txt:' flags needsterminal
2783
2784              When  zsh-mime-setup is subsequently run, it will look for mail‐
2785              cap entries in the two files given.  Files of suffix  .txt  will
2786              be  handled  by running `less file.txt'.  The flag needsterminal
2787              is set to show that this program must run attached to  a  termi‐
2788              nal.
2789
2790              As there are several steps to dispatching a command, the follow‐
2791              ing should be checked if attempting to execute a file by  exten‐
2792              sion .ext does not have the expected effect.
2793
2794              The  command  `alias  -s ext' should show `ps=zsh-mime-handler'.
2795              If it shows something else, another  suffix  alias  was  already
2796              installed and was not overwritten.  If it shows nothing, no han‐
2797              dler was installed:  this is most likely because no handler  was
2798              found in the .mime.types and mailcap combination for .ext files.
2799              In  that  case,  appropriate  handling  should   be   added   to
2800              ~/.mime.types and mailcap.
2801
2802              If  the extension is handled by zsh-mime-handler but the file is
2803              not opened correctly, either the handler defined for the type is
2804              incorrect,  or  the flags associated with it are in appropriate.
2805              Running zsh-mime-setup -l will show the handler  and,  if  there
2806              are any, the flags.  A %s in the handler is replaced by the file
2807              (suitably quoted if necessary).  Check that the handler  program
2808              listed  lists  and can be run in the way shown.  Also check that
2809              the flags needsterminal or copiousoutput are set if the  handler
2810              needs to be run under a terminal; the second flag is used if the
2811              output should be sent to a pager.   An  example  of  a  suitable
2812              mailcap entry for such a program is:
2813
2814                     text/html; /usr/bin/lynx '%s'; needsterminal
2815
2816              Running  `zsh-mime-handler  -l  command line' prints the command
2817              line that would be executed, simplified to remove the effect  of
2818              any  flags,  and  quoted so that the output can be run as a com‐
2819              plete zsh command line.  This is used by the  completion  system
2820              to  decide how to complete after a file handled by zsh-mime-set‐
2821              up.
2822
2823       pick-web-browser
2824              This function is separate from the two MIME functions  described
2825              above and can be assigned directly to a suffix:
2826
2827                     autoload -U pick-web-browser
2828                     alias -s html=pick-web-browser
2829
2830              It  is  provided  as  an intelligent front end to dispatch a web
2831              browser.  It may be run as either a function or a shell  script.
2832              The status 255 is returned if no browser could be started.
2833
2834              Various   styles  are  available  to  customize  the  choice  of
2835              browsers:
2836
2837              browser-style
2838                     The value of the style is an array giving preferences  in
2839                     decreasing  order  for  the  type of browser to use.  The
2840                     values of elements may be
2841
2842                     running
2843                            Use a GUI browser that is already running when  an
2844                            X  Window  display  is  available.   The  browsers
2845                            listed in the x-browsers style are tried in  order
2846                            until  one  is  found;  if it is, the file will be
2847                            displayed in that browser, so the user may need to
2848                            check  whether  it  has  appeared.   If no running
2849                            browser is found, one is  not  started.   Browsers
2850                            other   than  Firefox,  Opera  and  Konqueror  are
2851                            assumed to understand the Mozilla syntax for open‐
2852                            ing a URL remotely.
2853
2854                     x      Start  a  new GUI browser when an X Window display
2855                            is available.  Search for the availability of  one
2856                            of the browsers listed in the x-browsers style and
2857                            start the first one that is found.   No  check  is
2858                            made for an already running browser.
2859
2860                     tty    Start  a  terminal-based  browser.  Search for the
2861                            availability of one of the browsers listed in  the
2862                            tty-browsers style and start the first one that is
2863                            found.
2864
2865                     If the style is not set the  default  running  x  tty  is
2866                     used.
2867
2868              x-browsers
2869                     An array in decreasing order of preference of browsers to
2870                     use when running under the X Window  System.   The  array
2871                     consists  of  the  command  name under which to start the
2872                     browser.  They are looked up in the context :mime: (which
2873                     may  be  extended  in  future, so appending `*' is recom‐
2874                     mended).  For example,
2875
2876                            zstyle ':mime:*' x-browsers opera konqueror firefox
2877
2878                     specifies that pick-web-browser should first look  for  a
2879                     running  instance of Opera, Konqueror or Firefox, in that
2880                     order, and if it fails to  find  any  should  attempt  to
2881                     start  Opera.   The  default  is firefox mozilla netscape
2882                     opera konqueror.
2883
2884              tty-browsers
2885                     An array similar to  x-browsers,  except  that  it  gives
2886                     browsers  to  use  when no X Window display is available.
2887                     The default is elinks links lynx.
2888
2889              command
2890                     If it is set this style is used to pick the command  used
2891                     to   open   a   page  for  a  browser.   The  context  is
2892                     :mime:browser:new:$browser: to start  a  new  browser  or
2893                     :mime:browser:running:$browser:   to  open  a  URL  in  a
2894                     browser already running on the current X  display,  where
2895                     $browser  is  the  value  matched  in  the  x-browsers or
2896                     tty-browsers  style.   The  escape  sequence  %b  in  the
2897                     style's  value  will be replaced by the browser, while %u
2898                     will be replaced by the URL.  If the style  is  not  set,
2899                     the  default for all new instances is equivalent to %b %u
2900                     and the defaults for using running browsers  are  equiva‐
2901                     lent  to  the  values kfmclient openURL %u for Konqueror,
2902                     firefox -new-tab %u for Firefox, opera  -newpage  %u  for
2903                     Opera, and %b -remote "openUrl(%u)" for all others.
2904

MATHEMATICAL FUNCTIONS

2906       zcalc [ expression ... ]
2907              A reasonably powerful calculator based on zsh's arithmetic eval‐
2908              uation facility.  The syntax is similar to that of  formulae  in
2909              most  programming languages; see the section `Arithmetic Evalua‐
2910              tion' in  zshmisc(1)  for  details.   The  mathematical  library
2911              zsh/mathfunc  will be loaded if it is available; see the section
2912              `The zsh/mathfunc Module' in  zshmodules(1).   The  mathematical
2913              functions correspond to the raw system libraries, so trigonomet‐
2914              ric functions are evaluated using radians, and so on.
2915
2916              Each line typed is evaluated as an expression.  The prompt shows
2917              a  number, which corresponds to a positional parameter where the
2918              result of that calculation is stored.  For example,  the  result
2919              of the calculation on the line preceded by `4> ' is available as
2920              $4.  The last value calculated is available as ans.   Full  com‐
2921              mand  line  editing,  including the history of previous calcula‐
2922              tions,  is  available;  the  history  is  saved  in   the   file
2923              ~/.zcalc_history.   To  exit, enter a blank line or type `:q' on
2924              its own (`q' is allowed for historical compatibility).
2925
2926              If arguments are given to zcalc on start up, they  are  used  to
2927              prime  the first few positional parameters.  A visual indication
2928              of this is given when the calculator starts.
2929
2930              The constants PI (3.14159...) and E (2.71828...)  are  provided.
2931              Parameter  assignment  is possible, but note that all parameters
2932              will be put into the global namespace.
2933
2934              The output  base  can  be  initialised  by  passing  the  option
2935              `-#base',  for  example  `zcalc  -#16'  (the  `#' may have to be
2936              quoted, depending on the globbing options set).
2937
2938              The prompt is configurable via the parameter ZCALCPROMPT,  which
2939              undergoes  standard  prompt expansion.  The index of the current
2940              entry is stored locally in the first element of the array psvar,
2941              which  can  be referred to in ZCALCPROMPT as `%1v'.  The default
2942              prompt is `%1v> '.
2943
2944              A few special commands are available; these are introduced by  a
2945              colon.  For backward compatibility, the colon may be omitted for
2946              certain commands.  Completion is available if compinit has  been
2947              run.
2948
2949              The  output  precision  may be specified within zcalc by special
2950              commands familiar from many calculators.
2951              :norm  The default output format.  It corresponds to the  printf
2952                     %g  specification.  Typically this shows six decimal dig‐
2953                     its.
2954
2955              :sci digits
2956                     Scientific notation, corresponding to the printf %g  out‐
2957                     put format with the precision given by digits.  This pro‐
2958                     duces either fixed point or exponential notation  depend‐
2959                     ing on the value output.
2960
2961              :fix digits
2962                     Fixed point notation, corresponding to the printf %f out‐
2963                     put format with the precision given by digits.
2964
2965              :eng digits
2966                     Exponential notation, corresponding to the printf %E out‐
2967                     put format with the precision given by digits.
2968
2969              :raw   Raw  output:  this is the default form of the output from
2970                     a math evaluation.  This may show more precision than the
2971                     number actually possesses.
2972
2973              Other special commands:
2974              :!line...
2975                     Execute  line...  as  a  normal shell command line.  Note
2976                     that it is executed in the context of the function,  i.e.
2977                     with local variables.  Space is optional after :!.
2978
2979              :local arg ...
2980                     Declare  variables local to the function.  Note that cer‐
2981                     tain variables are used by the function for its own  pur‐
2982                     poses.   Other  variables may be used, too, but they will
2983                     be taken from or put into the global scope.
2984
2985              :function name [ body ]
2986                     Define a mathematical function or (with no  body)  delete
2987                     it.   The  function  is  defined  using zmathfuncdef, see
2988                     below.
2989
2990                     Note that zcalc takes care of  all  quoting.   Hence  for
2991                     example:
2992
2993                            function cube $1 * $1 * $1
2994
2995                     defines a function to cube the sole argument.
2996
2997              [#base]
2998                     This  is  not  a  special  command, rather part of normal
2999                     arithmetic syntax; however, when this form appears  on  a
3000                     line  by  itself the default output radix is set to base.
3001                     Use, for example, `[#16]' to display  hexadecimal  output
3002                     preceded  by  an indication of the base, or `[##16]' just
3003                     to display the raw number in the given base.  Bases them‐
3004                     selves  are  always  specified in decimal. `[#]' restores
3005                     the normal output format.  Note that  setting  an  output
3006                     base  suppresses  floating  point  output;  use  `[#]' to
3007                     return to normal operation.
3008
3009              See the comments in the function for a few extra tips.
3010
3011       zmathfuncdef [ mathfunc [ body ] ]
3012              A convenient front end to functions -M.
3013
3014              With two arguments, define a mathematical function  named  math‐
3015              func  which  can  be  used in any form of arithmetic evaluation.
3016              body is a mathematical expression to implement the function.  It
3017              may  contain  references  to position parameters $1, $2, ...  to
3018              refer to mandatory parameters and ${1:-defvalue} ...   to  refer
3019              to  optional  parameters.   Note that the forms must be strictly
3020              adhered to for the function to calculate the correct  number  of
3021              arguments.  The implementation is held in a shell function named
3022              zsh_math_func_mathfunc; usually the user will not need to  refer
3023              to  the  shell  function directly.  Any existing function of the
3024              same name is silently replaced.
3025
3026              With one argument, remove the mathematical function mathfunc  as
3027              well as the shell function implementation.
3028
3029              With  no  arguments, list all mathfunc functions in a form suit‐
3030              able for restoring the definition.  The functions have not  nec‐
3031              essarily been defined by zmathfuncdef.
3032

USER CONFIGURATION FUNCTIONS

3034       The  zsh/newuser  module  comes  with  a function to aid in configuring
3035       shell options for new users.  If the module is installed, this function
3036       can  also be run by hand.  It is available even if the module's default
3037       behaviour, namely running the function for a new user logging in  with‐
3038       out startup files, is inhibited.
3039
3040       zsh-newuser-install [ -f ]
3041              The  function  presents  the  user with various options for cus‐
3042              tomizing their initialization scripts.  Currently only  ~/.zshrc
3043              is  handled.   $ZDOTDIR/.zshrc  is used instead if the parameter
3044              ZDOTDIR is set; this provides a way for the user to configure  a
3045              file without altering an existing .zshrc.
3046
3047              By default the function exits immediately if it finds any of the
3048              files .zshenv, .zprofile, .zshrc, or .zlogin in the  appropriate
3049              directory.   The  option  -f  is  required in order to force the
3050              function to continue.  Note  this  may  happen  even  if  .zshrc
3051              itself does not exist.
3052
3053              As  currently  configured, the function will exit immediately if
3054              the user has root privileges; this behaviour cannot be  overrid‐
3055              den.
3056
3057              Once  activated,  the  function's  behaviour  is  supposed to be
3058              self-explanatory.  Menus are present allowing the user to  alter
3059              the  value  of options and parameters.  Suggestions for improve‐
3060              ments are always welcome.
3061
3062              When the script exits, the user is given the opportunity to save
3063              the  new  file  or  not; changes are not irreversible until this
3064              point.  However, the script is careful to  restrict  changes  to
3065              the file only to a group marked by the lines `# Lines configured
3066              by zsh-newuser-install'  and  `#  End  of  lines  configured  by
3067              zsh-newuser-install'.  In addition, the old version of .zshrc is
3068              saved to a file with the suffix .zni appended.
3069
3070              If the function edits an existing .zshrc, it is up to  the  user
3071              to  ensure that the changes made will take effect.  For example,
3072              if control usually returns early from the  existing  .zshrc  the
3073              lines  will  not be executed; or a later initialization file may
3074              override options or parameters, and so on.  The function  itself
3075              does not attempt to detect any such conflicts.
3076

OTHER FUNCTIONS

3078       There  are  a  large  number of helpful functions in the Functions/Misc
3079       directory of the zsh distribution.  Most are very  simple  and  do  not
3080       require documentation here, but a few are worthy of special mention.
3081
3082   Descriptions
3083       colors This  function  initializes  several  associative  arrays to map
3084              color names to (and from) the ANSI standard eight-color terminal
3085              codes.   These  are used by the prompt theme system (see above).
3086              You seldom should need to run colors more than once.
3087
3088              The eight base colors are:  black,  red,  green,  yellow,  blue,
3089              magenta,  cyan,  and  white.   Each of these has codes for fore‐
3090              ground and background.  In addition there  are  eight  intensity
3091              attributes:  bold,  faint,  standout, underline, blink, reverse,
3092              and conceal.  Finally,  there  are  six  codes  used  to  negate
3093              attributes:  none (reset all attributes to the defaults), normal
3094              (neither bold nor faint), no-standout,  no-underline,  no-blink,
3095              and no-reverse.
3096
3097              Some  terminals  do  not  support all combinations of colors and
3098              intensities.
3099
3100              The associative arrays are:
3101
3102              color
3103              colour Map all the color names to their integer codes, and inte‐
3104                     ger  codes  to the color names.  The eight base names map
3105                     to the foreground color codes, as do names prefixed  with
3106                     `fg-', such as `fg-red'.  Names prefixed with `bg-', such
3107                     as `bg-blue', refer to the background codes.  The reverse
3108                     mapping  from  code  to  color yields base name for fore‐
3109                     ground codes and the bg- form for backgrounds.
3110
3111                     Although it is a misnomer to call  them  `colors',  these
3112                     arrays  also map the other fourteen attributes from names
3113                     to codes and codes to names.
3114
3115              fg
3116              fg_bold
3117              fg_no_bold
3118                     Map the eight basic color names to ANSI  terminal  escape
3119                     sequences  that  set  the  corresponding  foreground text
3120                     properties.  The fg sequences change  the  color  without
3121                     changing the eight intensity attributes.
3122
3123              bg
3124              bg_bold
3125              bg_no_bold
3126                     Map  the  eight basic color names to ANSI terminal escape
3127                     sequences that set the corresponding  background  proper‐
3128                     ties.  The bg sequences change the color without changing
3129                     the eight intensity attributes.
3130
3131              In addition, the scalar parameters  reset_color  and  bold_color
3132              are  set  to  the  ANSI  terminal  escapes  that  turn  off  all
3133              attributes and turn on bold intensity, respectively.
3134
3135       fned name
3136              Same as zed -f.  This function does not appear in the  zsh  dis‐
3137              tribution, but can be created by linking zed to the name fned in
3138              some directory in your fpath.
3139
3140       is-at-least needed [ present ]
3141              Perform a greater-than-or-equal-to  comparison  of  two  strings
3142              having  the format of a zsh version number; that is, a string of
3143              numbers and text with segments separated by dots or dashes.   If
3144              the  present string is not provided, $ZSH_VERSION is used.  Seg‐
3145              ments are paired left-to-right in the two strings  with  leading
3146              non-number parts ignored.  If one string has fewer segments than
3147              the other, the missing segments are considered zero.
3148
3149              This is useful in startup files to set options and  other  state
3150              that are not available in all versions of zsh.
3151
3152                     is-at-least 3.1.6-15 && setopt NO_GLOBAL_RCS
3153                     is-at-least 3.1.0 && setopt HIST_REDUCE_BLANKS
3154                     is-at-least 2.6-17 || print "You can't use is-at-least here."
3155
3156       nslookup [ arg ... ]
3157              This  wrapper  function  for  the  nslookup command requires the
3158              zsh/zpty module (see zshmodules(1)).  It  behaves  exactly  like
3159              the  standard  nslookup  except  that  it  provides customizable
3160              prompts  (including  a  right-side  prompt)  and  completion  of
3161              nslookup  commands,  host  names,  etc.  (if  you  use the func‐
3162              tion-based completion system).  Completion  styles  may  be  set
3163              with the context prefix `:completion:nslookup'.
3164
3165              See also the pager, prompt and rprompt styles below.
3166
3167       regexp-replace var regexp replace
3168              Use  regular  expressions to perform a global search and replace
3169              operation on a variable.  If the  option  RE_MATCH_PCRE  is  not
3170              set, POSIX extended regular expressions are used, else Perl-com‐
3171              patible regular expressions  (this  requires  the  shell  to  be
3172              linked against the pcre library).
3173
3174              var  is  the  name  of  the variable containing the string to be
3175              matched.  The variable will be modified directly  by  the  func‐
3176              tion.   The  variables  MATCH, MBEGIN, MEND, match, mbegin, mend
3177              should be avoided as these are used by  the  regular  expression
3178              code.
3179
3180              regexp is the regular expression to match against the string.
3181
3182              replace  is  the  replacement text.  This can contain parameter,
3183              command and arithmetic expressions which will be  replaced:   in
3184              particular,  a  reference to $MATCH will be replaced by the text
3185              matched by the pattern.
3186
3187              The return status is 0 if at least one match was performed, else
3188              1.
3189
3190       run-help cmd
3191              This function is designed to be invoked by the run-help ZLE wid‐
3192              get, in place of the  default  alias.   See  `Accessing  On-Line
3193              Help' above for setup instructions.
3194
3195              In  the  discussion which follows, if cmd is a file system path,
3196              it is first reduced to its rightmost component (the file name).
3197
3198              Help is first sought by looking for a  file  named  cmd  in  the
3199              directory  named by the HELPDIR parameter.  If no file is found,
3200              an assistant function, alias, or command named  run-help-cmd  is
3201              sought.   If  found,  the assistant is executed with the rest of
3202              the current command line (everything after the command name cmd)
3203              as its arguments.  When neither file nor assistant is found, the
3204              external command `man cmd' is run.
3205
3206              An example assistant for the "ssh" command:
3207
3208                     run-help-ssh() {
3209                         emulate -LR zsh
3210                         local -a args
3211                         # Delete the "-l username" option
3212                         zparseopts -D -E -a args l:
3213                         # Delete other options, leaving: host command
3214                         args=(${@:#-*})
3215                         if [[ ${#args} -lt 2 ]]; then
3216                             man ssh
3217                         else
3218                             run-help $args[2]
3219                         fi
3220                     }
3221
3222              Several of these assistants are provided in  the  Functions/Misc
3223              directory.   These  must  be autoloaded, or placed as executable
3224              scripts in your search path, in order to be found  and  used  by
3225              run-help.
3226
3227              run-help-git
3228              run-help-svk
3229              run-help-svn
3230                     Assistant functions for the git, svk, and svn commands.
3231
3232       tetris Zsh  was once accused of not being as complete as Emacs, because
3233              it lacked a Tetris game.  This function was  written  to  refute
3234              this vicious slander.
3235
3236              This function must be used as a ZLE widget:
3237
3238                     autoload -U tetris
3239                     zle -N tetris
3240                     bindkey keys tetris
3241
3242              To  start  a game, execute the widget by typing the keys.  What‐
3243              ever command line you were editing disappears  temporarily,  and
3244              your  keymap  is also temporarily replaced by the Tetris control
3245              keys.  The previous editor state is restored when you  quit  the
3246              game (by pressing `q') or when you lose.
3247
3248              If  you quit in the middle of a game, the next invocation of the
3249              tetris widget will continue where you left off.  If you lost, it
3250              will start a new game.
3251
3252       zargs [ option ... -- ] [ input ... ] [ -- command [ arg ... ] ]
3253              This  function  has  a similar purpose to GNU xargs.  Instead of
3254              reading lines of arguments from the  standard  input,  it  takes
3255              them  from  the command line.  This is useful because zsh, espe‐
3256              cially with recursive glob operators, often can construct a com‐
3257              mand  line  for  a  shell  function  that  is longer than can be
3258              accepted by an external command.
3259
3260              The option list represents options of the zargs command  itself,
3261              which  are  the  same  as those of xargs.  The input list is the
3262              collection of strings (often file names) that become  the  argu‐
3263              ments  of the command, analogous to the standard input of xargs.
3264              Finally, the arg  list  consists  of  those  arguments  (usually
3265              options)  that are passed to the command each time it runs.  The
3266              arg list precedes the elements from the input list in each  run.
3267              If no command is provided, then no arg list may be provided, and
3268              in that event the default command is `print' with arguments  `-r
3269              --'.
3270
3271              For  example, to get a long ls listing of all plain files in the
3272              current directory or its subdirectories:
3273
3274                     autoload -U zargs
3275                     zargs -- **/*(.) -- ls -l
3276
3277              Note that `--' is used both to mark the end of the  option  list
3278              and  to  mark the end of the input list, so it must appear twice
3279              whenever the input list may be empty.  If there is guaranteed to
3280              be  at least one input and the first input does not begin with a
3281              `-', then the first `--' may be omitted.
3282
3283              In the event that the string `--' is or may be an input, the  -e
3284              option  may  be  used  to change the end-of-inputs marker.  Note
3285              that this does not change the end-of-options marker.  For  exam‐
3286              ple, to use `..' as the marker:
3287
3288                     zargs -e.. -- **/*(.) .. ls -l
3289
3290              This  is a good choice in that example because no plain file can
3291              be named `..', but the best end-marker depends  on  the  circum‐
3292              stances.
3293
3294              The  options  -i,  -I, -l, -L, and -n differ slightly from their
3295              usage in xargs.  There are no input lines for zargs to count, so
3296              -l and -L count through the input list, and -n counts the number
3297              of arguments passed to each execution of command, including  any
3298              arg  list.   Also, any time -i or -I is used, each input is pro‐
3299              cessed separately as if by `-L 1'.
3300
3301              For details of the other zargs options, see xargs(1)  (but  note
3302              the difference in function between zargs and xargs) or run zargs
3303              with the --help option.
3304
3305       zed [ -f ] name
3306       zed -b This function uses the ZLE editor to edit a file or function.
3307
3308              Only one name argument is allowed.  If the -f option  is  given,
3309              the  name  is taken to be that of a function; if the function is
3310              marked for autoloading, zed searches for it  in  the  fpath  and
3311              loads  it.   Note  that  functions edited this way are installed
3312              into the current shell, but not written  back  to  the  autoload
3313              file.
3314
3315              Without  -f,  name  is  the path name of the file to edit, which
3316              need not exist; it is created on write, if necessary.
3317
3318              While editing, the function sets the main keymap to zed and  the
3319              vi  command  keymap to zed-vicmd.  These will be copied from the
3320              existing main and vicmd keymaps if they do not exist  the  first
3321              time  zed is run.  They can be used to provide special key bind‐
3322              ings used only in zed.
3323
3324              If it creates the keymap, zed rebinds the return key to insert a
3325              line  break and `^X^W' to accept the edit in the zed keymap, and
3326              binds `ZZ' to accept the edit in the zed-vicmd keymap.
3327
3328              The bindings alone can be installed by running `zed  -b'.   This
3329              is  suitable  for  putting  into  a startup file.  Note that, if
3330              rerun, this  will  overwrite  the  existing  zed  and  zed-vicmd
3331              keymaps.
3332
3333              Completion  is available, and styles may be set with the context
3334              prefix `:completion:zed'.
3335
3336              A zle widget zed-set-file-name is available.  This can be called
3337              by  name  from  within  zed using `\ex zed-set-file-name' (note,
3338              however, that because of zed's rebindings you will have to  type
3339              ^j  at  the end instead of the return key), or can be bound to a
3340              key in either of the zed or zed-vicmd keymaps after `zed -b' has
3341              been  run.  When the widget is called, it prompts for a new name
3342              for the file being edited.  When zed  exits  the  file  will  be
3343              written  under  that  name  and  the  original file will be left
3344              alone.  The widget has no effect with `zed -f'.
3345
3346              While zed-set-file-name is running, zed uses the keymap zed-nor‐
3347              mal-keymap,  which  is  linked from the main keymap in effect at
3348              the time zed initialised its bindings.  (This  is  to  make  the
3349              return  key  operate  normally.)  The result is that if the main
3350              keymap has been changed, the widget won't notice.  This is not a
3351              concern for most users.
3352
3353       zcp [ -finqQvwW ] srcpat dest
3354       zln [ -finqQsvwW ] srcpat dest
3355              Same as zmv -C and zmv -L, respectively.  These functions do not
3356              appear in the zsh distribution, but can be  created  by  linking
3357              zmv to the names zcp and zln in some directory in your fpath.
3358
3359       zkbd   See `Keyboard Definition' above.
3360
3361       zmv  [ -finqQsvwW ] [ -C | -L | -M | -p program ] [ -o optstring ] src‐
3362       pat dest
3363              Move (usually, rename) files matching the pattern srcpat to cor‐
3364              responding  files  having names of the form given by dest, where
3365              srcpat contains parentheses surrounding patterns which  will  be
3366              replaced in turn by $1, $2, ... in dest.  For example,
3367
3368                     zmv '(*).lis' '$1.txt'
3369
3370              renames    `foo.lis'   to   `foo.txt',   `my.old.stuff.lis'   to
3371              `my.old.stuff.txt', and so on.
3372
3373              The pattern is always treated as an EXTENDED_GLOB pattern.   Any
3374              file  whose  name  is  not changed by the substitution is simply
3375              ignored.  Any error (a substitution resulted in an empty string,
3376              two  substitutions  gave the same result, the destination was an
3377              existing regular file and -f was not given)  causes  the  entire
3378              function to abort without doing anything.
3379
3380              Options:
3381
3382              -f     Force  overwriting  of  destination files.  Not currently
3383                     passed down to the mv/cp/ln command due  to  vagaries  of
3384                     implementations (but you can use -o-f to do that).
3385              -i     Interactive:  show  each  line to be executed and ask the
3386                     user whether to execute it.  `Y' or `y' will execute  it,
3387                     anything  else  will skip it.  Note that you just need to
3388                     type one character.
3389              -n     No execution: print what would happen, but don't do it.
3390              -q     Turn bare glob qualifiers off: now assumed by default, so
3391                     this has no effect.
3392              -Q     Force bare glob qualifiers on.  Don't turn this on unless
3393                     you are actually using glob qualifiers in a pattern.
3394              -s     Symbolic, passed down to ln; only works with -L.
3395              -v     Verbose: print each command as it's being executed.
3396              -w     Pick out wildcard parts  of  the  pattern,  as  described
3397                     above,  and  implicitly  add parentheses for referring to
3398                     them.
3399              -W     Just like -w, with the addition of turning  wildcards  in
3400                     the replacement pattern into sequential ${1} .. ${N} ref‐
3401                     erences.
3402              -C
3403              -L
3404              -M     Force cp, ln or mv, respectively, regardless of the  name
3405                     of the function.
3406              -p program
3407                     Call  program instead of cp, ln or mv.  Whatever it does,
3408                     it should at least understand the form `program  --  old‐
3409                     name  newname'  where  oldname  and newname are filenames
3410                     generated by zmv.
3411              -o optstring
3412                     The optstring is split into words and passed down  verba‐
3413                     tim  to  the  cp,  ln or mv command called to perform the
3414                     work.  It should probably begin with a `-'.
3415
3416              Further examples:
3417
3418                     zmv -v '(* *)' '${1// /_}'
3419
3420              For any file in the current directory with at least one space in
3421              the  name,  replace every space by an underscore and display the
3422              commands executed.
3423
3424              For more complete examples and other implementation details, see
3425              the  zmv  source file, usually located in one of the directories
3426              named in your fpath, or in Functions/Misc/zmv in the zsh distri‐
3427              bution.
3428
3429       zrecompile
3430              See `Recompiling Functions' above.
3431
3432       zstyle+ context style value [ + subcontext style value ... ]
3433              This  makes  defining styles a bit simpler by using a single `+'
3434              as a special token that allows you to append a context  name  to
3435              the previously used context name.  Like this:
3436
3437                     zstyle+ ':foo:bar' style1 value1 \
3438                           + ':baz'     style2 value2 \
3439                           + ':frob'    style3 value3
3440
3441              This  defines `style1' with `value1' for the context :foo:bar as
3442              usual, but it also defines `style2' with `value2' for  the  con‐
3443              text  :foo:bar:baz and `style3' with `value3' for :foo:bar:frob.
3444              Any subcontext may be the empty string to re-use the first  con‐
3445              text unchanged.
3446
3447   Styles
3448       insert-tab
3449              The  zed function sets this style in context `:completion:zed:*'
3450              to turn off completion when TAB is typed at the beginning  of  a
3451              line.   You may override this by setting your own value for this
3452              context and style.
3453
3454       pager  The nslookup  function  looks  up  this  style  in  the  context
3455              `:nslookup' to determine the program used to display output that
3456              does not fit on a single screen.
3457
3458       prompt
3459       rprompt
3460              The nslookup  function  looks  up  this  style  in  the  context
3461              `:nslookup' to set the prompt and the right-side prompt, respec‐
3462              tively.  The usual expansions for the PS1  and  RPS1  parameters
3463              may be used (see EXPANSION OF PROMPT SEQUENCES in zshmisc(1)).
3464
3465
3466
3467zsh 5.0.2                      December 21, 2012                 ZSHCONTRIB(1)
Impressum