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-4.3.11/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-4.3.11/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-4.3.11/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 or preexec,  the  special
266              functions in question.
267
268              functions  is name of an ordinary shell function.  If no options
269              are given this will be added to the array  of  functions  to  be
270              executed in the given context.
271
272              If  the  option  -d  is  given, the function is removed from the
273              array of functions to be executed.
274
275              If the option -D is given, the function is treated as a  pattern
276              and  any  matching names of functions are removed from the array
277              of functions to be executed.
278

REMEMBERING RECENT DIRECTORIES

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

GATHERING INFORMATION FROM VERSION CONTROL SYSTEMS

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

PROMPT THEMES

1377   Installation
1378       You should make sure  all  the  functions  from  the  Functions/Prompts
1379       directory of the source distribution are available; they all begin with
1380       the string `prompt_' except for the special function`promptinit'.   You
1381       also  need  the  `colors'  function  from Functions/Misc.  All of these
1382       functions may already have been installed on your system; if  not,  you
1383       will  need  to find them and copy them.  The directory should appear as
1384       one of the elements of the fpath array (this should already be the case
1385       if they were installed), and at least the function promptinit should be
1386       autoloaded; it will autoload the rest.  Finally, to initialize the  use
1387       of  the system you need to call the promptinit function.  The following
1388       code in your .zshrc will arrange for this;  assume  the  functions  are
1389       stored in the directory ~/myfns:
1390
1391              fpath=(~/myfns $fpath)
1392              autoload -U promptinit
1393              promptinit
1394
1395   Theme Selection
1396       Use  the  prompt  command to select your preferred theme.  This command
1397       may be added to your .zshrc following the call to promptinit  in  order
1398       to start zsh with a theme already selected.
1399
1400       prompt [ -c | -l ]
1401       prompt [ -p | -h ] [ theme ... ]
1402       prompt [ -s ] theme [ arg ... ]
1403              Set  or  examine  the prompt theme.  With no options and a theme
1404              argument, the theme with that name is set as the current  theme.
1405              The  available  themes  are  determined  at run time; use the -l
1406              option to see a list.  The special  theme  `random'  selects  at
1407              random one of the available themes and sets your prompt to that.
1408
1409              In  some  cases  the  theme may be modified by one or more argu‐
1410              ments, which should be given after the theme name.  See the help
1411              for each theme for descriptions of these arguments.
1412
1413              Options are:
1414
1415              -c     Show  the currently selected theme and its parameters, if
1416                     any.
1417              -l     List all available prompt themes.
1418              -p     Preview the theme named by theme, or  all  themes  if  no
1419                     theme is given.
1420              -h     Show help for the theme named by theme, or for the prompt
1421                     function if no theme is given.
1422              -s     Set theme as the current theme and save state.
1423
1424       prompt_theme_setup
1425              Each available theme has a setup function which is called by the
1426              prompt function to install that theme.  This function may define
1427              other functions as necessary to maintain the  prompt,  including
1428              functions  used  to  preview  the prompt or provide help for its
1429              use.  You should not normally  call  a  theme's  setup  function
1430              directly.
1431

ZLE FUNCTIONS

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

EXCEPTION HANDLING

2434       Two  functions are provided to enable zsh to provide exception handling
2435       in a form that should be familiar from other languages.
2436
2437       throw exception
2438              The function throw throws the named exception.  The name  is  an
2439              arbitrary  string  and is only used by the throw and catch func‐
2440              tions.  An exception is for the most part treated the same as  a
2441              shell error, i.e. an unhandled exception will cause the shell to
2442              abort all processing in a function or script and  to  return  to
2443              the top level in an interactive shell.
2444
2445       catch exception-pattern
2446              The  function  catch  returns  status  zero  if an exception was
2447              thrown and the pattern exception-pattern matches its name.  Oth‐
2448              erwise  it  returns  status  1.  exception-pattern is a standard
2449              shell  pattern,  respecting   the   current   setting   of   the
2450              EXTENDED_GLOB option.  An alias catch is also defined to prevent
2451              the argument to the function from matching  filenames,  so  pat‐
2452              terns  may  be  used  unquoted.  Note that as exceptions are not
2453              fundamentally different from other shell errors it  is  possible
2454              to  catch shell errors by using an empty string as the exception
2455              name.  The shell variable CAUGHT is set by catch to the name  of
2456              the exception caught.  It is possible to rethrow an exception by
2457              calling the throw function again  once  an  exception  has  been
2458              caught.
2459
2460       The  functions  are  designed  to be used together with the always con‐
2461       struct described in zshmisc(1).  This is important as  only  this  con‐
2462       struct provides the required support for exceptions.  A typical example
2463       is as follows.
2464
2465              {
2466                # "try" block
2467                # ... nested code here calls "throw MyExcept"
2468              } always {
2469                # "always" block
2470                if catch MyExcept; then
2471                  print "Caught exception MyExcept"
2472                elif catch ''; then
2473                  print "Caught a shell error.  Propagating..."
2474                  throw ''
2475                fi
2476                # Other exceptions are not handled but may be caught further
2477                # up the call stack.
2478              }
2479
2480       If all exceptions should  be  caught,  the  following  idiom  might  be
2481       preferable.
2482
2483              {
2484                # ... nested code here throws an exception
2485              } always {
2486                if catch *; then
2487                  case $CAUGHT in
2488                    (MyExcept)
2489                    print "Caught my own exception"
2490                    ;;
2491                    (*)
2492                    print "Caught some other exception"
2493                    ;;
2494                  esac
2495                fi
2496              }
2497
2498       In common with exception handling in other languages, the exception may
2499       be thrown by code deeply nested inside the `try' block.  However,  note
2500       that  it  must  be  thrown  inside the current shell, not in a subshell
2501       forked for a pipeline, parenthesised current-shell construct,  or  some
2502       form of command or process substitution.
2503
2504       The  system  internally uses the shell variable EXCEPTION to record the
2505       name of the exception between throwing and catching.  One  drawback  of
2506       this scheme is that if the exception is not handled the variable EXCEP‐
2507       TION remains set and may be incorrectly recognised as the  name  of  an
2508       exception if a shell error subsequently occurs.  Adding unset EXCEPTION
2509       at the start of the outermost layer of any  code  that  uses  exception
2510       handling will eliminate this problem.
2511

MIME FUNCTIONS

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

MATHEMATICAL FUNCTIONS

2826       zcalc [ expression ... ]
2827              A reasonably powerful calculator based on zsh's arithmetic eval‐
2828              uation facility.  The syntax is similar to that of  formulae  in
2829              most  programming languages; see the section `Arithmetic Evalua‐
2830              tion' in  zshmisc(1)  for  details.   The  mathematical  library
2831              zsh/mathfunc  will be loaded if it is available; see the section
2832              `The zsh/mathfunc Module' in  zshmodules(1).   The  mathematical
2833              functions correspond to the raw system libraries, so trigonomet‐
2834              ric functions are evaluated using radians, and so on.
2835
2836              Each line typed is evaluated as an expression.  The prompt shows
2837              a  number, which corresponds to a positional parameter where the
2838              result of that calculation is stored.  For example,  the  result
2839              of the calculation on the line preceded by `4> ' is available as
2840              $4.  The last value calculated is available as ans.   Full  com‐
2841              mand  line  editing,  including the history of previous calcula‐
2842              tions,  is  available;  the  history  is  saved  in   the   file
2843              ~/.zcalc_history.   To  exit, enter a blank line or type `:q' on
2844              its own (`q' is allowed for historical compatibility).
2845
2846              If arguments are given to zcalc on start up, they  are  used  to
2847              prime  the first few positional parameters.  A visual indication
2848              of this is given when the calculator starts.
2849
2850              The constants PI (3.14159...) and E (2.71828...)  are  provided.
2851              Parameter  assignment  is possible, but note that all parameters
2852              will be put into the global namespace.
2853
2854              The output  base  can  be  initialised  by  passing  the  option
2855              `-#base',  for  example  `zcalc  -#16'  (the  `#' may have to be
2856              quoted, depending on the globbing options set).
2857
2858              The prompt is configurable via the parameter ZCALCPROMPT,  which
2859              undergoes  standard  prompt expansion.  The index of the current
2860              entry is stored locally in the first element of the array psvar,
2861              which  can  be referred to in ZCALCPROMPT as `%1v'.  The default
2862              prompt is `%1v> '.
2863
2864              A few special commands are available; these are introduced by  a
2865              colon.  For backward compatibility, the colon may be omitted for
2866              certain commands.  Completion is available if compinit has  been
2867              run.
2868
2869              The  output  precision  may be specified within zcalc by special
2870              commands familiar from many calculators.
2871              :norm  The default output format.  It corresponds to the  printf
2872                     %g  specification.  Typically this shows six decimal dig‐
2873                     its.
2874
2875              :sci digits
2876                     Scientific notation, corresponding to the printf %g  out‐
2877                     put format with the precision given by digits.  This pro‐
2878                     duces either fixed point or exponential notation  depend‐
2879                     ing on the value output.
2880
2881              :fix digits
2882                     Fixed point notation, corresponding to the printf %f out‐
2883                     put format with the precision given by digits.
2884
2885              :eng digits
2886                     Exponential notation, corresponding to the printf %E out‐
2887                     put format with the precision given by digits.
2888
2889              :raw   Raw  output:  this is the default form of the output from
2890                     a math evaluation.  This may show more precision than the
2891                     number actually possesses.
2892
2893              Other special commands:
2894              :!line...
2895                     Execute  line...  as  a  normal shell command line.  Note
2896                     that it is executed in the context of the function,  i.e.
2897                     with local variables.  Space is optional after :!.
2898
2899              :local arg ...
2900                     Declare  variables local to the function.  Note that cer‐
2901                     tain variables are used by the function for its own  pur‐
2902                     poses.   Other  variables may be used, too, but they will
2903                     be taken from or put into the global scope.
2904
2905              :function name [ body ]
2906                     Define a mathematical function or (with no  body)  delete
2907                     it.   The  function  is  defined  using zmathfuncdef, see
2908                     below.
2909
2910                     Note that zcalc takes care of  all  quoting.   Hence  for
2911                     example:
2912
2913                            function cube $1 * $1 * $1
2914
2915                     defines a function to cube the sole argument.
2916
2917              [#base]
2918                     This  is  not  a  special  command, rather part of normal
2919                     arithmetic syntax; however, when this form appears  on  a
2920                     line  by  itself the default output radix is set to base.
2921                     Use, for example, `[#16]' to display  hexadecimal  output
2922                     preceded  by  an indication of the base, or `[##16]' just
2923                     to display the raw number in the given base.  Bases them‐
2924                     selves  are  always  specified in decimal. `[#]' restores
2925                     the normal output format.  Note that  setting  an  output
2926                     base  suppresses  floating  point  output;  use  `[#]' to
2927                     return to normal operation.
2928
2929              See the comments in the function for a few extra tips.
2930
2931       zmathfuncdef [ mathfunc [ body ] ]
2932              A convenient front end to functions -M.
2933
2934              With two arguments, define a mathematical function  named  math‐
2935              func  which  can  be  used in any form of arithmetic evaluation.
2936              body is a mathematical expression to implement the function.  It
2937              may  contain  references  to position parameters $1, $2, ...  to
2938              refer to mandatory parameters and ${1:-defvalue} ...   to  refer
2939              to  optional  parameters.   Note that the forms must be strictly
2940              adhered to for the function to calculate the correct  number  of
2941              arguments.  The implementation is held in a shell function named
2942              zsh_math_func_mathfunc; usually the user will not need to  refer
2943              to  the  shell  function directly.  Any existing function of the
2944              same name is silently replaced.
2945
2946              With one argument, remove the mathematical function mathfunc  as
2947              well as the shell function implementation.
2948
2949              With  no  arguments, list all mathfunc functions in a form suit‐
2950              able for restoring the definition.  The functions have not  nec‐
2951              essarily been defined by zmathfuncdef.
2952

USER CONFIGURATION FUNCTIONS

2954       The  zsh/newuser  module  comes  with  a function to aid in configuring
2955       shell options for new users.  If the module is installed, this function
2956       can  also be run by hand.  It is available even if the module's default
2957       behaviour, namely running the function for a new user logging in  with‐
2958       out startup files, is inhibited.
2959
2960       zsh-newuser-install [ -f ]
2961              The  function  presents  the  user with various options for cus‐
2962              tomizing their initialization scripts.  Currently only  ~/.zshrc
2963              is  handled.   $ZDOTDIR/.zshrc  is used instead if the parameter
2964              ZDOTDIR is set; this provides a way for the user to configure  a
2965              file without altering an existing .zshrc.
2966
2967              By default the function exits immediately if it finds any of the
2968              files .zshenv, .zprofile, .zshrc, or .zlogin in the  appropriate
2969              directory.   The  option  -f  is  required in order to force the
2970              function to continue.  Note  this  may  happen  even  if  .zshrc
2971              itself does not exist.
2972
2973              As  currently  configured, the function will exit immediately if
2974              the user has root privileges; this behaviour cannot be  overrid‐
2975              den.
2976
2977              Once  activated,  the  function's  behaviour  is  supposed to be
2978              self-explanatory.  Menus are present allowing the user to  alter
2979              the  value  of options and parameters.  Suggestions for improve‐
2980              ments are always welcome.
2981
2982              When the script exits, the user is given the opportunity to save
2983              the  new  file  or  not; changes are not irreversible until this
2984              point.  However, the script is careful to  restrict  changes  to
2985              the file only to a group marked by the lines `# Lines configured
2986              by zsh-newuser-install'  and  `#  End  of  lines  configured  by
2987              zsh-newuser-install'.  In addition, the old version of .zshrc is
2988              saved to a file with the suffix .zni appended.
2989
2990              If the function edits an existing .zshrc, it is up to  the  user
2991              to  ensure that the changes made will take effect.  For example,
2992              if control usually returns early from the  existing  .zshrc  the
2993              lines  will  not be executed; or a later initialization file may
2994              override options or parameters, and so on.  The function  itself
2995              does not attempt to detect any such conflicts.
2996

OTHER FUNCTIONS

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