1ZSHCONTRIB(1) General Commands Manual ZSHCONTRIB(1)
2
3
4
6 zshcontrib - user contributions to zsh
7
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
17 Accessing On-Line Help
18 The key sequence ESC h is normally bound by ZLE to execute the run-help
19 widget (see zshzle(1)). This invokes the run-help command with the
20 command word from the current input line as its argument. By default,
21 run-help is an alias for the man command, so this often fails when the
22 command word is a shell builtin or a user-defined function. By re‐
23 defining the run-help alias, one can improve the on-line help provided
24 by the shell.
25
26 The helpfiles utility, found in the Util directory of the distribution,
27 is a Perl program that can be used to process the zsh manual to produce
28 a separate help file for each shell builtin and for many other shell
29 features as well. The autoloadable run-help function, found in Func‐
30 tions/Misc, searches for these helpfiles and performs several other
31 tests to produce the most complete help possible for the command.
32
33 Help files are installed by default to a subdirectory of /usr/share/zsh
34 or /usr/local/share/zsh.
35
36 To create your own help files with helpfiles, choose or create a direc‐
37 tory where the individual command help files will reside. For example,
38 you might choose ~/zsh_help. If you unpacked the zsh distribution in
39 your home directory, you would use the commands:
40
41 mkdir ~/zsh_help
42 perl ~/zsh-5.8.1/Util/helpfiles ~/zsh_help
43
44 The HELPDIR parameter tells run-help where to look for the help files.
45 When unset, it uses the default installation path. To use your own set
46 of help files, set this to the appropriate path in one of your startup
47 files:
48
49 HELPDIR=~/zsh_help
50
51 To use the run-help function, you need to add lines something like the
52 following to your .zshrc or equivalent startup file:
53
54 unalias run-help
55 autoload run-help
56
57 Note that in order for `autoload run-help' to work, the run-help file
58 must be in one of the directories named in your fpath array (see zsh‐
59 param(1)). This should already be the case if you have a standard zsh
60 installation; if it is not, copy Functions/Misc/run-help to an appro‐
61 priate directory.
62
63 Recompiling Functions
64 If you frequently edit your zsh functions, or periodically update your
65 zsh installation to track the latest developments, you may find that
66 function digests compiled with the zcompile builtin are frequently out
67 of date with respect to the function source files. This is not usually
68 a problem, because zsh always looks for the newest file when loading a
69 function, but it may cause slower shell startup and function loading.
70 Also, if a digest file is explicitly used as an element of fpath, zsh
71 won't check whether any of its source files has changed.
72
73 The zrecompile autoloadable function, found in Functions/Misc, can be
74 used to keep function digests up to date.
75
76 zrecompile [ -qt ] [ name ... ]
77 zrecompile [ -qt ] -p arg ... [ -- arg ... ]
78 This tries to find *.zwc files and automatically re-compile them
79 if at least one of the original files is newer than the compiled
80 file. This works only if the names stored in the compiled files
81 are full paths or are relative to the directory that contains
82 the .zwc file.
83
84 In the first form, each name is the name of a compiled file or a
85 directory containing *.zwc files that should be checked. If no
86 arguments are given, the directories and *.zwc files in fpath
87 are used.
88
89 When -t is given, no compilation is performed, but a return sta‐
90 tus of zero (true) is set if there are files that need to be
91 re-compiled and non-zero (false) otherwise. The -q option qui‐
92 ets the chatty output that describes what zrecompile is doing.
93
94 Without the -t option, the return status is zero if all files
95 that needed re-compilation could be compiled and non-zero if
96 compilation for at least one of the files failed.
97
98 If the -p option is given, the args are interpreted as one or
99 more sets of arguments for zcompile, separated by `--'. For ex‐
100 ample:
101
102 zrecompile -p \
103 -R ~/.zshrc -- \
104 -M ~/.zcompdump -- \
105 ~/zsh/comp.zwc ~/zsh/Completion/*/_*
106
107 This compiles ~/.zshrc into ~/.zshrc.zwc if that doesn't exist
108 or if it is older than ~/.zshrc. The compiled file will be
109 marked for reading instead of mapping. The same is done for
110 ~/.zcompdump and ~/.zcompdump.zwc, but this compiled file is
111 marked for mapping. The last line re-creates the file
112 ~/zsh/comp.zwc if any of the files matching the given pattern is
113 newer than it.
114
115 Without the -p option, zrecompile does not create function di‐
116 gests that do not already exist, nor does it add new functions
117 to the digest.
118
119 The following shell loop is an example of a method for creating func‐
120 tion digests for all functions in your fpath, assuming that you have
121 write permission to the directories:
122
123 for ((i=1; i <= $#fpath; ++i)); do
124 dir=$fpath[i]
125 zwc=${dir:t}.zwc
126 if [[ $dir == (.|..) || $dir == (.|..)/* ]]; then
127 continue
128 fi
129 files=($dir/*(N-.))
130 if [[ -w $dir:h && -n $files ]]; then
131 files=(${${(M)files%/*/*}#/})
132 if ( cd $dir:h &&
133 zrecompile -p -U -z $zwc $files ); then
134 fpath[i]=$fpath[i].zwc
135 fi
136 fi
137 done
138
139 The -U and -z options are appropriate for functions in the default zsh
140 installation fpath; you may need to use different options for your per‐
141 sonal function directories.
142
143 Once the digests have been created and your fpath modified to refer to
144 them, you can keep them up to date by running zrecompile with no argu‐
145 ments.
146
147 Keyboard Definition
148 The large number of possible combinations of keyboards, workstations,
149 terminals, emulators, and window systems makes it impossible for zsh to
150 have built-in key bindings for every situation. The zkbd utility,
151 found in Functions/Misc, can help you quickly create key bindings for
152 your configuration.
153
154 Run zkbd either as an autoloaded function, or as a shell script:
155
156 zsh -f ~/zsh-5.8.1/Functions/Misc/zkbd
157
158 When you run zkbd, it first asks you to enter your terminal type; if
159 the default it offers is correct, just press return. It then asks you
160 to press a number of different keys to determine characteristics of
161 your keyboard and terminal; zkbd warns you if it finds anything out of
162 the ordinary, such as a Delete key that sends neither ^H nor ^?.
163
164 The keystrokes read by zkbd are recorded as a definition for an asso‐
165 ciative array named key, written to a file in the subdirectory .zkbd
166 within either your HOME or ZDOTDIR directory. The name of the file is
167 composed from the TERM, VENDOR and OSTYPE parameters, joined by hy‐
168 phens.
169
170 You may read this file into your .zshrc or another startup file with
171 the `source' or `.' commands, then reference the key parameter in bind‐
172 key commands, like this:
173
174 source ${ZDOTDIR:-$HOME}/.zkbd/$TERM-$VENDOR-$OSTYPE
175 [[ -n ${key[Left]} ]] && bindkey "${key[Left]}" backward-char
176 [[ -n ${key[Right]} ]] && bindkey "${key[Right]}" forward-char
177 # etc.
178
179 Note that in order for `autoload zkbd' to work, the zkdb file must be
180 in one of the directories named in your fpath array (see zshparam(1)).
181 This should already be the case if you have a standard zsh installa‐
182 tion; if it is not, copy Functions/Misc/zkbd to an appropriate direc‐
183 tory.
184
185 Dumping Shell State
186 Occasionally you may encounter what appears to be a bug in the shell,
187 particularly if you are using a beta version of zsh or a development
188 release. Usually it is sufficient to send a description of the problem
189 to one of the zsh mailing lists (see zsh(1)), but sometimes one of the
190 zsh developers will need to recreate your environment in order to track
191 the problem down.
192
193 The script named reporter, found in the Util directory of the distribu‐
194 tion, is provided for this purpose. (It is also possible to autoload
195 reporter, but reporter is not installed in fpath by default.) This
196 script outputs a detailed dump of the shell state, in the form of an‐
197 other script that can be read with `zsh -f' to recreate that state.
198
199 To use reporter, read the script into your shell with the `.' command
200 and redirect the output into a file:
201
202 . ~/zsh-5.8.1/Util/reporter > zsh.report
203
204 You should check the zsh.report file for any sensitive information such
205 as passwords and delete them by hand before sending the script to the
206 developers. Also, as the output can be voluminous, it's best to wait
207 for the developers to ask for this information before sending it.
208
209 You can also use reporter to dump only a subset of the shell state.
210 This is sometimes useful for creating startup files for the first time.
211 Most of the output from reporter is far more detailed than usually is
212 necessary for a startup file, but the aliases, options, and zstyles
213 states may be useful because they include only changes from the de‐
214 faults. The bindings state may be useful if you have created any of
215 your own keymaps, because reporter arranges to dump the keymap creation
216 commands as well as the bindings for every keymap.
217
218 As is usual with automated tools, if you create a startup file with re‐
219 porter, you should edit the results to remove unnecessary commands.
220 Note that if you're using the new completion system, you should not
221 dump the functions state to your startup files with reporter; use the
222 compdump function instead (see zshcompsys(1)).
223
224 reporter [ state ... ]
225 Print to standard output the indicated subset of the current
226 shell state. The state arguments may be one or more of:
227
228 all Output everything listed below.
229 aliases
230 Output alias definitions.
231 bindings
232 Output ZLE key maps and bindings.
233 completion
234 Output old-style compctl commands. New completion is
235 covered by functions and zstyles.
236 functions
237 Output autoloads and function definitions.
238 limits Output limit commands.
239 options
240 Output setopt commands.
241 styles Same as zstyles.
242 variables
243 Output shell parameter assignments, plus export commands
244 for any environment variables.
245 zstyles
246 Output zstyle commands.
247
248 If the state is omitted, all is assumed.
249
250 With the exception of `all', every state can be abbreviated by any pre‐
251 fix, even a single letter; thus a is the same as aliases, z is the same
252 as zstyles, etc.
253
254 Manipulating Hook Functions
255 add-zsh-hook [ -L | -dD ] [ -Uzk ] hook function
256 Several functions are special to the shell, as described in the
257 section SPECIAL FUNCTIONS, see zshmisc(1), in that they are au‐
258 tomatically called at specific points during shell execution.
259 Each has an associated array consisting of names of functions to
260 be called at the same point; these are so-called `hook func‐
261 tions'. The shell function add-zsh-hook provides a simple way
262 of adding or removing functions from the array.
263
264 hook is one of chpwd, periodic, precmd, preexec, zshaddhistory,
265 zshexit, or zsh_directory_name, the special functions in ques‐
266 tion. Note that zsh_directory_name is called in a different way
267 from the other functions, but may still be manipulated as a
268 hook.
269
270 function is name of an ordinary shell function. If no options
271 are given this will be added to the array of functions to be ex‐
272 ecuted in the given context. Functions are invoked in the order
273 they were added.
274
275 If the option -L is given, the current values for the hook ar‐
276 rays are listed with typeset.
277
278 If the option -d is given, the function is removed from the ar‐
279 ray of functions to be executed.
280
281 If the option -D is given, the function is treated as a pattern
282 and any matching names of functions are removed from the array
283 of functions to be executed.
284
285 The options -U, -z and -k are passed as arguments to autoload
286 for function. For functions contributed with zsh, the options
287 -Uz are appropriate.
288
289 add-zle-hook-widget [ -L | -dD ] [ -Uzk ] hook widgetname
290 Several widget names are special to the line editor, as de‐
291 scribed in the section Special Widgets, see zshzle(1), in that
292 they are automatically called at specific points during editing.
293 Unlike function hooks, these do not use a predefined array of
294 other names to call at the same point; the shell function
295 add-zle-hook-widget maintains a similar array and arranges for
296 the special widget to invoke those additional widgets.
297
298 hook is one of isearch-exit, isearch-update, line-pre-redraw,
299 line-init, line-finish, history-line-set, or keymap-select, cor‐
300 responding to each of the special widgets zle-isearch-exit, etc.
301 The special widget names are also accepted as the hook argument.
302
303 widgetname is the name of a ZLE widget. If no options are given
304 this is added to the array of widgets to be invoked in the given
305 hook context. Widgets are invoked in the order they were added,
306 with
307 zle widgetname -Nw -- "$@"
308
309 Note that this means that the `WIDGET' special parameter tracks
310 the widgetname when the widget function is called, rather than
311 tracking the name of the corresponding special hook widget.
312
313 If the option -d is given, the widgetname is removed from the
314 array of widgets to be executed.
315
316 If the option -D is given, the widgetname is treated as a pat‐
317 tern and any matching names of widgets are removed from the ar‐
318 ray.
319
320 If widgetname does not name an existing widget when added to the
321 array, it is assumed that a shell function also named widgetname
322 is meant to provide the implementation of the widget. This name
323 is therefore marked for autoloading, and the options -U, -z and
324 -k are passed as arguments to autoload as with add-zsh-hook.
325 The widget is also created with `zle -N widgetname' to cause the
326 corresponding function to be loaded the first time the hook is
327 called.
328
329 The arrays of widgetname are currently maintained in zstyle con‐
330 texts, one for each hook context, with a style of `widgets'. If
331 the -L option is given, this set of styles is listed with
332 `zstyle -L'. This implementation may change, and the special
333 widgets that refer to the styles are created only if
334 add-zle-hook-widget is called to add at least one widget, so if
335 this function is used for any hooks, then all hooks should be
336 managed only via this function.
337
339 The function cdr allows you to change the working directory to a previ‐
340 ous working directory from a list maintained automatically. It is sim‐
341 ilar in concept to the directory stack controlled by the pushd, popd
342 and dirs builtins, but is more configurable, and as it stores all en‐
343 tries in files it is maintained across sessions and (by default) be‐
344 tween terminal emulators in the current session. Duplicates are auto‐
345 matically removed, so that the list reflects the single most recent use
346 of each directory.
347
348 Note that the pushd directory stack is not actually modified or used by
349 cdr unless you configure it to do so as described in the configuration
350 section below.
351
352 Installation
353 The system works by means of a hook function that is called every time
354 the directory changes. To install the system, autoload the required
355 functions and use the add-zsh-hook function described above:
356
357 autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
358 add-zsh-hook chpwd chpwd_recent_dirs
359
360 Now every time you change directly interactively, no matter which com‐
361 mand you use, the directory to which you change will be remembered in
362 most-recent-first order.
363
364 Use
365 All direct user interaction is via the cdr function.
366
367 The argument to cdr is a number N corresponding to the Nth most re‐
368 cently changed-to directory. 1 is the immediately preceding directory;
369 the current directory is remembered but is not offered as a destina‐
370 tion. Note that if you have multiple windows open 1 may refer to a di‐
371 rectory changed to in another window; you can avoid this by having
372 per-terminal files for storing directory as described for the re‐
373 cent-dirs-file style below.
374
375 If you set the recent-dirs-default style described below cdr will be‐
376 have the same as cd if given a non-numeric argument, or more than one
377 argument. The recent directory list is updated just the same however
378 you change directory.
379
380 If the argument is omitted, 1 is assumed. This is similar to pushd's
381 behaviour of swapping the two most recent directories on the stack.
382
383 Completion for the argument to cdr is available if compinit has been
384 run; menu selection is recommended, using:
385
386 zstyle ':completion:*:*:cdr:*:*' menu selection
387
388 to allow you to cycle through recent directories; the order is pre‐
389 served, so the first choice is the most recent directory before the
390 current one. The verbose style is also recommended to ensure the di‐
391 rectory is shown; this style is on by default so no action is required
392 unless you have changed it.
393
394 Options
395 The behaviour of cdr may be modified by the following options.
396
397 -l lists the numbers and the corresponding directories in abbrevi‐
398 ated form (i.e. with ~ substitution reapplied), one per line.
399 The directories here are not quoted (this would only be an issue
400 if a directory name contained a newline). This is used by the
401 completion system.
402
403 -r sets the variable reply to the current set of directories.
404 Nothing is printed and the directory is not changed.
405
406 -e allows you to edit the list of directories, one per line. The
407 list can be edited to any extent you like; no sanity checking is
408 performed. Completion is available. No quoting is necessary
409 (except for newlines, where I have in any case no sympathy); di‐
410 rectories are in unabbreviated from and contain an absolute
411 path, i.e. they start with /. Usually the first entry should be
412 left as the current directory.
413
414 -p 'pattern'
415 Prunes any items in the directory list that match the given ex‐
416 tended glob pattern; the pattern needs to be quoted from immedi‐
417 ate expansion on the command line. The pattern is matched
418 against each completely expanded file name in the list; the full
419 string must match, so wildcards at the end (e.g. '*removeme*')
420 are needed to remove entries with a given substring.
421
422 If output is to a terminal, then the function will print the new
423 list after pruning and prompt for confirmation by the user.
424 This output and confirmation step can be skipped by using -P in‐
425 stead of -p.
426
427 Configuration
428 Configuration is by means of the styles mechanism that should be famil‐
429 iar from completion; if not, see the description of the zstyle command
430 in see zshmodules(1). The context for setting styles should be ':ch‐
431 pwd:*' in case the meaning of the context is extended in future, for
432 example:
433
434 zstyle ':chpwd:*' recent-dirs-max 0
435
436 sets the value of the recent-dirs-max style to 0. In practice the
437 style name is specific enough that a context of '*' should be fine.
438
439 An exception is recent-dirs-insert, which is used exclusively by the
440 completion system and so has the usual completion system context
441 (':completion:*' if nothing more specific is needed), though again '*'
442 should be fine in practice.
443
444 recent-dirs-default
445 If true, and the command is expecting a recent directory index,
446 and either there is more than one argument or the argument is
447 not an integer, then fall through to "cd". This allows the lazy
448 to use only one command for directory changing. Completion
449 recognises this, too; see recent-dirs-insert for how to control
450 completion when this option is in use.
451
452 recent-dirs-file
453 The file where the list of directories is saved. The default is
454 ${ZDOTDIR:-$HOME}/.chpwd-recent-dirs, i.e. this is in your home
455 directory unless you have set the variable ZDOTDIR to point
456 somewhere else. Directory names are saved in $'...' quoted
457 form, so each line in the file can be supplied directly to the
458 shell as an argument.
459
460 The value of this style may be an array. In this case, the
461 first file in the list will always be used for saving directo‐
462 ries while any other files are left untouched. When reading the
463 recent directory list, if there are fewer than the maximum num‐
464 ber of entries in the first file, the contents of later files in
465 the array will be appended with duplicates removed from the list
466 shown. The contents of the two files are not sorted together,
467 i.e. all the entries in the first file are shown first. The
468 special value + can appear in the list to indicate the default
469 file should be read at that point. This allows effects like the
470 following:
471
472 zstyle ':chpwd:*' recent-dirs-file \
473 ~/.chpwd-recent-dirs-${TTY##*/} +
474
475 Recent directories are read from a file numbered according to
476 the terminal. If there are insufficient entries the list is
477 supplemented from the default file.
478
479 It is possible to use zstyle -e to make the directory config‐
480 urable at run time:
481
482 zstyle -e ':chpwd:*' recent-dirs-file pick-recent-dirs-file
483 pick-recent-dirs-file() {
484 if [[ $PWD = ~/text/writing(|/*) ]]; then
485 reply=(~/.chpwd-recent-dirs-writing)
486 else
487 reply=(+)
488 fi
489 }
490
491 In this example, if the current directory is ~/text/writing or a
492 directory under it, then use a special file for saving recent
493 directories, else use the default.
494
495 recent-dirs-insert
496 Used by completion. If recent-dirs-default is true, then set‐
497 ting this to true causes the actual directory, rather than its
498 index, to be inserted on the command line; this has the same ef‐
499 fect as using the corresponding index, but makes the history
500 clearer and the line easier to edit. With this setting, if part
501 of an argument was already typed, normal directory completion
502 rather than recent directory completion is done; this is because
503 recent directory completion is expected to be done by cycling
504 through entries menu fashion.
505
506 If the value of the style is always, then only recent directo‐
507 ries will be completed; in that case, use the cd command when
508 you want to complete other directories.
509
510 If the value is fallback, recent directories will be tried
511 first, then normal directory completion is performed if recent
512 directory completion failed to find a match.
513
514 Finally, if the value is both then both sets of completions are
515 presented; the usual tag mechanism can be used to distinguish
516 results, with recent directories tagged as recent-dirs. Note
517 that the recent directories inserted are abbreviated with direc‐
518 tory names where appropriate.
519
520 recent-dirs-max
521 The maximum number of directories to save to the file. If this
522 is zero or negative there is no maximum. The default is 20.
523 Note this includes the current directory, which isn't offered,
524 so the highest number of directories you will be offered is one
525 less than the maximum.
526
527 recent-dirs-prune
528 This style is an array determining what directories should (or
529 should not) be added to the recent list. Elements of the array
530 can include:
531
532 parent Prune parents (more accurately, ancestors) from the re‐
533 cent list. If present, changing directly down by any
534 number of directories causes the current directory to be
535 overwritten. For example, changing from ~pws to
536 ~pws/some/other/dir causes ~pws not to be left on the re‐
537 cent directory stack. This only applies to direct
538 changes to descendant directories; earlier directories on
539 the list are not pruned. For example, changing from
540 ~pws/yet/another to ~pws/some/other/dir does not cause
541 ~pws to be pruned.
542
543 pattern:pattern
544 Gives a zsh pattern for directories that should not be
545 added to the recent list (if not already there). This
546 element can be repeated to add different patterns. For
547 example, 'pattern:/tmp(|/*)' stops /tmp or its descen‐
548 dants from being added. The EXTENDED_GLOB option is al‐
549 ways turned on for these patterns.
550
551 recent-dirs-pushd
552 If set to true, cdr will use pushd instead of cd to change the
553 directory, so the directory is saved on the directory stack. As
554 the directory stack is completely separate from the list of
555 files saved by the mechanism used in this file there is no obvi‐
556 ous reason to do this.
557
558 Use with dynamic directory naming
559 It is possible to refer to recent directories using the dynamic direc‐
560 tory name syntax by using the supplied function zsh_directory_name_cdr
561 a hook:
562
563 autoload -Uz add-zsh-hook
564 add-zsh-hook -Uz zsh_directory_name zsh_directory_name_cdr
565
566 When this is done, ~[1] will refer to the most recent directory other
567 than $PWD, and so on. Completion after ~[... also works.
568
569 Details of directory handling
570 This section is for the curious or confused; most users will not need
571 to know this information.
572
573 Recent directories are saved to a file immediately and hence are pre‐
574 served across sessions. Note currently no file locking is applied: the
575 list is updated immediately on interactive commands and nowhere else
576 (unlike history), and it is assumed you are only going to change direc‐
577 tory in one window at once. This is not safe on shared accounts, but
578 in any case the system has limited utility when someone else is chang‐
579 ing to a different set of directories behind your back.
580
581 To make this a little safer, only directory changes instituted from the
582 command line, either directly or indirectly through shell function
583 calls (but not through subshells, evals, traps, completion functions
584 and the like) are saved. Shell functions should use cd -q or pushd -q
585 to avoid side effects if the change to the directory is to be invisible
586 at the command line. See the contents of the function chpwd_re‐
587 cent_dirs for more details.
588
590 The dynamic directory naming system is described in the subsection Dy‐
591 namic named directories of the section Filename Expansion in expn(1).
592 In this, a reference to ~[...] is expanded by a function found by the
593 hooks mechanism.
594
595 The contributed function zsh_directory_name_generic provides a system
596 allowing the user to refer to directories with only a limited amount of
597 new code. It supports all three of the standard interfaces for direc‐
598 tory naming: converting from a name to a directory, converting in the
599 reverse direction to find a short name, and completion of names.
600
601 The main feature of this function is a path-like syntax, combining ab‐
602 breviations at multiple levels separated by ":". As an example,
603 ~[g:p:s] might specify:
604 g The top level directory for your git area. This first component
605 has to match, or the function will return indicating another di‐
606 rectory name hook function should be tried.
607
608 p The name of a project within your git area.
609
610 s The source area within that project. This allows you to col‐
611 lapse references to long hierarchies to a very compact form,
612 particularly if the hierarchies are similar across different ar‐
613 eas of the disk.
614
615 Name components may be completed: if a description is shown at the top
616 of the list of completions, it includes the path to which previous com‐
617 ponents expand, while the description for an individual completion
618 shows the path segment it would add. No additional configuration is
619 needed for this as the completion system is aware of the dynamic direc‐
620 tory name mechanism.
621
622 Usage
623 To use the function, first define a wrapper function for your specific
624 case. We'll assume it's to be autoloaded. This can have any name but
625 we'll refer to it as zdn_mywrapper. This wrapper function will define
626 various variables and then call this function with the same arguments
627 that the wrapper function gets. This configuration is described below.
628
629 Then arrange for the wrapper to be run as a zsh_directory_name hook:
630
631 autoload -Uz add-zsh-hook zsh_diretory_name_generic zdn_mywrapper
632 add-zsh-hook -U zsh_directory_name zdn_mywrapper
633
634 Configuration
635 The wrapper function should define a local associative array zdn_top.
636 Alternatively, this can be set with a style called mapping. The con‐
637 text for the style is :zdn:wrapper-name where wrapper-name is the func‐
638 tion calling zsh_directory_name_generic; for example:
639
640 zstyle :zdn:zdn_mywrapper: mapping zdn_mywrapper_top
641
642 The keys in this associative array correspond to the first component of
643 the name. The values are matching directories. They may have an op‐
644 tional suffix with a slash followed by a colon and the name of a vari‐
645 able in the same format to give the next component. (The slash before
646 the colon is to disambiguate the case where a colon is needed in the
647 path for a drive. There is otherwise no syntax for escaping this, so
648 path components whose names start with a colon are not supported.) A
649 special component :default: specifies a variable in the form /:var (the
650 path section is ignored and so is usually empty) that will be used for
651 the next component if no variable is given for the path. Variables re‐
652 ferred to within zdn_top have the same format as zdn_top itself, but
653 contain relative paths.
654
655 For example,
656
657 local -A zdn_top=(
658 g ~/git
659 ga ~/alternate/git
660 gs /scratch/$USER/git/:second2
661 :default: /:second1
662 )
663
664 This specifies the behaviour of a directory referred to as ~[g:...] or
665 ~[ga:...] or ~[gs:...]. Later path components are optional; in that
666 case ~[g] expands to ~/git, and so on. gs expands to
667 /scratch/$USER/git and uses the associative array second2 to match the
668 second component; g and ga use the associative array second1 to match
669 the second component.
670
671 When expanding a name to a directory, if the first component is not g
672 or ga or gs, it is not an error; the function simply returns 1 so that
673 a later hook function can be tried. However, matching the first compo‐
674 nent commits the function, so if a later component does not match, an
675 error is printed (though this still does not stop later hooks from be‐
676 ing executed).
677
678 For components after the first, a relative path is expected, but note
679 that multiple levels may still appear. Here is an example of second1:
680
681 local -A second1=(
682 p myproject
683 s somproject
684 os otherproject/subproject/:third
685 )
686
687 The path as found from zdn_top is extended with the matching directory,
688 so ~[g:p] becomes ~/git/myproject. The slash between is added automat‐
689 ically (it's not possible to have a later component modify the name of
690 a directory already matched). Only os specifies a variable for a third
691 component, and there's no :default:, so it's an error to use a name
692 like ~[g:p:x] or ~[ga:s:y] because there's nowhere to look up the x or
693 y.
694
695 The associative arrays need to be visible within this function; the
696 generic function therefore uses internal variable names beginning _zdn_
697 in order to avoid clashes. Note that the variable reply needs to be
698 passed back to the shell, so should not be local in the calling func‐
699 tion.
700
701 The function does not test whether directories assembled by component
702 actually exist; this allows the system to work across automounted file
703 systems. The error from the command trying to use a non-existent di‐
704 rectory should be sufficient to indicate the problem.
705
706 Complete example
707 Here is a full fictitious but usable autoloadable definition of the ex‐
708 ample function defined by the code above. So ~[gs:p:s] expands to
709 /scratch/$USER/git/myscratchproject/top/srcdir (with $USER also ex‐
710 panded).
711
712 local -A zdn_top=(
713 g ~/git
714 ga ~/alternate/git
715 gs /scratch/$USER/git/:second2
716 :default: /:second1
717 )
718
719 local -A second1=(
720 p myproject
721 s somproject
722 os otherproject/subproject/:third
723 )
724
725 local -A second2=(
726 p myscratchproject
727 s somescratchproject
728 )
729
730 local -A third=(
731 s top/srcdir
732 d top/documentation
733 )
734
735 # autoload not needed if you did this at initialisation...
736 autoload -Uz zsh_directory_name_generic
737 zsh_directory_name_generic "$@
738
739 It is also possible to use global associative arrays, suitably named,
740 and set the style for the context of your wrapper function to refer to
741 this. Then your set up code would contain the following:
742
743 typeset -A zdn_mywrapper_top=(...)
744 # ... and so on for other associative arrays ...
745 zstyle ':zdn:zdn_mywrapper:' mapping zdn_mywrapper_top
746 autoload -Uz add-zsh-hook zsh_directory_name_generic zdn_mywrapper
747 add-zsh-hook -U zsh_directory_name zdn_mywrapper
748
749 and the function zdn_mywrapper would contain only the following:
750
751 zsh_directory_name_generic "$@"
752
754 In a lot of cases, it is nice to automatically retrieve information
755 from version control systems (VCSs), such as subversion, CVS or git, to
756 be able to provide it to the user; possibly in the user's prompt. So
757 that you can instantly tell which branch you are currently on, for ex‐
758 ample.
759
760 In order to do that, you may use the vcs_info function.
761
762 The following VCSs are supported, showing the abbreviated name by which
763 they are referred to within the system:
764 Bazaar (bzr)
765 https://bazaar.canonical.com/
766 Codeville (cdv)
767 http://freecode.com/projects/codeville/
768 Concurrent Versioning System (cvs)
769 https://www.nongnu.org/cvs/
770 Darcs (darcs)
771 http://darcs.net/
772 Fossil (fossil)
773 https://fossil-scm.org/
774 Git (git)
775 https://git-scm.com/
776 GNU arch (tla)
777 https://www.gnu.org/software/gnu-arch/
778 Mercurial (hg)
779 https://www.mercurial-scm.org/
780 Monotone (mtn)
781 https://monotone.ca/
782 Perforce (p4)
783 https://www.perforce.com/
784 Subversion (svn)
785 https://subversion.apache.org/
786 SVK (svk)
787 https://svk.bestpractical.com/
788
789 There is also support for the patch management system quilt
790 (https://savannah.nongnu.org/projects/quilt). See Quilt Support below
791 for details.
792
793 To load vcs_info:
794
795 autoload -Uz vcs_info
796
797 It can be used in any existing prompt, because it does not require any
798 specific $psvar entries to be available.
799
800 Quickstart
801 To get this feature working quickly (including colors), you can do the
802 following (assuming, you loaded vcs_info properly - see above):
803
804 zstyle ':vcs_info:*' actionformats \
805 '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f '
806 zstyle ':vcs_info:*' formats \
807 '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{5}]%f '
808 zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r'
809 precmd () { vcs_info }
810 PS1='%F{5}[%F{2}%n%F{5}] %F{3}%3~ ${vcs_info_msg_0_}%f%# '
811
812 Obviously, the last two lines are there for demonstration. You need to
813 call vcs_info from your precmd function. Once that is done you need a
814 single quoted '${vcs_info_msg_0_}' in your prompt.
815
816 To be able to use '${vcs_info_msg_0_}' directly in your prompt like
817 this, you will need to have the PROMPT_SUBST option enabled.
818
819 Now call the vcs_info_printsys utility from the command line:
820
821 % vcs_info_printsys
822 ## list of supported version control backends:
823 ## disabled systems are prefixed by a hash sign (#)
824 bzr
825 cdv
826 cvs
827 darcs
828 fossil
829 git
830 hg
831 mtn
832 p4
833 svk
834 svn
835 tla
836 ## flavours (cannot be used in the enable or disable styles; they
837 ## are enabled and disabled with their master [git-svn -> git])
838 ## they *can* be used in contexts: ':vcs_info:git-svn:*'.
839 git-p4
840 git-svn
841 hg-git
842 hg-hgsubversion
843 hg-hgsvn
844
845 You may not want all of these because there is no point in running the
846 code to detect systems you do not use. So there is a way to disable
847 some backends altogether:
848
849 zstyle ':vcs_info:*' disable bzr cdv darcs mtn svk tla
850
851 You may also pick a few from that list and enable only those:
852
853 zstyle ':vcs_info:*' enable git cvs svn
854
855 If you rerun vcs_info_printsys after one of these commands, you will
856 see the backends listed in the disable style (or backends not in the
857 enable style - if you used that) marked as disabled by a hash sign.
858 That means the detection of these systems is skipped completely. No
859 wasted time there.
860
861 Configuration
862 The vcs_info feature can be configured via zstyle.
863
864 First, the context in which we are working:
865 :vcs_info:vcs-string:user-context:repo-root-name
866
867 vcs-string
868 is one of: git, git-svn, git-p4, hg, hg-git, hg-hgsubversion,
869 hg-hgsvn, darcs, bzr, cdv, mtn, svn, cvs, svk, tla, p4 or fos‐
870 sil. This is followed by `.quilt-quilt-mode' in Quilt mode (see
871 Quilt Support for details) and by `+hook-name' while hooks are
872 active (see Hooks in vcs_info for details).
873
874 Currently, hooks in quilt mode don't add the `.quilt-quilt-mode'
875 information. This may change in the future.
876
877 user-context
878 is a freely configurable string, assignable by the user as the
879 first argument to vcs_info (see its description below).
880
881 repo-root-name
882 is the name of a repository in which you want a style to match.
883 So, if you want a setting specific to /usr/src/zsh, with that
884 being a CVS checkout, you can set repo-root-name to zsh to make
885 it so.
886
887 There are three special values for vcs-string: The first is named
888 -init-, that is in effect as long as there was no decision what VCS
889 backend to use. The second is -preinit-; it is used before vcs_info is
890 run, when initializing the data exporting variables. The third special
891 value is formats and is used by the vcs_info_lastmsg for looking up its
892 styles.
893
894 The initial value of repo-root-name is -all- and it is replaced with
895 the actual name, as soon as it is known. Only use this part of the con‐
896 text for defining the formats, actionformats or branchformat styles, as
897 it is guaranteed that repo-root-name is set up correctly for these
898 only. For all other styles, just use '*' instead.
899
900 There are two pre-defined values for user-context:
901 default
902 the one used if none is specified
903 command
904 used by vcs_info_lastmsg to lookup its styles
905
906 You can of course use ':vcs_info:*' to match all VCSs in all user-con‐
907 texts at once.
908
909 This is a description of all styles that are looked up.
910
911 formats
912 A list of formats, used when actionformats is not used (which is
913 most of the time).
914
915 actionformats
916 A list of formats, used if there is a special action going on in
917 your current repository; like an interactive rebase or a merge
918 conflict.
919
920 branchformat
921 Some backends replace %b in the formats and actionformats styles
922 above, not only by a branch name but also by a revision number.
923 This style lets you modify how that string should look.
924
925 nvcsformats
926 These "formats" are set when we didn't detect a version control
927 system for the current directory or vcs_info was disabled. This
928 is useful if you want vcs_info to completely take over the gen‐
929 eration of your prompt. You would do something like
930 PS1='${vcs_info_msg_0_}' to accomplish that.
931
932 hgrevformat
933 hg uses both a hash and a revision number to reference a spe‐
934 cific changeset in a repository. With this style you can format
935 the revision string (see branchformat) to include either or
936 both. It's only useful when get-revision is true. Note, the full
937 40-character revision id is not available (except when using the
938 use-simple option) because executing hg more than once per
939 prompt is too slow; you may customize this behavior using hooks.
940
941 max-exports
942 Defines the maximum number of vcs_info_msg_*_ variables vcs_info
943 will set.
944
945 enable A list of backends you want to use. Checked in the -init- con‐
946 text. If this list contains an item called NONE no backend is
947 used at all and vcs_info will do nothing. If this list contains
948 ALL, vcs_info will use all known backends. Only with ALL in en‐
949 able will the disable style have any effect. ALL and NONE are
950 case insensitive.
951
952 disable
953 A list of VCSs you don't want vcs_info to test for repositories
954 (checked in the -init- context, too). Only used if enable con‐
955 tains ALL.
956
957 disable-patterns
958 A list of patterns that are checked against $PWD. If a pattern
959 matches, vcs_info will be disabled. This style is checked in the
960 :vcs_info:-init-:*:-all- context.
961
962 Say, ~/.zsh is a directory under version control, in which you
963 do not want vcs_info to be active, do:
964 zstyle ':vcs_info:*' disable-patterns "${(b)HOME}/.zsh(|/*)"
965
966 use-quilt
967 If enabled, the quilt support code is active in `addon' mode.
968 See Quilt Support for details.
969
970 quilt-standalone
971 If enabled, `standalone' mode detection is attempted if no VCS
972 is active in a given directory. See Quilt Support for details.
973
974 quilt-patch-dir
975 Overwrite the value of the $QUILT_PATCHES environment variable.
976 See Quilt Support for details.
977
978 quiltcommand
979 When quilt itself is called in quilt support, the value of this
980 style is used as the command name.
981
982 check-for-changes
983 If enabled, this style causes the %c and %u format escapes to
984 show when the working directory has uncommitted changes. The
985 strings displayed by these escapes can be controlled via the
986 stagedstr and unstagedstr styles. The only backends that cur‐
987 rently support this option are git, hg, and bzr (the latter two
988 only support unstaged).
989
990 For this style to be evaluated with the hg backend, the get-re‐
991 vision style needs to be set and the use-simple style needs to
992 be unset. The latter is the default; the former is not.
993
994 With the bzr backend, lightweight checkouts only honor this
995 style if the use-server style is set.
996
997 Note, the actions taken if this style is enabled are potentially
998 expensive (read: they may be slow, depending on how big the cur‐
999 rent repository is). Therefore, it is disabled by default.
1000
1001 check-for-staged-changes
1002 This style is like check-for-changes, but it never checks the
1003 worktree files, only the metadata in the .${vcs} dir. There‐
1004 fore, this style initializes only the %c escape (with stagedstr)
1005 but not the %u escape. This style is faster than
1006 check-for-changes.
1007
1008 In the git backend, this style checks for changes in the index.
1009 Other backends do not currently implement this style.
1010
1011 This style is disabled by default.
1012
1013 stagedstr
1014 This string will be used in the %c escape if there are staged
1015 changes in the repository.
1016
1017 unstagedstr
1018 This string will be used in the %u escape if there are unstaged
1019 changes in the repository.
1020
1021 command
1022 This style causes vcs_info to use the supplied string as the
1023 command to use as the VCS's binary. Note, that setting this in
1024 ':vcs_info:*' is not a good idea.
1025
1026 If the value of this style is empty (which is the default), the
1027 used binary name is the name of the backend in use (e.g. svn is
1028 used in an svn repository).
1029
1030 The repo-root-name part in the context is always the default
1031 -all- when this style is looked up.
1032
1033 For example, this style can be used to use binaries from non-de‐
1034 fault installation directories. Assume, git is installed in
1035 /usr/bin but your sysadmin installed a newer version in /usr/lo‐
1036 cal/bin. Instead of changing the order of your $PATH parameter,
1037 you can do this:
1038 zstyle ':vcs_info:git:*:-all-' command /usr/local/bin/git
1039
1040 use-server
1041 This is used by the Perforce backend (p4) to decide if it should
1042 contact the Perforce server to find out if a directory is man‐
1043 aged by Perforce. This is the only reliable way of doing this,
1044 but runs the risk of a delay if the server name cannot be found.
1045 If the server (more specifically, the host:port pair describing
1046 the server) cannot be contacted, its name is put into the asso‐
1047 ciative array vcs_info_p4_dead_servers and is not contacted
1048 again during the session until it is removed by hand. If you do
1049 not set this style, the p4 backend is only usable if you have
1050 set the environment variable P4CONFIG to a file name and have
1051 corresponding files in the root directories of each Perforce
1052 client. See comments in the function VCS_INFO_detect_p4 for
1053 more detail.
1054
1055 The Bazaar backend (bzr) uses this to permit contacting the
1056 server about lightweight checkouts, see the check-for-changes
1057 style.
1058
1059 use-simple
1060 If there are two different ways of gathering information, you
1061 can select the simpler one by setting this style to true; the
1062 default is to use the not-that-simple code, which is potentially
1063 a lot slower but might be more accurate in all possible cases.
1064 This style is used by the bzr and hg backends. In the case of hg
1065 it will invoke the external hexdump program to parse the binary
1066 dirstate cache file; this method will not return the local revi‐
1067 sion number.
1068
1069 get-revision
1070 If set to true, vcs_info goes the extra mile to figure out the
1071 revision of a repository's work tree (currently for the git and
1072 hg backends, where this kind of information is not always vi‐
1073 tal). For git, the hash value of the currently checked out com‐
1074 mit is available via the %i expansion. With hg, the local revi‐
1075 sion number and the corresponding global hash are available via
1076 %i.
1077
1078 get-mq If set to true, the hg backend will look for a Mercurial Queue
1079 (mq) patch directory. Information will be available via the `%m'
1080 replacement.
1081
1082 get-bookmarks
1083 If set to true, the hg backend will try to get a list of current
1084 bookmarks. They will be available via the `%m' replacement.
1085
1086 The default is to generate a comma-separated list of all book‐
1087 mark names that refer to the currently checked out revision. If
1088 a bookmark is active, its name is suffixed an asterisk and
1089 placed first in the list.
1090
1091 use-prompt-escapes
1092 Determines if we assume that the assembled string from vcs_info
1093 includes prompt escapes. (Used by vcs_info_lastmsg.)
1094
1095 debug Enable debugging output to track possible problems. Currently
1096 this style is only used by vcs_info's hooks system.
1097
1098 hooks A list style that defines hook-function names. See Hooks in
1099 vcs_info below for details.
1100
1101 patch-format
1102 nopatch-format
1103 This pair of styles format the patch information used by the %m
1104 expando in formats and actionformats for the git and hg back‐
1105 ends. The value is subject to certain %-expansions described
1106 below. The expanded value is made available in the global back‐
1107 end_misc array as ${backend_misc[patches]} (also if a
1108 set-patch-format hook is used).
1109
1110 get-unapplied
1111 This boolean style controls whether a backend should attempt to
1112 gather a list of unapplied patches (for example with Mercurial
1113 Queue patches).
1114
1115 Used by the quilt and hg backends.
1116
1117 The default values for these styles in all contexts are:
1118
1119 formats
1120 " (%s)-[%b]%u%c-"
1121 actionformats
1122 " (%s)-[%b|%a]%u%c-"
1123 branchformat
1124 "%b:%r" (for bzr, svn, svk and hg)
1125 nvcsformats
1126 ""
1127 hgrevformat
1128 "%r:%h"
1129 max-exports
1130 2
1131 enable ALL
1132 disable
1133 (empty list)
1134 disable-patterns
1135 (empty list)
1136 check-for-changes
1137 false
1138 check-for-staged-changes
1139 false
1140 stagedstr
1141 (string: "S")
1142 unstagedstr
1143 (string: "U")
1144 command
1145 (empty string)
1146 use-server
1147 false
1148 use-simple
1149 false
1150 get-revision
1151 false
1152 get-mq true
1153 get-bookmarks
1154 false
1155 use-prompt-escapes
1156 true
1157 debug false
1158 hooks (empty list)
1159 use-quilt
1160 false
1161 quilt-standalone
1162 false
1163 quilt-patch-dir
1164 empty - use $QUILT_PATCHES
1165 quiltcommand
1166 quilt
1167 patch-format
1168 backend dependent
1169 nopatch-format
1170 backend dependent
1171 get-unapplied
1172 false
1173
1174 In normal formats and actionformats the following replacements are
1175 done:
1176
1177 %s The VCS in use (git, hg, svn, etc.).
1178 %b Information about the current branch.
1179 %a An identifier that describes the action. Only makes sense in ac‐
1180 tionformats.
1181 %i The current revision number or identifier. For hg the hgrevfor‐
1182 mat style may be used to customize the output.
1183 %c The string from the stagedstr style if there are staged changes
1184 in the repository.
1185 %u The string from the unstagedstr style if there are unstaged
1186 changes in the repository.
1187 %R The base directory of the repository.
1188 %r The repository name. If %R is /foo/bar/repoXY, %r is repoXY.
1189 %S A subdirectory within a repository. If $PWD is /foo/bar/re‐
1190 poXY/beer/tasty, %S is beer/tasty.
1191 %m A "misc" replacement. It is at the discretion of the backend to
1192 decide what this replacement expands to.
1193
1194 The hg and git backends use this expando to display patch infor‐
1195 mation. hg sources patch information from the mq extensions;
1196 git from in-progress rebase and cherry-pick operations and from
1197 the stgit extension. The patch-format and nopatch-format styles
1198 control the generated string. The former is used when at least
1199 one patch from the patch queue has been applied, and the latter
1200 otherwise.
1201
1202 The hg backend displays bookmark information in this expando (in
1203 addition to mq information). See the get-mq and get-bookmarks
1204 styles. Both of these styles may be enabled at the same time.
1205 If both are enabled, both resulting strings will be shown sepa‐
1206 rated by a semicolon (that cannot currently be customized).
1207
1208 The quilt `standalone' backend sets this expando to the same
1209 value as the %Q expando.
1210
1211 %Q Quilt series information. When quilt is used (either in `addon'
1212 mode or as a `standalone' backend), this expando is set to quilt
1213 series' patch-format string. The set-patch-format hook and
1214 nopatch-format style are honoured.
1215
1216 See Quilt Support below for details.
1217
1218 In branchformat these replacements are done:
1219
1220 %b The branch name.
1221 %r The current revision number or the hgrevformat style for hg.
1222
1223 In hgrevformat these replacements are done:
1224
1225 %r The current local revision number.
1226 %h The current global revision identifier.
1227
1228 In patch-format and nopatch-format these replacements are done:
1229
1230 %p The name of the top-most applied patch; may be overridden by the
1231 applied-string hook.
1232 %u The number of unapplied patches; may be overridden by the unap‐
1233 plied-string hook.
1234 %n The number of applied patches.
1235 %c The number of unapplied patches.
1236 %a The number of all patches (%a = %n + %c).
1237 %g The names of active mq guards (hg backend).
1238 %G The number of active mq guards (hg backend).
1239
1240 Not all VCS backends have to support all replacements. For nvcsformats
1241 no replacements are performed at all, it is just a string.
1242
1243 Oddities
1244 If you want to use the %b (bold off) prompt expansion in formats, which
1245 expands %b itself, use %%b. That will cause the vcs_info expansion to
1246 replace %%b with %b, so that zsh's prompt expansion mechanism can han‐
1247 dle it. Similarly, to hand down %b from branchformat, use %%%%b. Sorry
1248 for this inconvenience, but it cannot be easily avoided. Luckily we do
1249 not clash with a lot of prompt expansions and this only needs to be
1250 done for those.
1251
1252 When one of the gen-applied-string, gen-unapplied-string, and
1253 set-patch-format hooks is defined, applying %-escaping
1254 (`foo=${foo//'%'/%%}') to the interpolated values for use in the prompt
1255 is the responsibility of those hooks (jointly); when neither of those
1256 hooks is defined, vcs_info handles escaping by itself. We regret this
1257 coupling, but it was required for backwards compatibility.
1258
1259 Quilt Support
1260 Quilt is not a version control system, therefore this is not imple‐
1261 mented as a backend. It can help keeping track of a series of patches.
1262 People use it to keep a set of changes they want to use on top of soft‐
1263 ware packages (which is tightly integrated into the package build
1264 process - the Debian project does this for a large number of packages).
1265 Quilt can also help individual developers keep track of their own
1266 patches on top of real version control systems.
1267
1268 The vcs_info integration tries to support both ways of using quilt by
1269 having two slightly different modes of operation: `addon' mode and
1270 `standalone' mode).
1271
1272 Quilt integration is off by default; to enable it, set the use-quilt
1273 style, and add %Q to your formats or actionformats style:
1274 zstyle ':vcs_info:*' use-quilt true
1275
1276 Styles looked up from the Quilt support code include
1277 `.quilt-quilt-mode' in the vcs-string part of the context, where
1278 quilt-mode is either addon or standalone. Example:
1279 :vcs_info:git.quilt-addon:default:repo-root-name.
1280
1281 For `addon' mode to become active vcs_info must have already detected a
1282 real version control system controlling the directory. If that is the
1283 case, a directory that holds quilt's patches needs to be found. That
1284 directory is configurable via the `QUILT_PATCHES' environment variable.
1285 If that variable exists its value is used, otherwise the value
1286 `patches' is assumed. The value from $QUILT_PATCHES can be overwritten
1287 using the `quilt-patches' style. (Note: you can use vcs_info to keep
1288 the value of $QUILT_PATCHES correct all the time via the post-quilt
1289 hook).
1290
1291 When the directory in question is found, quilt is assumed to be active.
1292 To gather more information, vcs_info looks for a directory called
1293 `.pc'; Quilt uses that directory to track its current state. If this
1294 directory does not exist we know that quilt has not done anything to
1295 the working directory (read: no patches have been applied yet).
1296
1297 If patches are applied, vcs_info will try to find out which. If you
1298 want to know which patches of a series are not yet applied, you need to
1299 activate the get-unapplied style in the appropriate context.
1300
1301 vcs_info allows for very detailed control over how the gathered infor‐
1302 mation is presented (see the Configuration and Hooks in vcs_info sec‐
1303 tions), all of which are documented below. Note there are a number of
1304 other patch tracking systems that work on top of a certain version con‐
1305 trol system (like stgit for git, or mq for hg); the configuration for
1306 systems like that are generally configured the same way as the quilt
1307 support.
1308
1309 If the quilt support is working in `addon' mode, the produced string is
1310 available as a simple format replacement (%Q to be precise), which can
1311 be used in formats and actionformats; see below for details).
1312
1313 If, on the other hand, the support code is working in `standalone'
1314 mode, vcs_info will pretend as if quilt were an actual version control
1315 system. That means that the version control system identifier (which
1316 otherwise would be something like `svn' or `cvs') will be set to
1317 `-quilt-'. This has implications on the used style context where this
1318 identifier is the second element. vcs_info will have filled in a proper
1319 value for the "repository's" root directory and the string containing
1320 the information about quilt's state will be available as the `misc' re‐
1321 placement (and %Q for compatibility with `addon' mode).
1322
1323 What is left to discuss is how `standalone' mode is detected. The de‐
1324 tection itself is a series of searches for directories. You can have
1325 this detection enabled all the time in every directory that is not oth‐
1326 erwise under version control. If you know there is only a limited set
1327 of trees where you would like vcs_info to try and look for Quilt in
1328 `standalone' mode to minimise the amount of searching on every call to
1329 vcs_info, there are a number of ways to do that:
1330
1331 Essentially, `standalone' mode detection is controlled by a style
1332 called `quilt-standalone'. It is a string style and its value can have
1333 different effects. The simplest values are: `always' to run detection
1334 every time vcs_info is run, and `never' to turn the detection off en‐
1335 tirely.
1336
1337 If the value of quilt-standalone is something else, it is interpreted
1338 differently. If the value is the name of a scalar variable the value of
1339 that variable is checked and that value is used in the same `al‐
1340 ways'/`never' way as described above.
1341
1342 If the value of quilt-standalone is an array, the elements of that ar‐
1343 ray are used as directory names under which you want the detection to
1344 be active.
1345
1346 If quilt-standalone is an associative array, the keys are taken as di‐
1347 rectory names under which you want the detection to be active, but only
1348 if the corresponding value is the string `true'.
1349
1350 Last, but not least, if the value of quilt-standalone is the name of a
1351 function, the function is called without arguments and the return value
1352 decides whether detection should be active. A `0' return value is true;
1353 a non-zero return value is interpreted as false.
1354
1355 Note, if there is both a function and a variable by the name of
1356 quilt-standalone, the function will take precedence.
1357
1358 Function Descriptions (Public API)
1359 vcs_info [user-context]
1360 The main function, that runs all backends and assembles all data
1361 into ${vcs_info_msg_*_}. This is the function you want to call
1362 from precmd if you want to include up-to-date information in
1363 your prompt (see Variable Description below). If an argument is
1364 given, that string will be used instead of default in the
1365 user-context field of the style context.
1366
1367 vcs_info_hookadd
1368 Statically registers a number of functions to a given hook. The
1369 hook needs to be given as the first argument; what follows is a
1370 list of hook-function names to register to the hook. The `+vi-'
1371 prefix needs to be left out here. See Hooks in vcs_info below
1372 for details.
1373
1374 vcs_info_hookdel
1375 Remove hook-functions from a given hook. The hook needs to be
1376 given as the first non-option argument; what follows is a list
1377 of hook-function names to un-register from the hook. If `-a' is
1378 used as the first argument, all occurrences of the functions are
1379 unregistered. Otherwise only the last occurrence is removed (if
1380 a function was registered to a hook more than once). The `+vi-'
1381 prefix needs to be left out here. See Hooks in vcs_info below
1382 for details.
1383
1384 vcs_info_lastmsg
1385 Outputs the last ${vcs_info_msg_*_} value. Takes into account
1386 the value of the use-prompt-escapes style in ':vcs_info:for‐
1387 mats:command:-all-'. It also only prints max-exports values.
1388
1389 vcs_info_printsys [user-context]
1390 Prints a list of all supported version control systems. Useful
1391 to find out possible contexts (and which of them are enabled) or
1392 values for the disable style.
1393
1394 vcs_info_setsys
1395 Initializes vcs_info's internal list of available backends. With
1396 this function, you can add support for new VCSs without restart‐
1397 ing the shell.
1398
1399 All functions named VCS_INFO_* are for internal use only.
1400
1401 Variable Description
1402 ${vcs_info_msg_N_} (Note the trailing underscore)
1403 Where N is an integer, e.g., vcs_info_msg_0_. These variables
1404 are the storage for the informational message the last vcs_info
1405 call has assembled. These are strongly connected to the formats,
1406 actionformats and nvcsformats styles described above. Those
1407 styles are lists. The first member of that list gets expanded
1408 into ${vcs_info_msg_0_}, the second into ${vcs_info_msg_1_} and
1409 the Nth into ${vcs_info_msg_N-1_}. (See the max-exports style
1410 above.)
1411
1412 All variables named VCS_INFO_* are for internal use only.
1413
1414 Hooks in vcs_info
1415 Hooks are places in vcs_info where you can run your own code. That code
1416 can communicate with the code that called it and through that, change
1417 the system's behaviour.
1418
1419 For configuration, hooks change the style context:
1420 :vcs_info:vcs-string+hook-name:user-context:repo-root-name
1421
1422 To register functions to a hook, you need to list them in the hooks
1423 style in the appropriate context.
1424
1425 Example:
1426 zstyle ':vcs_info:*+foo:*' hooks bar baz
1427
1428 This registers functions to the hook `foo' for all backends. In order
1429 to avoid namespace problems, all registered function names are
1430 prepended by a `+vi-', so the actual functions called for the `foo'
1431 hook are `+vi-bar' and `+vi-baz'.
1432
1433 If you would like to register a function to a hook regardless of the
1434 current context, you may use the vcs_info_hookadd function. To remove a
1435 function that was added like that, the vcs_info_hookdel function can be
1436 used.
1437
1438 If something seems weird, you can enable the `debug' boolean style in
1439 the proper context and the hook-calling code will print what it tried
1440 to execute and whether the function in question existed.
1441
1442 When you register more than one function to a hook, all functions are
1443 executed one after another until one function returns non-zero or until
1444 all functions have been called. Context-sensitive hook functions are
1445 executed before statically registered ones (the ones added by
1446 vcs_info_hookadd).
1447
1448 You may pass data between functions via an associative array,
1449 user_data. For example:
1450 +vi-git-myfirsthook(){
1451 user_data[myval]=$myval
1452 }
1453 +vi-git-mysecondhook(){
1454 # do something with ${user_data[myval]}
1455 }
1456
1457 There are a number of variables that are special in hook contexts:
1458
1459 ret The return value that the hooks system will return to the
1460 caller. The default is an integer `zero'. If and how a changed
1461 ret value changes the execution of the caller depends on the
1462 specific hook. See the hook documentation below for details.
1463
1464 hook_com
1465 An associated array which is used for bidirectional communica‐
1466 tion from the caller to hook functions. The used keys depend on
1467 the specific hook.
1468
1469 context
1470 The active context of the hook. Functions that wish to change
1471 this variable should make it local scope first.
1472
1473 vcs The current VCS after it was detected. The same values as in the
1474 enable/disable style are used. Available in all hooks except
1475 start-up.
1476
1477 Finally, the full list of currently available hooks:
1478
1479 start-up
1480 Called after starting vcs_info but before the VCS in this direc‐
1481 tory is determined. It can be used to deactivate vcs_info tempo‐
1482 rarily if necessary. When ret is set to 1, vcs_info aborts and
1483 does nothing; when set to 2, vcs_info sets up everything as if
1484 no version control were active and exits.
1485
1486 pre-get-data
1487 Same as start-up but after the VCS was detected.
1488
1489 gen-hg-bookmark-string
1490 Called in the Mercurial backend when a bookmark string is gener‐
1491 ated; the get-revision and get-bookmarks styles must be true.
1492
1493 This hook gets the names of the Mercurial bookmarks that
1494 vcs_info collected from `hg'.
1495
1496 If a bookmark is active, the key ${hook_com[hg-active-bookmark]}
1497 is set to its name. The key is otherwise unset.
1498
1499 When setting ret to non-zero, the string in ${hook_com[hg-book‐
1500 mark-string]} will be used in the %m escape in formats and ac‐
1501 tionformats and will be available in the global backend_misc ar‐
1502 ray as ${backend_misc[bookmarks]}.
1503
1504 gen-applied-string
1505 Called in the git (with stgit or during rebase or merge), and hg
1506 (with mq) backends and in quilt support when the applied-string
1507 is generated; the use-quilt zstyle must be true for quilt (the
1508 mq and stgit backends are active by default).
1509
1510 This hook gets the names of all applied patches which vcs_info
1511 collected so far in the opposite order, which means that the
1512 first argument is the top-most patch and so forth.
1513
1514 When setting ret to non-zero, the string in ${hook_com[ap‐
1515 plied-string]} will be available as %p in the patch-format and
1516 nopatch-format styles. This hook is, in concert with
1517 set-patch-format, responsible for %-escaping that value for use
1518 in the prompt. (See the Oddities section.)
1519
1520 gen-unapplied-string
1521 Called in the git (with stgit or during rebase), and hg (with
1522 mq) backend and in quilt support when the unapplied-string is
1523 generated; the get-unapplied style must be true.
1524
1525 This hook gets the names of all unapplied patches which vcs_info
1526 collected so far in order, which means that the first argument
1527 is the patch next-in-line to be applied and so forth.
1528
1529 When setting ret to non-zero, the string in ${hook_com[unap‐
1530 plied-string]} will be available as %u in the patch-format and
1531 nopatch-format styles. This hook is, in concert with
1532 set-patch-format, responsible for %-escaping that value for use
1533 in the prompt. (See the Oddities section.)
1534
1535 gen-mqguards-string
1536 Called in the hg backend when guards-string is generated; the
1537 get-mq style must be true (default).
1538
1539 This hook gets the names of any active mq guards.
1540
1541 When setting ret to non-zero, the string in
1542 ${hook_com[guards-string]} will be used in the %g escape in the
1543 patch-format and nopatch-format styles.
1544
1545 no-vcs This hooks is called when no version control system was de‐
1546 tected.
1547
1548 The `hook_com' parameter is not used.
1549
1550 post-backend
1551 Called as soon as the backend has finished collecting informa‐
1552 tion.
1553
1554 The `hook_com' keys available are as for the set-message hook.
1555
1556 post-quilt
1557 Called after the quilt support is done. The following informa‐
1558 tion is passed as arguments to the hook: 1. the quilt-support
1559 mode (`addon' or `standalone'); 2. the directory that contains
1560 the patch series; 3. the directory that holds quilt's status in‐
1561 formation (the `.pc' directory) or the string "-nopc-" if that
1562 directory wasn't found.
1563
1564 The `hook_com' parameter is not used.
1565
1566 set-branch-format
1567 Called before `branchformat' is set. The only argument to the
1568 hook is the format that is configured at this point.
1569
1570 The `hook_com' keys considered are `branch' and `revision'.
1571 They are set to the values figured out so far by vcs_info and
1572 any change will be used directly when the actual replacement is
1573 done.
1574
1575 If ret is set to non-zero, the string in ${hook_com[branch-re‐
1576 place]} will be used unchanged as the `%b' replacement in the
1577 variables set by vcs_info.
1578
1579 set-hgrev-format
1580 Called before a `hgrevformat' is set. The only argument to the
1581 hook is the format that is configured at this point.
1582
1583 The `hook_com' keys considered are `hash' and `localrev'. They
1584 are set to the values figured out so far by vcs_info and any
1585 change will be used directly when the actual replacement is
1586 done.
1587
1588 If ret is set to non-zero, the string in ${hook_com[rev-re‐
1589 place]} will be used unchanged as the `%i' replacement in the
1590 variables set by vcs_info.
1591
1592 pre-addon-quilt
1593 This hook is used when vcs_info's quilt functionality is active
1594 in "addon" mode (quilt used on top of a real version control
1595 system). It is activated right before any quilt specific action
1596 is taken.
1597
1598 Setting the `ret' variable in this hook to a non-zero value
1599 avoids any quilt specific actions from being run at all.
1600
1601 set-patch-format
1602 This hook is used to control some of the possible expansions in
1603 patch-format and nopatch-format styles with patch queue systems
1604 such as quilt, mqueue and the like.
1605
1606 This hook is used in the git, hg and quilt backends.
1607
1608 The hook allows the control of the %p (${hook_com[applied]}) and
1609 %u (${hook_com[unapplied]}) expansion in all backends that use
1610 the hook. With the mercurial backend, the %g
1611 (${hook_com[guards]}) expansion is controllable in addition to
1612 that.
1613
1614 If ret is set to non-zero, the string in ${hook_com[patch-re‐
1615 place]} will be used unchanged instead of an expanded format
1616 from patch-format or nopatch-format.
1617
1618 This hook is, in concert with the gen-applied-string or gen-un‐
1619 applied-string hooks if they are defined, responsible for %-es‐
1620 caping the final patch-format value for use in the prompt. (See
1621 the Oddities section.)
1622
1623 set-message
1624 Called each time before a `vcs_info_msg_N_' message is set. It
1625 takes two arguments; the first being the `N' in the message
1626 variable name, the second is the currently configured formats or
1627 actionformats.
1628
1629 There are a number of `hook_com' keys, that are used here: `ac‐
1630 tion', `branch', `base', `base-name', `subdir', `staged', `un‐
1631 staged', `revision', `misc', `vcs' and one `miscN' entry for
1632 each backend-specific data field (N starting at zero). They are
1633 set to the values figured out so far by vcs_info and any change
1634 will be used directly when the actual replacement is done.
1635
1636 Since this hook is triggered multiple times (once for each con‐
1637 figured formats or actionformats), each of the `hook_com' keys
1638 mentioned above (except for the miscN entries) has an `_orig'
1639 counterpart, so even if you changed a value to your liking you
1640 can still get the original value in the next run. Changing the
1641 `_orig' values is probably not a good idea.
1642
1643 If ret is set to non-zero, the string in ${hook_com[message]}
1644 will be used unchanged as the message by vcs_info.
1645
1646 If all of this sounds rather confusing, take a look at the Examples
1647 section below and also in the Misc/vcs_info-examples file in the Zsh
1648 source. They contain some explanatory code.
1649
1650 Examples
1651 Don't use vcs_info at all (even though it's in your prompt):
1652 zstyle ':vcs_info:*' enable NONE
1653
1654 Disable the backends for bzr and svk:
1655 zstyle ':vcs_info:*' disable bzr svk
1656
1657 Disable everything but bzr and svk:
1658 zstyle ':vcs_info:*' enable bzr svk
1659
1660 Provide a special formats for git:
1661 zstyle ':vcs_info:git:*' formats ' GIT, BABY! [%b]'
1662 zstyle ':vcs_info:git:*' actionformats ' GIT ACTION! [%b|%a]'
1663
1664 All %x expansion in all sorts of formats (formats, actionformats,
1665 branchformat, you name it) are done using the `zformat' builtin from
1666 the `zsh/zutil' module. That means you can do everything with these %x
1667 items what zformat supports. In particular, if you want something that
1668 is really long to have a fixed width, like a hash in a mercurial
1669 branchformat, you can do this: %12.12i. That'll shrink the 40 character
1670 hash to its 12 leading characters. The form is actually `%min.maxx'.
1671 More is possible. See the section `The zsh/zutil Module' in zshmod‐
1672 ules(1) for details.
1673
1674 Use the quicker bzr backend
1675 zstyle ':vcs_info:bzr:*' use-simple true
1676
1677 If you do use use-simple, please report if it does
1678 `the-right-thing[tm]'.
1679
1680 Display the revision number in yellow for bzr and svn:
1681 zstyle ':vcs_info:(svn|bzr):*' \
1682 branchformat '%b%{'${fg[yellow]}'%}:%r'
1683
1684 If you want colors, make sure you enclose the color codes in %{...%} if
1685 you want to use the string provided by vcs_info in prompts.
1686
1687 Here is how to print the VCS information as a command (not in a
1688 prompt):
1689 alias vcsi='vcs_info command; vcs_info_lastmsg'
1690
1691 This way, you can even define different formats for output via
1692 vcs_info_lastmsg in the ':vcs_info:*:command:*' namespace.
1693
1694 Now as promised, some code that uses hooks: say, you'd like to replace
1695 the string `svn' by `subversion' in vcs_info's %s formats replacement.
1696
1697 First, we will tell vcs_info to call a function when populating the
1698 message variables with the gathered information:
1699 zstyle ':vcs_info:*+set-message:*' hooks svn2subversion
1700
1701 Nothing happens. Which is reasonable, since we didn't define the actual
1702 function yet. To see what the hooks subsystem is trying to do, enable
1703 the `debug' style:
1704 zstyle ':vcs_info:*+*:*' debug true
1705
1706 That should give you an idea what is going on. Specifically, the func‐
1707 tion that we are looking for is `+vi-svn2subversion'. Note, the `+vi-'
1708 prefix. So, everything is in order, just as documented. When you are
1709 done checking out the debugging output, disable it again:
1710 zstyle ':vcs_info:*+*:*' debug false
1711
1712 Now, let's define the function:
1713 function +vi-svn2subversion() {
1714 [[ ${hook_com[vcs_orig]} == svn ]] && hook_com[vcs]=subversion
1715 }
1716
1717 Simple enough. And it could have even been simpler, if only we had reg‐
1718 istered our function in a less generic context. If we do it only in the
1719 `svn' backend's context, we don't need to test which the active backend
1720 is:
1721 zstyle ':vcs_info:svn+set-message:*' hooks svn2subversion
1722 function +vi-svn2subversion() {
1723 hook_com[vcs]=subversion
1724 }
1725
1726 And finally a little more elaborate example, that uses a hook to create
1727 a customised bookmark string for the hg backend.
1728
1729 Again, we start off by registering a function:
1730 zstyle ':vcs_info:hg+gen-hg-bookmark-string:*' hooks hgbookmarks
1731
1732 And then we define the `+vi-hgbookmarks' function:
1733 function +vi-hgbookmarks() {
1734 # The default is to connect all bookmark names by
1735 # commas. This mixes things up a little.
1736 # Imagine, there's one type of bookmarks that is
1737 # special to you. Say, because it's *your* work.
1738 # Those bookmarks look always like this: "sh/*"
1739 # (because your initials are sh, for example).
1740 # This makes the bookmarks string use only those
1741 # bookmarks. If there's more than one, it
1742 # concatenates them using commas.
1743 # The bookmarks returned by `hg' are available in
1744 # the function's positional parameters.
1745 local s="${(Mj:,:)@:#sh/*}"
1746 # Now, the communication with the code that calls
1747 # the hook functions is done via the hook_com[]
1748 # hash. The key at which the `gen-hg-bookmark-string'
1749 # hook looks is `hg-bookmark-string'. So:
1750 hook_com[hg-bookmark-string]=$s
1751 # And to signal that we want to use the string we
1752 # just generated, set the special variable `ret' to
1753 # something other than the default zero:
1754 ret=1
1755 return 0
1756 }
1757
1758 Some longer examples and code snippets which might be useful are avail‐
1759 able in the examples file located at Misc/vcs_info-examples in the Zsh
1760 source directory.
1761
1762 This concludes our guided tour through zsh's vcs_info.
1763
1765 Installation
1766 You should make sure all the functions from the Functions/Prompts di‐
1767 rectory of the source distribution are available; they all begin with
1768 the string `prompt_' except for the special function`promptinit'. You
1769 also need the `colors' and `add-zsh-hook' functions from Func‐
1770 tions/Misc. All these functions may already be installed on your sys‐
1771 tem; if not, you will need to find them and copy them. The directory
1772 should appear as one of the elements of the fpath array (this should
1773 already be the case if they were installed), and at least the function
1774 promptinit should be autoloaded; it will autoload the rest. Finally,
1775 to initialize the use of the system you need to call the promptinit
1776 function. The following code in your .zshrc will arrange for this; as‐
1777 sume the functions are stored in the directory ~/myfns:
1778
1779 fpath=(~/myfns $fpath)
1780 autoload -U promptinit
1781 promptinit
1782
1783 Theme Selection
1784 Use the prompt command to select your preferred theme. This command
1785 may be added to your .zshrc following the call to promptinit in order
1786 to start zsh with a theme already selected.
1787
1788 prompt [ -c | -l ]
1789 prompt [ -p | -h ] [ theme ... ]
1790 prompt [ -s ] theme [ arg ... ]
1791 Set or examine the prompt theme. With no options and a theme
1792 argument, the theme with that name is set as the current theme.
1793 The available themes are determined at run time; use the -l op‐
1794 tion to see a list. The special theme `random' selects at ran‐
1795 dom one of the available themes and sets your prompt to that.
1796
1797 In some cases the theme may be modified by one or more argu‐
1798 ments, which should be given after the theme name. See the help
1799 for each theme for descriptions of these arguments.
1800
1801 Options are:
1802
1803 -c Show the currently selected theme and its parameters, if
1804 any.
1805 -l List all available prompt themes.
1806 -p Preview the theme named by theme, or all themes if no
1807 theme is given.
1808 -h Show help for the theme named by theme, or for the prompt
1809 function if no theme is given.
1810 -s Set theme as the current theme and save state.
1811
1812 prompt_theme_setup
1813 Each available theme has a setup function which is called by the
1814 prompt function to install that theme. This function may define
1815 other functions as necessary to maintain the prompt, including
1816 functions used to preview the prompt or provide help for its
1817 use. You should not normally call a theme's setup function di‐
1818 rectly.
1819
1820 Utility Themes
1821 prompt off
1822 The theme `off' sets all the prompt variables to minimal values
1823 with no special effects.
1824
1825 prompt default
1826 The theme `default' sets all prompt variables to the same state
1827 as if an interactive zsh was started with no initialization
1828 files.
1829
1830 prompt restore
1831 The special theme `restore' erases all theme settings and sets
1832 prompt variables to their state before the first time the
1833 `prompt' function was run, provided each theme has properly de‐
1834 fined its cleanup (see below).
1835
1836 Note that you can undo `prompt off' and `prompt default' with
1837 `prompt restore', but a second restore does not undo the first.
1838
1839 Writing Themes
1840 The first step for adding your own theme is to choose a name for it,
1841 and create a file `prompt_name_setup' in a directory in your fpath,
1842 such as ~/myfns in the example above. The file should at minimum con‐
1843 tain assignments for the prompt variables that your theme wishes to
1844 modify. By convention, themes use PS1, PS2, RPS1, etc., rather than
1845 the longer PROMPT and RPROMPT.
1846
1847 The file is autoloaded as a function in the current shell context, so
1848 it may contain any necessary commands to customize your theme, includ‐
1849 ing defining additional functions. To make some complex tasks easier,
1850 your setup function may also do any of the following:
1851
1852 Assign prompt_opts
1853 The array prompt_opts may be assigned any of "bang", "cr", "per‐
1854 cent", "sp", and/or "subst" as values. The corresponding se‐
1855 topts (promptbang, etc.) are turned on, all other prompt-related
1856 options are turned off. The prompt_opts array preserves setopts
1857 even beyond the scope of localoptions, should your function need
1858 that.
1859
1860 Modify precmd and preexec
1861 Use of add-zsh-hook is recommended. The precmd and preexec
1862 hooks are automatically adjusted if the prompt theme changes or
1863 is disabled.
1864
1865 Declare cleanup
1866 If your function makes any other changes that should be undone
1867 when the theme is disabled, your setup function may call
1868 prompt_cleanup command
1869 where command should be suitably quoted. If your theme is ever dis‐
1870 abled or replaced by another, command is executed with eval. You may
1871 declare more than one such cleanup hook.
1872
1873 Define preview
1874 Define or autoload a function prompt_name_preview to display a
1875 simulated version of your prompt. A simple default previewer is
1876 defined by promptinit for themes that do not define their own.
1877 This preview function is called by `prompt -p'.
1878
1879 Provide help
1880 Define or autoload a function prompt_name_help to display docu‐
1881 mentation or help text for your theme. This help function is
1882 called by `prompt -h'.
1883
1885 Widgets
1886 These functions all implement user-defined ZLE widgets (see zshzle(1))
1887 which can be bound to keystrokes in interactive shells. To use them,
1888 your .zshrc should contain lines of the form
1889
1890 autoload function
1891 zle -N function
1892
1893 followed by an appropriate bindkey command to associate the function
1894 with a key sequence. Suggested bindings are described below.
1895
1896 bash-style word functions
1897 If you are looking for functions to implement moving over and
1898 editing words in the manner of bash, where only alphanumeric
1899 characters are considered word characters, you can use the func‐
1900 tions described in the next section. The following is suffi‐
1901 cient:
1902
1903 autoload -U select-word-style
1904 select-word-style bash
1905
1906 forward-word-match, backward-word-match
1907 kill-word-match, backward-kill-word-match
1908 transpose-words-match, capitalize-word-match
1909 up-case-word-match, down-case-word-match
1910 delete-whole-word-match, select-word-match
1911 select-word-style, match-word-context, match-words-by-style
1912 The first eight `-match' functions are drop-in replacements for
1913 the builtin widgets without the suffix. By default they behave
1914 in a similar way. However, by the use of styles and the func‐
1915 tion select-word-style, the way words are matched can be al‐
1916 tered. select-word-match is intended to be used as a text object
1917 in vi mode but with custom word styles. For comparison, the wid‐
1918 gets described in zshzle(1) under Text Objects use fixed defini‐
1919 tions of words, compatible with the vim editor.
1920
1921 The simplest way of configuring the functions is to use se‐
1922 lect-word-style, which can either be called as a normal function
1923 with the appropriate argument, or invoked as a user-defined wid‐
1924 get that will prompt for the first character of the word style
1925 to be used. The first time it is invoked, the first eight
1926 -match functions will automatically replace the builtin ver‐
1927 sions, so they do not need to be loaded explicitly.
1928
1929 The word styles available are as follows. Only the first char‐
1930 acter is examined.
1931
1932 bash Word characters are alphanumeric characters only.
1933
1934 normal As in normal shell operation: word characters are al‐
1935 phanumeric characters plus any characters present in the
1936 string given by the parameter $WORDCHARS.
1937
1938 shell Words are complete shell command arguments, possibly in‐
1939 cluding complete quoted strings, or any tokens special to
1940 the shell.
1941
1942 whitespace
1943 Words are any set of characters delimited by whitespace.
1944
1945 default
1946 Restore the default settings; this is usually the same as
1947 `normal'.
1948
1949 All but `default' can be input as an upper case character, which
1950 has the same effect but with subword matching turned on. In
1951 this case, words with upper case characters are treated spe‐
1952 cially: each separate run of upper case characters, or an upper
1953 case character followed by any number of other characters, is
1954 considered a word. The style subword-range can supply an alter‐
1955 native character range to the default `[:upper:]'; the value of
1956 the style is treated as the contents of a `[...]' pattern (note
1957 that the outer brackets should not be supplied, only those sur‐
1958 rounding named ranges).
1959
1960 More control can be obtained using the zstyle command, as de‐
1961 scribed in zshmodules(1). Each style is looked up in the con‐
1962 text :zle:widget where widget is the name of the user-defined
1963 widget, not the name of the function implementing it, so in the
1964 case of the definitions supplied by select-word-style the appro‐
1965 priate contexts are :zle:forward-word, and so on. The function
1966 select-word-style itself always defines styles for the context
1967 `:zle:*' which can be overridden by more specific (longer) pat‐
1968 terns as well as explicit contexts.
1969
1970 The style word-style specifies the rules to use. This may have
1971 the following values.
1972
1973 normal Use the standard shell rules, i.e. alphanumerics and
1974 $WORDCHARS, unless overridden by the styles word-chars or
1975 word-class.
1976
1977 specified
1978 Similar to normal, but only the specified characters, and
1979 not also alphanumerics, are considered word characters.
1980
1981 unspecified
1982 The negation of specified. The given characters are
1983 those which will not be considered part of a word.
1984
1985 shell Words are obtained by using the syntactic rules for gen‐
1986 erating shell command arguments. In addition, special
1987 tokens which are never command arguments such as `()' are
1988 also treated as words.
1989
1990 whitespace
1991 Words are whitespace-delimited strings of characters.
1992
1993 The first three of those rules usually use $WORDCHARS, but the
1994 value in the parameter can be overridden by the style
1995 word-chars, which works in exactly the same way as $WORDCHARS.
1996 In addition, the style word-class uses character class syntax to
1997 group characters and takes precedence over word-chars if both
1998 are set. The word-class style does not include the surrounding
1999 brackets of the character class; for example, `-:[:alnum:]' is a
2000 valid word-class to include all alphanumerics plus the charac‐
2001 ters `-' and `:'. Be careful including `]', `^' and `-' as
2002 these are special inside character classes.
2003
2004 word-style may also have `-subword' appended to its value to
2005 turn on subword matching, as described above.
2006
2007 The style skip-chars is mostly useful for transpose-words and
2008 similar functions. If set, it gives a count of characters
2009 starting at the cursor position which will not be considered
2010 part of the word and are treated as space, regardless of what
2011 they actually are. For example, if
2012
2013 zstyle ':zle:transpose-words' skip-chars 1
2014
2015 has been set, and transpose-words-match is called with the cur‐
2016 sor on the X of fooXbar, where X can be any character, then the
2017 resulting expression is barXfoo.
2018
2019 Finer grained control can be obtained by setting the style
2020 word-context to an array of pairs of entries. Each pair of en‐
2021 tries consists of a pattern and a subcontext. The shell argu‐
2022 ment the cursor is on is matched against each pattern in turn
2023 until one matches; if it does, the context is extended by a
2024 colon and the corresponding subcontext. Note that the test is
2025 made against the original word on the line, with no stripping of
2026 quotes. Special handling is done between words: the current
2027 context is examined and if it contains the string between the
2028 word is set to a single space; else if it is contains the string
2029 back, the word before the cursor is considered, else the word
2030 after cursor is considered. Some examples are given below.
2031
2032 The style skip-whitespace-first is only used with the for‐
2033 ward-word widget. If it is set to true, then forward-word skips
2034 any non-word-characters, followed by any non-word-characters:
2035 this is similar to the behaviour of other word-orientated wid‐
2036 gets, and also that used by other editors, however it differs
2037 from the standard zsh behaviour. When using select-word-style
2038 the widget is set in the context :zle:* to true if the word
2039 style is bash and false otherwise. It may be overridden by set‐
2040 ting it in the more specific context :zle:forward-word*.
2041
2042 It is possible to create widgets with specific behaviour by
2043 defining a new widget implemented by the appropriate generic
2044 function, then setting a style for the context of the specific
2045 widget. For example, the following defines a widget back‐
2046 ward-kill-space-word using backward-kill-word-match, the generic
2047 widget implementing backward-kill-word behaviour, and ensures
2048 that the new widget always implements space-delimited behaviour.
2049
2050 zle -N backward-kill-space-word backward-kill-word-match
2051 zstyle :zle:backward-kill-space-word word-style space
2052
2053 The widget backward-kill-space-word can now be bound to a key.
2054
2055 Here are some further examples of use of the styles, actually
2056 taken from the simplified interface in select-word-style:
2057
2058 zstyle ':zle:*' word-style standard
2059 zstyle ':zle:*' word-chars ''
2060
2061 Implements bash-style word handling for all widgets, i.e. only
2062 alphanumerics are word characters; equivalent to setting the pa‐
2063 rameter WORDCHARS empty for the given context.
2064
2065 style ':zle:*kill*' word-style space
2066
2067 Uses space-delimited words for widgets with the word `kill' in
2068 the name. Neither of the styles word-chars nor word-class is
2069 used in this case.
2070
2071 Here are some examples of use of the word-context style to ex‐
2072 tend the context.
2073
2074 zstyle ':zle:*' word-context \
2075 "*/*" filename "[[:space:]]" whitespace
2076 zstyle ':zle:transpose-words:whitespace' word-style shell
2077 zstyle ':zle:transpose-words:filename' word-style normal
2078 zstyle ':zle:transpose-words:filename' word-chars ''
2079
2080 This provides two different ways of using transpose-words de‐
2081 pending on whether the cursor is on whitespace between words or
2082 on a filename, here any word containing a /. On whitespace,
2083 complete arguments as defined by standard shell rules will be
2084 transposed. In a filename, only alphanumerics will be trans‐
2085 posed. Elsewhere, words will be transposed using the default
2086 style for :zle:transpose-words.
2087
2088 The word matching and all the handling of zstyle settings is ac‐
2089 tually implemented by the function match-words-by-style. This
2090 can be used to create new user-defined widgets. The calling
2091 function should set the local parameter curcontext to :zle:wid‐
2092 get, create the local parameter matched_words and call
2093 match-words-by-style with no arguments. On return,
2094 matched_words will be set to an array with the elements: (1) the
2095 start of the line (2) the word before the cursor (3) any
2096 non-word characters between that word and the cursor (4) any
2097 non-word character at the cursor position plus any remaining
2098 non-word characters before the next word, including all charac‐
2099 ters specified by the skip-chars style, (5) the word at or fol‐
2100 lowing the cursor (6) any non-word characters following that
2101 word (7) the remainder of the line. Any of the elements may be
2102 an empty string; the calling function should test for this to
2103 decide whether it can perform its function.
2104
2105 If the variable matched_words is defined by the caller to
2106 match-words-by-style as an associative array (local -A
2107 matched_words), then the seven values given above should be re‐
2108 trieved from it as elements named start, word-before-cursor,
2109 ws-before-cursor, ws-after-cursor, word-after-cursor, ws-af‐
2110 ter-word, and end. In addition the element is-word-start is 1
2111 if the cursor is on the start of a word or subword, or on white
2112 space before it (the cases can be distinguished by testing the
2113 ws-after-cursor element) and 0 otherwise. This form is recom‐
2114 mended for future compatibility.
2115
2116 It is possible to pass options with arguments to
2117 match-words-by-style to override the use of styles. The options
2118 are:
2119 -w word-style
2120 -s skip-chars
2121 -c word-class
2122 -C word-chars
2123 -r subword-range
2124
2125 For example, match-words-by-style -w shell -c 0 may be used to
2126 extract the command argument around the cursor.
2127
2128 The word-context style is implemented by the function
2129 match-word-context. This should not usually need to be called
2130 directly.
2131
2132 bracketed-paste-magic
2133 The bracketed-paste widget (see subsection Miscellaneous in zsh‐
2134 zle(1)) inserts pasted text literally into the editor buffer
2135 rather than interpret it as keystrokes. This disables some com‐
2136 mon usages where the self-insert widget is replaced in order to
2137 accomplish some extra processing. An example is the contributed
2138 url-quote-magic widget described below.
2139
2140 The bracketed-paste-magic widget is meant to replace brack‐
2141 eted-paste with a wrapper that re-enables these self-insert ac‐
2142 tions, and other actions as selected by zstyles. Therefore this
2143 widget is installed with
2144
2145 autoload -Uz bracketed-paste-magic
2146 zle -N bracketed-paste bracketed-paste-magic
2147
2148 Other than enabling some widget processing, brack‐
2149 eted-paste-magic attempts to replicate bracketed-paste as faith‐
2150 fully as possible.
2151
2152 The following zstyles may be set to control processing of pasted
2153 text. All are looked up in the context `:brack‐
2154 eted-paste-magic'.
2155
2156 active-widgets
2157 A list of patterns matching widget names that should be
2158 activated during the paste. All other key sequences are
2159 processed as self-insert-unmeta. The default is `self-*'
2160 so any user-defined widgets named with that prefix are
2161 active along with the builtin self-insert.
2162
2163 If this style is not set (explicitly deleted) or set to
2164 an empty value, no widgets are active and the pasted text
2165 is inserted literally. If the value includes `unde‐
2166 fined-key', any unknown sequences are discarded from the
2167 pasted text.
2168
2169 inactive-keys
2170 The inverse of active-widgets, a list of key sequences
2171 that always use self-insert-unmeta even when bound to an
2172 active widget. Note that this is a list of literal key
2173 sequences, not patterns.
2174
2175 paste-init
2176 A list of function names, called in widget context (but
2177 not as widgets). The functions are called in order until
2178 one of them returns a non-zero status. The parameter
2179 `PASTED' contains the initial state of the pasted text.
2180 All other ZLE parameters such as `BUFFER' have their nor‐
2181 mal values and side-effects, and full history is avail‐
2182 able, so for example paste-init functions may move words
2183 from BUFFER into PASTED to make those words visible to
2184 the active-widgets.
2185
2186 A non-zero return from a paste-init function does not
2187 prevent the paste itself from proceeding.
2188
2189 Loading bracketed-paste-magic defines backward-ex‐
2190 tend-paste, a helper function for use in paste-init.
2191
2192 zstyle :bracketed-paste-magic paste-init \
2193 backward-extend-paste
2194
2195 When a paste would insert into the middle of a word or
2196 append text to a word already on the line, backward-ex‐
2197 tend-paste moves the prefix from LBUFFER into PASTED so
2198 that the active-widgets see the full word so far. This
2199 may be useful with url-quote-magic.
2200
2201 paste-finish
2202 Another list of function names called in order until one
2203 returns non-zero. These functions are called after the
2204 pasted text has been processed by the active-widgets, but
2205 before it is inserted into `BUFFER'. ZLE parameters have
2206 their normal values and side-effects.
2207
2208 A non-zero return from a paste-finish function does not
2209 prevent the paste itself from proceeding.
2210
2211 Loading bracketed-paste-magic also defines quote-paste, a
2212 helper function for use in paste-finish.
2213
2214 zstyle :bracketed-paste-magic paste-finish \
2215 quote-paste
2216 zstyle :bracketed-paste-magic:finish quote-style \
2217 qqq
2218
2219 When the pasted text is inserted into BUFFER, it is
2220 quoted per the quote-style value. To forcibly turn off
2221 the built-in numeric prefix quoting of bracketed-paste,
2222 use:
2223
2224 zstyle :bracketed-paste-magic:finish quote-style \
2225 none
2226
2227 Important: During active-widgets processing of the paste (after
2228 paste-init and before paste-finish), BUFFER starts empty and
2229 history is restricted, so cursor motions, etc., may not pass
2230 outside of the pasted content. Text assigned to BUFFER by the
2231 active widgets is copied back into PASTED before paste-finish.
2232
2233 copy-earlier-word
2234 This widget works like a combination of insert-last-word and
2235 copy-prev-shell-word. Repeated invocations of the widget re‐
2236 trieve earlier words on the relevant history line. With a nu‐
2237 meric argument N, insert the Nth word from the history line; N
2238 may be negative to count from the end of the line.
2239
2240 If insert-last-word has been used to retrieve the last word on a
2241 previous history line, repeated invocations will replace that
2242 word with earlier words from the same line.
2243
2244 Otherwise, the widget applies to words on the line currently be‐
2245 ing edited. The widget style can be set to the name of another
2246 widget that should be called to retrieve words. This widget
2247 must accept the same three arguments as insert-last-word.
2248
2249 cycle-completion-positions
2250 After inserting an unambiguous string into the command line, the
2251 new function based completion system may know about multiple
2252 places in this string where characters are missing or differ
2253 from at least one of the possible matches. It will then place
2254 the cursor on the position it considers to be the most interest‐
2255 ing one, i.e. the one where one can disambiguate between as many
2256 matches as possible with as little typing as possible.
2257
2258 This widget allows the cursor to be easily moved to the other
2259 interesting spots. It can be invoked repeatedly to cycle be‐
2260 tween all positions reported by the completion system.
2261
2262 delete-whole-word-match
2263 This is another function which works like the -match functions
2264 described immediately above, i.e. using styles to decide the
2265 word boundaries. However, it is not a replacement for any ex‐
2266 isting function.
2267
2268 The basic behaviour is to delete the word around the cursor.
2269 There is no numeric argument handling; only the single word
2270 around the cursor is considered. If the widget contains the
2271 string kill, the removed text will be placed in the cutbuffer
2272 for future yanking. This can be obtained by defining
2273 kill-whole-word-match as follows:
2274
2275 zle -N kill-whole-word-match delete-whole-word-match
2276
2277 and then binding the widget kill-whole-word-match.
2278
2279 up-line-or-beginning-search, down-line-or-beginning-search
2280 These widgets are similar to the builtin functions
2281 up-line-or-search and down-line-or-search: if in a multiline
2282 buffer they move up or down within the buffer, otherwise they
2283 search for a history line matching the start of the current
2284 line. In this case, however, they search for a line which
2285 matches the current line up to the current cursor position, in
2286 the manner of history-beginning-search-backward and -forward,
2287 rather than the first word on the line.
2288
2289 edit-command-line
2290 Edit the command line using your visual editor, as in ksh.
2291
2292 bindkey -M vicmd v edit-command-line
2293
2294 expand-absolute-path
2295 Expand the file name under the cursor to an absolute path, re‐
2296 solving symbolic links. Where possible, the initial path seg‐
2297 ment is turned into a named directory or reference to a user's
2298 home directory.
2299
2300 history-search-end
2301 This function implements the widgets history-begin‐
2302 ning-search-backward-end and history-beginning-search-for‐
2303 ward-end. These commands work by first calling the correspond‐
2304 ing builtin widget (see `History Control' in zshzle(1)) and then
2305 moving the cursor to the end of the line. The original cursor
2306 position is remembered and restored before calling the builtin
2307 widget a second time, so that the same search is repeated to
2308 look farther through the history.
2309
2310 Although you autoload only one function, the commands to use it
2311 are slightly different because it implements two widgets.
2312
2313 zle -N history-beginning-search-backward-end \
2314 history-search-end
2315 zle -N history-beginning-search-forward-end \
2316 history-search-end
2317 bindkey '\e^P' history-beginning-search-backward-end
2318 bindkey '\e^N' history-beginning-search-forward-end
2319
2320 history-beginning-search-menu
2321 This function implements yet another form of history searching.
2322 The text before the cursor is used to select lines from the his‐
2323 tory, as for history-beginning-search-backward except that all
2324 matches are shown in a numbered menu. Typing the appropriate
2325 digits inserts the full history line. Note that leading zeroes
2326 must be typed (they are only shown when necessary for removing
2327 ambiguity). The entire history is searched; there is no dis‐
2328 tinction between forwards and backwards.
2329
2330 With a numeric argument, the search is not anchored to the start
2331 of the line; the string typed by the use may appear anywhere in
2332 the line in the history.
2333
2334 If the widget name contains `-end' the cursor is moved to the
2335 end of the line inserted. If the widget name contains `-space'
2336 any space in the text typed is treated as a wildcard and can
2337 match anything (hence a leading space is equivalent to giving a
2338 numeric argument). Both forms can be combined, for example:
2339
2340 zle -N history-beginning-search-menu-space-end \
2341 history-beginning-search-menu
2342
2343 history-pattern-search
2344 The function history-pattern-search implements widgets which
2345 prompt for a pattern with which to search the history backwards
2346 or forwards. The pattern is in the usual zsh format, however
2347 the first character may be ^ to anchor the search to the start
2348 of the line, and the last character may be $ to anchor the
2349 search to the end of the line. If the search was not anchored
2350 to the end of the line the cursor is positioned just after the
2351 pattern found.
2352
2353 The commands to create bindable widgets are similar to those in
2354 the example immediately above:
2355
2356 autoload -U history-pattern-search
2357 zle -N history-pattern-search-backward history-pattern-search
2358 zle -N history-pattern-search-forward history-pattern-search
2359
2360 incarg Typing the keystrokes for this widget with the cursor placed on
2361 or to the left of an integer causes that integer to be incre‐
2362 mented by one. With a numeric argument, the number is incre‐
2363 mented by the amount of the argument (decremented if the numeric
2364 argument is negative). The shell parameter incarg may be set to
2365 change the default increment to something other than one.
2366
2367 bindkey '^X+' incarg
2368
2369 incremental-complete-word
2370 This allows incremental completion of a word. After starting
2371 this command, a list of completion choices can be shown after
2372 every character you type, which you can delete with ^H or DEL.
2373 Pressing return accepts the completion so far and returns you to
2374 normal editing (that is, the command line is not immediately ex‐
2375 ecuted). You can hit TAB to do normal completion, ^G to abort
2376 back to the state when you started, and ^D to list the matches.
2377
2378 This works only with the new function based completion system.
2379
2380 bindkey '^Xi' incremental-complete-word
2381
2382 insert-composed-char
2383 This function allows you to compose characters that don't appear
2384 on the keyboard to be inserted into the command line. The com‐
2385 mand is followed by two keys corresponding to ASCII characters
2386 (there is no prompt). For accented characters, the two keys are
2387 a base character followed by a code for the accent, while for
2388 other special characters the two characters together form a mne‐
2389 monic for the character to be inserted. The two-character codes
2390 are a subset of those given by RFC 1345 (see for example
2391 http://www.faqs.org/rfcs/rfc1345.html).
2392
2393 The function may optionally be followed by up to two characters
2394 which replace one or both of the characters read from the key‐
2395 board; if both characters are supplied, no input is read. For
2396 example, insert-composed-char a: can be used within a widget to
2397 insert an a with umlaut into the command line. This has the ad‐
2398 vantages over use of a literal character that it is more porta‐
2399 ble.
2400
2401 For best results zsh should have been built with support for
2402 multibyte characters (configured with --enable-multibyte); how‐
2403 ever, the function works for the limited range of characters
2404 available in single-byte character sets such as ISO-8859-1.
2405
2406 The character is converted into the local representation and in‐
2407 serted into the command line at the cursor position. (The con‐
2408 version is done within the shell, using whatever facilities the
2409 C library provides.) With a numeric argument, the character and
2410 its code are previewed in the status line
2411
2412 The function may be run outside zle in which case it prints the
2413 character (together with a newline) to standard output. Input
2414 is still read from keystrokes.
2415
2416 See insert-unicode-char for an alternative way of inserting Uni‐
2417 code characters using their hexadecimal character number.
2418
2419 The set of accented characters is reasonably complete up to Uni‐
2420 code character U+0180, the set of special characters less so.
2421 However, it is very sporadic from that point. Adding new char‐
2422 acters is easy, however; see the function define-composed-chars.
2423 Please send any additions to zsh-workers@zsh.org.
2424
2425 The codes for the second character when used to accent the first
2426 are as follows. Note that not every character can take every
2427 accent.
2428 ! Grave.
2429 ' Acute.
2430 > Circumflex.
2431 ? Tilde. (This is not ~ as RFC 1345 does not assume that
2432 character is present on the keyboard.)
2433 - Macron. (A horizontal bar over the base character.)
2434 ( Breve. (A shallow dish shape over the base character.)
2435 . Dot above the base character, or in the case of i no dot,
2436 or in the case of L and l a centered dot.
2437 : Diaeresis (Umlaut).
2438 c Cedilla.
2439 _ Underline, however there are currently no underlined
2440 characters.
2441 / Stroke through the base character.
2442 " Double acute (only supported on a few letters).
2443 ; Ogonek. (A little forward facing hook at the bottom
2444 right of the character.)
2445 < Caron. (A little v over the letter.)
2446 0 Circle over the base character.
2447 2 Hook over the base character.
2448 9 Horn over the base character.
2449
2450 The most common characters from the Arabic, Cyrillic, Greek and
2451 Hebrew alphabets are available; consult RFC 1345 for the appro‐
2452 priate sequences. In addition, a set of two letter codes not in
2453 RFC 1345 are available for the double-width characters corre‐
2454 sponding to ASCII characters from ! to ~ (0x21 to 0x7e) by pre‐
2455 ceding the character with ^, for example ^A for a double-width
2456 A.
2457
2458 The following other two-character sequences are understood.
2459
2460 ASCII characters
2461 These are already present on most keyboards:
2462 <( Left square bracket
2463 // Backslash (solidus)
2464 )> Right square bracket
2465 (! Left brace (curly bracket)
2466 !! Vertical bar (pipe symbol)
2467 !) Right brace (curly bracket)
2468 '? Tilde
2469
2470 Special letters
2471 Characters found in various variants of the Latin alpha‐
2472 bet:
2473 ss Eszett (scharfes S)
2474 D-, d- Eth
2475 TH, th Thorn
2476 kk Kra
2477 'n 'n
2478 NG, ng Ng
2479 OI, oi Oi
2480 yr yr
2481 ED ezh
2482
2483 Currency symbols
2484 Ct Cent
2485 Pd Pound sterling (also lira and others)
2486 Cu Currency
2487 Ye Yen
2488 Eu Euro (N.B. not in RFC 1345)
2489
2490 Punctuation characters
2491 References to "right" quotes indicate the shape (like a 9
2492 rather than 6) rather than their grammatical use. (For
2493 example, a "right" low double quote is used to open quo‐
2494 tations in German.)
2495 !I Inverted exclamation mark
2496 BB Broken vertical bar
2497 SE Section
2498 Co Copyright
2499 -a Spanish feminine ordinal indicator
2500 << Left guillemet
2501 -- Soft hyphen
2502 Rg Registered trade mark
2503 PI Pilcrow (paragraph)
2504 -o Spanish masculine ordinal indicator
2505 >> Right guillemet
2506 ?I Inverted question mark
2507 -1 Hyphen
2508 -N En dash
2509 -M Em dash
2510 -3 Horizontal bar
2511 :3 Vertical ellipsis
2512 .3 Horizontal midline ellipsis
2513 !2 Double vertical line
2514 =2 Double low line
2515 '6 Left single quote
2516 '9 Right single quote
2517 .9 "Right" low quote
2518 9' Reversed "right" quote
2519 "6 Left double quote
2520 "9 Right double quote
2521 :9 "Right" low double quote
2522 9" Reversed "right" double quote
2523 /- Dagger
2524 /= Double dagger
2525
2526 Mathematical symbols
2527 DG Degree
2528 -2, +-, -+
2529 - sign, +/- sign, -/+ sign
2530 2S Superscript 2
2531 3S Superscript 3
2532 1S Superscript 1
2533 My Micro
2534 .M Middle dot
2535 14 Quarter
2536 12 Half
2537 34 Three quarters
2538 *X Multiplication
2539 -: Division
2540 %0 Per mille
2541 FA, TE, /0
2542 For all, there exists, empty set
2543 dP, DE, NB
2544 Partial derivative, delta (increment), del (nabla)
2545 (-, -) Element of, contains
2546 *P, +Z Product, sum
2547 *-, Ob, Sb
2548 Asterisk, ring, bullet
2549 RT, 0(, 00
2550 Root sign, proportional to, infinity
2551
2552 Other symbols
2553 cS, cH, cD, cC
2554 Card suits: spades, hearts, diamonds, clubs
2555 Md, M8, M2, Mb, Mx, MX
2556 Musical notation: crotchet (quarter note), quaver (eighth
2557 note), semiquavers (sixteenth notes), flag sign, natural
2558 sign, sharp sign
2559 Fm, Ml Female, male
2560
2561 Accents on their own
2562 '> Circumflex (same as caret, ^)
2563 '! Grave (same as backtick, `)
2564 ', Cedilla
2565 ': Diaeresis (Umlaut)
2566 'm Macron
2567 '' Acute
2568
2569 insert-files
2570 This function allows you type a file pattern, and see the re‐
2571 sults of the expansion at each step. When you hit return, all
2572 expansions are inserted into the command line.
2573
2574 bindkey '^Xf' insert-files
2575
2576 insert-unicode-char
2577 When first executed, the user inputs a set of hexadecimal dig‐
2578 its. This is terminated with another call to insert-uni‐
2579 code-char. The digits are then turned into the corresponding
2580 Unicode character. For example, if the widget is bound to ^XU,
2581 the character sequence `^XU 4 c ^XU' inserts L (Unicode U+004c).
2582
2583 See insert-composed-char for a way of inserting characters using
2584 a two-character mnemonic.
2585
2586
2587 narrow-to-region [ -p pre ] [ -P post ]
2588 [ -S statepm | -R statepm | [ -l lbufvar ] [ -r rbuf‐
2589 var ] ]
2590 [ -n ] [ start end ]
2591 narrow-to-region-invisible
2592 Narrow the editable portion of the buffer to the region between
2593 the cursor and the mark, which may be in either order. The re‐
2594 gion may not be empty.
2595
2596 narrow-to-region may be used as a widget or called as a function
2597 from a user-defined widget; by default, the text outside the ed‐
2598 itable area remains visible. A recursive-edit is performed and
2599 the original widening status is then restored. Various options
2600 and arguments are available when it is called as a function.
2601
2602 The options -p pretext and -P posttext may be used to replace
2603 the text before and after the display for the duration of the
2604 function; either or both may be an empty string.
2605
2606 If the option -n is also given, pretext or posttext will only be
2607 inserted if there is text before or after the region respec‐
2608 tively which will be made invisible.
2609
2610 Two numeric arguments may be given which will be used instead of
2611 the cursor and mark positions.
2612
2613 The option -S statepm is used to narrow according to the other
2614 options while saving the original state in the parameter with
2615 name statepm, while the option -R statepm is used to restore the
2616 state from the parameter; note in both cases the name of the pa‐
2617 rameter is required. In the second case, other options and ar‐
2618 guments are irrelevant. When this method is used, no recur‐
2619 sive-edit is performed; the calling widget should call this
2620 function with the option -S, perform its own editing on the com‐
2621 mand line or pass control to the user via `zle recursive-edit',
2622 then call this function with the option -R. The argument
2623 statepm must be a suitable name for an ordinary parameter, ex‐
2624 cept that parameters beginning with the prefix _ntr_ are re‐
2625 served for use within narrow-to-region. Typically the parameter
2626 will be local to the calling function.
2627
2628 The options -l lbufvar and -r rbufvar may be used to specify pa‐
2629 rameters where the widget will store the resulting text from the
2630 operation. The parameter lbufvar will contain LBUFFER and rbuf‐
2631 var will contain RBUFFER. Neither of these two options may be
2632 used with -S or -R.
2633
2634 narrow-to-region-invisible is a simple widget which calls nar‐
2635 row-to-region with arguments which replace any text outside the
2636 region with `...'. It does not take any arguments.
2637
2638 The display is restored (and the widget returns) upon any zle
2639 command which would usually cause the line to be accepted or
2640 aborted. Hence an additional such command is required to accept
2641 or abort the current line.
2642
2643 The return status of both widgets is zero if the line was ac‐
2644 cepted, else non-zero.
2645
2646 Here is a trivial example of a widget using this feature.
2647 local state
2648 narrow-to-region -p $'Editing restricted region\n' \
2649 -P '' -S state
2650 zle recursive-edit
2651 narrow-to-region -R state
2652
2653 predict-on
2654 This set of functions implements predictive typing using history
2655 search. After predict-on, typing characters causes the editor
2656 to look backward in the history for the first line beginning
2657 with what you have typed so far. After predict-off, editing re‐
2658 turns to normal for the line found. In fact, you often don't
2659 even need to use predict-off, because if the line doesn't match
2660 something in the history, adding a key performs standard comple‐
2661 tion, and then inserts itself if no completions were found.
2662 However, editing in the middle of a line is liable to confuse
2663 prediction; see the toggle style below.
2664
2665 With the function based completion system (which is needed for
2666 this), you should be able to type TAB at almost any point to ad‐
2667 vance the cursor to the next ``interesting'' character position
2668 (usually the end of the current word, but sometimes somewhere in
2669 the middle of the word). And of course as soon as the entire
2670 line is what you want, you can accept with return, without need‐
2671 ing to move the cursor to the end first.
2672
2673 The first time predict-on is used, it creates several additional
2674 widget functions:
2675
2676 delete-backward-and-predict
2677 Replaces the backward-delete-char widget. You do not
2678 need to bind this yourself.
2679 insert-and-predict
2680 Implements predictive typing by replacing the self-insert
2681 widget. You do not need to bind this yourself.
2682 predict-off
2683 Turns off predictive typing.
2684
2685 Although you autoload only the predict-on function, it is neces‐
2686 sary to create a keybinding for predict-off as well.
2687
2688 zle -N predict-on
2689 zle -N predict-off
2690 bindkey '^X^Z' predict-on
2691 bindkey '^Z' predict-off
2692
2693 read-from-minibuffer
2694 This is most useful when called as a function from inside a wid‐
2695 get, but will work correctly as a widget in its own right. It
2696 prompts for a value below the current command line; a value may
2697 be input using all of the standard zle operations (and not
2698 merely the restricted set available when executing, for example,
2699 execute-named-cmd). The value is then returned to the calling
2700 function in the parameter $REPLY and the editing buffer restored
2701 to its previous state. If the read was aborted by a keyboard
2702 break (typically ^G), the function returns status 1 and $REPLY
2703 is not set.
2704
2705 If one argument is supplied to the function it is taken as a
2706 prompt, otherwise `? ' is used. If two arguments are supplied,
2707 they are the prompt and the initial value of $LBUFFER, and if a
2708 third argument is given it is the initial value of $RBUFFER.
2709 This provides a default value and starting cursor placement.
2710 Upon return the entire buffer is the value of $REPLY.
2711
2712 One option is available: `-k num' specifies that num characters
2713 are to be read instead of a whole line. The line editor is not
2714 invoked recursively in this case, so depending on the terminal
2715 settings the input may not be visible, and only the input keys
2716 are placed in $REPLY, not the entire buffer. Note that unlike
2717 the read builtin num must be given; there is no default.
2718
2719 The name is a slight misnomer, as in fact the shell's own
2720 minibuffer is not used. Hence it is still possible to call exe‐
2721 cuted-named-cmd and similar functions while reading a value.
2722
2723 replace-argument, replace-argument-edit
2724 The function replace-argument can be used to replace a command
2725 line argument in the current command line or, if the current
2726 command line is empty, in the last command line executed (the
2727 new command line is not executed). Arguments are as delimited
2728 by standard shell syntax,
2729
2730 If a numeric argument is given, that specifies the argument to
2731 be replaced. 0 means the command name, as in history expansion.
2732 A negative numeric argument counts backward from the last word.
2733
2734 If no numeric argument is given, the current argument is re‐
2735 placed; this is the last argument if the previous history line
2736 is being used.
2737
2738 The function prompts for a replacement argument.
2739
2740 If the widget contains the string edit, for example is defined
2741 as
2742
2743 zle -N replace-argument-edit replace-argument
2744
2745 then the function presents the current value of the argument for
2746 editing, otherwise the editing buffer for the replacement is
2747 initially empty.
2748
2749 replace-string, replace-pattern
2750 replace-string-again, replace-pattern-again
2751 The function replace-string implements three widgets. If de‐
2752 fined under the same name as the function, it prompts for two
2753 strings; the first (source) string will be replaced by the sec‐
2754 ond everywhere it occurs in the line editing buffer.
2755
2756 If the widget name contains the word `pattern', for example by
2757 defining the widget using the command `zle -N replace-pattern
2758 replace-string', then the matching is performed using zsh pat‐
2759 terns. All zsh extended globbing patterns can be used in the
2760 source string; note that unlike filename generation the pattern
2761 does not need to match an entire word, nor do glob qualifiers
2762 have any effect. In addition, the replacement string can con‐
2763 tain parameter or command substitutions. Furthermore, a `&' in
2764 the replacement string will be replaced with the matched source
2765 string, and a backquoted digit `\N' will be replaced by the Nth
2766 parenthesised expression matched. The form `\{N}' may be used
2767 to protect the digit from following digits.
2768
2769 If the widget instead contains the word `regex' (or `regexp'),
2770 then the matching is performed using regular expressions, re‐
2771 specting the setting of the option RE_MATCH_PCRE (see the de‐
2772 scription of the function regexp-replace below). The special
2773 replacement facilities described above for pattern matching are
2774 available.
2775
2776 By default the previous source or replacement string will not be
2777 offered for editing. However, this feature can be activated by
2778 setting the style edit-previous in the context :zle:widget (for
2779 example, :zle:replace-string) to true. In addition, a positive
2780 numeric argument forces the previous values to be offered, a
2781 negative or zero argument forces them not to be.
2782
2783 The function replace-string-again can be used to repeat the pre‐
2784 vious replacement; no prompting is done. As with re‐
2785 place-string, if the name of the widget contains the word `pat‐
2786 tern' or `regex', pattern or regular expression matching is per‐
2787 formed, else a literal string replacement. Note that the previ‐
2788 ous source and replacement text are the same whether pattern,
2789 regular expression or string matching is used.
2790
2791 In addition, replace-string shows the previous replacement above
2792 the prompt, so long as there was one during the current session;
2793 if the source string is empty, that replacement will be repeated
2794 without the widget prompting for a replacement string.
2795
2796 For example, starting from the line:
2797
2798 print This line contains fan and fond
2799
2800 and invoking replace-pattern with the source string `f(?)n' and
2801 the replacement string `c\1r' produces the not very useful line:
2802
2803 print This line contains car and cord
2804
2805 The range of the replacement string can be limited by using the
2806 narrow-to-region-invisible widget. One limitation of the cur‐
2807 rent version is that undo will cycle through changes to the re‐
2808 placement and source strings before undoing the replacement it‐
2809 self.
2810
2811 send-invisible
2812 This is similar to read-from-minibuffer in that it may be called
2813 as a function from a widget or as a widget of its own, and in‐
2814 teractively reads input from the keyboard. However, the input
2815 being typed is concealed and a string of asterisks (`*') is
2816 shown instead. The value is saved in the parameter $INVISIBLE
2817 to which a reference is inserted into the editing buffer at the
2818 restored cursor position. If the read was aborted by a keyboard
2819 break (typically ^G) or another escape from editing such as
2820 push-line, $INVISIBLE is set to empty and the original buffer is
2821 restored unchanged.
2822
2823 If one argument is supplied to the function it is taken as a
2824 prompt, otherwise `Non-echoed text: ' is used (as in emacs). If
2825 a second and third argument are supplied they are used to begin
2826 and end the reference to $INVISIBLE that is inserted into the
2827 buffer. The default is to open with ${, then INVISIBLE, and
2828 close with }, but many other effects are possible.
2829
2830 smart-insert-last-word
2831 This function may replace the insert-last-word widget, like so:
2832
2833 zle -N insert-last-word smart-insert-last-word
2834
2835 With a numeric argument, or when passed command line arguments
2836 in a call from another widget, it behaves like insert-last-word,
2837 except that words in comments are ignored when INTERACTIVE_COM‐
2838 MENTS is set.
2839
2840 Otherwise, the rightmost ``interesting'' word from the previous
2841 command is found and inserted. The default definition of ``in‐
2842 teresting'' is that the word contains at least one alphabetic
2843 character, slash, or backslash. This definition may be overrid‐
2844 den by use of the match style. The context used to look up the
2845 style is the widget name, so usually the context is :in‐
2846 sert-last-word. However, you can bind this function to differ‐
2847 ent widgets to use different patterns:
2848
2849 zle -N insert-last-assignment smart-insert-last-word
2850 zstyle :insert-last-assignment match '[[:alpha:]][][[:alnum:]]#=*'
2851 bindkey '\e=' insert-last-assignment
2852
2853 If no interesting word is found and the auto-previous style is
2854 set to a true value, the search continues upward through the
2855 history. When auto-previous is unset or false (the default),
2856 the widget must be invoked repeatedly in order to search earlier
2857 history lines.
2858
2859 transpose-lines
2860 Only useful with a multi-line editing buffer; the lines here are
2861 lines within the current on-screen buffer, not history lines.
2862 The effect is similar to the function of the same name in Emacs.
2863
2864 Transpose the current line with the previous line and move the
2865 cursor to the start of the next line. Repeating this (which can
2866 be done by providing a positive numeric argument) has the effect
2867 of moving the line above the cursor down by a number of lines.
2868
2869 With a negative numeric argument, requires two lines above the
2870 cursor. These two lines are transposed and the cursor moved to
2871 the start of the previous line. Using a numeric argument less
2872 than -1 has the effect of moving the line above the cursor up by
2873 minus that number of lines.
2874
2875 url-quote-magic
2876 This widget replaces the built-in self-insert to make it easier
2877 to type URLs as command line arguments. As you type, the input
2878 character is analyzed and, if it may need quoting, the current
2879 word is checked for a URI scheme. If one is found and the cur‐
2880 rent word is not already in quotes, a backslash is inserted be‐
2881 fore the input character.
2882
2883 Styles to control quoting behavior:
2884
2885 url-metas
2886 This style is looked up in the context
2887 `:url-quote-magic:scheme' (where scheme is that of the
2888 current URL, e.g. "ftp"). The value is a string listing
2889 the characters to be treated as globbing metacharacters
2890 when appearing in a URL using that scheme. The default
2891 is to quote all zsh extended globbing characters, exclud‐
2892 ing '<' and '>' but including braces (as in brace expan‐
2893 sion). See also url-seps.
2894
2895 url-seps
2896 Like url-metas, but lists characters that should be con‐
2897 sidered command separators, redirections, history refer‐
2898 ences, etc. The default is to quote the standard set of
2899 shell separators, excluding those that overlap with the
2900 extended globbing characters, but including '<' and '>'
2901 and the first character of $histchars.
2902
2903 url-globbers
2904 This style is looked up in the context
2905 `:url-quote-magic'. The values form a list of command
2906 names that are expected to do their own globbing on the
2907 URL string. This implies that they are aliased to use
2908 the `noglob' modifier. When the first word on the line
2909 matches one of the values and the URL refers to a local
2910 file (see url-local-schema), only the url-seps characters
2911 are quoted; the url-metas are left alone, allowing them
2912 to affect command-line parsing, completion, etc. The de‐
2913 fault values are a literal `noglob' plus (when the
2914 zsh/parameter module is available) any commands aliased
2915 to the helper function `urlglobber' or its alias
2916 `globurl'.
2917
2918 url-local-schema
2919 This style is always looked up in the context `:urlglob‐
2920 ber', even though it is used by both url-quote-magic and
2921 urlglobber. The values form a list of URI schema that
2922 should be treated as referring to local files by their
2923 real local path names, as opposed to files which are
2924 specified relative to a web-server-defined document root.
2925 The defaults are "ftp" and "file".
2926
2927 url-other-schema
2928 Like url-local-schema, but lists all other URI schema
2929 upon which urlglobber and url-quote-magic should act. If
2930 the URI on the command line does not have a scheme ap‐
2931 pearing either in this list or in url-local-schema, it is
2932 not magically quoted. The default values are "http",
2933 "https", and "ftp". When a scheme appears both here and
2934 in url-local-schema, it is quoted differently depending
2935 on whether the command name appears in url-globbers.
2936
2937 Loading url-quote-magic also defines a helper function `urlglob‐
2938 ber' and aliases `globurl' to `noglob urlglobber'. This func‐
2939 tion takes a local URL apart, attempts to pattern-match the lo‐
2940 cal file portion of the URL path, and then puts the results back
2941 into URL format again.
2942
2943 vi-pipe
2944 This function reads a movement command from the keyboard and
2945 then prompts for an external command. The part of the buffer
2946 covered by the movement is piped to the external command and
2947 then replaced by the command's output. If the movement command
2948 is bound to vi-pipe, the current line is used.
2949
2950 The function serves as an example for reading a vi movement com‐
2951 mand from within a user-defined widget.
2952
2953 which-command
2954 This function is a drop-in replacement for the builtin widget
2955 which-command. It has enhanced behaviour, in that it correctly
2956 detects whether or not the command word needs to be expanded as
2957 an alias; if so, it continues tracing the command word from the
2958 expanded alias until it reaches the command that will be exe‐
2959 cuted.
2960
2961 The style whence is available in the context :zle:$WIDGET; this
2962 may be set to an array to give the command and options that will
2963 be used to investigate the command word found. The default is
2964 whence -c.
2965
2966 zcalc-auto-insert
2967 This function is useful together with the zcalc function de‐
2968 scribed in the section Mathematical Functions. It should be
2969 bound to a key representing a binary operator such as `+', `-',
2970 `*' or `/'. When running in zcalc, if the key occurs at the
2971 start of the line or immediately following an open parenthesis,
2972 the text "ans " is inserted before the representation of the key
2973 itself. This allows easy use of the answer from the previous
2974 calculation in the current line. The text to be inserted before
2975 the symbol typed can be modified by setting the variable
2976 ZCALC_AUTO_INSERT_PREFIX.
2977
2978 Hence, for example, typing `+12' followed by return adds 12 to
2979 the previous result.
2980
2981 If zcalc is in RPN mode (-r option) the effect of this binding
2982 is automatically suppressed as operators alone on a line are
2983 meaningful.
2984
2985 When not in zcalc, the key simply inserts the symbol itself.
2986
2987 Utility Functions
2988 These functions are useful in constructing widgets. They should be
2989 loaded with `autoload -U function' and called as indicated from
2990 user-defined widgets.
2991
2992 split-shell-arguments
2993 This function splits the line currently being edited into shell
2994 arguments and whitespace. The result is stored in the array re‐
2995 ply. The array contains all the parts of the line in order,
2996 starting with any whitespace before the first argument, and fin‐
2997 ishing with any whitespace after the last argument. Hence (so
2998 long as the option KSH_ARRAYS is not set) whitespace is given by
2999 odd indices in the array and arguments by even indices. Note
3000 that no stripping of quotes is done; joining together all the
3001 elements of reply in order is guaranteed to produce the original
3002 line.
3003
3004 The parameter REPLY is set to the index of the word in reply
3005 which contains the character after the cursor, where the first
3006 element has index 1. The parameter REPLY2 is set to the index
3007 of the character under the cursor in that word, where the first
3008 character has index 1.
3009
3010 Hence reply, REPLY and REPLY2 should all be made local to the
3011 enclosing function.
3012
3013 See the function modify-current-argument, described below, for
3014 an example of how to call this function.
3015
3016 modify-current-argument [ expr-using-$ARG | func ]
3017 This function provides a simple method of allowing user-defined
3018 widgets to modify the command line argument under the cursor (or
3019 immediately to the left of the cursor if the cursor is between
3020 arguments).
3021
3022 The argument can be an expression which when evaluated operates
3023 on the shell parameter ARG, which will have been set to the com‐
3024 mand line argument under the cursor. The expression should be
3025 suitably quoted to prevent it being evaluated too early.
3026
3027 Alternatively, if the argument does not contain the string ARG,
3028 it is assumed to be a shell function, to which the current com‐
3029 mand line argument is passed as the only argument. The function
3030 should set the variable REPLY to the new value for the command
3031 line argument. If the function returns non-zero status, so does
3032 the calling function.
3033
3034 For example, a user-defined widget containing the following code
3035 converts the characters in the argument under the cursor into
3036 all upper case:
3037
3038 modify-current-argument '${(U)ARG}'
3039
3040 The following strips any quoting from the current word (whether
3041 backslashes or one of the styles of quotes), and replaces it
3042 with single quoting throughout:
3043
3044 modify-current-argument '${(qq)${(Q)ARG}}'
3045
3046 The following performs directory expansion on the command line
3047 argument and replaces it by the absolute path:
3048
3049 expand-dir() {
3050 REPLY=${~1}
3051 REPLY=${REPLY:a}
3052 }
3053 modify-current-argument expand-dir
3054
3055 In practice the function expand-dir would probably not be de‐
3056 fined within the widget where modify-current-argument is called.
3057
3058 Styles
3059 The behavior of several of the above widgets can be controlled by the
3060 use of the zstyle mechanism. In particular, widgets that interact with
3061 the completion system pass along their context to any completions that
3062 they invoke.
3063
3064 break-keys
3065 This style is used by the incremental-complete-word widget. Its
3066 value should be a pattern, and all keys matching this pattern
3067 will cause the widget to stop incremental completion without the
3068 key having any further effect. Like all styles used directly by
3069 incremental-complete-word, this style is looked up using the
3070 context `:incremental'.
3071
3072 completer
3073 The incremental-complete-word and insert-and-predict widgets set
3074 up their top-level context name before calling completion. This
3075 allows one to define different sets of completer functions for
3076 normal completion and for these widgets. For example, to use
3077 completion, approximation and correction for normal completion,
3078 completion and correction for incremental completion and only
3079 completion for prediction one could use:
3080
3081 zstyle ':completion:*' completer \
3082 _complete _correct _approximate
3083 zstyle ':completion:incremental:*' completer \
3084 _complete _correct
3085 zstyle ':completion:predict:*' completer \
3086 _complete
3087
3088 It is a good idea to restrict the completers used in prediction,
3089 because they may be automatically invoked as you type. The
3090 _list and _menu completers should never be used with prediction.
3091 The _approximate, _correct, _expand, and _match completers may
3092 be used, but be aware that they may change characters anywhere
3093 in the word behind the cursor, so you need to watch carefully
3094 that the result is what you intended.
3095
3096 cursor The insert-and-predict widget uses this style, in the context
3097 `:predict', to decide where to place the cursor after completion
3098 has been tried. Values are:
3099
3100 complete
3101 The cursor is left where it was when completion finished,
3102 but only if it is after a character equal to the one just
3103 inserted by the user. If it is after another character,
3104 this value is the same as `key'.
3105
3106 key The cursor is left after the nth occurrence of the char‐
3107 acter just inserted, where n is the number of times that
3108 character appeared in the word before completion was at‐
3109 tempted. In short, this has the effect of leaving the
3110 cursor after the character just typed even if the comple‐
3111 tion code found out that no other characters need to be
3112 inserted at that position.
3113
3114 Any other value for this style unconditionally leaves the cursor
3115 at the position where the completion code left it.
3116
3117 list When using the incremental-complete-word widget, this style says
3118 if the matches should be listed on every key press (if they fit
3119 on the screen). Use the context prefix `:completion:incremen‐
3120 tal'.
3121
3122 The insert-and-predict widget uses this style to decide if the
3123 completion should be shown even if there is only one possible
3124 completion. This is done if the value of this style is the
3125 string always. In this case the context is `:predict' (not
3126 `:completion:predict').
3127
3128 match This style is used by smart-insert-last-word to provide a pat‐
3129 tern (using full EXTENDED_GLOB syntax) that matches an interest‐
3130 ing word. The context is the name of the widget to which
3131 smart-insert-last-word is bound (see above). The default behav‐
3132 ior of smart-insert-last-word is equivalent to:
3133
3134 zstyle :insert-last-word match '*[[:alpha:]/\\]*'
3135
3136 However, you might want to include words that contain spaces:
3137
3138 zstyle :insert-last-word match '*[[:alpha:][:space:]/\\]*'
3139
3140 Or include numbers as long as the word is at least two charac‐
3141 ters long:
3142
3143 zstyle :insert-last-word match '*([[:digit:]]?|[[:alpha:]/\\])*'
3144
3145 The above example causes redirections like "2>" to be included.
3146
3147 prompt The incremental-complete-word widget shows the value of this
3148 style in the status line during incremental completion. The
3149 string value may contain any of the following substrings in the
3150 manner of the PS1 and other prompt parameters:
3151
3152 %c Replaced by the name of the completer function that gen‐
3153 erated the matches (without the leading underscore).
3154
3155 %l When the list style is set, replaced by `...' if the list
3156 of matches is too long to fit on the screen and with an
3157 empty string otherwise. If the list style is `false' or
3158 not set, `%l' is always removed.
3159
3160 %n Replaced by the number of matches generated.
3161
3162 %s Replaced by `-no match-', `-no prefix-', or an empty
3163 string if there is no completion matching the word on the
3164 line, if the matches have no common prefix different from
3165 the word on the line, or if there is such a common pre‐
3166 fix, respectively.
3167
3168 %u Replaced by the unambiguous part of all matches, if there
3169 is any, and if it is different from the word on the line.
3170
3171 Like `break-keys', this uses the `:incremental' context.
3172
3173 stop-keys
3174 This style is used by the incremental-complete-word widget. Its
3175 value is treated similarly to the one for the break-keys style
3176 (and uses the same context: `:incremental'). However, in this
3177 case all keys matching the pattern given as its value will stop
3178 incremental completion and will then execute their usual func‐
3179 tion.
3180
3181 toggle This boolean style is used by predict-on and its related widgets
3182 in the context `:predict'. If set to one of the standard `true'
3183 values, predictive typing is automatically toggled off in situa‐
3184 tions where it is unlikely to be useful, such as when editing a
3185 multi-line buffer or after moving into the middle of a line and
3186 then deleting a character. The default is to leave prediction
3187 turned on until an explicit call to predict-off.
3188
3189 verbose
3190 This boolean style is used by predict-on and its related widgets
3191 in the context `:predict'. If set to one of the standard `true'
3192 values, these widgets display a message below the prompt when
3193 the predictive state is toggled. This is most useful in combi‐
3194 nation with the toggle style. The default does not display
3195 these messages.
3196
3197 widget This style is similar to the command style: For widget functions
3198 that use zle to call other widgets, this style can sometimes be
3199 used to override the widget which is called. The context for
3200 this style is the name of the calling widget (not the name of
3201 the calling function, because one function may be bound to mul‐
3202 tiple widget names).
3203
3204 zstyle :copy-earlier-word widget smart-insert-last-word
3205
3206 Check the documentation for the calling widget or function to
3207 determine whether the widget style is used.
3208
3210 Two functions are provided to enable zsh to provide exception handling
3211 in a form that should be familiar from other languages.
3212
3213 throw exception
3214 The function throw throws the named exception. The name is an
3215 arbitrary string and is only used by the throw and catch func‐
3216 tions. An exception is for the most part treated the same as a
3217 shell error, i.e. an unhandled exception will cause the shell to
3218 abort all processing in a function or script and to return to
3219 the top level in an interactive shell.
3220
3221 catch exception-pattern
3222 The function catch returns status zero if an exception was
3223 thrown and the pattern exception-pattern matches its name. Oth‐
3224 erwise it returns status 1. exception-pattern is a standard
3225 shell pattern, respecting the current setting of the EX‐
3226 TENDED_GLOB option. An alias catch is also defined to prevent
3227 the argument to the function from matching filenames, so pat‐
3228 terns may be used unquoted. Note that as exceptions are not
3229 fundamentally different from other shell errors it is possible
3230 to catch shell errors by using an empty string as the exception
3231 name. The shell variable CAUGHT is set by catch to the name of
3232 the exception caught. It is possible to rethrow an exception by
3233 calling the throw function again once an exception has been
3234 caught.
3235
3236 The functions are designed to be used together with the always con‐
3237 struct described in zshmisc(1). This is important as only this con‐
3238 struct provides the required support for exceptions. A typical example
3239 is as follows.
3240
3241 {
3242 # "try" block
3243 # ... nested code here calls "throw MyExcept"
3244 } always {
3245 # "always" block
3246 if catch MyExcept; then
3247 print "Caught exception MyExcept"
3248 elif catch ''; then
3249 print "Caught a shell error. Propagating..."
3250 throw ''
3251 fi
3252 # Other exceptions are not handled but may be caught further
3253 # up the call stack.
3254 }
3255
3256 If all exceptions should be caught, the following idiom might be
3257 preferable.
3258
3259 {
3260 # ... nested code here throws an exception
3261 } always {
3262 if catch *; then
3263 case $CAUGHT in
3264 (MyExcept)
3265 print "Caught my own exception"
3266 ;;
3267 (*)
3268 print "Caught some other exception"
3269 ;;
3270 esac
3271 fi
3272 }
3273
3274 In common with exception handling in other languages, the exception may
3275 be thrown by code deeply nested inside the `try' block. However, note
3276 that it must be thrown inside the current shell, not in a subshell
3277 forked for a pipeline, parenthesised current-shell construct, or some
3278 form of command or process substitution.
3279
3280 The system internally uses the shell variable EXCEPTION to record the
3281 name of the exception between throwing and catching. One drawback of
3282 this scheme is that if the exception is not handled the variable EXCEP‐
3283 TION remains set and may be incorrectly recognised as the name of an
3284 exception if a shell error subsequently occurs. Adding unset EXCEPTION
3285 at the start of the outermost layer of any code that uses exception
3286 handling will eliminate this problem.
3287
3289 Three functions are available to provide handling of files recognised
3290 by extension, for example to dispatch a file text.ps when executed as a
3291 command to an appropriate viewer.
3292
3293 zsh-mime-setup [ -fv ] [ -l [ suffix ... ] ]
3294 zsh-mime-handler [ -l ] command argument ...
3295 These two functions use the files ~/.mime.types and
3296 /etc/mime.types, which associate types and extensions, as well
3297 as ~/.mailcap and /etc/mailcap files, which associate types and
3298 the programs that handle them. These are provided on many sys‐
3299 tems with the Multimedia Internet Mail Extensions.
3300
3301 To enable the system, the function zsh-mime-setup should be au‐
3302 toloaded and run. This allows files with extensions to be
3303 treated as executable; such files be completed by the function
3304 completion system. The function zsh-mime-handler should not
3305 need to be called by the user.
3306
3307 The system works by setting up suffix aliases with `alias -s'.
3308 Suffix aliases already installed by the user will not be over‐
3309 written.
3310
3311 For suffixes defined in lower case, upper case variants will
3312 also automatically be handled (e.g. PDF is automatically handled
3313 if handling for the suffix pdf is defined), but not vice versa.
3314
3315 Repeated calls to zsh-mime-setup do not override the existing
3316 mapping between suffixes and executable files unless the option
3317 -f is given. Note, however, that this does not override exist‐
3318 ing suffix aliases assigned to handlers other than zsh-mime-han‐
3319 dler.
3320
3321 Calling zsh-mime-setup with the option -l lists the existing
3322 mappings without altering them. Suffixes to list (which may
3323 contain pattern characters that should be quoted from immediate
3324 interpretation on the command line) may be given as additional
3325 arguments, otherwise all suffixes are listed.
3326
3327 Calling zsh-mime-setup with the option -v causes verbose output
3328 to be shown during the setup operation.
3329
3330 The system respects the mailcap flags needsterminal and copi‐
3331 ousoutput, see mailcap(4).
3332
3333 The functions use the following styles, which are defined with
3334 the zstyle builtin command (see zshmodules(1)). They should be
3335 defined before zsh-mime-setup is run. The contexts used all
3336 start with :mime:, with additional components in some cases. It
3337 is recommended that a trailing * (suitably quoted) be appended
3338 to style patterns in case the system is extended in future.
3339 Some examples are given below.
3340
3341 For files that have multiple suffixes, e.g. .pdf.gz, where the
3342 context includes the suffix it will be looked up starting with
3343 the longest possible suffix until a match for the style is
3344 found. For example, if .pdf.gz produces a match for the han‐
3345 dler, that will be used; otherwise the handler for .gz will be
3346 used. Note that, owing to the way suffix aliases work, it is
3347 always required that there be a handler for the shortest possi‐
3348 ble suffix, so in this example .pdf.gz can only be handled if
3349 .gz is also handled (though not necessarily in the same way).
3350 Alternatively, if no handling for .gz on its own is needed, sim‐
3351 ply adding the command
3352
3353 alias -s gz=zsh-mime-handler
3354
3355 to the initialisation code is sufficient; .gz will not be han‐
3356 dled on its own, but may be in combination with other suffixes.
3357
3358 current-shell
3359 If this boolean style is true, the mailcap handler for
3360 the context in question is run using the eval builtin in‐
3361 stead of by starting a new sh process. This is more ef‐
3362 ficient, but may not work in the occasional cases where
3363 the mailcap handler uses strict POSIX syntax.
3364
3365 disown If this boolean style is true, mailcap handlers started
3366 in the background will be disowned, i.e. not subject to
3367 job control within the parent shell. Such handlers
3368 nearly always produce their own windows, so the only
3369 likely harmful side effect of setting the style is that
3370 it becomes harder to kill jobs from within the shell.
3371
3372 execute-as-is
3373 This style gives a list of patterns to be matched against
3374 files passed for execution with a handler program. If
3375 the file matches the pattern, the entire command line is
3376 executed in its current form, with no handler. This is
3377 useful for files which might have suffixes but nonethe‐
3378 less be executable in their own right. If the style is
3379 not set, the pattern *(*) *(/) is used; hence executable
3380 files are executed directly and not passed to a handler,
3381 and the option AUTO_CD may be used to change to directo‐
3382 ries that happen to have MIME suffixes.
3383
3384 execute-never
3385 This style is useful in combination with execute-as-is.
3386 It is set to an array of patterns corresponding to full
3387 paths to files that should never be treated as exe‐
3388 cutable, even if the file passed to the MIME handler
3389 matches execute-as-is. This is useful for file systems
3390 that don't handle execute permission or that contain exe‐
3391 cutables from another operating system. For example, if
3392 /mnt/windows is a Windows mount, then
3393
3394 zstyle ':mime:*' execute-never '/mnt/windows/*'
3395
3396 will ensure that any files found in that area will be ex‐
3397 ecuted as MIME types even if they are executable. As
3398 this example shows, the complete file name is matched
3399 against the pattern, regardless of how the file was
3400 passed to the handler. The file is resolved to a full
3401 path using the :P modifier described in the subsection
3402 Modifiers in zshexpn(1); this means that symbolic links
3403 are resolved where possible, so that links into other
3404 file systems behave in the correct fashion.
3405
3406 file-path
3407 Used if the style find-file-in-path is true for the same
3408 context. Set to an array of directories that are used
3409 for searching for the file to be handled; the default is
3410 the command path given by the special parameter path.
3411 The shell option PATH_DIRS is respected; if that is set,
3412 the appropriate path will be searched even if the name of
3413 the file to be handled as it appears on the command line
3414 contains a `/'. The full context is :mime:.suffix:, as
3415 described for the style handler.
3416
3417 find-file-in-path
3418 If set, allows files whose names do not contain absolute
3419 paths to be searched for in the command path or the path
3420 specified by the file-path style. If the file is not
3421 found in the path, it is looked for locally (whether or
3422 not the current directory is in the path); if it is not
3423 found locally, the handler will abort unless the han‐
3424 dle-nonexistent style is set. Files found in the path
3425 are tested as described for the style execute-as-is. The
3426 full context is :mime:.suffix:, as described for the
3427 style handler.
3428
3429 flags Defines flags to go with a handler; the context is as for
3430 the handler style, and the format is as for the flags in
3431 mailcap.
3432
3433 handle-nonexistent
3434 By default, arguments that don't correspond to files are
3435 not passed to the MIME handler in order to prevent it
3436 from intercepting commands found in the path that happen
3437 to have suffixes. This style may be set to an array of
3438 extended glob patterns for arguments that will be passed
3439 to the handler even if they don't exist. If it is not
3440 explicitly set it defaults to [[:alpha:]]#:/* which al‐
3441 lows URLs to be passed to the MIME handler even though
3442 they don't exist in that format in the file system. The
3443 full context is :mime:.suffix:, as described for the
3444 style handler.
3445
3446 handler
3447 Specifies a handler for a suffix; the suffix is given by
3448 the context as :mime:.suffix:, and the format of the han‐
3449 dler is exactly that in mailcap. Note in particular the
3450 `.' and trailing colon to distinguish this use of the
3451 context. This overrides any handler specified by the
3452 mailcap files. If the handler requires a terminal, the
3453 flags style should be set to include the word needstermi‐
3454 nal, or if the output is to be displayed through a pager
3455 (but not if the handler is itself a pager), it should in‐
3456 clude copiousoutput.
3457
3458 mailcap
3459 A list of files in the format of ~/.mailcap and
3460 /etc/mailcap to be read during setup, replacing the de‐
3461 fault list which consists of those two files. The con‐
3462 text is :mime:. A + in the list will be replaced by the
3463 default files.
3464
3465 mailcap-priorities
3466 This style is used to resolve multiple mailcap entries
3467 for the same MIME type. It consists of an array of the
3468 following elements, in descending order of priority;
3469 later entries will be used if earlier entries are unable
3470 to resolve the entries being compared. If none of the
3471 tests resolve the entries, the first entry encountered is
3472 retained.
3473
3474 files The order of files (entries in the mailcap style)
3475 read. Earlier files are preferred. (Note this
3476 does not resolve entries in the same file.)
3477
3478 priority
3479 The priority flag from the mailcap entry. The
3480 priority is an integer from 0 to 9 with the de‐
3481 fault value being 5.
3482
3483 flags The test given by the mailcap-prio-flags option is
3484 used to resolve entries.
3485
3486 place Later entries are preferred; as the entries are
3487 strictly ordered, this test always succeeds.
3488
3489 Note that as this style is handled during initialisation,
3490 the context is always :mime:, with no discrimination by
3491 suffix.
3492
3493 mailcap-prio-flags
3494 This style is used when the keyword flags is encountered
3495 in the list of tests specified by the mailcap-priorities
3496 style. It should be set to a list of patterns, each of
3497 which is tested against the flags specified in the mail‐
3498 cap entry (in other words, the sets of assignments found
3499 with some entries in the mailcap file). Earlier patterns
3500 in the list are preferred to later ones, and matched pat‐
3501 terns are preferred to unmatched ones.
3502
3503 mime-types
3504 A list of files in the format of ~/.mime.types and
3505 /etc/mime.types to be read during setup, replacing the
3506 default list which consists of those two files. The con‐
3507 text is :mime:. A + in the list will be replaced by the
3508 default files.
3509
3510 never-background
3511 If this boolean style is set, the handler for the given
3512 context is always run in the foreground, even if the
3513 flags provided in the mailcap entry suggest it need not
3514 be (for example, it doesn't require a terminal).
3515
3516 pager If set, will be used instead of $PAGER or more to handle
3517 suffixes where the copiousoutput flag is set. The con‐
3518 text is as for handler, i.e. :mime:.suffix: for handling
3519 a file with the given suffix.
3520
3521 Examples:
3522
3523 zstyle ':mime:*' mailcap ~/.mailcap /usr/local/etc/mailcap
3524 zstyle ':mime:.txt:' handler less %s
3525 zstyle ':mime:.txt:' flags needsterminal
3526
3527 When zsh-mime-setup is subsequently run, it will look for mail‐
3528 cap entries in the two files given. Files of suffix .txt will
3529 be handled by running `less file.txt'. The flag needsterminal
3530 is set to show that this program must run attached to a termi‐
3531 nal.
3532
3533 As there are several steps to dispatching a command, the follow‐
3534 ing should be checked if attempting to execute a file by exten‐
3535 sion .ext does not have the expected effect.
3536
3537 The command `alias -s ext' should show `ps=zsh-mime-handler'.
3538 If it shows something else, another suffix alias was already in‐
3539 stalled and was not overwritten. If it shows nothing, no han‐
3540 dler was installed: this is most likely because no handler was
3541 found in the .mime.types and mailcap combination for .ext files.
3542 In that case, appropriate handling should be added to
3543 ~/.mime.types and mailcap.
3544
3545 If the extension is handled by zsh-mime-handler but the file is
3546 not opened correctly, either the handler defined for the type is
3547 incorrect, or the flags associated with it are in appropriate.
3548 Running zsh-mime-setup -l will show the handler and, if there
3549 are any, the flags. A %s in the handler is replaced by the file
3550 (suitably quoted if necessary). Check that the handler program
3551 listed lists and can be run in the way shown. Also check that
3552 the flags needsterminal or copiousoutput are set if the handler
3553 needs to be run under a terminal; the second flag is used if the
3554 output should be sent to a pager. An example of a suitable
3555 mailcap entry for such a program is:
3556
3557 text/html; /usr/bin/lynx '%s'; needsterminal
3558
3559 Running `zsh-mime-handler -l command line' prints the command
3560 line that would be executed, simplified to remove the effect of
3561 any flags, and quoted so that the output can be run as a com‐
3562 plete zsh command line. This is used by the completion system
3563 to decide how to complete after a file handled by
3564 zsh-mime-setup.
3565
3566 pick-web-browser
3567 This function is separate from the two MIME functions described
3568 above and can be assigned directly to a suffix:
3569
3570 autoload -U pick-web-browser
3571 alias -s html=pick-web-browser
3572
3573 It is provided as an intelligent front end to dispatch a web
3574 browser. It may be run as either a function or a shell script.
3575 The status 255 is returned if no browser could be started.
3576
3577 Various styles are available to customize the choice of
3578 browsers:
3579
3580 browser-style
3581 The value of the style is an array giving preferences in
3582 decreasing order for the type of browser to use. The
3583 values of elements may be
3584
3585 running
3586 Use a GUI browser that is already running when an
3587 X Window display is available. The browsers
3588 listed in the x-browsers style are tried in order
3589 until one is found; if it is, the file will be
3590 displayed in that browser, so the user may need to
3591 check whether it has appeared. If no running
3592 browser is found, one is not started. Browsers
3593 other than Firefox, Opera and Konqueror are as‐
3594 sumed to understand the Mozilla syntax for opening
3595 a URL remotely.
3596
3597 x Start a new GUI browser when an X Window display
3598 is available. Search for the availability of one
3599 of the browsers listed in the x-browsers style and
3600 start the first one that is found. No check is
3601 made for an already running browser.
3602
3603 tty Start a terminal-based browser. Search for the
3604 availability of one of the browsers listed in the
3605 tty-browsers style and start the first one that is
3606 found.
3607
3608 If the style is not set the default running x tty is
3609 used.
3610
3611 x-browsers
3612 An array in decreasing order of preference of browsers to
3613 use when running under the X Window System. The array
3614 consists of the command name under which to start the
3615 browser. They are looked up in the context :mime: (which
3616 may be extended in future, so appending `*' is recom‐
3617 mended). For example,
3618
3619 zstyle ':mime:*' x-browsers opera konqueror firefox
3620
3621 specifies that pick-web-browser should first look for a
3622 running instance of Opera, Konqueror or Firefox, in that
3623 order, and if it fails to find any should attempt to
3624 start Opera. The default is firefox mozilla netscape
3625 opera konqueror.
3626
3627 tty-browsers
3628 An array similar to x-browsers, except that it gives
3629 browsers to use when no X Window display is available.
3630 The default is elinks links lynx.
3631
3632 command
3633 If it is set this style is used to pick the command used
3634 to open a page for a browser. The context is
3635 :mime:browser:new:$browser: to start a new browser or
3636 :mime:browser:running:$browser: to open a URL in a
3637 browser already running on the current X display, where
3638 $browser is the value matched in the x-browsers or
3639 tty-browsers style. The escape sequence %b in the
3640 style's value will be replaced by the browser, while %u
3641 will be replaced by the URL. If the style is not set,
3642 the default for all new instances is equivalent to %b %u
3643 and the defaults for using running browsers are equiva‐
3644 lent to the values kfmclient openURL %u for Konqueror,
3645 firefox -new-tab %u for Firefox, opera -newpage %u for
3646 Opera, and %b -remote "openUrl(%u)" for all others.
3647
3649 zcalc [ -erf ] [ expression ... ]
3650 A reasonably powerful calculator based on zsh's arithmetic eval‐
3651 uation facility. The syntax is similar to that of formulae in
3652 most programming languages; see the section `Arithmetic Evalua‐
3653 tion' in zshmisc(1) for details.
3654
3655 Non-programmers should note that, as in many other programming
3656 languages, expressions involving only integers (whether con‐
3657 stants without a `.', variables containing such constants as
3658 strings, or variables declared to be integers) are by default
3659 evaluated using integer arithmetic, which is not how an ordinary
3660 desk calculator operates. To force floating point operation,
3661 pass the option -f; see further notes below.
3662
3663 If the file ~/.zcalcrc exists it will be sourced inside the
3664 function once it is set up and about to process the command
3665 line. This can be used, for example, to set shell options; emu‐
3666 late -L zsh and setopt extendedglob are in effect at this point.
3667 Any failure to source the file if it exists is treated as fatal.
3668 As with other initialisation files, the directory $ZDOTDIR is
3669 used instead of $HOME if it is set.
3670
3671 The mathematical library zsh/mathfunc will be loaded if it is
3672 available; see the section `The zsh/mathfunc Module' in zshmod‐
3673 ules(1). The mathematical functions correspond to the raw sys‐
3674 tem libraries, so trigonometric functions are evaluated using
3675 radians, and so on.
3676
3677 Each line typed is evaluated as an expression. The prompt shows
3678 a number, which corresponds to a positional parameter where the
3679 result of that calculation is stored. For example, the result
3680 of the calculation on the line preceded by `4> ' is available as
3681 $4. The last value calculated is available as ans. Full com‐
3682 mand line editing, including the history of previous calcula‐
3683 tions, is available; the history is saved in the file
3684 ~/.zcalc_history. To exit, enter a blank line or type `:q' on
3685 its own (`q' is allowed for historical compatibility).
3686
3687 A line ending with a single backslash is treated in the same
3688 fashion as it is in command line editing: the backslash is re‐
3689 moved, the function prompts for more input (the prompt is pre‐
3690 ceded by `...' to indicate this), and the lines are combined
3691 into one to get the final result. In addition, if the input so
3692 far contains more open than close parentheses zcalc will prompt
3693 for more input.
3694
3695 If arguments are given to zcalc on start up, they are used to
3696 prime the first few positional parameters. A visual indication
3697 of this is given when the calculator starts.
3698
3699 The constants PI (3.14159...) and E (2.71828...) are provided.
3700 Parameter assignment is possible, but note that all parameters
3701 will be put into the global namespace unless the :local special
3702 command is used. The function creates local variables whose
3703 names start with _, so users should avoid doing so. The vari‐
3704 ables ans (the last answer) and stack (the stack in RPN mode)
3705 may be referred to directly; stack is an array but elements of
3706 it are numeric. Various other special variables are used lo‐
3707 cally with their standard meaning, for example compcontext,
3708 match, mbegin, mend, psvar.
3709
3710 The output base can be initialised by passing the option
3711 `-#base', for example `zcalc -#16' (the `#' may have to be
3712 quoted, depending on the globbing options set).
3713
3714 If the option `-e' is set, the function runs non-interactively:
3715 the arguments are treated as expressions to be evaluated as if
3716 entered interactively line by line.
3717
3718 If the option `-f' is set, all numbers are treated as floating
3719 point, hence for example the expression `3/4' evaluates to 0.75
3720 rather than 0. Options must appear in separate words.
3721
3722 If the option `-r' is set, RPN (Reverse Polish Notation) mode is
3723 entered. This has various additional properties:
3724 Stack Evaluated values are maintained in a stack; this is con‐
3725 tained in an array named stack with the most recent value
3726 in ${stack[1]}.
3727
3728 Operators and functions
3729 If the line entered matches an operator (+, -, *, /, **,
3730 ^, | or &) or a function supplied by the zsh/mathfunc li‐
3731 brary, the bottom element or elements of the stack are
3732 popped to use as the argument or arguments. The higher
3733 elements of stack (least recent) are used as earlier ar‐
3734 guments. The result is then pushed into ${stack[1]}.
3735
3736 Expressions
3737 Other expressions are evaluated normally, printed, and
3738 added to the stack as numeric values. The syntax within
3739 expressions on a single line is normal shell arithmetic
3740 (not RPN).
3741
3742 Stack listing
3743 If an integer follows the option -r with no space, then
3744 on every evaluation that many elements of the stack,
3745 where available, are printed instead of just the most re‐
3746 cent result. Hence, for example, zcalc -r4 shows
3747 $stack[4] to $stack[1] each time results are printed.
3748
3749 Duplication: =
3750 The pseudo-operator = causes the most recent element of
3751 the stack to be duplicated onto the stack.
3752
3753 pop The pseudo-function pop causes the most recent element of
3754 the stack to be popped. A `>' on its own has the same
3755 effect.
3756
3757 >ident The expression > followed (with no space) by a shell
3758 identifier causes the most recent element of the stack to
3759 be popped and assigned to the variable with that name.
3760 The variable is local to the zcalc function.
3761
3762 <ident The expression < followed (with no space) by a shell
3763 identifier causes the value of the variable with that
3764 name to be pushed onto the stack. ident may be an inte‐
3765 ger, in which case the previous result with that number
3766 (as shown before the > in the standard zcalc prompt) is
3767 put on the stack.
3768
3769 Exchange: xy
3770 The pseudo-function xy causes the most recent two ele‐
3771 ments of the stack to be exchanged. `<>' has the same
3772 effect.
3773
3774 The prompt is configurable via the parameter ZCALCPROMPT, which
3775 undergoes standard prompt expansion. The index of the current
3776 entry is stored locally in the first element of the array psvar,
3777 which can be referred to in ZCALCPROMPT as `%1v'. The default
3778 prompt is `%1v> '.
3779
3780 The variable ZCALC_ACTIVE is set within the function and can be
3781 tested by nested functions; it has the value rpn if RPN mode is
3782 active, else 1.
3783
3784 A few special commands are available; these are introduced by a
3785 colon. For backward compatibility, the colon may be omitted for
3786 certain commands. Completion is available if compinit has been
3787 run.
3788
3789 The output precision may be specified within zcalc by special
3790 commands familiar from many calculators.
3791 :norm The default output format. It corresponds to the printf
3792 %g specification. Typically this shows six decimal dig‐
3793 its.
3794
3795 :sci digits
3796 Scientific notation, corresponding to the printf %g out‐
3797 put format with the precision given by digits. This pro‐
3798 duces either fixed point or exponential notation depend‐
3799 ing on the value output.
3800
3801 :fix digits
3802 Fixed point notation, corresponding to the printf %f out‐
3803 put format with the precision given by digits.
3804
3805 :eng digits
3806 Exponential notation, corresponding to the printf %E out‐
3807 put format with the precision given by digits.
3808
3809 :raw Raw output: this is the default form of the output from
3810 a math evaluation. This may show more precision than the
3811 number actually possesses.
3812
3813 Other special commands:
3814 :!line...
3815 Execute line... as a normal shell command line. Note
3816 that it is executed in the context of the function, i.e.
3817 with local variables. Space is optional after :!.
3818
3819 :local arg ...
3820 Declare variables local to the function. Other variables
3821 may be used, too, but they will be taken from or put into
3822 the global scope.
3823
3824 :function name [ body ]
3825 Define a mathematical function or (with no body) delete
3826 it. :function may be abbreviated to :func or simply :f.
3827 The name may contain the same characters as a shell func‐
3828 tion name. The function is defined using zmathfuncdef,
3829 see below.
3830
3831 Note that zcalc takes care of all quoting. Hence for ex‐
3832 ample:
3833
3834 :f cube $1 * $1 * $1
3835
3836 defines a function to cube the sole argument. Functions
3837 so defined, or indeed any functions defined directly or
3838 indirectly using functions -M, are available to execute
3839 by typing only the name on the line in RPN mode; this
3840 pops the appropriate number of arguments off the stack to
3841 pass to the function, i.e. 1 in the case of the example
3842 cube function. If there are optional arguments only the
3843 mandatory arguments are supplied by this means.
3844
3845 [#base]
3846 This is not a special command, rather part of normal
3847 arithmetic syntax; however, when this form appears on a
3848 line by itself the default output radix is set to base.
3849 Use, for example, `[#16]' to display hexadecimal output
3850 preceded by an indication of the base, or `[##16]' just
3851 to display the raw number in the given base. Bases them‐
3852 selves are always specified in decimal. `[#]' restores
3853 the normal output format. Note that setting an output
3854 base suppresses floating point output; use `[#]' to re‐
3855 turn to normal operation.
3856
3857 $var Print out the value of var literally; does not affect the
3858 calculation. To use the value of var, omit the leading
3859 `$'.
3860
3861 See the comments in the function for a few extra tips.
3862
3863 min(arg, ...)
3864 max(arg, ...)
3865 sum(arg, ...)
3866 zmathfunc
3867 The function zmathfunc defines the three mathematical functions
3868 min, max, and sum. The functions min and max take one or more
3869 arguments. The function sum takes zero or more arguments. Ar‐
3870 guments can be of different types (ints and floats).
3871
3872 Not to be confused with the zsh/mathfunc module, described in
3873 the section `The zsh/mathfunc Module' in zshmodules(1).
3874
3875 zmathfuncdef [ mathfunc [ body ] ]
3876 A convenient front end to functions -M.
3877
3878 With two arguments, define a mathematical function named math‐
3879 func which can be used in any form of arithmetic evaluation.
3880 body is a mathematical expression to implement the function. It
3881 may contain references to position parameters $1, $2, ... to
3882 refer to mandatory parameters and ${1:-defvalue} ... to refer
3883 to optional parameters. Note that the forms must be strictly
3884 adhered to for the function to calculate the correct number of
3885 arguments. The implementation is held in a shell function named
3886 zsh_math_func_mathfunc; usually the user will not need to refer
3887 to the shell function directly. Any existing function of the
3888 same name is silently replaced.
3889
3890 With one argument, remove the mathematical function mathfunc as
3891 well as the shell function implementation.
3892
3893 With no arguments, list all mathfunc functions in a form suit‐
3894 able for restoring the definition. The functions have not nec‐
3895 essarily been defined by zmathfuncdef.
3896
3898 The zsh/newuser module comes with a function to aid in configuring
3899 shell options for new users. If the module is installed, this function
3900 can also be run by hand. It is available even if the module's default
3901 behaviour, namely running the function for a new user logging in with‐
3902 out startup files, is inhibited.
3903
3904 zsh-newuser-install [ -f ]
3905 The function presents the user with various options for cus‐
3906 tomizing their initialization scripts. Currently only ~/.zshrc
3907 is handled. $ZDOTDIR/.zshrc is used instead if the parameter
3908 ZDOTDIR is set; this provides a way for the user to configure a
3909 file without altering an existing .zshrc.
3910
3911 By default the function exits immediately if it finds any of the
3912 files .zshenv, .zprofile, .zshrc, or .zlogin in the appropriate
3913 directory. The option -f is required in order to force the
3914 function to continue. Note this may happen even if .zshrc it‐
3915 self does not exist.
3916
3917 As currently configured, the function will exit immediately if
3918 the user has root privileges; this behaviour cannot be overrid‐
3919 den.
3920
3921 Once activated, the function's behaviour is supposed to be
3922 self-explanatory. Menus are present allowing the user to alter
3923 the value of options and parameters. Suggestions for improve‐
3924 ments are always welcome.
3925
3926 When the script exits, the user is given the opportunity to save
3927 the new file or not; changes are not irreversible until this
3928 point. However, the script is careful to restrict changes to
3929 the file only to a group marked by the lines `# Lines configured
3930 by zsh-newuser-install' and `# End of lines configured by
3931 zsh-newuser-install'. In addition, the old version of .zshrc is
3932 saved to a file with the suffix .zni appended.
3933
3934 If the function edits an existing .zshrc, it is up to the user
3935 to ensure that the changes made will take effect. For example,
3936 if control usually returns early from the existing .zshrc the
3937 lines will not be executed; or a later initialization file may
3938 override options or parameters, and so on. The function itself
3939 does not attempt to detect any such conflicts.
3940
3942 There are a large number of helpful functions in the Functions/Misc di‐
3943 rectory of the zsh distribution. Most are very simple and do not re‐
3944 quire documentation here, but a few are worthy of special mention.
3945
3946 Descriptions
3947 colors This function initializes several associative arrays to map
3948 color names to (and from) the ANSI standard eight-color terminal
3949 codes. These are used by the prompt theme system (see above).
3950 You seldom should need to run colors more than once.
3951
3952 The eight base colors are: black, red, green, yellow, blue, ma‐
3953 genta, cyan, and white. Each of these has codes for foreground
3954 and background. In addition there are seven intensity at‐
3955 tributes: bold, faint, standout, underline, blink, reverse, and
3956 conceal. Finally, there are seven codes used to negate at‐
3957 tributes: none (reset all attributes to the defaults), normal
3958 (neither bold nor faint), no-standout, no-underline, no-blink,
3959 no-reverse, and no-conceal.
3960
3961 Some terminals do not support all combinations of colors and in‐
3962 tensities.
3963
3964 The associative arrays are:
3965
3966 color
3967 colour Map all the color names to their integer codes, and inte‐
3968 ger codes to the color names. The eight base names map
3969 to the foreground color codes, as do names prefixed with
3970 `fg-', such as `fg-red'. Names prefixed with `bg-', such
3971 as `bg-blue', refer to the background codes. The reverse
3972 mapping from code to color yields base name for fore‐
3973 ground codes and the bg- form for backgrounds.
3974
3975 Although it is a misnomer to call them `colors', these
3976 arrays also map the other fourteen attributes from names
3977 to codes and codes to names.
3978
3979 fg
3980 fg_bold
3981 fg_no_bold
3982 Map the eight basic color names to ANSI terminal escape
3983 sequences that set the corresponding foreground text
3984 properties. The fg sequences change the color without
3985 changing the eight intensity attributes.
3986
3987 bg
3988 bg_bold
3989 bg_no_bold
3990 Map the eight basic color names to ANSI terminal escape
3991 sequences that set the corresponding background proper‐
3992 ties. The bg sequences change the color without changing
3993 the eight intensity attributes.
3994
3995 In addition, the scalar parameters reset_color and bold_color
3996 are set to the ANSI terminal escapes that turn off all at‐
3997 tributes and turn on bold intensity, respectively.
3998
3999 fned [ -x num ] name
4000 Same as zed -f. This function does not appear in the zsh dis‐
4001 tribution, but can be created by linking zed to the name fned in
4002 some directory in your fpath.
4003
4004 is-at-least needed [ present ]
4005 Perform a greater-than-or-equal-to comparison of two strings
4006 having the format of a zsh version number; that is, a string of
4007 numbers and text with segments separated by dots or dashes. If
4008 the present string is not provided, $ZSH_VERSION is used. Seg‐
4009 ments are paired left-to-right in the two strings with leading
4010 non-number parts ignored. If one string has fewer segments than
4011 the other, the missing segments are considered zero.
4012
4013 This is useful in startup files to set options and other state
4014 that are not available in all versions of zsh.
4015
4016 is-at-least 3.1.6-15 && setopt NO_GLOBAL_RCS
4017 is-at-least 3.1.0 && setopt HIST_REDUCE_BLANKS
4018 is-at-least 2.6-17 || print "You can't use is-at-least here."
4019
4020 nslookup [ arg ... ]
4021 This wrapper function for the nslookup command requires the
4022 zsh/zpty module (see zshmodules(1)). It behaves exactly like
4023 the standard nslookup except that it provides customizable
4024 prompts (including a right-side prompt) and completion of
4025 nslookup commands, host names, etc. (if you use the func‐
4026 tion-based completion system). Completion styles may be set
4027 with the context prefix `:completion:nslookup'.
4028
4029 See also the pager, prompt and rprompt styles below.
4030
4031 regexp-replace var regexp replace
4032 Use regular expressions to perform a global search and replace
4033 operation on a variable. POSIX extended regular expressions are
4034 used, unless the option RE_MATCH_PCRE has been set, in which
4035 case Perl-compatible regular expressions are used (this requires
4036 the shell to be linked against the pcre library).
4037
4038 var is the name of the variable containing the string to be
4039 matched. The variable will be modified directly by the func‐
4040 tion. The variables MATCH, MBEGIN, MEND, match, mbegin, mend
4041 should be avoided as these are used by the regular expression
4042 code.
4043
4044 regexp is the regular expression to match against the string.
4045
4046 replace is the replacement text. This can contain parameter,
4047 command and arithmetic expressions which will be replaced: in
4048 particular, a reference to $MATCH will be replaced by the text
4049 matched by the pattern.
4050
4051 The return status is 0 if at least one match was performed, else
4052 1.
4053
4054 run-help cmd
4055 This function is designed to be invoked by the run-help ZLE wid‐
4056 get, in place of the default alias. See `Accessing On-Line
4057 Help' above for setup instructions.
4058
4059 In the discussion which follows, if cmd is a file system path,
4060 it is first reduced to its rightmost component (the file name).
4061
4062 Help is first sought by looking for a file named cmd in the di‐
4063 rectory named by the HELPDIR parameter. If no file is found, an
4064 assistant function, alias, or command named run-help-cmd is
4065 sought. If found, the assistant is executed with the rest of
4066 the current command line (everything after the command name cmd)
4067 as its arguments. When neither file nor assistant is found, the
4068 external command `man cmd' is run.
4069
4070 An example assistant for the "ssh" command:
4071
4072 run-help-ssh() {
4073 emulate -LR zsh
4074 local -a args
4075 # Delete the "-l username" option
4076 zparseopts -D -E -a args l:
4077 # Delete other options, leaving: host command
4078 args=(${@:#-*})
4079 if [[ ${#args} -lt 2 ]]; then
4080 man ssh
4081 else
4082 run-help $args[2]
4083 fi
4084 }
4085
4086 Several of these assistants are provided in the Functions/Misc
4087 directory. These must be autoloaded, or placed as executable
4088 scripts in your search path, in order to be found and used by
4089 run-help.
4090
4091 run-help-git
4092 run-help-ip
4093 run-help-openssl
4094 run-help-p4
4095 run-help-sudo
4096 run-help-svk
4097 run-help-svn
4098 Assistant functions for the git, ip, openssl, p4, sudo,
4099 svk, and svn, commands.
4100
4101 tetris Zsh was once accused of not being as complete as Emacs, because
4102 it lacked a Tetris game. This function was written to refute
4103 this vicious slander.
4104
4105 This function must be used as a ZLE widget:
4106
4107 autoload -U tetris
4108 zle -N tetris
4109 bindkey keys tetris
4110
4111 To start a game, execute the widget by typing the keys. What‐
4112 ever command line you were editing disappears temporarily, and
4113 your keymap is also temporarily replaced by the Tetris control
4114 keys. The previous editor state is restored when you quit the
4115 game (by pressing `q') or when you lose.
4116
4117 If you quit in the middle of a game, the next invocation of the
4118 tetris widget will continue where you left off. If you lost, it
4119 will start a new game.
4120
4121 tetriscurses
4122 This is a port of the above to zcurses. The input handling is
4123 improved a bit so that moving a block sideways doesn't automati‐
4124 cally advance a timestep, and the graphics use unicode block
4125 graphics.
4126
4127 This version does not save the game state between invocations,
4128 and is not invoked as a widget, but rather as:
4129
4130 autoload -U tetriscurses
4131 tetriscurses
4132
4133 zargs [ option ... -- ] [ input ... ] [ -- command [ arg ... ] ]
4134 This function has a similar purpose to GNU xargs. Instead of
4135 reading lines of arguments from the standard input, it takes
4136 them from the command line. This is useful because zsh, espe‐
4137 cially with recursive glob operators, often can construct a com‐
4138 mand line for a shell function that is longer than can be ac‐
4139 cepted by an external command.
4140
4141 The option list represents options of the zargs command itself,
4142 which are the same as those of xargs. The input list is the
4143 collection of strings (often file names) that become the argu‐
4144 ments of the command, analogous to the standard input of xargs.
4145 Finally, the arg list consists of those arguments (usually op‐
4146 tions) that are passed to the command each time it runs. The
4147 arg list precedes the elements from the input list in each run.
4148 If no command is provided, then no arg list may be provided, and
4149 in that event the default command is `print' with arguments `-r
4150 --'.
4151
4152 For example, to get a long ls listing of all non-hidden plain
4153 files in the current directory or its subdirectories:
4154
4155 autoload -U zargs
4156 zargs -- **/*(.) -- ls -ld --
4157
4158 The first and third occurrences of `--' are used to mark the end
4159 of options for zargs and ls respectively to guard against file‐
4160 names starting with `-', while the second is used to separate
4161 the list of files from the command to run (`ls -ld --').
4162
4163 The first `--' would also be needed if there was a chance the
4164 list might be empty as in:
4165
4166 zargs -r -- ./*.back(#qN) -- rm -f
4167
4168 In the event that the string `--' is or may be an input, the -e
4169 option may be used to change the end-of-inputs marker. Note
4170 that this does not change the end-of-options marker. For exam‐
4171 ple, to use `..' as the marker:
4172
4173 zargs -e.. -- **/*(.) .. ls -ld --
4174
4175 This is a good choice in that example because no plain file can
4176 be named `..', but the best end-marker depends on the circum‐
4177 stances.
4178
4179 The options -i, -I, -l, -L, and -n differ slightly from their
4180 usage in xargs. There are no input lines for zargs to count, so
4181 -l and -L count through the input list, and -n counts the number
4182 of arguments passed to each execution of command, including any
4183 arg list. Also, any time -i or -I is used, each input is pro‐
4184 cessed separately as if by `-L 1'.
4185
4186 For details of the other zargs options, see xargs(1) (but note
4187 the difference in function between zargs and xargs) or run zargs
4188 with the --help option.
4189
4190 zed [ -f [ -x num ] ] name
4191 zed -b This function uses the ZLE editor to edit a file or function.
4192
4193 Only one name argument is allowed. If the -f option is given,
4194 the name is taken to be that of a function; if the function is
4195 marked for autoloading, zed searches for it in the fpath and
4196 loads it. Note that functions edited this way are installed
4197 into the current shell, but not written back to the autoload
4198 file. In this case the -x option specifies that leading tabs
4199 indenting the function according to syntax should be converted
4200 into the given number of spaces; `-x 2' is consistent with the
4201 layout of functions distributed with the shell.
4202
4203 Without -f, name is the path name of the file to edit, which
4204 need not exist; it is created on write, if necessary.
4205
4206 While editing, the function sets the main keymap to zed and the
4207 vi command keymap to zed-vicmd. These will be copied from the
4208 existing main and vicmd keymaps if they do not exist the first
4209 time zed is run. They can be used to provide special key bind‐
4210 ings used only in zed.
4211
4212 If it creates the keymap, zed rebinds the return key to insert a
4213 line break and `^X^W' to accept the edit in the zed keymap, and
4214 binds `ZZ' to accept the edit in the zed-vicmd keymap.
4215
4216 The bindings alone can be installed by running `zed -b'. This
4217 is suitable for putting into a startup file. Note that, if re‐
4218 run, this will overwrite the existing zed and zed-vicmd keymaps.
4219
4220 Completion is available, and styles may be set with the context
4221 prefix `:completion:zed'.
4222
4223 A zle widget zed-set-file-name is available. This can be called
4224 by name from within zed using `\ex zed-set-file-name' (note,
4225 however, that because of zed's rebindings you will have to type
4226 ^j at the end instead of the return key), or can be bound to a
4227 key in either of the zed or zed-vicmd keymaps after `zed -b' has
4228 been run. When the widget is called, it prompts for a new name
4229 for the file being edited. When zed exits the file will be
4230 written under that name and the original file will be left
4231 alone. The widget has no effect with `zed -f'.
4232
4233 While zed-set-file-name is running, zed uses the keymap zed-nor‐
4234 mal-keymap, which is linked from the main keymap in effect at
4235 the time zed initialised its bindings. (This is to make the re‐
4236 turn key operate normally.) The result is that if the main
4237 keymap has been changed, the widget won't notice. This is not a
4238 concern for most users.
4239
4240 zcp [ -finqQvwW ] srcpat dest
4241 zln [ -finqQsvwW ] srcpat dest
4242 Same as zmv -C and zmv -L, respectively. These functions do not
4243 appear in the zsh distribution, but can be created by linking
4244 zmv to the names zcp and zln in some directory in your fpath.
4245
4246 zkbd See `Keyboard Definition' above.
4247
4248
4249 zmv [ -finqQsvwW ] [ -C | -L | -M | -{p|P} program ] [ -o optstring ]
4250 srcpat dest
4251 Move (usually, rename) files matching the pattern srcpat to cor‐
4252 responding files having names of the form given by dest, where
4253 srcpat contains parentheses surrounding patterns which will be
4254 replaced in turn by $1, $2, ... in dest. For example,
4255
4256 zmv '(*).lis' '$1.txt'
4257
4258 renames `foo.lis' to `foo.txt', `my.old.stuff.lis' to
4259 `my.old.stuff.txt', and so on.
4260
4261 The pattern is always treated as an EXTENDED_GLOB pattern. Any
4262 file whose name is not changed by the substitution is simply ig‐
4263 nored. Any error (a substitution resulted in an empty string,
4264 two substitutions gave the same result, the destination was an
4265 existing regular file and -f was not given) causes the entire
4266 function to abort without doing anything.
4267
4268 In addition to pattern replacement, the variable $f can be re‐
4269 ferrred to in the second (replacement) argument. This makes it
4270 possible to use variable substitution to alter the argument; see
4271 examples below.
4272
4273 Options:
4274
4275 -f Force overwriting of destination files. Not currently
4276 passed down to the mv/cp/ln command due to vagaries of
4277 implementations (but you can use -o-f to do that).
4278 -i Interactive: show each line to be executed and ask the
4279 user whether to execute it. `Y' or `y' will execute it,
4280 anything else will skip it. Note that you just need to
4281 type one character.
4282 -n No execution: print what would happen, but don't do it.
4283 -q Turn bare glob qualifiers off: now assumed by default, so
4284 this has no effect.
4285 -Q Force bare glob qualifiers on. Don't turn this on unless
4286 you are actually using glob qualifiers in a pattern.
4287 -s Symbolic, passed down to ln; only works with -L.
4288 -v Verbose: print each command as it's being executed.
4289 -w Pick out wildcard parts of the pattern, as described
4290 above, and implicitly add parentheses for referring to
4291 them.
4292 -W Just like -w, with the addition of turning wildcards in
4293 the replacement pattern into sequential ${1} .. ${N} ref‐
4294 erences.
4295 -C
4296 -L
4297 -M Force cp, ln or mv, respectively, regardless of the name
4298 of the function.
4299 -p program
4300 Call program instead of cp, ln or mv. Whatever it does,
4301 it should at least understand the form `program -- old‐
4302 name newname' where oldname and newname are filenames
4303 generated by zmv. program will be split into words, so
4304 might be e.g. the name of an archive tool plus a copy or
4305 rename subcommand.
4306 -P program
4307 As -p program, except that program does not accept a fol‐
4308 lowing -- to indicate the end of options. In this case
4309 filenames must already be in a sane form for the program
4310 in question.
4311 -o optstring
4312 The optstring is split into words and passed down verba‐
4313 tim to the cp, ln or mv command called to perform the
4314 work. It should probably begin with a `-'.
4315
4316 Further examples:
4317
4318 zmv -v '(* *)' '${1// /_}'
4319
4320 For any file in the current directory with at least one space in
4321 the name, replace every space by an underscore and display the
4322 commands executed.
4323
4324 zmv -v '* *' '${f// /_}'
4325
4326 This does exactly the same by referring to the file name stored
4327 in $f.
4328
4329 For more complete examples and other implementation details, see
4330 the zmv source file, usually located in one of the directories
4331 named in your fpath, or in Functions/Misc/zmv in the zsh distri‐
4332 bution.
4333
4334 zrecompile
4335 See `Recompiling Functions' above.
4336
4337 zstyle+ context style value [ + subcontext style value ... ]
4338 This makes defining styles a bit simpler by using a single `+'
4339 as a special token that allows you to append a context name to
4340 the previously used context name. Like this:
4341
4342 zstyle+ ':foo:bar' style1 value1 \
4343 +':baz' style2 value2 \
4344 +':frob' style3 value3
4345
4346 This defines style1 with value1 for the context :foo:bar as
4347 usual, but it also defines style2 with value2 for the context
4348 :foo:bar:baz and style3 with value3 for :foo:bar:frob. Any sub‐
4349 context may be the empty string to re-use the first context un‐
4350 changed.
4351
4352 Styles
4353 insert-tab
4354 The zed function sets this style in context `:completion:zed:*'
4355 to turn off completion when TAB is typed at the beginning of a
4356 line. You may override this by setting your own value for this
4357 context and style.
4358
4359 pager The nslookup function looks up this style in the context
4360 `:nslookup' to determine the program used to display output that
4361 does not fit on a single screen.
4362
4363 prompt
4364 rprompt
4365 The nslookup function looks up this style in the context
4366 `:nslookup' to set the prompt and the right-side prompt, respec‐
4367 tively. The usual expansions for the PS1 and RPS1 parameters
4368 may be used (see EXPANSION OF PROMPT SEQUENCES in zshmisc(1)).
4369
4370
4371
4372zsh 5.8.1 February 12, 2022 ZSHCONTRIB(1)