1ZSHALL(1) General Commands Manual ZSHALL(1)
2
3
4
6 zshall - the Z shell meta-man page
7
9 Because zsh contains many features, the zsh manual has been split into
10 a number of sections. This manual page includes all the separate man‐
11 ual pages in the following order:
12
13 zsh Zsh overview
14 zshroadmap Informal introduction to the manual
15 zshmisc Anything not fitting into the other sections
16 zshexpn Zsh command and parameter expansion
17 zshparam Zsh parameters
18 zshoptions Zsh options
19 zshbuiltins Zsh built-in functions
20 zshzle Zsh command line editing
21 zshcompwid Zsh completion widgets
22 zshcompsys Zsh completion system
23 zshcompctl Zsh completion control
24 zshmodules Zsh loadable modules
25 zshcalsys Zsh built-in calendar functions
26 zshtcpsys Zsh built-in TCP functions
27 zshzftpsys Zsh built-in FTP client
28 zshcontrib Additional zsh functions and utilities
29
31 Zsh is a UNIX command interpreter (shell) usable as an interactive lo‐
32 gin shell and as a shell script command processor. Of the standard
33 shells, zsh most closely resembles ksh but includes many enhancements.
34 It does not provide compatibility with POSIX or other shells in its de‐
35 fault operating mode: see the section `Compatibility' below.
36
37 Zsh has command line editing, builtin spelling correction, programmable
38 command completion, shell functions (with autoloading), a history mech‐
39 anism, and a host of other features.
40
42 Zsh was originally written by Paul Falstad. Zsh is now maintained by
43 the members of the zsh-workers mailing list <zsh-workers@zsh.org>. The
44 development is currently coordinated by Peter Stephenson <pws@zsh.org>.
45 The coordinator can be contacted at <coordinator@zsh.org>, but matters
46 relating to the code should generally go to the mailing list.
47
49 Zsh is available from the following HTTP and anonymous FTP site.
50
51 ftp://ftp.zsh.org/pub/
52 https://www.zsh.org/pub/
53
54 The up-to-date source code is available via Git from Sourceforge. See
55 https://sourceforge.net/projects/zsh/ for details. A summary of in‐
56 structions for the archive can be found at https://zsh.sourceforge.io/.
57
59 Zsh has several mailing lists:
60
61 <zsh-announce@zsh.org>
62 Announcements about releases, major changes in the shell and the
63 monthly posting of the Zsh FAQ. (moderated)
64
65 <zsh-users@zsh.org>
66 User discussions.
67
68 <zsh-workers@zsh.org>
69 Hacking, development, bug reports and patches.
70
71 <zsh-security@zsh.org>
72 Private mailing list (the general public cannot subscribe to it)
73 for discussing bug reports with security implications, i.e., po‐
74 tential vulnerabilities.
75
76 If you find a security problem in zsh itself, please mail this
77 address.
78
79 To subscribe or unsubscribe, send mail to the associated administrative
80 address for the mailing list.
81
82 <zsh-announce-subscribe@zsh.org>
83 <zsh-users-subscribe@zsh.org>
84 <zsh-workers-subscribe@zsh.org>
85 <zsh-announce-unsubscribe@zsh.org>
86 <zsh-users-unsubscribe@zsh.org>
87 <zsh-workers-unsubscribe@zsh.org>
88
89 YOU ONLY NEED TO JOIN ONE OF THE MAILING LISTS AS THEY ARE NESTED. All
90 submissions to zsh-announce are automatically forwarded to zsh-users.
91 All submissions to zsh-users are automatically forwarded to zsh-work‐
92 ers.
93
94 If you have problems subscribing/unsubscribing to any of the mailing
95 lists, send mail to <listmaster@zsh.org>.
96
97 The mailing lists are archived; the archives can be accessed via the
98 administrative addresses listed above. There is also a hypertext ar‐
99 chive available at https://www.zsh.org/mla/.
100
102 Zsh has a list of Frequently Asked Questions (FAQ), maintained by Peter
103 Stephenson <pws@zsh.org>. It is regularly posted to the newsgroup
104 comp.unix.shell and the zsh-announce mailing list. The latest version
105 can be found at any of the Zsh FTP sites, or at
106 https://www.zsh.org/FAQ/. The contact address for FAQ-related matters
107 is <faqmaster@zsh.org>.
108
110 Zsh has a web page which is located at https://www.zsh.org/. The con‐
111 tact address for web-related matters is <webmaster@zsh.org>.
112
114 A userguide is currently in preparation. It is intended to complement
115 the manual, with explanations and hints on issues where the manual can
116 be cabbalistic, hierographic, or downright mystifying (for example, the
117 word `hierographic' does not exist). It can be viewed in its current
118 state at https://zsh.sourceforge.io/Guide/. At the time of writing,
119 chapters dealing with startup files and their contents and the new com‐
120 pletion system were essentially complete.
121
123 The following flags are interpreted by the shell when invoked to deter‐
124 mine where the shell will read commands from:
125
126 -c Take the first argument as a command to execute, rather than
127 reading commands from a script or standard input. If any fur‐
128 ther arguments are given, the first one is assigned to $0,
129 rather than being used as a positional parameter.
130
131 -i Force shell to be interactive. It is still possible to specify
132 a script to execute.
133
134 -s Force shell to read commands from the standard input. If the -s
135 flag is not present and an argument is given, the first argument
136 is taken to be the pathname of a script to execute.
137
138 If there are any remaining arguments after option processing, and nei‐
139 ther of the options -c or -s was supplied, the first argument is taken
140 as the file name of a script containing shell commands to be executed.
141 If the option PATH_SCRIPT is set, and the file name does not contain a
142 directory path (i.e. there is no `/' in the name), first the current
143 directory and then the command path given by the variable PATH are
144 searched for the script. If the option is not set or the file name
145 contains a `/' it is used directly.
146
147 After the first one or two arguments have been appropriated as de‐
148 scribed above, the remaining arguments are assigned to the positional
149 parameters.
150
151 For further options, which are common to invocation and the set
152 builtin, see zshoptions(1).
153
154 The long option `--emulate' followed (in a separate word) by an emula‐
155 tion mode may be passed to the shell. The emulation modes are those
156 described for the emulate builtin, see zshbuiltins(1). The `--emulate'
157 option must precede any other options (which might otherwise be over‐
158 ridden), but following options are honoured, so may be used to modify
159 the requested emulation mode. Note that certain extra steps are taken
160 to ensure a smooth emulation when this option is used compared with the
161 emulate command within the shell: for example, variables that conflict
162 with POSIX usage such as path are not defined within the shell.
163
164 Options may be specified by name using the -o option. -o acts like a
165 single-letter option, but takes a following string as the option name.
166 For example,
167
168 zsh -x -o shwordsplit scr
169
170 runs the script scr, setting the XTRACE option by the corresponding
171 letter `-x' and the SH_WORD_SPLIT option by name. Options may be
172 turned off by name by using +o instead of -o. -o can be stacked up
173 with preceding single-letter options, so for example `-xo shwordsplit'
174 or `-xoshwordsplit' is equivalent to `-x -o shwordsplit'.
175
176 Options may also be specified by name in GNU long option style, `--op‐
177 tion-name'. When this is done, `-' characters in the option name are
178 permitted: they are translated into `_', and thus ignored. So, for ex‐
179 ample, `zsh --sh-word-split' invokes zsh with the SH_WORD_SPLIT option
180 turned on. Like other option syntaxes, options can be turned off by
181 replacing the initial `-' with a `+'; thus `+-sh-word-split' is equiva‐
182 lent to `--no-sh-word-split'. Unlike other option syntaxes, GNU-style
183 long options cannot be stacked with any other options, so for example
184 `-x-shwordsplit' is an error, rather than being treated like `-x
185 --shwordsplit'.
186
187 The special GNU-style option `--version' is handled; it sends to stan‐
188 dard output the shell's version information, then exits successfully.
189 `--help' is also handled; it sends to standard output a list of options
190 that can be used when invoking the shell, then exits successfully.
191
192 Option processing may be finished, allowing following arguments that
193 start with `-' or `+' to be treated as normal arguments, in two ways.
194 Firstly, a lone `-' (or `+') as an argument by itself ends option pro‐
195 cessing. Secondly, a special option `--' (or `+-'), which may be spec‐
196 ified on its own (which is the standard POSIX usage) or may be stacked
197 with preceding options (so `-x-' is equivalent to `-x --'). Options
198 are not permitted to be stacked after `--' (so `-x-f' is an error), but
199 note the GNU-style option form discussed above, where `--shwordsplit'
200 is permitted and does not end option processing.
201
202 Except when the sh/ksh emulation single-letter options are in effect,
203 the option `-b' (or `+b') ends option processing. `-b' is like `--',
204 except that further single-letter options can be stacked after the `-b'
205 and will take effect as normal.
206
208 Zsh tries to emulate sh or ksh when it is invoked as sh or ksh respec‐
209 tively; more precisely, it looks at the first letter of the name by
210 which it was invoked, excluding any initial `r' (assumed to stand for
211 `restricted'), and if that is `b', `s' or `k' it will emulate sh or
212 ksh. Furthermore, if invoked as su (which happens on certain systems
213 when the shell is executed by the su command), the shell will try to
214 find an alternative name from the SHELL environment variable and per‐
215 form emulation based on that.
216
217 In sh and ksh compatibility modes the following parameters are not spe‐
218 cial and not initialized by the shell: ARGC, argv, cdpath, fignore,
219 fpath, HISTCHARS, mailpath, MANPATH, manpath, path, prompt, PROMPT,
220 PROMPT2, PROMPT3, PROMPT4, psvar, status.
221
222 The usual zsh startup/shutdown scripts are not executed. Login shells
223 source /etc/profile followed by $HOME/.profile. If the ENV environment
224 variable is set on invocation, $ENV is sourced after the profile
225 scripts. The value of ENV is subjected to parameter expansion, command
226 substitution, and arithmetic expansion before being interpreted as a
227 pathname. Note that the PRIVILEGED option also affects the execution
228 of startup files.
229
230 The following options are set if the shell is invoked as sh or ksh:
231 NO_BAD_PATTERN, NO_BANG_HIST, NO_BG_NICE, NO_EQUALS, NO_FUNC‐
232 TION_ARGZERO, GLOB_SUBST, NO_GLOBAL_EXPORT, NO_HUP, INTERACTIVE_COM‐
233 MENTS, KSH_ARRAYS, NO_MULTIOS, NO_NOMATCH, NO_NOTIFY, POSIX_BUILTINS,
234 NO_PROMPT_PERCENT, RM_STAR_SILENT, SH_FILE_EXPANSION, SH_GLOB, SH_OP‐
235 TION_LETTERS, SH_WORD_SPLIT. Additionally the BSD_ECHO and IG‐
236 NORE_BRACES options are set if zsh is invoked as sh. Also, the KSH_OP‐
237 TION_PRINT, LOCAL_OPTIONS, PROMPT_BANG, PROMPT_SUBST and SIN‐
238 GLE_LINE_ZLE options are set if zsh is invoked as ksh.
239
240 Please note that, whilst reasonable efforts are taken to address incom‐
241 patibilities when they arise, zsh does not guarantee complete emulation
242 of other shells, nor POSIX compliance. For more information on the dif‐
243 ferences between zsh and other shells, please refer to chapter 2 of the
244 shell FAQ, https://www.zsh.org/FAQ/.
245
247 When the basename of the command used to invoke zsh starts with the
248 letter `r' or the `-r' command line option is supplied at invocation,
249 the shell becomes restricted. Emulation mode is determined after
250 stripping the letter `r' from the invocation name. The following are
251 disabled in restricted mode:
252
253 • changing directories with the cd builtin
254
255 • changing or unsetting the EGID, EUID, GID, HISTFILE, HISTSIZE,
256 IFS, LD_AOUT_LIBRARY_PATH, LD_AOUT_PRELOAD, LD_LIBRARY_PATH,
257 LD_PRELOAD, MODULE_PATH, module_path, PATH, path, SHELL, UID and
258 USERNAME parameters
259
260 • specifying command names containing /
261
262 • specifying command pathnames using hash
263
264 • redirecting output to files
265
266 • using the exec builtin command to replace the shell with another
267 command
268
269 • using jobs -Z to overwrite the shell process' argument and envi‐
270 ronment space
271
272 • using the ARGV0 parameter to override argv[0] for external com‐
273 mands
274
275 • turning off restricted mode with set +r or unsetopt RESTRICTED
276
277 These restrictions are enforced after processing the startup files.
278 The startup files should set up PATH to point to a directory of com‐
279 mands which can be safely invoked in the restricted environment. They
280 may also add further restrictions by disabling selected builtins.
281
282 Restricted mode can also be activated any time by setting the RE‐
283 STRICTED option. This immediately enables all the restrictions de‐
284 scribed above even if the shell still has not processed all startup
285 files.
286
287 A shell Restricted Mode is an outdated way to restrict what users may
288 do: modern systems have better, safer and more reliable ways to con‐
289 fine user actions, such as chroot jails, containers and zones.
290
291 A restricted shell is very difficult to implement safely. The feature
292 may be removed in a future version of zsh.
293
294 It is important to realise that the restrictions only apply to the
295 shell, not to the commands it runs (except for some shell builtins).
296 While a restricted shell can only run the restricted list of commands
297 accessible via the predefined `PATH' variable, it does not prevent
298 those commands from running any other command.
299
300 As an example, if `env' is among the list of allowed commands, then it
301 allows the user to run any command as `env' is not a shell builtin com‐
302 mand and can run arbitrary executables.
303
304 So when implementing a restricted shell framework it is important to be
305 fully aware of what actions each of the allowed commands or features
306 (which may be regarded as modules) can perform.
307
308 Many commands can have their behaviour affected by environment vari‐
309 ables. Except for the few listed above, zsh does not restrict the set‐
310 ting of environment variables.
311
312 If a `perl', `python', `bash', or other general purpose interpreted
313 script it treated as a restricted command, the user can work around the
314 restriction by setting specially crafted `PERL5LIB', `PYTHONPATH',
315 `BASHENV' (etc.) environment variables. On GNU systems, any command can
316 be made to run arbitrary code when performing character set conversion
317 (including zsh itself) by setting a `GCONV_PATH' environment variable.
318 Those are only a few examples.
319
320 Bear in mind that, contrary to some other shells, `readonly' is not a
321 security feature in zsh as it can be undone and so cannot be used to
322 mitigate the above.
323
324 A restricted shell only works if the allowed commands are few and care‐
325 fully written so as not to grant more access to users than intended.
326 It is also important to restrict what zsh module the user may load as
327 some of them, such as `zsh/system', `zsh/mapfile' and `zsh/files', al‐
328 low bypassing most of the restrictions.
329
331 Commands are first read from /etc/zshenv; this cannot be overridden.
332 Subsequent behaviour is modified by the RCS and GLOBAL_RCS options; the
333 former affects all startup files, while the second only affects global
334 startup files (those shown here with an path starting with a /). If
335 one of the options is unset at any point, any subsequent startup
336 file(s) of the corresponding type will not be read. It is also possi‐
337 ble for a file in $ZDOTDIR to re-enable GLOBAL_RCS. Both RCS and
338 GLOBAL_RCS are set by default.
339
340 Commands are then read from $ZDOTDIR/.zshenv. If the shell is a login
341 shell, commands are read from /etc/zprofile and then $ZDOTDIR/.zpro‐
342 file. Then, if the shell is interactive, commands are read from
343 /etc/zshrc and then $ZDOTDIR/.zshrc. Finally, if the shell is a login
344 shell, /etc/zlogin and $ZDOTDIR/.zlogin are read.
345
346 When a login shell exits, the files $ZDOTDIR/.zlogout and then /etc/zl‐
347 ogout are read. This happens with either an explicit exit via the exit
348 or logout commands, or an implicit exit by reading end-of-file from the
349 terminal. However, if the shell terminates due to exec'ing another
350 process, the logout files are not read. These are also affected by the
351 RCS and GLOBAL_RCS options. Note also that the RCS option affects the
352 saving of history files, i.e. if RCS is unset when the shell exits, no
353 history file will be saved.
354
355 If ZDOTDIR is unset, HOME is used instead. Files listed above as being
356 in /etc may be in another directory, depending on the installation.
357
358 As /etc/zshenv is run for all instances of zsh, it is important that it
359 be kept as small as possible. In particular, it is a good idea to put
360 code that does not need to be run for every single shell behind a test
361 of the form `if [[ -o rcs ]]; then ...' so that it will not be executed
362 when zsh is invoked with the `-f' option.
363
364 Any of these files may be pre-compiled with the zcompile builtin com‐
365 mand (see zshbuiltins(1)). If a compiled file exists (named for the
366 original file plus the .zwc extension) and it is newer than the origi‐
367 nal file, the compiled file will be used instead.
368
369
370
371ZSHROADMAP(1) General Commands Manual ZSHROADMAP(1)
372
373
374
376 zshroadmap - informal introduction to the zsh manual The Zsh Manual,
377 like the shell itself, is large and often complicated. This section of
378 the manual provides some pointers to areas of the shell that are likely
379 to be of particular interest to new users, and indicates where in the
380 rest of the manual the documentation is to be found.
381
383 When it starts, the shell reads commands from various files. These can
384 be created or edited to customize the shell. See the section
385 Startup/Shutdown Files in zsh(1).
386
387 If no personal initialization files exist for the current user, a func‐
388 tion is run to help you change some of the most common settings. It
389 won't appear if your administrator has disabled the zsh/newuser module.
390 The function is designed to be self-explanatory. You can run it by
391 hand with `autoload -Uz zsh-newuser-install; zsh-newuser-install -f'.
392 See also the section `User Configuration Functions' in zshcontrib(1).
393
395 Interaction with the shell uses the builtin Zsh Line Editor, ZLE. This
396 is described in detail in zshzle(1).
397
398 The first decision a user must make is whether to use the Emacs or Vi
399 editing mode as the keys for editing are substantially different.
400 Emacs editing mode is probably more natural for beginners and can be
401 selected explicitly with the command bindkey -e.
402
403 A history mechanism for retrieving previously typed lines (most simply
404 with the Up or Down arrow keys) is available; note that, unlike other
405 shells, zsh will not save these lines when the shell exits unless you
406 set appropriate variables, and the number of history lines retained by
407 default is quite small (30 lines). See the description of the shell
408 variables (referred to in the documentation as parameters) HISTFILE,
409 HISTSIZE and SAVEHIST in zshparam(1). Note that it's currently only
410 possible to read and write files saving history when the shell is in‐
411 teractive, i.e. it does not work from scripts.
412
413 The shell now supports the UTF-8 character set (and also others if sup‐
414 ported by the operating system). This is (mostly) handled transpar‐
415 ently by the shell, but the degree of support in terminal emulators is
416 variable. There is some discussion of this in the shell FAQ,
417 https://www.zsh.org/FAQ/. Note in particular that for combining char‐
418 acters to be handled the option COMBINING_CHARS needs to be set. Be‐
419 cause the shell is now more sensitive to the definition of the charac‐
420 ter set, note that if you are upgrading from an older version of the
421 shell you should ensure that the appropriate variable, either LANG (to
422 affect all aspects of the shell's operation) or LC_CTYPE (to affect
423 only the handling of character sets) is set to an appropriate value.
424 This is true even if you are using a single-byte character set includ‐
425 ing extensions of ASCII such as ISO-8859-1 or ISO-8859-15. See the de‐
426 scription of LC_CTYPE in zshparam(1).
427
428 Completion
429 Completion is a feature present in many shells. It allows the user to
430 type only a part (usually the prefix) of a word and have the shell fill
431 in the rest. The completion system in zsh is programmable. For exam‐
432 ple, the shell can be set to complete email addresses in arguments to
433 the mail command from your ~/.abook/addressbook; usernames, hostnames,
434 and even remote paths in arguments to scp, and so on. Anything that
435 can be written in or glued together with zsh can be the source of what
436 the line editor offers as possible completions.
437
438 Zsh has two completion systems, an old, so called compctl completion
439 (named after the builtin command that serves as its complete and only
440 user interface), and a new one, referred to as compsys, organized as
441 library of builtin and user-defined functions. The two systems differ
442 in their interface for specifying the completion behavior. The new
443 system is more customizable and is supplied with completions for many
444 commonly used commands; it is therefore to be preferred.
445
446 The completion system must be enabled explicitly when the shell starts.
447 For more information see zshcompsys(1).
448
449 Extending the line editor
450 Apart from completion, the line editor is highly extensible by means of
451 shell functions. Some useful functions are provided with the shell;
452 they provide facilities such as:
453
454 insert-composed-char
455 composing characters not found on the keyboard
456
457 match-words-by-style
458 configuring what the line editor considers a word when moving or
459 deleting by word
460
461 history-beginning-search-backward-end, etc.
462 alternative ways of searching the shell history
463
464 replace-string, replace-pattern
465 functions for replacing strings or patterns globally in the com‐
466 mand line
467
468 edit-command-line
469 edit the command line with an external editor.
470
471 See the section `ZLE Functions' in zshcontrib(1) for descriptions of
472 these.
473
475 The shell has a large number of options for changing its behaviour.
476 These cover all aspects of the shell; browsing the full documentation
477 is the only good way to become acquainted with the many possibilities.
478 See zshoptions(1).
479
481 The shell has a rich set of patterns which are available for file
482 matching (described in the documentation as `filename generation' and
483 also known for historical reasons as `globbing') and for use when pro‐
484 gramming. These are described in the section `Filename Generation' in
485 zshexpn(1).
486
487 Of particular interest are the following patterns that are not commonly
488 supported by other systems of pattern matching:
489
490 ** for matching over multiple directories
491
492 | for matching either of two alternatives
493
494 ~, ^ the ability to exclude patterns from matching when the EX‐
495 TENDED_GLOB option is set
496
497 (...) glob qualifiers, included in parentheses at the end of the pat‐
498 tern, which select files by type (such as directories) or attri‐
499 bute (such as size).
500
502 Although the syntax of zsh is in ways similar to the Korn shell, and
503 therefore more remotely to the original UNIX shell, the Bourne shell,
504 its default behaviour does not entirely correspond to those shells.
505 General shell syntax is introduced in the section `Shell Grammar' in
506 zshmisc(1).
507
508 One commonly encountered difference is that variables substituted onto
509 the command line are not split into words. See the description of the
510 shell option SH_WORD_SPLIT in the section `Parameter Expansion' in zsh‐
511 expn(1). In zsh, you can either explicitly request the splitting (e.g.
512 ${=foo}) or use an array when you want a variable to expand to more
513 than one word. See the section `Array Parameters' in zshparam(1).
514
516 The most convenient way of adding enhancements to the shell is typi‐
517 cally by writing a shell function and arranging for it to be au‐
518 toloaded. Functions are described in the section `Functions' in zsh‐
519 misc(1). Users changing from the C shell and its relatives should no‐
520 tice that aliases are less used in zsh as they don't perform argument
521 substitution, only simple text replacement.
522
523 A few general functions, other than those for the line editor described
524 above, are provided with the shell and are described in zshcontrib(1).
525 Features include:
526
527 promptinit
528 a prompt theme system for changing prompts easily, see the sec‐
529 tion `Prompt Themes'
530
531
532 zsh-mime-setup
533 a MIME-handling system which dispatches commands according to
534 the suffix of a file as done by graphical file managers
535
536 zcalc a calculator
537
538 zargs a version of xargs that makes the find command redundant
539
540 zmv a command for renaming files by means of shell patterns.
541
542
543
544ZSHMISC(1) General Commands Manual ZSHMISC(1)
545
547 zshmisc - everything and then some
548
550 A simple command is a sequence of optional parameter assignments fol‐
551 lowed by blank-separated words, with optional redirections inter‐
552 spersed. For a description of assignment, see the beginning of zsh‐
553 param(1).
554
555 The first word is the command to be executed, and the remaining words,
556 if any, are arguments to the command. If a command name is given, the
557 parameter assignments modify the environment of the command when it is
558 executed. The value of a simple command is its exit status, or 128
559 plus the signal number if terminated by a signal. For example,
560
561 echo foo
562
563 is a simple command with arguments.
564
565 A pipeline is either a simple command, or a sequence of two or more
566 simple commands where each command is separated from the next by `|' or
567 `|&'. Where commands are separated by `|', the standard output of the
568 first command is connected to the standard input of the next. `|&' is
569 shorthand for `2>&1 |', which connects both the standard output and the
570 standard error of the command to the standard input of the next. The
571 value of a pipeline is the value of the last command, unless the pipe‐
572 line is preceded by `!' in which case the value is the logical inverse
573 of the value of the last command. For example,
574
575 echo foo | sed 's/foo/bar/'
576
577 is a pipeline, where the output (`foo' plus a newline) of the first
578 command will be passed to the input of the second.
579
580 If a pipeline is preceded by `coproc', it is executed as a coprocess; a
581 two-way pipe is established between it and the parent shell. The shell
582 can read from or write to the coprocess by means of the `>&p' and `<&p'
583 redirection operators or with `print -p' and `read -p'. A pipeline
584 cannot be preceded by both `coproc' and `!'. If job control is active,
585 the coprocess can be treated in other than input and output as an ordi‐
586 nary background job.
587
588 A sublist is either a single pipeline, or a sequence of two or more
589 pipelines separated by `&&' or `||'. If two pipelines are separated by
590 `&&', the second pipeline is executed only if the first succeeds (re‐
591 turns a zero status). If two pipelines are separated by `||', the sec‐
592 ond is executed only if the first fails (returns a nonzero status).
593 Both operators have equal precedence and are left associative. The
594 value of the sublist is the value of the last pipeline executed. For
595 example,
596
597 dmesg | grep panic && print yes
598
599 is a sublist consisting of two pipelines, the second just a simple com‐
600 mand which will be executed if and only if the grep command returns a
601 zero status. If it does not, the value of the sublist is that return
602 status, else it is the status returned by the print (almost certainly
603 zero).
604
605 A list is a sequence of zero or more sublists, in which each sublist is
606 terminated by `;', `&', `&|', `&!', or a newline. This terminator may
607 optionally be omitted from the last sublist in the list when the list
608 appears as a complex command inside `(...)' or `{...}'. When a sublist
609 is terminated by `;' or newline, the shell waits for it to finish be‐
610 fore executing the next sublist. If a sublist is terminated by a `&',
611 `&|', or `&!', the shell executes the last pipeline in it in the back‐
612 ground, and does not wait for it to finish (note the difference from
613 other shells which execute the whole sublist in the background). A
614 backgrounded pipeline returns a status of zero.
615
616 More generally, a list can be seen as a set of any shell commands what‐
617 soever, including the complex commands below; this is implied wherever
618 the word `list' appears in later descriptions. For example, the com‐
619 mands in a shell function form a special sort of list.
620
622 A simple command may be preceded by a precommand modifier, which will
623 alter how the command is interpreted. These modifiers are shell
624 builtin commands with the exception of nocorrect which is a reserved
625 word.
626
627 - The command is executed with a `-' prepended to its argv[0]
628 string.
629
630 builtin
631 The command word is taken to be the name of a builtin command,
632 rather than a shell function or external command.
633
634 command [ -pvV ]
635 The command word is taken to be the name of an external command,
636 rather than a shell function or builtin. If the POSIX_BUILTINS
637 option is set, builtins will also be executed but certain spe‐
638 cial properties of them are suppressed. The -p flag causes a de‐
639 fault path to be searched instead of that in $path. With the -v
640 flag, command is similar to whence and with -V, it is equivalent
641 to whence -v.
642
643 exec [ -cl ] [ -a argv0 ]
644 The following command together with any arguments is run in
645 place of the current process, rather than as a sub-process. The
646 shell does not fork and is replaced. The shell does not invoke
647 TRAPEXIT, nor does it source zlogout files. The options are
648 provided for compatibility with other shells.
649
650 The -c option clears the environment.
651
652 The -l option is equivalent to the - precommand modifier, to
653 treat the replacement command as a login shell; the command is
654 executed with a - prepended to its argv[0] string. This flag
655 has no effect if used together with the -a option.
656
657 The -a option is used to specify explicitly the argv[0] string
658 (the name of the command as seen by the process itself) to be
659 used by the replacement command and is directly equivalent to
660 setting a value for the ARGV0 environment variable.
661
662 nocorrect
663 Spelling correction is not done on any of the words. This must
664 appear before any other precommand modifier, as it is inter‐
665 preted immediately, before any parsing is done. It has no ef‐
666 fect in non-interactive shells.
667
668 noglob Filename generation (globbing) is not performed on any of the
669 words.
670
672 A complex command in zsh is one of the following:
673
674 if list then list [ elif list then list ] ... [ else list ] fi
675 The if list is executed, and if it returns a zero exit status,
676 the then list is executed. Otherwise, the elif list is executed
677 and if its status is zero, the then list is executed. If each
678 elif list returns nonzero status, the else list is executed.
679
680 for name ... [ in word ... ] term do list done
681 Expand the list of words, and set the parameter name to each of
682 them in turn, executing list each time. If the `in word' is
683 omitted, use the positional parameters instead of the words.
684
685 The term consists of one or more newline or ; which terminate
686 the words, and are optional when the `in word' is omitted.
687
688 More than one parameter name can appear before the list of
689 words. If N names are given, then on each execution of the loop
690 the next N words are assigned to the corresponding parameters.
691 If there are more names than remaining words, the remaining pa‐
692 rameters are each set to the empty string. Execution of the
693 loop ends when there is no remaining word to assign to the first
694 name. It is only possible for in to appear as the first name in
695 the list, else it will be treated as marking the end of the
696 list.
697
698 for (( [expr1] ; [expr2] ; [expr3] )) do list done
699 The arithmetic expression expr1 is evaluated first (see the sec‐
700 tion `Arithmetic Evaluation'). The arithmetic expression expr2
701 is repeatedly evaluated until it evaluates to zero and when
702 non-zero, list is executed and the arithmetic expression expr3
703 evaluated. If any expression is omitted, then it behaves as if
704 it evaluated to 1.
705
706 while list do list done
707 Execute the do list as long as the while list returns a zero
708 exit status.
709
710 until list do list done
711 Execute the do list as long as until list returns a nonzero exit
712 status.
713
714 repeat word do list done
715 word is expanded and treated as an arithmetic expression, which
716 must evaluate to a number n. list is then executed n times.
717
718 The repeat syntax is disabled by default when the shell starts
719 in a mode emulating another shell. It can be enabled with the
720 command `enable -r repeat'
721
722 case word in [ [(] pattern [ | pattern ] ... ) list (;;|;&|;|) ] ...
723 esac
724 Execute the list associated with the first pattern that matches
725 word, if any. The form of the patterns is the same as that used
726 for filename generation. See the section `Filename Generation'.
727
728 Note further that, unless the SH_GLOB option is set, the whole
729 pattern with alternatives is treated by the shell as equivalent
730 to a group of patterns within parentheses, although white space
731 may appear about the parentheses and the vertical bar and will
732 be stripped from the pattern at those points. White space may
733 appear elsewhere in the pattern; this is not stripped. If the
734 SH_GLOB option is set, so that an opening parenthesis can be un‐
735 ambiguously treated as part of the case syntax, the expression
736 is parsed into separate words and these are treated as strict
737 alternatives (as in other shells).
738
739 If the list that is executed is terminated with ;& rather than
740 ;;, the following list is also executed. The rule for the ter‐
741 minator of the following list ;;, ;& or ;| is applied unless the
742 esac is reached.
743
744 If the list that is executed is terminated with ;| the shell
745 continues to scan the patterns looking for the next match, exe‐
746 cuting the corresponding list, and applying the rule for the
747 corresponding terminator ;;, ;& or ;|. Note that word is not
748 re-expanded; all applicable patterns are tested with the same
749 word.
750
751 select name [ in word ... term ] do list done
752 where term is one or more newline or ; to terminate the words.
753 Print the set of words, each preceded by a number. If the in
754 word is omitted, use the positional parameters. The PROMPT3
755 prompt is printed and a line is read from the line editor if the
756 shell is interactive and that is active, or else standard input.
757 If this line consists of the number of one of the listed words,
758 then the parameter name is set to the word corresponding to this
759 number. If this line is empty, the selection list is printed
760 again. Otherwise, the value of the parameter name is set to
761 null. The contents of the line read from standard input is
762 saved in the parameter REPLY. list is executed for each selec‐
763 tion until a break or end-of-file is encountered.
764
765 ( list )
766 Execute list in a subshell. Traps set by the trap builtin are
767 reset to their default values while executing list; an exception
768 is that ignored signals will continue to be ignored if the op‐
769 tion POSIXTRAPS is set.
770
771 { list }
772 Execute list.
773
774 { try-list } always { always-list }
775 First execute try-list. Regardless of errors, or break or con‐
776 tinue commands encountered within try-list, execute always-list.
777 Execution then continues from the result of the execution of
778 try-list; in other words, any error, or break or continue com‐
779 mand is treated in the normal way, as if always-list were not
780 present. The two chunks of code are referred to as the `try
781 block' and the `always block'.
782
783 Optional newlines or semicolons may appear after the always;
784 note, however, that they may not appear between the preceding
785 closing brace and the always.
786
787 An `error' in this context is a condition such as a syntax error
788 which causes the shell to abort execution of the current func‐
789 tion, script, or list. Syntax errors encountered while the
790 shell is parsing the code do not cause the always-list to be ex‐
791 ecuted. For example, an erroneously constructed if block in
792 try-list would cause the shell to abort during parsing, so that
793 always-list would not be executed, while an erroneous substitu‐
794 tion such as ${*foo*} would cause a run-time error, after which
795 always-list would be executed.
796
797 An error condition can be tested and reset with the special in‐
798 teger variable TRY_BLOCK_ERROR. Outside an always-list the
799 value is irrelevant, but it is initialised to -1. Inside al‐
800 ways-list, the value is 1 if an error occurred in the try-list,
801 else 0. If TRY_BLOCK_ERROR is set to 0 during the always-list,
802 the error condition caused by the try-list is reset, and shell
803 execution continues normally after the end of always-list. Al‐
804 tering the value during the try-list is not useful (unless this
805 forms part of an enclosing always block).
806
807 Regardless of TRY_BLOCK_ERROR, after the end of always-list the
808 normal shell status $? is the value returned from try-list.
809 This will be non-zero if there was an error, even if
810 TRY_BLOCK_ERROR was set to zero.
811
812 The following executes the given code, ignoring any errors it
813 causes. This is an alternative to the usual convention of pro‐
814 tecting code by executing it in a subshell.
815
816 {
817 # code which may cause an error
818 } always {
819 # This code is executed regardless of the error.
820 (( TRY_BLOCK_ERROR = 0 ))
821 }
822 # The error condition has been reset.
823
824 When a try block occurs outside of any function, a return or a
825 exit encountered in try-list does not cause the execution of al‐
826 ways-list. Instead, the shell exits immediately after any EXIT
827 trap has been executed. Otherwise, a return command encountered
828 in try-list will cause the execution of always-list, just like
829 break and continue.
830
831 function [ -T ] word ... [ () ] [ term ] { list }
832 word ... () [ term ] { list }
833 word ... () [ term ] command
834 where term is one or more newline or ;. Define a function which
835 is referenced by any one of word. Normally, only one word is
836 provided; multiple words are usually only useful for setting
837 traps. The body of the function is the list between the { and
838 }. See the section `Functions'.
839
840 The options of function have the following meanings:
841
842 -T Enable tracing for this function, as though with func‐
843 tions -T. See the documentation of the -f option to the
844 typeset builtin, in zshbuiltins(1).
845
846 If the option SH_GLOB is set for compatibility with other
847 shells, then whitespace may appear between the left and right
848 parentheses when there is a single word; otherwise, the paren‐
849 theses will be treated as forming a globbing pattern in that
850 case.
851
852 In any of the forms above, a redirection may appear outside the
853 function body, for example
854
855 func() { ... } 2>&1
856
857 The redirection is stored with the function and applied whenever
858 the function is executed. Any variables in the redirection are
859 expanded at the point the function is executed, but outside the
860 function scope.
861
862 time [ pipeline ]
863 The pipeline is executed, and timing statistics are reported on
864 the standard error in the form specified by the TIMEFMT parame‐
865 ter. If pipeline is omitted, print statistics about the shell
866 process and its children.
867
868 [[ exp ]]
869 Evaluates the conditional expression exp and return a zero exit
870 status if it is true. See the section `Conditional Expressions'
871 for a description of exp.
872
874 Many of zsh's complex commands have alternate forms. These are
875 non-standard and are likely not to be obvious even to seasoned shell
876 programmers; they should not be used anywhere that portability of shell
877 code is a concern.
878
879 The short versions below only work if sublist is of the form `{ list }'
880 or if the SHORT_LOOPS option is set. For the if, while and until com‐
881 mands, in both these cases the test part of the loop must also be suit‐
882 ably delimited, such as by `[[ ... ]]' or `(( ... ))', else the end of
883 the test will not be recognized. For the for, repeat, case and select
884 commands no such special form for the arguments is necessary, but the
885 other condition (the special form of sublist or use of the SHORT_LOOPS
886 option) still applies. The SHORT_REPEAT option is available to enable
887 the short version only for the repeat command.
888
889 if list { list } [ elif list { list } ] ... [ else { list } ]
890 An alternate form of if. The rules mean that
891
892 if [[ -o ignorebraces ]] {
893 print yes
894 }
895
896 works, but
897
898 if true { # Does not work!
899 print yes
900 }
901
902 does not, since the test is not suitably delimited.
903
904 if list sublist
905 A short form of the alternate if. The same limitations on the
906 form of list apply as for the previous form.
907
908 for name ... ( word ... ) sublist
909 A short form of for.
910
911 for name ... [ in word ... ] term sublist
912 where term is at least one newline or ;. Another short form of
913 for.
914
915 for (( [expr1] ; [expr2] ; [expr3] )) sublist
916 A short form of the arithmetic for command.
917
918 foreach name ... ( word ... ) list end
919 Another form of for.
920
921 while list { list }
922 An alternative form of while. Note the limitations on the form
923 of list mentioned above.
924
925 until list { list }
926 An alternative form of until. Note the limitations on the form
927 of list mentioned above.
928
929 repeat word sublist
930 This is a short form of repeat.
931
932 case word { [ [(] pattern [ | pattern ] ... ) list (;;|;&|;|) ] ... }
933 An alternative form of case.
934
935 select name [ in word ... term ] sublist
936 where term is at least one newline or ;. A short form of se‐
937 lect.
938
939 function word ... [ () ] [ term ] sublist
940 This is a short form of function.
941
943 The following words are recognized as reserved words when used as the
944 first word of a command unless quoted or disabled using disable -r:
945
946 do done esac then elif else fi for case if while function repeat time
947 until select coproc nocorrect foreach end ! [[ { } declare export float
948 integer local readonly typeset
949
950 Additionally, `}' is recognized in any position if neither the IG‐
951 NORE_BRACES option nor the IGNORE_CLOSE_BRACES option is set.
952
954 Certain errors are treated as fatal by the shell: in an interactive
955 shell, they cause control to return to the command line, and in a
956 non-interactive shell they cause the shell to be aborted. In older
957 versions of zsh, a non-interactive shell running a script would not
958 abort completely, but would resume execution at the next command to be
959 read from the script, skipping the remainder of any functions or shell
960 constructs such as loops or conditions; this somewhat illogical behav‐
961 iour can be recovered by setting the option CONTINUE_ON_ERROR.
962
963 Fatal errors found in non-interactive shells include:
964
965 • Failure to parse shell options passed when invoking the shell
966
967 • Failure to change options with the set builtin
968
969 • Parse errors of all sorts, including failures to parse mathemat‐
970 ical expressions
971
972 • Failures to set or modify variable behaviour with typeset, lo‐
973 cal, declare, export, integer, float
974
975 • Execution of incorrectly positioned loop control structures
976 (continue, break)
977
978 • Attempts to use regular expression with no regular expression
979 module available
980
981 • Disallowed operations when the RESTRICTED options is set
982
983 • Failure to create a pipe needed for a pipeline
984
985 • Failure to create a multio
986
987 • Failure to autoload a module needed for a declared shell feature
988
989 • Errors creating command or process substitutions
990
991 • Syntax errors in glob qualifiers
992
993 • File generation errors where not caught by the option BAD_PAT‐
994 TERN
995
996 • All bad patterns used for matching within case statements
997
998 • File generation failures where not caused by NO_MATCH or similar
999 options
1000
1001 • All file generation errors where the pattern was used to create
1002 a multio
1003
1004 • Memory errors where detected by the shell
1005
1006 • Invalid subscripts to shell variables
1007
1008 • Attempts to assign read-only variables
1009
1010 • Logical errors with variables such as assignment to the wrong
1011 type
1012
1013 • Use of invalid variable names
1014
1015 • Errors in variable substitution syntax
1016
1017 • Failure to convert characters in $'...' expressions
1018
1019 If the POSIX_BUILTINS option is set, more errors associated with shell
1020 builtin commands are treated as fatal, as specified by the POSIX stan‐
1021 dard.
1022
1024 In non-interactive shells, or in interactive shells with the INTERAC‐
1025 TIVE_COMMENTS option set, a word beginning with the third character of
1026 the histchars parameter (`#' by default) causes that word and all the
1027 following characters up to a newline to be ignored.
1028
1030 Every eligible word in the shell input is checked to see if there is an
1031 alias defined for it. If so, it is replaced by the text of the alias
1032 if it is in command position (if it could be the first word of a simple
1033 command), or if the alias is global. If the replacement text ends with
1034 a space, the next word in the shell input is always eligible for pur‐
1035 poses of alias expansion.
1036
1037 It is an error for the function name, word, in the sh-compatible func‐
1038 tion definition syntax `word () ...' to be a word that resulted from
1039 alias expansion, unless the ALIAS_FUNC_DEF option is set.
1040
1041 An alias is defined using the alias builtin; global aliases may be de‐
1042 fined using the -g option to that builtin.
1043
1044 A word is defined as:
1045
1046 • Any plain string or glob pattern
1047
1048 • Any quoted string, using any quoting method (note that the
1049 quotes must be part of the alias definition for this to be eli‐
1050 gible)
1051
1052 • Any parameter reference or command substitution
1053
1054 • Any series of the foregoing, concatenated without whitespace or
1055 other tokens between them
1056
1057 • Any reserved word (case, do, else, etc.)
1058
1059 • With global aliasing, any command separator, any redirection op‐
1060 erator, and `(' or `)' when not part of a glob pattern
1061
1062 Alias expansion is done on the shell input before any other expansion
1063 except history expansion. Therefore, if an alias is defined for the
1064 word foo, alias expansion may be avoided by quoting part of the word,
1065 e.g. \foo. Any form of quoting works, although there is nothing to
1066 prevent an alias being defined for the quoted form such as \foo as
1067 well.
1068
1069 In particular, note that quoting must be used when using unalias to re‐
1070 move global aliases:
1071
1072 % alias -g foo=bar
1073 % unalias foo
1074 unalias: no such hash table element: bar
1075 % unalias \foo
1076 %
1077
1078 When POSIX_ALIASES is set, only plain unquoted strings are eligible for
1079 aliasing. The alias builtin does not reject ineligible aliases, but
1080 they are not expanded.
1081
1082 For use with completion, which would remove an initial backslash fol‐
1083 lowed by a character that isn't special, it may be more convenient to
1084 quote the word by starting with a single quote, i.e. 'foo; completion
1085 will automatically add the trailing single quote.
1086
1087 Alias difficulties
1088 Although aliases can be used in ways that bend normal shell syntax, not
1089 every string of non-white-space characters can be used as an alias.
1090
1091 Any set of characters not listed as a word above is not a word, hence
1092 no attempt is made to expand it as an alias, no matter how it is de‐
1093 fined (i.e. via the builtin or the special parameter aliases described
1094 in the section THE ZSH/PARAMETER MODULE in zshmodules(1)). However, as
1095 noted in the case of POSIX_ALIASES above, the shell does not attempt to
1096 deduce whether the string corresponds to a word at the time the alias
1097 is created.
1098
1099 For example, an expression containing an = at the start of a command
1100 line is an assignment and cannot be expanded as an alias; a lone = is
1101 not an assignment but can only be set as an alias using the parameter,
1102 as otherwise the = is taken part of the syntax of the builtin command.
1103
1104 It is not presently possible to alias the `((' token that introduces
1105 arithmetic expressions, because until a full statement has been parsed,
1106 it cannot be distinguished from two consecutive `(' tokens introducing
1107 nested subshells. Also, if a separator such as && is aliased, \&&
1108 turns into the two tokens \& and &, each of which may have been aliased
1109 separately. Similarly for \<<, \>|, etc.
1110
1111 There is a commonly encountered problem with aliases illustrated by the
1112 following code:
1113
1114 alias echobar='echo bar'; echobar
1115
1116 This prints a message that the command echobar could not be found.
1117 This happens because aliases are expanded when the code is read in; the
1118 entire line is read in one go, so that when echobar is executed it is
1119 too late to expand the newly defined alias. This is often a problem in
1120 shell scripts, functions, and code executed with `source' or `.'. Con‐
1121 sequently, use of functions rather than aliases is recommended in
1122 non-interactive code.
1123
1125 A character may be quoted (that is, made to stand for itself) by pre‐
1126 ceding it with a `\'. `\' followed by a newline is ignored.
1127
1128 A string enclosed between `$'' and `'' is processed the same way as the
1129 string arguments of the print builtin, and the resulting string is con‐
1130 sidered to be entirely quoted. A literal `'' character can be included
1131 in the string by using the `\'' escape.
1132
1133 All characters enclosed between a pair of single quotes ('') that is
1134 not preceded by a `$' are quoted. A single quote cannot appear within
1135 single quotes unless the option RC_QUOTES is set, in which case a pair
1136 of single quotes are turned into a single quote. For example,
1137
1138 print ''''
1139
1140 outputs nothing apart from a newline if RC_QUOTES is not set, but one
1141 single quote if it is set.
1142
1143 Inside double quotes (""), parameter and command substitution occur,
1144 and `\' quotes the characters `\', ``', `"', `$', and the first charac‐
1145 ter of $histchars (default `!').
1146
1148 If a command is followed by & and job control is not active, then the
1149 default standard input for the command is the empty file /dev/null.
1150 Otherwise, the environment for the execution of a command contains the
1151 file descriptors of the invoking shell as modified by input/output
1152 specifications.
1153
1154 The following may appear anywhere in a simple command or may precede or
1155 follow a complex command. Expansion occurs before word or digit is
1156 used except as noted below. If the result of substitution on word pro‐
1157 duces more than one filename, redirection occurs for each separate
1158 filename in turn.
1159
1160 < word Open file word for reading as standard input. It is an error to
1161 open a file in this fashion if it does not exist.
1162
1163 <> word
1164 Open file word for reading and writing as standard input. If
1165 the file does not exist then it is created.
1166
1167 > word Open file word for writing as standard output. If the file does
1168 not exist then it is created. If the file exists, and the CLOB‐
1169 BER option is unset, this causes an error; otherwise, it is
1170 truncated to zero length.
1171
1172 >| word
1173 >! word
1174 Same as >, except that the file is truncated to zero length if
1175 it exists, regardless of CLOBBER.
1176
1177 >> word
1178 Open file word for writing in append mode as standard output.
1179 If the file does not exist, and the CLOBBER and APPEND_CREATE
1180 options are both unset, this causes an error; otherwise, the
1181 file is created.
1182
1183 >>| word
1184 >>! word
1185 Same as >>, except that the file is created if it does not ex‐
1186 ist, regardless of CLOBBER and APPEND_CREATE.
1187
1188 <<[-] word
1189 The shell input is read up to a line that is the same as word,
1190 or to an end-of-file. No parameter expansion, command substitu‐
1191 tion or filename generation is performed on word. The resulting
1192 document, called a here-document, becomes the standard input.
1193
1194 If any character of word is quoted with single or double quotes
1195 or a `\', no interpretation is placed upon the characters of the
1196 document. Otherwise, parameter and command substitution occurs,
1197 `\' followed by a newline is removed, and `\' must be used to
1198 quote the characters `\', `$', ``' and the first character of
1199 word.
1200
1201 Note that word itself does not undergo shell expansion. Back‐
1202 quotes in word do not have their usual effect; instead they be‐
1203 have similarly to double quotes, except that the backquotes
1204 themselves are passed through unchanged. (This information is
1205 given for completeness and it is not recommended that backquotes
1206 be used.) Quotes in the form $'...' have their standard effect
1207 of expanding backslashed references to special characters.
1208
1209 If <<- is used, then all leading tabs are stripped from word and
1210 from the document.
1211
1212 <<< word
1213 Perform shell expansion on word and pass the result to standard
1214 input. This is known as a here-string. Compare the use of word
1215 in here-documents above, where word does not undergo shell ex‐
1216 pansion. The result will have a trailing newline after it.
1217
1218 <& number
1219 >& number
1220 The standard input/output is duplicated from file descriptor
1221 number (see dup2(2)).
1222
1223 <& -
1224 >& - Close the standard input/output.
1225
1226 <& p
1227 >& p The input/output from/to the coprocess is moved to the standard
1228 input/output.
1229
1230 >& word
1231 &> word
1232 (Except where `>& word' matches one of the above syntaxes; `&>'
1233 can always be used to avoid this ambiguity.) Redirects both
1234 standard output and standard error (file descriptor 2) in the
1235 manner of `> word'. Note that this does not have the same ef‐
1236 fect as `> word 2>&1' in the presence of multios (see the sec‐
1237 tion below).
1238
1239 >&| word
1240 >&! word
1241 &>| word
1242 &>! word
1243 Redirects both standard output and standard error (file descrip‐
1244 tor 2) in the manner of `>| word'.
1245
1246 >>& word
1247 &>> word
1248 Redirects both standard output and standard error (file descrip‐
1249 tor 2) in the manner of `>> word'.
1250
1251 >>&| word
1252 >>&! word
1253 &>>| word
1254 &>>! word
1255 Redirects both standard output and standard error (file descrip‐
1256 tor 2) in the manner of `>>| word'.
1257
1258 If one of the above is preceded by a digit, then the file descriptor
1259 referred to is that specified by the digit instead of the default 0 or
1260 1. The order in which redirections are specified is significant. The
1261 shell evaluates each redirection in terms of the (file descriptor,
1262 file) association at the time of evaluation. For example:
1263
1264 ... 1>fname 2>&1
1265
1266 first associates file descriptor 1 with file fname. It then associates
1267 file descriptor 2 with the file associated with file descriptor 1 (that
1268 is, fname). If the order of redirections were reversed, file descrip‐
1269 tor 2 would be associated with the terminal (assuming file descriptor 1
1270 had been) and then file descriptor 1 would be associated with file
1271 fname.
1272
1273 The `|&' command separator described in Simple Commands & Pipelines in
1274 zshmisc(1) is a shorthand for `2>&1 |'.
1275
1276 The various forms of process substitution, `<(list)', and `=(list)' for
1277 input and `>(list)' for output, are often used together with redirect‐
1278 ion. For example, if word in an output redirection is of the form
1279 `>(list)' then the output is piped to the command represented by list.
1280 See Process Substitution in zshexpn(1).
1281
1283 When the shell is parsing arguments to a command, and the shell option
1284 IGNORE_BRACES is not set, a different form of redirection is allowed:
1285 instead of a digit before the operator there is a valid shell identi‐
1286 fier enclosed in braces. The shell will open a new file descriptor
1287 that is guaranteed to be at least 10 and set the parameter named by the
1288 identifier to the file descriptor opened. No whitespace is allowed be‐
1289 tween the closing brace and the redirection character. For example:
1290
1291 ... {myfd}>&1
1292
1293 This opens a new file descriptor that is a duplicate of file descriptor
1294 1 and sets the parameter myfd to the number of the file descriptor,
1295 which will be at least 10. The new file descriptor can be written to
1296 using the syntax >&$myfd. The file descriptor remains open in sub‐
1297 shells and forked external executables.
1298
1299 The syntax {varid}>&-, for example {myfd}>&-, may be used to close a
1300 file descriptor opened in this fashion. Note that the parameter given
1301 by varid must previously be set to a file descriptor in this case.
1302
1303 It is an error to open or close a file descriptor in this fashion when
1304 the parameter is readonly. However, it is not an error to read or
1305 write a file descriptor using <&$param or >&$param if param is read‐
1306 only.
1307
1308 If the option CLOBBER is unset, it is an error to open a file descrip‐
1309 tor using a parameter that is already set to an open file descriptor
1310 previously allocated by this mechanism. Unsetting the parameter before
1311 using it for allocating a file descriptor avoids the error.
1312
1313 Note that this mechanism merely allocates or closes a file descriptor;
1314 it does not perform any redirections from or to it. It is usually con‐
1315 venient to allocate a file descriptor prior to use as an argument to
1316 exec. The syntax does not in any case work when used around complex
1317 commands such as parenthesised subshells or loops, where the opening
1318 brace is interpreted as part of a command list to be executed in the
1319 current shell.
1320
1321 The following shows a typical sequence of allocation, use, and closing
1322 of a file descriptor:
1323
1324 integer myfd
1325 exec {myfd}>~/logs/mylogfile.txt
1326 print This is a log message. >&$myfd
1327 exec {myfd}>&-
1328
1329 Note that the expansion of the variable in the expression >&$myfd oc‐
1330 curs at the point the redirection is opened. This is after the expan‐
1331 sion of command arguments and after any redirections to the left on the
1332 command line have been processed.
1333
1335 If the user tries to open a file descriptor for writing more than once,
1336 the shell opens the file descriptor as a pipe to a process that copies
1337 its input to all the specified outputs, similar to tee, provided the
1338 MULTIOS option is set, as it is by default. Thus:
1339
1340 date >foo >bar
1341
1342 writes the date to two files, named `foo' and `bar'. Note that a pipe
1343 is an implicit redirection; thus
1344
1345 date >foo | cat
1346
1347 writes the date to the file `foo', and also pipes it to cat.
1348
1349 Note that the shell opens all the files to be used in the multio
1350 process immediately, not at the point they are about to be written.
1351
1352 Note also that redirections are always expanded in order. This happens
1353 regardless of the setting of the MULTIOS option, but with the option in
1354 effect there are additional consequences. For example, the meaning of
1355 the expression >&1 will change after a previous redirection:
1356
1357 date >&1 >output
1358
1359 In the case above, the >&1 refers to the standard output at the start
1360 of the line; the result is similar to the tee command. However, con‐
1361 sider:
1362
1363 date >output >&1
1364
1365 As redirections are evaluated in order, when the >&1 is encountered the
1366 standard output is set to the file output and another copy of the out‐
1367 put is therefore sent to that file. This is unlikely to be what is in‐
1368 tended.
1369
1370 If the MULTIOS option is set, the word after a redirection operator is
1371 also subjected to filename generation (globbing). Thus
1372
1373 : > *
1374
1375 will truncate all files in the current directory, assuming there's at
1376 least one. (Without the MULTIOS option, it would create an empty file
1377 called `*'.) Similarly, you can do
1378
1379 echo exit 0 >> *.sh
1380
1381 If the user tries to open a file descriptor for reading more than once,
1382 the shell opens the file descriptor as a pipe to a process that copies
1383 all the specified inputs to its output in the order specified, provided
1384 the MULTIOS option is set. It should be noted that each file is opened
1385 immediately, not at the point where it is about to be read: this behav‐
1386 iour differs from cat, so if strictly standard behaviour is needed, cat
1387 should be used instead.
1388
1389 Thus
1390
1391 sort <foo <fubar
1392
1393 or even
1394
1395 sort <f{oo,ubar}
1396
1397 is equivalent to `cat foo fubar | sort'.
1398
1399 Expansion of the redirection argument occurs at the point the redirect‐
1400 ion is opened, at the point described above for the expansion of the
1401 variable in >&$myfd.
1402
1403 Note that a pipe is an implicit redirection; thus
1404
1405 cat bar | sort <foo
1406
1407 is equivalent to `cat bar foo | sort' (note the order of the inputs).
1408
1409 If the MULTIOS option is unset, each redirection replaces the previous
1410 redirection for that file descriptor. However, all files redirected to
1411 are actually opened, so
1412
1413 echo Hello > bar > baz
1414
1415 when MULTIOS is unset will truncate `bar', and write `Hello' into
1416 `baz'.
1417
1418 There is a problem when an output multio is attached to an external
1419 program. A simple example shows this:
1420
1421 cat file >file1 >file2
1422 cat file1 file2
1423
1424 Here, it is possible that the second `cat' will not display the full
1425 contents of file1 and file2 (i.e. the original contents of file re‐
1426 peated twice).
1427
1428 The reason for this is that the multios are spawned after the cat
1429 process is forked from the parent shell, so the parent shell does not
1430 wait for the multios to finish writing data. This means the command as
1431 shown can exit before file1 and file2 are completely written. As a
1432 workaround, it is possible to run the cat process as part of a job in
1433 the current shell:
1434
1435 { cat file } >file >file2
1436
1437 Here, the {...} job will pause to wait for both files to be written.
1438
1440 When a simple command consists of one or more redirection operators and
1441 zero or more parameter assignments, but no command name, zsh can behave
1442 in several ways.
1443
1444 If the parameter NULLCMD is not set or the option CSH_NULLCMD is set,
1445 an error is caused. This is the csh behavior and CSH_NULLCMD is set by
1446 default when emulating csh.
1447
1448 If the option SH_NULLCMD is set, the builtin `:' is inserted as a com‐
1449 mand with the given redirections. This is the default when emulating
1450 sh or ksh.
1451
1452 Otherwise, if the parameter NULLCMD is set, its value will be used as a
1453 command with the given redirections. If both NULLCMD and READNULLCMD
1454 are set, then the value of the latter will be used instead of that of
1455 the former when the redirection is an input. The default for NULLCMD
1456 is `cat' and for READNULLCMD is `more'. Thus
1457
1458 < file
1459
1460 shows the contents of file on standard output, with paging if that is a
1461 terminal. NULLCMD and READNULLCMD may refer to shell functions.
1462
1464 If a command name contains no slashes, the shell attempts to locate it.
1465 If there exists a shell function by that name, the function is invoked
1466 as described in the section `Functions'. If there exists a shell
1467 builtin by that name, the builtin is invoked.
1468
1469 Otherwise, the shell searches each element of $path for a directory
1470 containing an executable file by that name.
1471
1472 If execution fails: an error message is printed, and one of the follow‐
1473 ing values is returned.
1474
1475 127 The search was unsuccessful. The error message is `command not
1476 found: cmd'.
1477 126 The executable file has insufficient permissions, is a directory
1478 or special file, or is not a script and is in a format unrecog‐
1479 nized by the operating system. The exact conditions and error
1480 message are operating system-dependent; see execve(2).
1481
1482 If execution fails because the file is not in executable format, and
1483 the file is not a directory, it is assumed to be a shell script.
1484 /bin/sh is spawned to execute it. If the program is a file beginning
1485 with `#!', the remainder of the first line specifies an interpreter for
1486 the program. The shell will execute the specified interpreter on oper‐
1487 ating systems that do not handle this executable format in the kernel.
1488
1489 If no external command is found but a function command_not_found_han‐
1490 dler exists the shell executes this function with all command line ar‐
1491 guments. The return status of the function becomes the status of the
1492 command. Note that the handler is executed in a subshell forked to ex‐
1493 ecute an external command, hence changes to directories, shell parame‐
1494 ters, etc. have no effect on the main shell.
1495
1497 Shell functions are defined with the function reserved word or the spe‐
1498 cial syntax `funcname ()'. Shell functions are read in and stored in‐
1499 ternally. Alias names are resolved when the function is read. Func‐
1500 tions are executed like commands with the arguments passed as posi‐
1501 tional parameters. (See the section `Command Execution'.)
1502
1503 Functions execute in the same process as the caller and share all files
1504 and present working directory with the caller. A trap on EXIT set in‐
1505 side a function is executed after the function completes in the envi‐
1506 ronment of the caller.
1507
1508 The return builtin is used to return from function calls.
1509
1510 Function identifiers can be listed with the functions builtin. Func‐
1511 tions can be undefined with the unfunction builtin.
1512
1514 A function can be marked as undefined using the autoload builtin (or
1515 `functions -u' or `typeset -fu'). Such a function has no body. When
1516 the function is first executed, the shell searches for its definition
1517 using the elements of the fpath variable. Thus to define functions for
1518 autoloading, a typical sequence is:
1519
1520 fpath=(~/myfuncs $fpath)
1521 autoload myfunc1 myfunc2 ...
1522
1523 The usual alias expansion during reading will be suppressed if the au‐
1524 toload builtin or its equivalent is given the option -U. This is recom‐
1525 mended for the use of functions supplied with the zsh distribution.
1526 Note that for functions precompiled with the zcompile builtin command
1527 the flag -U must be provided when the .zwc file is created, as the cor‐
1528 responding information is compiled into the latter.
1529
1530 For each element in fpath, the shell looks for three possible files,
1531 the newest of which is used to load the definition for the function:
1532
1533 element.zwc
1534 A file created with the zcompile builtin command, which is ex‐
1535 pected to contain the definitions for all functions in the di‐
1536 rectory named element. The file is treated in the same manner
1537 as a directory containing files for functions and is searched
1538 for the definition of the function. If the definition is not
1539 found, the search for a definition proceeds with the other two
1540 possibilities described below.
1541
1542 If element already includes a .zwc extension (i.e. the extension
1543 was explicitly given by the user), element is searched for the
1544 definition of the function without comparing its age to that of
1545 other files; in fact, there does not need to be any directory
1546 named element without the suffix. Thus including an element
1547 such as `/usr/local/funcs.zwc' in fpath will speed up the search
1548 for functions, with the disadvantage that functions included
1549 must be explicitly recompiled by hand before the shell notices
1550 any changes.
1551
1552 element/function.zwc
1553 A file created with zcompile, which is expected to contain the
1554 definition for function. It may include other function defini‐
1555 tions as well, but those are neither loaded nor executed; a file
1556 found in this way is searched only for the definition of func‐
1557 tion.
1558
1559 element/function
1560 A file of zsh command text, taken to be the definition for func‐
1561 tion.
1562
1563 In summary, the order of searching is, first, in the parents of direc‐
1564 tories in fpath for the newer of either a compiled directory or a di‐
1565 rectory in fpath; second, if more than one of these contains a defini‐
1566 tion for the function that is sought, the leftmost in the fpath is cho‐
1567 sen; and third, within a directory, the newer of either a compiled
1568 function or an ordinary function definition is used.
1569
1570 If the KSH_AUTOLOAD option is set, or the file contains only a simple
1571 definition of the function, the file's contents will be executed. This
1572 will normally define the function in question, but may also perform
1573 initialization, which is executed in the context of the function execu‐
1574 tion, and may therefore define local parameters. It is an error if the
1575 function is not defined by loading the file.
1576
1577 Otherwise, the function body (with no surrounding `funcname() {...}')
1578 is taken to be the complete contents of the file. This form allows the
1579 file to be used directly as an executable shell script. If processing
1580 of the file results in the function being re-defined, the function it‐
1581 self is not re-executed. To force the shell to perform initialization
1582 and then call the function defined, the file should contain initializa‐
1583 tion code (which will be executed then discarded) in addition to a com‐
1584 plete function definition (which will be retained for subsequent calls
1585 to the function), and a call to the shell function, including any argu‐
1586 ments, at the end.
1587
1588 For example, suppose the autoload file func contains
1589
1590 func() { print This is func; }
1591 print func is initialized
1592
1593 then `func; func' with KSH_AUTOLOAD set will produce both messages on
1594 the first call, but only the message `This is func' on the second and
1595 subsequent calls. Without KSH_AUTOLOAD set, it will produce the ini‐
1596 tialization message on the first call, and the other message on the
1597 second and subsequent calls.
1598
1599 It is also possible to create a function that is not marked as au‐
1600 toloaded, but which loads its own definition by searching fpath, by us‐
1601 ing `autoload -X' within a shell function. For example, the following
1602 are equivalent:
1603
1604 myfunc() {
1605 autoload -X
1606 }
1607 myfunc args...
1608
1609 and
1610
1611 unfunction myfunc # if myfunc was defined
1612 autoload myfunc
1613 myfunc args...
1614
1615 In fact, the functions command outputs `builtin autoload -X' as the
1616 body of an autoloaded function. This is done so that
1617
1618 eval "$(functions)"
1619
1620 produces a reasonable result. A true autoloaded function can be iden‐
1621 tified by the presence of the comment `# undefined' in the body, be‐
1622 cause all comments are discarded from defined functions.
1623
1624 To load the definition of an autoloaded function myfunc without execut‐
1625 ing myfunc, use:
1626
1627 autoload +X myfunc
1628
1630 If no name is given for a function, it is `anonymous' and is handled
1631 specially. Either form of function definition may be used: a `()' with
1632 no preceding name, or a `function' with an immediately following open
1633 brace. The function is executed immediately at the point of definition
1634 and is not stored for future use. The function name is set to
1635 `(anon)'.
1636
1637 Arguments to the function may be specified as words following the clos‐
1638 ing brace defining the function, hence if there are none no arguments
1639 (other than $0) are set. This is a difference from the way other func‐
1640 tions are parsed: normal function definitions may be followed by cer‐
1641 tain keywords such as `else' or `fi', which will be treated as argu‐
1642 ments to anonymous functions, so that a newline or semicolon is needed
1643 to force keyword interpretation.
1644
1645 Note also that the argument list of any enclosing script or function is
1646 hidden (as would be the case for any other function called at this
1647 point).
1648
1649 Redirections may be applied to the anonymous function in the same man‐
1650 ner as to a current-shell structure enclosed in braces. The main use
1651 of anonymous functions is to provide a scope for local variables. This
1652 is particularly convenient in start-up files as these do not provide
1653 their own local variable scope.
1654
1655 For example,
1656
1657 variable=outside
1658 function {
1659 local variable=inside
1660 print "I am $variable with arguments $*"
1661 } this and that
1662 print "I am $variable"
1663
1664 outputs the following:
1665
1666 I am inside with arguments this and that
1667 I am outside
1668
1669 Note that function definitions with arguments that expand to nothing,
1670 for example `name=; function $name { ... }', are not treated as anony‐
1671 mous functions. Instead, they are treated as normal function defini‐
1672 tions where the definition is silently discarded.
1673
1675 Certain functions, if defined, have special meaning to the shell.
1676
1677 Hook Functions
1678 For the functions below, it is possible to define an array that has the
1679 same name as the function with `_functions' appended. Any element in
1680 such an array is taken as the name of a function to execute; it is exe‐
1681 cuted in the same context and with the same arguments and same initial
1682 value of $? as the basic function. For example, if $chpwd_functions
1683 is an array containing the values `mychpwd', `chpwd_save_dirstack',
1684 then the shell attempts to execute the functions `chpwd', `mychpwd' and
1685 `chpwd_save_dirstack', in that order. Any function that does not exist
1686 is silently ignored. A function found by this mechanism is referred to
1687 elsewhere as a hook function. An error in any function causes subse‐
1688 quent functions not to be run. Note further that an error in a precmd
1689 hook causes an immediately following periodic function not to run
1690 (though it may run at the next opportunity).
1691
1692 chpwd Executed whenever the current working directory is changed.
1693
1694 periodic
1695 If the parameter PERIOD is set, this function is executed every
1696 $PERIOD seconds, just before a prompt. Note that if multiple
1697 functions are defined using the array periodic_functions only
1698 one period is applied to the complete set of functions, and the
1699 scheduled time is not reset if the list of functions is altered.
1700 Hence the set of functions is always called together.
1701
1702 precmd Executed before each prompt. Note that precommand functions are
1703 not re-executed simply because the command line is redrawn, as
1704 happens, for example, when a notification about an exiting job
1705 is displayed.
1706
1707 preexec
1708 Executed just after a command has been read and is about to be
1709 executed. If the history mechanism is active (regardless of
1710 whether the line was discarded from the history buffer), the
1711 string that the user typed is passed as the first argument, oth‐
1712 erwise it is an empty string. The actual command that will be
1713 executed (including expanded aliases) is passed in two different
1714 forms: the second argument is a single-line, size-limited ver‐
1715 sion of the command (with things like function bodies elided);
1716 the third argument contains the full text that is being exe‐
1717 cuted.
1718
1719 zshaddhistory
1720 Executed when a history line has been read interactively, but
1721 before it is executed. The sole argument is the complete his‐
1722 tory line (so that any terminating newline will still be
1723 present).
1724
1725 If any of the hook functions returns status 1 (or any non-zero
1726 value other than 2, though this is not guaranteed for future
1727 versions of the shell) the history line will not be saved, al‐
1728 though it lingers in the history until the next line is exe‐
1729 cuted, allowing you to reuse or edit it immediately.
1730
1731 If any of the hook functions returns status 2 the history line
1732 will be saved on the internal history list, but not written to
1733 the history file. In case of a conflict, the first non-zero
1734 status value is taken.
1735
1736 A hook function may call `fc -p ...' to switch the history con‐
1737 text so that the history is saved in a different file from that
1738 in the global HISTFILE parameter. This is handled specially:
1739 the history context is automatically restored after the process‐
1740 ing of the history line is finished.
1741
1742 The following example function works with one of the options
1743 INC_APPEND_HISTORY or SHARE_HISTORY set, in order that the line
1744 is written out immediately after the history entry is added. It
1745 first adds the history line to the normal history with the new‐
1746 line stripped, which is usually the correct behaviour. Then it
1747 switches the history context so that the line will be written to
1748 a history file in the current directory.
1749
1750 zshaddhistory() {
1751 print -sr -- ${1%%$'\n'}
1752 fc -p .zsh_local_history
1753 }
1754
1755 zshexit
1756 Executed at the point where the main shell is about to exit nor‐
1757 mally. This is not called by exiting subshells, nor when the
1758 exec precommand modifier is used before an external command.
1759 Also, unlike TRAPEXIT, it is not called when functions exit.
1760
1761 Trap Functions
1762 The functions below are treated specially but do not have corresponding
1763 hook arrays.
1764
1765 TRAPNAL
1766 If defined and non-null, this function will be executed whenever
1767 the shell catches a signal SIGNAL, where NAL is a signal name as
1768 specified for the kill builtin. The signal number will be
1769 passed as the first parameter to the function.
1770
1771 If a function of this form is defined and null, the shell and
1772 processes spawned by it will ignore SIGNAL.
1773
1774 The return status from the function is handled specially. If it
1775 is zero, the signal is assumed to have been handled, and execu‐
1776 tion continues normally. Otherwise, the shell will behave as
1777 interrupted except that the return status of the trap is re‐
1778 tained.
1779
1780 Programs terminated by uncaught signals typically return the
1781 status 128 plus the signal number. Hence the following causes
1782 the handler for SIGINT to print a message, then mimic the usual
1783 effect of the signal.
1784
1785 TRAPINT() {
1786 print "Caught SIGINT, aborting."
1787 return $(( 128 + $1 ))
1788 }
1789
1790 The functions TRAPZERR, TRAPDEBUG and TRAPEXIT are never exe‐
1791 cuted inside other traps.
1792
1793 TRAPDEBUG
1794 If the option DEBUG_BEFORE_CMD is set (as it is by default), ex‐
1795 ecuted before each command; otherwise executed after each com‐
1796 mand. See the description of the trap builtin in zshbuiltins(1)
1797 for details of additional features provided in debug traps.
1798
1799 TRAPEXIT
1800 Executed when the shell exits, or when the current function ex‐
1801 its if defined inside a function. The value of $? at the start
1802 of execution is the exit status of the shell or the return sta‐
1803 tus of the function exiting.
1804
1805 TRAPZERR
1806 Executed whenever a command has a non-zero exit status. How‐
1807 ever, the function is not executed if the command occurred in a
1808 sublist followed by `&&' or `||'; only the final command in a
1809 sublist of this type causes the trap to be executed. The func‐
1810 tion TRAPERR acts the same as TRAPZERR on systems where there is
1811 no SIGERR (this is the usual case).
1812
1813 The functions beginning `TRAP' may alternatively be defined with the
1814 trap builtin: this may be preferable for some uses. Setting a trap
1815 with one form removes any trap of the other form for the same signal;
1816 removing a trap in either form removes all traps for the same signal.
1817 The forms
1818
1819 TRAPNAL() {
1820 # code
1821 }
1822
1823 ('function traps') and
1824
1825 trap '
1826 # code
1827 ' NAL
1828
1829 ('list traps') are equivalent in most ways, the exceptions being the
1830 following:
1831
1832 • Function traps have all the properties of normal functions, ap‐
1833 pearing in the list of functions and being called with their own
1834 function context rather than the context where the trap was
1835 triggered.
1836
1837 • The return status from function traps is special, whereas a re‐
1838 turn from a list trap causes the surrounding context to return
1839 with the given status.
1840
1841 • Function traps are not reset within subshells, in accordance
1842 with zsh behaviour; list traps are reset, in accordance with
1843 POSIX behaviour.
1844
1846 If the MONITOR option is set, an interactive shell associates a job
1847 with each pipeline. It keeps a table of current jobs, printed by the
1848 jobs command, and assigns them small integer numbers. When a job is
1849 started asynchronously with `&', the shell prints a line to standard
1850 error which looks like:
1851
1852 [1] 1234
1853
1854 indicating that the job which was started asynchronously was job number
1855 1 and had one (top-level) process, whose process ID was 1234.
1856
1857 If a job is started with `&|' or `&!', then that job is immediately
1858 disowned. After startup, it does not have a place in the job table,
1859 and is not subject to the job control features described here.
1860
1861 If you are running a job and wish to do something else you may hit the
1862 key ^Z (control-Z) which sends a TSTP signal to the current job: this
1863 key may be redefined by the susp option of the external stty command.
1864 The shell will then normally indicate that the job has been `sus‐
1865 pended', and print another prompt. You can then manipulate the state
1866 of this job, putting it in the background with the bg command, or run
1867 some other commands and then eventually bring the job back into the
1868 foreground with the foreground command fg. A ^Z takes effect immedi‐
1869 ately and is like an interrupt in that pending output and unread input
1870 are discarded when it is typed.
1871
1872 A job being run in the background will suspend if it tries to read from
1873 the terminal.
1874
1875 Note that if the job running in the foreground is a shell function,
1876 then suspending it will have the effect of causing the shell to fork.
1877 This is necessary to separate the function's state from that of the
1878 parent shell performing the job control, so that the latter can return
1879 to the command line prompt. As a result, even if fg is used to con‐
1880 tinue the job the function will no longer be part of the parent shell,
1881 and any variables set by the function will not be visible in the parent
1882 shell. Thus the behaviour is different from the case where the func‐
1883 tion was never suspended. Zsh is different from many other shells in
1884 this regard.
1885
1886 One additional side effect is that use of disown with a job created by
1887 suspending shell code in this fashion is delayed: the job can only be
1888 disowned once any process started from the parent shell has terminated.
1889 At that point, the disowned job disappears silently from the job list.
1890
1891 The same behaviour is found when the shell is executing code as the
1892 right hand side of a pipeline or any complex shell construct such as
1893 if, for, etc., in order that the entire block of code can be managed as
1894 a single job. Background jobs are normally allowed to produce output,
1895 but this can be disabled by giving the command `stty tostop'. If you
1896 set this tty option, then background jobs will suspend when they try to
1897 produce output like they do when they try to read input.
1898
1899 When a command is suspended and continued later with the fg or wait
1900 builtins, zsh restores tty modes that were in effect when it was sus‐
1901 pended. This (intentionally) does not apply if the command is contin‐
1902 ued via `kill -CONT', nor when it is continued with bg.
1903
1904 There are several ways to refer to jobs in the shell. A job can be re‐
1905 ferred to by the process ID of any process of the job or by one of the
1906 following:
1907
1908 %number
1909 The job with the given number.
1910 %string
1911 The last job whose command line begins with string.
1912 %?string
1913 The last job whose command line contains string.
1914 %% Current job.
1915 %+ Equivalent to `%%'.
1916 %- Previous job.
1917
1918 The shell learns immediately whenever a process changes state. It nor‐
1919 mally informs you whenever a job becomes blocked so that no further
1920 progress is possible. If the NOTIFY option is not set, it waits until
1921 just before it prints a prompt before it informs you. All such notifi‐
1922 cations are sent directly to the terminal, not to the standard output
1923 or standard error.
1924
1925 When the monitor mode is on, each background job that completes trig‐
1926 gers any trap set for CHLD.
1927
1928 When you try to leave the shell while jobs are running or suspended,
1929 you will be warned that `You have suspended (running) jobs'. You may
1930 use the jobs command to see what they are. If you do this or immedi‐
1931 ately try to exit again, the shell will not warn you a second time; the
1932 suspended jobs will be terminated, and the running jobs will be sent a
1933 SIGHUP signal, if the HUP option is set.
1934
1935 To avoid having the shell terminate the running jobs, either use the
1936 nohup(1) command or the disown builtin.
1937
1939 The INT and QUIT signals for an invoked command are ignored if the com‐
1940 mand is followed by `&' and the MONITOR option is not active. The
1941 shell itself always ignores the QUIT signal. Otherwise, signals have
1942 the values inherited by the shell from its parent (but see the TRAPNAL
1943 special functions in the section `Functions').
1944
1945 Certain jobs are run asynchronously by the shell other than those ex‐
1946 plicitly put into the background; even in cases where the shell would
1947 usually wait for such jobs, an explicit exit command or exit due to the
1948 option ERR_EXIT will cause the shell to exit without waiting. Examples
1949 of such asynchronous jobs are process substitution, see the section
1950 PROCESS SUBSTITUTION in the zshexpn(1) manual page, and the handler
1951 processes for multios, see the section MULTIOS in the zshmisc(1) manual
1952 page.
1953
1955 The shell can perform integer and floating point arithmetic, either us‐
1956 ing the builtin let, or via a substitution of the form $((...)). For
1957 integers, the shell is usually compiled to use 8-byte precision where
1958 this is available, otherwise precision is 4 bytes. This can be tested,
1959 for example, by giving the command `print - $(( 12345678901 ))'; if the
1960 number appears unchanged, the precision is at least 8 bytes. Floating
1961 point arithmetic always uses the `double' type with whatever corre‐
1962 sponding precision is provided by the compiler and the library.
1963
1964 The let builtin command takes arithmetic expressions as arguments; each
1965 is evaluated separately. Since many of the arithmetic operators, as
1966 well as spaces, require quoting, an alternative form is provided: for
1967 any command which begins with a `((', all the characters until a match‐
1968 ing `))' are treated as a double-quoted expression and arithmetic ex‐
1969 pansion performed as for an argument of let. More precisely, `((...))'
1970 is equivalent to `let "..."'. The return status is 0 if the arithmetic
1971 value of the expression is non-zero, 1 if it is zero, and 2 if an error
1972 occurred.
1973
1974 For example, the following statement
1975
1976 (( val = 2 + 1 ))
1977
1978 is equivalent to
1979
1980 let "val = 2 + 1"
1981
1982 both assigning the value 3 to the shell variable val and returning a
1983 zero status.
1984
1985 Integers can be in bases other than 10. A leading `0x' or `0X' denotes
1986 hexadecimal and a leading `0b' or `0B' binary. Integers may also be of
1987 the form `base#n', where base is a decimal number between two and
1988 thirty-six representing the arithmetic base and n is a number in that
1989 base (for example, `16#ff' is 255 in hexadecimal). The base# may also
1990 be omitted, in which case base 10 is used. For backwards compatibility
1991 the form `[base]n' is also accepted.
1992
1993 An integer expression or a base given in the form `base#n' may contain
1994 underscores (`_') after the leading digit for visual guidance; these
1995 are ignored in computation. Examples are 1_000_000 or 0xffff_ffff
1996 which are equivalent to 1000000 and 0xffffffff respectively.
1997
1998 It is also possible to specify a base to be used for output in the form
1999 `[#base]', for example `[#16]'. This is used when outputting arith‐
2000 metical substitutions or when assigning to scalar parameters, but an
2001 explicitly defined integer or floating point parameter will not be af‐
2002 fected. If an integer variable is implicitly defined by an arithmetic
2003 expression, any base specified in this way will be set as the vari‐
2004 able's output arithmetic base as if the option `-i base' to the typeset
2005 builtin had been used. The expression has no precedence and if it oc‐
2006 curs more than once in a mathematical expression, the last encountered
2007 is used. For clarity it is recommended that it appear at the beginning
2008 of an expression. As an example:
2009
2010 typeset -i 16 y
2011 print $(( [#8] x = 32, y = 32 ))
2012 print $x $y
2013
2014 outputs first `8#40', the rightmost value in the given output base, and
2015 then `8#40 16#20', because y has been explicitly declared to have out‐
2016 put base 16, while x (assuming it does not already exist) is implicitly
2017 typed by the arithmetic evaluation, where it acquires the output base
2018 8.
2019
2020 The base may be replaced or followed by an underscore, which may itself
2021 be followed by a positive integer (if it is missing the value 3 is
2022 used). This indicates that underscores should be inserted into the
2023 output string, grouping the number for visual clarity. The following
2024 integer specifies the number of digits to group together. For example:
2025
2026 setopt cbases
2027 print $(( [#16_4] 65536 ** 2 ))
2028
2029 outputs `0x1_0000_0000'.
2030
2031 The feature can be used with floating point numbers, in which case the
2032 base must be omitted; grouping is away from the decimal point. For ex‐
2033 ample,
2034
2035 zmodload zsh/mathfunc
2036 print $(( [#_] sqrt(1e7) ))
2037
2038 outputs `3_162.277_660_168_379_5' (the number of decimal places shown
2039 may vary).
2040
2041 If the C_BASES option is set, hexadecimal numbers are output in the
2042 standard C format, for example `0xFF' instead of the usual `16#FF'. If
2043 the option OCTAL_ZEROES is also set (it is not by default), octal num‐
2044 bers will be treated similarly and hence appear as `077' instead of
2045 `8#77'. This option has no effect on the output of bases other than
2046 hexadecimal and octal, and these formats are always understood on in‐
2047 put.
2048
2049 When an output base is specified using the `[#base]' syntax, an appro‐
2050 priate base prefix will be output if necessary, so that the value out‐
2051 put is valid syntax for input. If the # is doubled, for example
2052 `[##16]', then no base prefix is output.
2053
2054 Floating point constants are recognized by the presence of a decimal
2055 point or an exponent. The decimal point may be the first character of
2056 the constant, but the exponent character e or E may not, as it will be
2057 taken for a parameter name. All numeric parts (before and after the
2058 decimal point and in the exponent) may contain underscores after the
2059 leading digit for visual guidance; these are ignored in computation.
2060
2061 An arithmetic expression uses nearly the same syntax and associativity
2062 of expressions as in C.
2063
2064 In the native mode of operation, the following operators are supported
2065 (listed in decreasing order of precedence):
2066
2067 + - ! ~ ++ --
2068 unary plus/minus, logical NOT, complement, {pre,post}{in,de}cre‐
2069 ment
2070 << >> bitwise shift left, right
2071 & bitwise AND
2072 ^ bitwise XOR
2073 | bitwise OR
2074 ** exponentiation
2075 * / % multiplication, division, modulus (remainder)
2076 + - addition, subtraction
2077 < > <= >=
2078 comparison
2079 == != equality and inequality
2080 && logical AND
2081 || ^^ logical OR, XOR
2082 ? : ternary operator
2083 = += -= *= /= %= &= ^= |= <<= >>= &&= ||= ^^= **=
2084 assignment
2085 , comma operator
2086
2087 The operators `&&', `||', `&&=', and `||=' are short-circuiting, and
2088 only one of the latter two expressions in a ternary operator is evalu‐
2089 ated. Note the precedence of the bitwise AND, OR, and XOR operators.
2090
2091 With the option C_PRECEDENCES the precedences (but no other properties)
2092 of the operators are altered to be the same as those in most other lan‐
2093 guages that support the relevant operators:
2094
2095 + - ! ~ ++ --
2096 unary plus/minus, logical NOT, complement, {pre,post}{in,de}cre‐
2097 ment
2098 ** exponentiation
2099 * / % multiplication, division, modulus (remainder)
2100 + - addition, subtraction
2101 << >> bitwise shift left, right
2102 < > <= >=
2103 comparison
2104 == != equality and inequality
2105 & bitwise AND
2106 ^ bitwise XOR
2107 | bitwise OR
2108 && logical AND
2109 ^^ logical XOR
2110 || logical OR
2111 ? : ternary operator
2112 = += -= *= /= %= &= ^= |= <<= >>= &&= ||= ^^= **=
2113 assignment
2114 , comma operator
2115
2116 Note the precedence of exponentiation in both cases is below that of
2117 unary operators, hence `-3**2' evaluates as `9', not `-9'. Use paren‐
2118 theses where necessary: `-(3**2)'. This is for compatibility with
2119 other shells.
2120
2121 Mathematical functions can be called with the syntax `func(args)',
2122 where the function decides if the args is used as a string or a
2123 comma-separated list of arithmetic expressions. The shell currently de‐
2124 fines no mathematical functions by default, but the module zsh/mathfunc
2125 may be loaded with the zmodload builtin to provide standard floating
2126 point mathematical functions.
2127
2128 An expression of the form `##x' where x is any character sequence such
2129 as `a', `^A', or `\M-\C-x' gives the value of this character and an ex‐
2130 pression of the form `#name' gives the value of the first character of
2131 the contents of the parameter name. Character values are according to
2132 the character set used in the current locale; for multibyte character
2133 handling the option MULTIBYTE must be set. Note that this form is dif‐
2134 ferent from `$#name', a standard parameter substitution which gives the
2135 length of the parameter name. `#\' is accepted instead of `##', but
2136 its use is deprecated.
2137
2138 Named parameters and subscripted arrays can be referenced by name
2139 within an arithmetic expression without using the parameter expansion
2140 syntax. For example,
2141
2142 ((val2 = val1 * 2))
2143
2144 assigns twice the value of $val1 to the parameter named val2.
2145
2146 An internal integer representation of a named parameter can be speci‐
2147 fied with the integer builtin. Arithmetic evaluation is performed on
2148 the value of each assignment to a named parameter declared integer in
2149 this manner. Assigning a floating point number to an integer results
2150 in rounding towards zero.
2151
2152 Likewise, floating point numbers can be declared with the float
2153 builtin; there are two types, differing only in their output format, as
2154 described for the typeset builtin. The output format can be bypassed
2155 by using arithmetic substitution instead of the parameter substitution,
2156 i.e. `${float}' uses the defined format, but `$((float))' uses a
2157 generic floating point format.
2158
2159 Promotion of integer to floating point values is performed where neces‐
2160 sary. In addition, if any operator which requires an integer (`&',
2161 `|', `^', `<<', `>>' and their equivalents with assignment) is given a
2162 floating point argument, it will be silently rounded towards zero ex‐
2163 cept for `~' which rounds down.
2164
2165 Users should beware that, in common with many other programming lan‐
2166 guages but not software designed for calculation, the evaluation of an
2167 expression in zsh is taken a term at a time and promotion of integers
2168 to floating point does not occur in terms only containing integers. A
2169 typical result of this is that a division such as 6/8 is truncated, in
2170 this being rounded towards 0. The FORCE_FLOAT shell option can be used
2171 in scripts or functions where floating point evaluation is required
2172 throughout.
2173
2174 Scalar variables can hold integer or floating point values at different
2175 times; there is no memory of the numeric type in this case.
2176
2177 If a variable is first assigned in a numeric context without previously
2178 being declared, it will be implicitly typed as integer or float and re‐
2179 tain that type either until the type is explicitly changed or until the
2180 end of the scope. This can have unforeseen consequences. For example,
2181 in the loop
2182
2183 for (( f = 0; f < 1; f += 0.1 )); do
2184 # use $f
2185 done
2186
2187 if f has not already been declared, the first assignment will cause it
2188 to be created as an integer, and consequently the operation `f += 0.1'
2189 will always cause the result to be truncated to zero, so that the loop
2190 will fail. A simple fix would be to turn the initialization into `f =
2191 0.0'. It is therefore best to declare numeric variables with explicit
2192 types.
2193
2195 A conditional expression is used with the [[ compound command to test
2196 attributes of files and to compare strings. Each expression can be
2197 constructed from one or more of the following unary or binary expres‐
2198 sions:
2199
2200 -a file
2201 true if file exists.
2202
2203 -b file
2204 true if file exists and is a block special file.
2205
2206 -c file
2207 true if file exists and is a character special file.
2208
2209 -d file
2210 true if file exists and is a directory.
2211
2212 -e file
2213 true if file exists.
2214
2215 -f file
2216 true if file exists and is a regular file.
2217
2218 -g file
2219 true if file exists and has its setgid bit set.
2220
2221 -h file
2222 true if file exists and is a symbolic link.
2223
2224 -k file
2225 true if file exists and has its sticky bit set.
2226
2227 -n string
2228 true if length of string is non-zero.
2229
2230 -o option
2231 true if option named option is on. option may be a single char‐
2232 acter, in which case it is a single letter option name. (See
2233 the section `Specifying Options'.)
2234
2235 When no option named option exists, and the POSIX_BUILTINS op‐
2236 tion hasn't been set, return 3 with a warning. If that option
2237 is set, return 1 with no warning.
2238
2239 -p file
2240 true if file exists and is a FIFO special file (named pipe).
2241
2242 -r file
2243 true if file exists and is readable by current process.
2244
2245 -s file
2246 true if file exists and has size greater than zero.
2247
2248 -t fd true if file descriptor number fd is open and associated with a
2249 terminal device. (note: fd is not optional)
2250
2251 -u file
2252 true if file exists and has its setuid bit set.
2253
2254 -v varname
2255 true if shell variable varname is set.
2256
2257 -w file
2258 true if file exists and is writable by current process.
2259
2260 -x file
2261 true if file exists and is executable by current process. If
2262 file exists and is a directory, then the current process has
2263 permission to search in the directory.
2264
2265 -z string
2266 true if length of string is zero.
2267
2268 -L file
2269 true if file exists and is a symbolic link.
2270
2271 -O file
2272 true if file exists and is owned by the effective user ID of
2273 this process.
2274
2275 -G file
2276 true if file exists and its group matches the effective group ID
2277 of this process.
2278
2279 -S file
2280 true if file exists and is a socket.
2281
2282 -N file
2283 true if file exists and its access time is not newer than its
2284 modification time.
2285
2286 file1 -nt file2
2287 true if file1 exists and is newer than file2.
2288
2289 file1 -ot file2
2290 true if file1 exists and is older than file2.
2291
2292 file1 -ef file2
2293 true if file1 and file2 exist and refer to the same file.
2294
2295 string = pattern
2296 string == pattern
2297 true if string matches pattern. The two forms are exactly
2298 equivalent. The `=' form is the traditional shell syntax (and
2299 hence the only one generally used with the test and [ builtins);
2300 the `==' form provides compatibility with other sorts of com‐
2301 puter language.
2302
2303 string != pattern
2304 true if string does not match pattern.
2305
2306 string =~ regexp
2307 true if string matches the regular expression regexp. If the
2308 option RE_MATCH_PCRE is set regexp is tested as a PCRE regular
2309 expression using the zsh/pcre module, else it is tested as a
2310 POSIX extended regular expression using the zsh/regex module.
2311 Upon successful match, some variables will be updated; no vari‐
2312 ables are changed if the matching fails.
2313
2314 If the option BASH_REMATCH is not set the scalar parameter MATCH
2315 is set to the substring that matched the pattern and the integer
2316 parameters MBEGIN and MEND to the index of the start and end,
2317 respectively, of the match in string, such that if string is
2318 contained in variable var the expression `${var[$MBEGIN,$MEND]}'
2319 is identical to `$MATCH'. The setting of the option KSH_ARRAYS
2320 is respected. Likewise, the array match is set to the sub‐
2321 strings that matched parenthesised subexpressions and the arrays
2322 mbegin and mend to the indices of the start and end positions,
2323 respectively, of the substrings within string. The arrays are
2324 not set if there were no parenthesised subexpressions. For ex‐
2325 ample, if the string `a short string' is matched against the
2326 regular expression `s(...)t', then (assuming the option KSH_AR‐
2327 RAYS is not set) MATCH, MBEGIN and MEND are `short', 3 and 7,
2328 respectively, while match, mbegin and mend are single entry ar‐
2329 rays containing the strings `hor', `4' and `6', respectively.
2330
2331 If the option BASH_REMATCH is set the array BASH_REMATCH is set
2332 to the substring that matched the pattern followed by the sub‐
2333 strings that matched parenthesised subexpressions within the
2334 pattern.
2335
2336 string1 < string2
2337 true if string1 comes before string2 based on ASCII value of
2338 their characters.
2339
2340 string1 > string2
2341 true if string1 comes after string2 based on ASCII value of
2342 their characters.
2343
2344 exp1 -eq exp2
2345 true if exp1 is numerically equal to exp2. Note that for purely
2346 numeric comparisons use of the ((...)) builtin described in the
2347 section `ARITHMETIC EVALUATION' is more convenient than condi‐
2348 tional expressions.
2349
2350 exp1 -ne exp2
2351 true if exp1 is numerically not equal to exp2.
2352
2353 exp1 -lt exp2
2354 true if exp1 is numerically less than exp2.
2355
2356 exp1 -gt exp2
2357 true if exp1 is numerically greater than exp2.
2358
2359 exp1 -le exp2
2360 true if exp1 is numerically less than or equal to exp2.
2361
2362 exp1 -ge exp2
2363 true if exp1 is numerically greater than or equal to exp2.
2364
2365 ( exp )
2366 true if exp is true.
2367
2368 ! exp true if exp is false.
2369
2370 exp1 && exp2
2371 true if exp1 and exp2 are both true.
2372
2373 exp1 || exp2
2374 true if either exp1 or exp2 is true.
2375
2376 For compatibility, if there is a single argument that is not syntacti‐
2377 cally significant, typically a variable, the condition is treated as a
2378 test for whether the expression expands as a string of non-zero length.
2379 In other words, [[ $var ]] is the same as [[ -n $var ]]. It is recom‐
2380 mended that the second, explicit, form be used where possible.
2381
2382 Normal shell expansion is performed on the file, string and pattern ar‐
2383 guments, but the result of each expansion is constrained to be a single
2384 word, similar to the effect of double quotes.
2385
2386 Filename generation is not performed on any form of argument to condi‐
2387 tions. However, it can be forced in any case where normal shell expan‐
2388 sion is valid and when the option EXTENDED_GLOB is in effect by using
2389 an explicit glob qualifier of the form (#q) at the end of the string.
2390 A normal glob qualifier expression may appear between the `q' and the
2391 closing parenthesis; if none appears the expression has no effect be‐
2392 yond causing filename generation. The results of filename generation
2393 are joined together to form a single word, as with the results of other
2394 forms of expansion.
2395
2396 This special use of filename generation is only available with the [[
2397 syntax. If the condition occurs within the [ or test builtin commands
2398 then globbing occurs instead as part of normal command line expansion
2399 before the condition is evaluated. In this case it may generate multi‐
2400 ple words which are likely to confuse the syntax of the test command.
2401
2402 For example,
2403
2404 [[ -n file*(#qN) ]]
2405
2406 produces status zero if and only if there is at least one file in the
2407 current directory beginning with the string `file'. The globbing qual‐
2408 ifier N ensures that the expression is empty if there is no matching
2409 file.
2410
2411 Pattern metacharacters are active for the pattern arguments; the pat‐
2412 terns are the same as those used for filename generation, see zsh‐
2413 expn(1), but there is no special behaviour of `/' nor initial dots, and
2414 no glob qualifiers are allowed.
2415
2416 In each of the above expressions, if file is of the form `/dev/fd/n',
2417 where n is an integer, then the test applied to the open file whose de‐
2418 scriptor number is n, even if the underlying system does not support
2419 the /dev/fd directory.
2420
2421 In the forms which do numeric comparison, the expressions exp undergo
2422 arithmetic expansion as if they were enclosed in $((...)).
2423
2424 For example, the following:
2425
2426 [[ ( -f foo || -f bar ) && $report = y* ]] && print File exists.
2427
2428 tests if either file foo or file bar exists, and if so, if the value of
2429 the parameter report begins with `y'; if the complete condition is
2430 true, the message `File exists.' is printed.
2431
2433 Prompt sequences undergo a special form of expansion. This type of ex‐
2434 pansion is also available using the -P option to the print builtin.
2435
2436 If the PROMPT_SUBST option is set, the prompt string is first subjected
2437 to parameter expansion, command substitution and arithmetic expansion.
2438 See zshexpn(1).
2439
2440 Certain escape sequences may be recognised in the prompt string.
2441
2442 If the PROMPT_BANG option is set, a `!' in the prompt is replaced by
2443 the current history event number. A literal `!' may then be repre‐
2444 sented as `!!'.
2445
2446 If the PROMPT_PERCENT option is set, certain escape sequences that
2447 start with `%' are expanded. Many escapes are followed by a single
2448 character, although some of these take an optional integer argument
2449 that should appear between the `%' and the next character of the se‐
2450 quence. More complicated escape sequences are available to provide
2451 conditional expansion.
2452
2454 Special characters
2455 %% A `%'.
2456
2457 %) A `)'.
2458
2459 Login information
2460 %l The line (tty) the user is logged in on, without `/dev/' prefix.
2461 If the name starts with `/dev/tty', that prefix is stripped.
2462
2463 %M The full machine hostname.
2464
2465 %m The hostname up to the first `.'. An integer may follow the `%'
2466 to specify how many components of the hostname are desired.
2467 With a negative integer, trailing components of the hostname are
2468 shown.
2469
2470 %n $USERNAME.
2471
2472 %y The line (tty) the user is logged in on, without `/dev/' prefix.
2473 This does not treat `/dev/tty' names specially.
2474
2475 Shell state
2476 %# A `#' if the shell is running with privileges, a `%' if not.
2477 Equivalent to `%(!.#.%%)'. The definition of `privileged', for
2478 these purposes, is that either the effective user ID is zero,
2479 or, if POSIX.1e capabilities are supported, that at least one
2480 capability is raised in either the Effective or Inheritable ca‐
2481 pability vectors.
2482
2483 %? The return status of the last command executed just before the
2484 prompt.
2485
2486 %_ The status of the parser, i.e. the shell constructs (like `if'
2487 and `for') that have been started on the command line. If given
2488 an integer number that many strings will be printed; zero or
2489 negative or no integer means print as many as there are. This
2490 is most useful in prompts PS2 for continuation lines and PS4 for
2491 debugging with the XTRACE option; in the latter case it will
2492 also work non-interactively.
2493
2494 %^ The status of the parser in reverse. This is the same as `%_'
2495 other than the order of strings. It is often used in RPS2.
2496
2497 %d
2498 %/ Current working directory. If an integer follows the `%', it
2499 specifies a number of trailing components of the current working
2500 directory to show; zero means the whole path. A negative inte‐
2501 ger specifies leading components, i.e. %-1d specifies the first
2502 component.
2503
2504 %~ As %d and %/, but if the current working directory starts with
2505 $HOME, that part is replaced by a `~'. Furthermore, if it has a
2506 named directory as its prefix, that part is replaced by a `~'
2507 followed by the name of the directory, but only if the result is
2508 shorter than the full path; see Dynamic and Static named direc‐
2509 tories in zshexpn(1).
2510
2511 %e Evaluation depth of the current sourced file, shell function, or
2512 eval. This is incremented or decremented every time the value
2513 of %N is set or reverted to a previous value, respectively.
2514 This is most useful for debugging as part of $PS4.
2515
2516 %h
2517 %! Current history event number.
2518
2519 %i The line number currently being executed in the script, sourced
2520 file, or shell function given by %N. This is most useful for
2521 debugging as part of $PS4.
2522
2523 %I The line number currently being executed in the file %x. This
2524 is similar to %i, but the line number is always a line number in
2525 the file where the code was defined, even if the code is a shell
2526 function.
2527
2528 %j The number of jobs.
2529
2530 %L The current value of $SHLVL.
2531
2532 %N The name of the script, sourced file, or shell function that zsh
2533 is currently executing, whichever was started most recently. If
2534 there is none, this is equivalent to the parameter $0. An inte‐
2535 ger may follow the `%' to specify a number of trailing path com‐
2536 ponents to show; zero means the full path. A negative integer
2537 specifies leading components.
2538
2539 %x The name of the file containing the source code currently being
2540 executed. This behaves as %N except that function and eval com‐
2541 mand names are not shown, instead the file where they were de‐
2542 fined.
2543
2544 %c
2545 %.
2546 %C Trailing component of the current working directory. An integer
2547 may follow the `%' to get more than one component. Unless `%C'
2548 is used, tilde contraction is performed first. These are depre‐
2549 cated as %c and %C are equivalent to %1~ and %1/, respectively,
2550 while explicit positive integers have the same effect as for the
2551 latter two sequences.
2552
2553 Date and time
2554 %D The date in yy-mm-dd format.
2555
2556 %T Current time of day, in 24-hour format.
2557
2558 %t
2559 %@ Current time of day, in 12-hour, am/pm format.
2560
2561 %* Current time of day in 24-hour format, with seconds.
2562
2563 %w The date in day-dd format.
2564
2565 %W The date in mm/dd/yy format.
2566
2567 %D{string}
2568 string is formatted using the strftime function. See strf‐
2569 time(3) for more details. Various zsh extensions provide num‐
2570 bers with no leading zero or space if the number is a single
2571 digit:
2572
2573 %f a day of the month
2574 %K the hour of the day on the 24-hour clock
2575 %L the hour of the day on the 12-hour clock
2576
2577 In addition, if the system supports the POSIX gettimeofday sys‐
2578 tem call, %. provides decimal fractions of a second since the
2579 epoch with leading zeroes. By default three decimal places are
2580 provided, but a number of digits up to 9 may be given following
2581 the %; hence %6. outputs microseconds, and %9. outputs nanosec‐
2582 onds. (The latter requires a nanosecond-precision clock_get‐
2583 time; systems lacking this will return a value multiplied by the
2584 appropriate power of 10.) A typical example of this is the for‐
2585 mat `%D{%H:%M:%S.%.}'.
2586
2587 The GNU extension %N is handled as a synonym for %9..
2588
2589 Additionally, the GNU extension that a `-' between the % and the
2590 format character causes a leading zero or space to be stripped
2591 is handled directly by the shell for the format characters d, f,
2592 H, k, l, m, M, S and y; any other format characters are provided
2593 to the system's strftime(3) with any leading `-' present, so the
2594 handling is system dependent. Further GNU (or other) extensions
2595 are also passed to strftime(3) and may work if the system sup‐
2596 ports them.
2597
2598 Visual effects
2599 %B (%b)
2600 Start (stop) boldface mode.
2601
2602 %E Clear to end of line.
2603
2604 %U (%u)
2605 Start (stop) underline mode.
2606
2607 %S (%s)
2608 Start (stop) standout mode.
2609
2610 %F (%f)
2611 Start (stop) using a different foreground colour, if supported
2612 by the terminal. The colour may be specified two ways: either
2613 as a numeric argument, as normal, or by a sequence in braces
2614 following the %F, for example %F{red}. In the latter case the
2615 values allowed are as described for the fg zle_highlight attri‐
2616 bute; see Character Highlighting in zshzle(1). This means that
2617 numeric colours are allowed in the second format also.
2618
2619 %K (%k)
2620 Start (stop) using a different bacKground colour. The syntax is
2621 identical to that for %F and %f.
2622
2623 %{...%}
2624 Include a string as a literal escape sequence. The string
2625 within the braces should not change the cursor position. Brace
2626 pairs can nest.
2627
2628 A positive numeric argument between the % and the { is treated
2629 as described for %G below.
2630
2631 %G Within a %{...%} sequence, include a `glitch': that is, assume
2632 that a single character width will be output. This is useful
2633 when outputting characters that otherwise cannot be correctly
2634 handled by the shell, such as the alternate character set on
2635 some terminals. The characters in question can be included
2636 within a %{...%} sequence together with the appropriate number
2637 of %G sequences to indicate the correct width. An integer be‐
2638 tween the `%' and `G' indicates a character width other than
2639 one. Hence %{seq%2G%} outputs seq and assumes it takes up the
2640 width of two standard characters.
2641
2642 Multiple uses of %G accumulate in the obvious fashion; the posi‐
2643 tion of the %G is unimportant. Negative integers are not han‐
2644 dled.
2645
2646 Note that when prompt truncation is in use it is advisable to
2647 divide up output into single characters within each %{...%}
2648 group so that the correct truncation point can be found.
2649
2651 %v The value of the first element of the psvar array parameter.
2652 Following the `%' with an integer gives that element of the ar‐
2653 ray. Negative integers count from the end of the array.
2654
2655 %(x.true-text.false-text)
2656 Specifies a ternary expression. The character following the x
2657 is arbitrary; the same character is used to separate the text
2658 for the `true' result from that for the `false' result. This
2659 separator may not appear in the true-text, except as part of a
2660 %-escape sequence. A `)' may appear in the false-text as `%)'.
2661 true-text and false-text may both contain arbitrarily-nested es‐
2662 cape sequences, including further ternary expressions.
2663
2664 The left parenthesis may be preceded or followed by a positive
2665 integer n, which defaults to zero. A negative integer will be
2666 multiplied by -1, except as noted below for `l'. The test char‐
2667 acter x may be any of the following:
2668
2669 ! True if the shell is running with privileges.
2670 # True if the effective uid of the current process is n.
2671 ? True if the exit status of the last command was n.
2672 _ True if at least n shell constructs were started.
2673 C
2674 / True if the current absolute path has at least n elements
2675 relative to the root directory, hence / is counted as 0
2676 elements.
2677 c
2678 .
2679 ~ True if the current path, with prefix replacement, has at
2680 least n elements relative to the root directory, hence /
2681 is counted as 0 elements.
2682 D True if the month is equal to n (January = 0).
2683 d True if the day of the month is equal to n.
2684 e True if the evaluation depth is at least n.
2685 g True if the effective gid of the current process is n.
2686 j True if the number of jobs is at least n.
2687 L True if the SHLVL parameter is at least n.
2688 l True if at least n characters have already been printed
2689 on the current line. When n is negative, true if at
2690 least abs(n) characters remain before the opposite margin
2691 (thus the left margin for RPROMPT).
2692 S True if the SECONDS parameter is at least n.
2693 T True if the time in hours is equal to n.
2694 t True if the time in minutes is equal to n.
2695 v True if the array psvar has at least n elements.
2696 V True if element n of the array psvar is set and
2697 non-empty.
2698 w True if the day of the week is equal to n (Sunday = 0).
2699
2700 %<string<
2701 %>string>
2702 %[xstring]
2703 Specifies truncation behaviour for the remainder of the prompt
2704 string. The third, deprecated, form is equivalent to
2705 `%xstringx', i.e. x may be `<' or `>'. The string will be dis‐
2706 played in place of the truncated portion of any string; note
2707 this does not undergo prompt expansion.
2708
2709 The numeric argument, which in the third form may appear immedi‐
2710 ately after the `[', specifies the maximum permitted length of
2711 the various strings that can be displayed in the prompt. In the
2712 first two forms, this numeric argument may be negative, in which
2713 case the truncation length is determined by subtracting the ab‐
2714 solute value of the numeric argument from the number of charac‐
2715 ter positions remaining on the current prompt line. If this re‐
2716 sults in a zero or negative length, a length of 1 is used. In
2717 other words, a negative argument arranges that after truncation
2718 at least n characters remain before the right margin (left mar‐
2719 gin for RPROMPT).
2720
2721 The forms with `<' truncate at the left of the string, and the
2722 forms with `>' truncate at the right of the string. For exam‐
2723 ple, if the current directory is `/home/pike', the prompt
2724 `%8<..<%/' will expand to `..e/pike'. In this string, the ter‐
2725 minating character (`<', `>' or `]'), or in fact any character,
2726 may be quoted by a preceding `\'; note when using print -P, how‐
2727 ever, that this must be doubled as the string is also subject to
2728 standard print processing, in addition to any backslashes re‐
2729 moved by a double quoted string: the worst case is therefore
2730 `print -P "%<\\\\<<..."'.
2731
2732 If the string is longer than the specified truncation length, it
2733 will appear in full, completely replacing the truncated string.
2734
2735 The part of the prompt string to be truncated runs to the end of
2736 the string, or to the end of the next enclosing group of the
2737 `%(' construct, or to the next truncation encountered at the
2738 same grouping level (i.e. truncations inside a `%(' are sepa‐
2739 rate), which ever comes first. In particular, a truncation with
2740 argument zero (e.g., `%<<') marks the end of the range of the
2741 string to be truncated while turning off truncation from there
2742 on. For example, the prompt `%10<...<%~%<<%# ' will print a
2743 truncated representation of the current directory, followed by a
2744 `%' or `#', followed by a space. Without the `%<<', those two
2745 characters would be included in the string to be truncated.
2746 Note that `%-0<<' is not equivalent to `%<<' but specifies that
2747 the prompt is truncated at the right margin.
2748
2749 Truncation applies only within each individual line of the
2750 prompt, as delimited by embedded newlines (if any). If the to‐
2751 tal length of any line of the prompt after truncation is greater
2752 than the terminal width, or if the part to be truncated contains
2753 embedded newlines, truncation behavior is undefined and may
2754 change in a future version of the shell. Use
2755 `%-n(l.true-text.false-text)' to remove parts of the prompt when
2756 the available space is less than n.
2757
2758
2759
2760ZSHEXPN(1) General Commands Manual ZSHEXPN(1)
2761
2762
2763
2765 zshexpn - zsh expansion and substitution
2766
2768 The following types of expansions are performed in the indicated order
2769 in five steps:
2770
2771 History Expansion
2772 This is performed only in interactive shells.
2773
2774 Alias Expansion
2775 Aliases are expanded immediately before the command line is
2776 parsed as explained under Aliasing in zshmisc(1).
2777
2778 Process Substitution
2779 Parameter Expansion
2780 Command Substitution
2781 Arithmetic Expansion
2782 Brace Expansion
2783 These five are performed in left-to-right fashion. On each ar‐
2784 gument, any of the five steps that are needed are performed one
2785 after the other. Hence, for example, all the parts of parameter
2786 expansion are completed before command substitution is started.
2787 After these expansions, all unquoted occurrences of the charac‐
2788 ters `\',`'' and `"' are removed.
2789
2790 Filename Expansion
2791 If the SH_FILE_EXPANSION option is set, the order of expansion
2792 is modified for compatibility with sh and ksh. In that case
2793 filename expansion is performed immediately after alias expan‐
2794 sion, preceding the set of five expansions mentioned above.
2795
2796 Filename Generation
2797 This expansion, commonly referred to as globbing, is always done
2798 last.
2799
2800 The following sections explain the types of expansion in detail.
2801
2803 History expansion allows you to use words from previous command lines
2804 in the command line you are typing. This simplifies spelling correc‐
2805 tions and the repetition of complicated commands or arguments.
2806
2807 Immediately before execution, each command is saved in the history
2808 list, the size of which is controlled by the HISTSIZE parameter. The
2809 one most recent command is always retained in any case. Each saved
2810 command in the history list is called a history event and is assigned a
2811 number, beginning with 1 (one) when the shell starts up. The history
2812 number that you may see in your prompt (see EXPANSION OF PROMPT SE‐
2813 QUENCES in zshmisc(1)) is the number that is to be assigned to the next
2814 command.
2815
2816 Overview
2817 A history expansion begins with the first character of the histchars
2818 parameter, which is `!' by default, and may occur anywhere on the com‐
2819 mand line, including inside double quotes (but not inside single quotes
2820 '...' or C-style quotes $'...' nor when escaped with a backslash).
2821
2822 The first character is followed by an optional event designator (see
2823 the section `Event Designators') and then an optional word designator
2824 (the section `Word Designators'); if neither of these designators is
2825 present, no history expansion occurs.
2826
2827 Input lines containing history expansions are echoed after being ex‐
2828 panded, but before any other expansions take place and before the com‐
2829 mand is executed. It is this expanded form that is recorded as the
2830 history event for later references.
2831
2832 History expansions do not nest.
2833
2834 By default, a history reference with no event designator refers to the
2835 same event as any preceding history reference on that command line; if
2836 it is the only history reference in a command, it refers to the previ‐
2837 ous command. However, if the option CSH_JUNKIE_HISTORY is set, then
2838 every history reference with no event specification always refers to
2839 the previous command.
2840
2841 For example, `!' is the event designator for the previous command, so
2842 `!!:1' always refers to the first word of the previous command, and
2843 `!!$' always refers to the last word of the previous command. With
2844 CSH_JUNKIE_HISTORY set, then `!:1' and `!$' function in the same manner
2845 as `!!:1' and `!!$', respectively. Conversely, if CSH_JUNKIE_HISTORY
2846 is unset, then `!:1' and `!$' refer to the first and last words, re‐
2847 spectively, of the same event referenced by the nearest other history
2848 reference preceding them on the current command line, or to the previ‐
2849 ous command if there is no preceding reference.
2850
2851 The character sequence `^foo^bar' (where `^' is actually the second
2852 character of the histchars parameter) repeats the last command, replac‐
2853 ing the string foo with bar. More precisely, the sequence `^foo^bar^'
2854 is synonymous with `!!:s^foo^bar^', hence other modifiers (see the sec‐
2855 tion `Modifiers') may follow the final `^'. In particular,
2856 `^foo^bar^:G' performs a global substitution.
2857
2858 If the shell encounters the character sequence `!"' in the input, the
2859 history mechanism is temporarily disabled until the current list (see
2860 zshmisc(1)) is fully parsed. The `!"' is removed from the input, and
2861 any subsequent `!' characters have no special significance.
2862
2863 A less convenient but more comprehensible form of command history sup‐
2864 port is provided by the fc builtin.
2865
2866 Event Designators
2867 An event designator is a reference to a command-line entry in the his‐
2868 tory list. In the list below, remember that the initial `!' in each
2869 item may be changed to another character by setting the histchars pa‐
2870 rameter.
2871
2872 ! Start a history expansion, except when followed by a blank, new‐
2873 line, `=' or `('. If followed immediately by a word designator
2874 (see the section `Word Designators'), this forms a history ref‐
2875 erence with no event designator (see the section `Overview').
2876
2877 !! Refer to the previous command. By itself, this expansion re‐
2878 peats the previous command.
2879
2880 !n Refer to command-line n.
2881
2882 !-n Refer to the current command-line minus n.
2883
2884 !str Refer to the most recent command starting with str.
2885
2886 !?str[?]
2887 Refer to the most recent command containing str. The trailing
2888 `?' is necessary if this reference is to be followed by a modi‐
2889 fier or followed by any text that is not to be considered part
2890 of str.
2891
2892 !# Refer to the current command line typed in so far. The line is
2893 treated as if it were complete up to and including the word be‐
2894 fore the one with the `!#' reference.
2895
2896 !{...} Insulate a history reference from adjacent characters (if neces‐
2897 sary).
2898
2899 Word Designators
2900 A word designator indicates which word or words of a given command line
2901 are to be included in a history reference. A `:' usually separates the
2902 event specification from the word designator. It may be omitted only
2903 if the word designator begins with a `^', `$', `*', `-' or `%'. Word
2904 designators include:
2905
2906 0 The first input word (command).
2907 n The nth argument.
2908 ^ The first argument. That is, 1.
2909 $ The last argument.
2910 % The word matched by (the most recent) ?str search.
2911 x-y A range of words; x defaults to 0.
2912 * All the arguments, or a null value if there are none.
2913 x* Abbreviates `x-$'.
2914 x- Like `x*' but omitting word $.
2915
2916 Note that a `%' word designator works only when used in one of `!%',
2917 `!:%' or `!?str?:%', and only when used after a !? expansion (possibly
2918 in an earlier command). Anything else results in an error, although
2919 the error may not be the most obvious one.
2920
2921 Modifiers
2922 After the optional word designator, you can add a sequence of one or
2923 more of the following modifiers, each preceded by a `:'. These modi‐
2924 fiers also work on the result of filename generation and parameter ex‐
2925 pansion, except where noted.
2926
2927 a Turn a file name into an absolute path: prepends the current
2928 directory, if necessary; remove `.' path segments; and remove
2929 `..' path segments and the segments that immediately precede
2930 them.
2931
2932 This transformation is agnostic about what is in the filesystem,
2933 i.e. is on the logical, not the physical directory. It takes
2934 place in the same manner as when changing directories when nei‐
2935 ther of the options CHASE_DOTS or CHASE_LINKS is set. For exam‐
2936 ple, `/before/here/../after' is always transformed to `/be‐
2937 fore/after', regardless of whether `/before/here' exists or what
2938 kind of object (dir, file, symlink, etc.) it is.
2939
2940 A Turn a file name into an absolute path as the `a' modifier does,
2941 and then pass the result through the realpath(3) library func‐
2942 tion to resolve symbolic links.
2943
2944 Note: on systems that do not have a realpath(3) library func‐
2945 tion, symbolic links are not resolved, so on those systems `a'
2946 and `A' are equivalent.
2947
2948 Note: foo:A and realpath(foo) are different on some inputs. For
2949 realpath(foo) semantics, see the `P` modifier.
2950
2951 c Resolve a command name into an absolute path by searching the
2952 command path given by the PATH variable. This does not work for
2953 commands containing directory parts. Note also that this does
2954 not usually work as a glob qualifier unless a file of the same
2955 name is found in the current directory.
2956
2957 e Remove all but the part of the filename extension following the
2958 `.'; see the definition of the filename extension in the de‐
2959 scription of the r modifier below. Note that according to that
2960 definition the result will be empty if the string ends with a
2961 `.'.
2962
2963 h [ digits ]
2964 Remove a trailing pathname component, shortening the path by one
2965 directory level: this is the `head' of the pathname. This works
2966 like `dirname'. If the h is followed immediately (with no spa‐
2967 ces or other separator) by any number of decimal digits, and the
2968 value of the resulting number is non-zero, that number of lead‐
2969 ing components is preserved instead of the final component being
2970 removed. In an absolute path the leading `/' is the first com‐
2971 ponent, so, for example, if var=/my/path/to/something, then
2972 ${var:h3} substitutes /my/path. Consecutive `/'s are treated
2973 the same as a single `/'. In parameter substitution, digits may
2974 only be used if the expression is in braces, so for example the
2975 short form substitution $var:h2 is treated as ${var:h}2, not as
2976 ${var:h2}. No restriction applies to the use of digits in his‐
2977 tory substitution or globbing qualifiers. If more components
2978 are requested than are present, the entire path is substituted
2979 (so this does not trigger a `failed modifier' error in history
2980 expansion).
2981
2982 l Convert the words to all lowercase.
2983
2984 p Print the new command but do not execute it. Only works with
2985 history expansion.
2986
2987 P Turn a file name into an absolute path, like realpath(3). The
2988 resulting path will be absolute, will refer to the same direc‐
2989 tory entry as the input filename, and none of its components
2990 will be symbolic links or equal to `.' or `..'.
2991
2992 Unlike realpath(3), non-existent trailing components are permit‐
2993 ted and preserved.
2994
2995 q Quote the substituted words, escaping further substitutions.
2996 Works with history expansion and parameter expansion, though for
2997 parameters it is only useful if the resulting text is to be
2998 re-evaluated such as by eval.
2999
3000 Q Remove one level of quotes from the substituted words.
3001
3002 r Remove a filename extension leaving the root name. Strings with
3003 no filename extension are not altered. A filename extension is
3004 a `.' followed by any number of characters (including zero) that
3005 are neither `.' nor `/' and that continue to the end of the
3006 string. For example, the extension of `foo.orig.c' is `.c', and
3007 `dir.c/foo' has no extension.
3008
3009 s/l/r[/]
3010 Substitute r for l as described below. The substitution is done
3011 only for the first string that matches l. For arrays and for
3012 filename generation, this applies to each word of the expanded
3013 text. See below for further notes on substitutions.
3014
3015 The forms `gs/l/r' and `s/l/r/:G' perform global substitution,
3016 i.e. substitute every occurrence of r for l. Note that the g or
3017 :G must appear in exactly the position shown.
3018
3019 See further notes on this form of substitution below.
3020
3021 & Repeat the previous s substitution. Like s, may be preceded im‐
3022 mediately by a g. In parameter expansion the & must appear in‐
3023 side braces, and in filename generation it must be quoted with a
3024 backslash.
3025
3026 t [ digits ]
3027 Remove all leading pathname components, leaving the final compo‐
3028 nent (tail). This works like `basename'. Any trailing slashes
3029 are first removed. Decimal digits are handled as described
3030 above for (h), but in this case that number of trailing compo‐
3031 nents is preserved instead of the default 1; 0 is treated the
3032 same as 1.
3033
3034 u Convert the words to all uppercase.
3035
3036 x Like q, but break into words at whitespace. Does not work with
3037 parameter expansion.
3038
3039 The s/l/r/ substitution works as follows. By default the left-hand
3040 side of substitutions are not patterns, but character strings. Any
3041 character can be used as the delimiter in place of `/'. A backslash
3042 quotes the delimiter character. The character `&', in the
3043 right-hand-side r, is replaced by the text from the left-hand-side l.
3044 The `&' can be quoted with a backslash. A null l uses the previous
3045 string either from the previous l or from the contextual scan string s
3046 from `!?s'. You can omit the rightmost delimiter if a newline immedi‐
3047 ately follows r; the rightmost `?' in a context scan can similarly be
3048 omitted. Note the same record of the last l and r is maintained across
3049 all forms of expansion.
3050
3051 Note that if a `&' is used within glob qualifiers an extra backslash is
3052 needed as a & is a special character in this case.
3053
3054 Also note that the order of expansions affects the interpretation of l
3055 and r. When used in a history expansion, which occurs before any other
3056 expansions, l and r are treated as literal strings (except as explained
3057 for HIST_SUBST_PATTERN below). When used in parameter expansion, the
3058 replacement of r into the parameter's value is done first, and then any
3059 additional process, parameter, command, arithmetic, or brace references
3060 are applied, which may evaluate those substitutions and expansions more
3061 than once if l appears more than once in the starting value. When used
3062 in a glob qualifier, any substitutions or expansions are performed once
3063 at the time the qualifier is parsed, even before the `:s' expression
3064 itself is divided into l and r sides.
3065
3066 If the option HIST_SUBST_PATTERN is set, l is treated as a pattern of
3067 the usual form described in the section FILENAME GENERATION below.
3068 This can be used in all the places where modifiers are available; note,
3069 however, that in globbing qualifiers parameter substitution has already
3070 taken place, so parameters in the replacement string should be quoted
3071 to ensure they are replaced at the correct time. Note also that com‐
3072 plicated patterns used in globbing qualifiers may need the extended
3073 glob qualifier notation (#q:s/.../.../) in order for the shell to rec‐
3074 ognize the expression as a glob qualifier. Further, note that bad pat‐
3075 terns in the substitution are not subject to the NO_BAD_PATTERN option
3076 so will cause an error.
3077
3078 When HIST_SUBST_PATTERN is set, l may start with a # to indicate that
3079 the pattern must match at the start of the string to be substituted,
3080 and a % may appear at the start or after an # to indicate that the pat‐
3081 tern must match at the end of the string to be substituted. The % or #
3082 may be quoted with two backslashes.
3083
3084 For example, the following piece of filename generation code with the
3085 EXTENDED_GLOB option:
3086
3087 print -r -- *.c(#q:s/#%(#b)s(*).c/'S${match[1]}.C'/)
3088
3089 takes the expansion of *.c and applies the glob qualifiers in the
3090 (#q...) expression, which consists of a substitution modifier anchored
3091 to the start and end of each word (#%). This turns on backreferences
3092 ((#b)), so that the parenthesised subexpression is available in the re‐
3093 placement string as ${match[1]}. The replacement string is quoted so
3094 that the parameter is not substituted before the start of filename gen‐
3095 eration.
3096
3097 The following f, F, w and W modifiers work only with parameter expan‐
3098 sion and filename generation. They are listed here to provide a single
3099 point of reference for all modifiers.
3100
3101 f Repeats the immediately (without a colon) following modifier un‐
3102 til the resulting word doesn't change any more.
3103
3104 F:expr:
3105 Like f, but repeats only n times if the expression expr evalu‐
3106 ates to n. Any character can be used instead of the `:'; if
3107 `(', `[', or `{' is used as the opening delimiter, the closing
3108 delimiter should be ')', `]', or `}', respectively.
3109
3110 w Makes the immediately following modifier work on each word in
3111 the string.
3112
3113 W:sep: Like w but words are considered to be the parts of the string
3114 that are separated by sep. Any character can be used instead of
3115 the `:'; opening parentheses are handled specially, see above.
3116
3118 Each part of a command argument that takes the form `<(list)',
3119 `>(list)' or `=(list)' is subject to process substitution. The expres‐
3120 sion may be preceded or followed by other strings except that, to pre‐
3121 vent clashes with commonly occurring strings and patterns, the last
3122 form must occur at the start of a command argument, and the forms are
3123 only expanded when first parsing command or assignment arguments.
3124 Process substitutions may be used following redirection operators; in
3125 this case, the substitution must appear with no trailing string.
3126
3127 Note that `<<(list)' is not a special syntax; it is equivalent to `<
3128 <(list)', redirecting standard input from the result of process substi‐
3129 tution. Hence all the following documentation applies. The second
3130 form (with the space) is recommended for clarity.
3131
3132 In the case of the < or > forms, the shell runs the commands in list as
3133 a subprocess of the job executing the shell command line. If the sys‐
3134 tem supports the /dev/fd mechanism, the command argument is the name of
3135 the device file corresponding to a file descriptor; otherwise, if the
3136 system supports named pipes (FIFOs), the command argument will be a
3137 named pipe. If the form with > is selected then writing on this spe‐
3138 cial file will provide input for list. If < is used, then the file
3139 passed as an argument will be connected to the output of the list
3140 process. For example,
3141
3142 paste <(cut -f1 file1) <(cut -f3 file2) |
3143 tee >(process1) >(process2) >/dev/null
3144
3145 cuts fields 1 and 3 from the files file1 and file2 respectively, pastes
3146 the results together, and sends it to the processes process1 and
3147 process2.
3148
3149 If =(...) is used instead of <(...), then the file passed as an argu‐
3150 ment will be the name of a temporary file containing the output of the
3151 list process. This may be used instead of the < form for a program
3152 that expects to lseek (see lseek(2)) on the input file.
3153
3154 There is an optimisation for substitutions of the form =(<<<arg), where
3155 arg is a single-word argument to the here-string redirection <<<. This
3156 form produces a file name containing the value of arg after any substi‐
3157 tutions have been performed. This is handled entirely within the cur‐
3158 rent shell. This is effectively the reverse of the special form
3159 $(<arg) which treats arg as a file name and replaces it with the file's
3160 contents.
3161
3162 The = form is useful as both the /dev/fd and the named pipe implementa‐
3163 tion of <(...) have drawbacks. In the former case, some programmes may
3164 automatically close the file descriptor in question before examining
3165 the file on the command line, particularly if this is necessary for se‐
3166 curity reasons such as when the programme is running setuid. In the
3167 second case, if the programme does not actually open the file, the sub‐
3168 shell attempting to read from or write to the pipe will (in a typical
3169 implementation, different operating systems may have different behav‐
3170 iour) block for ever and have to be killed explicitly. In both cases,
3171 the shell actually supplies the information using a pipe, so that pro‐
3172 grammes that expect to lseek (see lseek(2)) on the file will not work.
3173
3174 Also note that the previous example can be more compactly and effi‐
3175 ciently written (provided the MULTIOS option is set) as:
3176
3177 paste <(cut -f1 file1) <(cut -f3 file2) > >(process1) > >(process2)
3178
3179 The shell uses pipes instead of FIFOs to implement the latter two
3180 process substitutions in the above example.
3181
3182 There is an additional problem with >(process); when this is attached
3183 to an external command, the parent shell does not wait for process to
3184 finish and hence an immediately following command cannot rely on the
3185 results being complete. The problem and solution are the same as de‐
3186 scribed in the section MULTIOS in zshmisc(1). Hence in a simplified
3187 version of the example above:
3188
3189 paste <(cut -f1 file1) <(cut -f3 file2) > >(process)
3190
3191 (note that no MULTIOS are involved), process will be run asynchronously
3192 as far as the parent shell is concerned. The workaround is:
3193
3194 { paste <(cut -f1 file1) <(cut -f3 file2) } > >(process)
3195
3196 The extra processes here are spawned from the parent shell which will
3197 wait for their completion.
3198
3199 Another problem arises any time a job with a substitution that requires
3200 a temporary file is disowned by the shell, including the case where
3201 `&!' or `&|' appears at the end of a command containing a substitution.
3202 In that case the temporary file will not be cleaned up as the shell no
3203 longer has any memory of the job. A workaround is to use a subshell,
3204 for example,
3205
3206 (mycmd =(myoutput)) &!
3207
3208 as the forked subshell will wait for the command to finish then remove
3209 the temporary file.
3210
3211 A general workaround to ensure a process substitution endures for an
3212 appropriate length of time is to pass it as a parameter to an anonymous
3213 shell function (a piece of shell code that is run immediately with
3214 function scope). For example, this code:
3215
3216 () {
3217 print File $1:
3218 cat $1
3219 } =(print This be the verse)
3220
3221 outputs something resembling the following
3222
3223 File /tmp/zsh6nU0kS:
3224 This be the verse
3225
3226 The temporary file created by the process substitution will be deleted
3227 when the function exits.
3228
3230 The character `$' is used to introduce parameter expansions. See zsh‐
3231 param(1) for a description of parameters, including arrays, associative
3232 arrays, and subscript notation to access individual array elements.
3233
3234 Note in particular the fact that words of unquoted parameters are not
3235 automatically split on whitespace unless the option SH_WORD_SPLIT is
3236 set; see references to this option below for more details. This is an
3237 important difference from other shells. However, as in other shells,
3238 null words are elided from unquoted parameters' expansions.
3239
3240 With default options, after the assignments:
3241
3242 array=("first word" "" "third word")
3243 scalar="only word"
3244
3245 then $array substitutes two words, `first word' and `third word', and
3246 $scalar substitutes a single word `only word'. Note that second ele‐
3247 ment of array was elided. Scalar parameters can be elided too if their
3248 value is null (empty). To avoid elision, use quoting as follows:
3249 "$scalar" for scalars and "${array[@]}" or "${(@)array}" for arrays.
3250 (The last two forms are equivalent.)
3251
3252 Parameter expansions can involve flags, as in `${(@kv)aliases}', and
3253 other operators, such as `${PREFIX:-"/usr/local"}'. Parameter expan‐
3254 sions can also be nested. These topics will be introduced below. The
3255 full rules are complicated and are noted at the end.
3256
3257 In the expansions discussed below that require a pattern, the form of
3258 the pattern is the same as that used for filename generation; see the
3259 section `Filename Generation'. Note that these patterns, along with
3260 the replacement text of any substitutions, are themselves subject to
3261 parameter expansion, command substitution, and arithmetic expansion.
3262 In addition to the following operations, the colon modifiers described
3263 in the section `Modifiers' in the section `History Expansion' can be
3264 applied: for example, ${i:s/foo/bar/} performs string substitution on
3265 the expansion of parameter $i.
3266
3267 In the following descriptions, `word' refers to a single word substi‐
3268 tuted on the command line, not necessarily a space delimited word.
3269
3270 ${name}
3271 The value, if any, of the parameter name is substituted. The
3272 braces are required if the expansion is to be followed by a let‐
3273 ter, digit, or underscore that is not to be interpreted as part
3274 of name. In addition, more complicated forms of substitution
3275 usually require the braces to be present; exceptions, which only
3276 apply if the option KSH_ARRAYS is not set, are a single sub‐
3277 script or any colon modifiers appearing after the name, or any
3278 of the characters `^', `=', `~', `#' or `+' appearing before the
3279 name, all of which work with or without braces.
3280
3281 If name is an array parameter, and the KSH_ARRAYS option is not
3282 set, then the value of each element of name is substituted, one
3283 element per word. Otherwise, the expansion results in one word
3284 only; with KSH_ARRAYS, this is the first element of an array.
3285 No field splitting is done on the result unless the
3286 SH_WORD_SPLIT option is set. See also the flags = and
3287 s:string:.
3288
3289 ${+name}
3290 If name is the name of a set parameter `1' is substituted, oth‐
3291 erwise `0' is substituted.
3292
3293 ${name-word}
3294 ${name:-word}
3295 If name is set, or in the second form is non-null, then substi‐
3296 tute its value; otherwise substitute word. In the second form
3297 name may be omitted, in which case word is always substituted.
3298
3299 ${name+word}
3300 ${name:+word}
3301 If name is set, or in the second form is non-null, then substi‐
3302 tute word; otherwise substitute nothing.
3303
3304 ${name=word}
3305 ${name:=word}
3306 ${name::=word}
3307 In the first form, if name is unset then set it to word; in the
3308 second form, if name is unset or null then set it to word; and
3309 in the third form, unconditionally set name to word. In all
3310 forms, the value of the parameter is then substituted.
3311
3312 ${name?word}
3313 ${name:?word}
3314 In the first form, if name is set, or in the second form if name
3315 is both set and non-null, then substitute its value; otherwise,
3316 print word and exit from the shell. Interactive shells instead
3317 return to the prompt. If word is omitted, then a standard mes‐
3318 sage is printed.
3319
3320 In any of the above expressions that test a variable and substitute an
3321 alternate word, note that you can use standard shell quoting in the
3322 word value to selectively override the splitting done by the
3323 SH_WORD_SPLIT option and the = flag, but not splitting by the s:string:
3324 flag.
3325
3326 In the following expressions, when name is an array and the substitu‐
3327 tion is not quoted, or if the `(@)' flag or the name[@] syntax is used,
3328 matching and replacement is performed on each array element separately.
3329
3330 ${name#pattern}
3331 ${name##pattern}
3332 If the pattern matches the beginning of the value of name, then
3333 substitute the value of name with the matched portion deleted;
3334 otherwise, just substitute the value of name. In the first
3335 form, the smallest matching pattern is preferred; in the second
3336 form, the largest matching pattern is preferred.
3337
3338 ${name%pattern}
3339 ${name%%pattern}
3340 If the pattern matches the end of the value of name, then sub‐
3341 stitute the value of name with the matched portion deleted; oth‐
3342 erwise, just substitute the value of name. In the first form,
3343 the smallest matching pattern is preferred; in the second form,
3344 the largest matching pattern is preferred.
3345
3346 ${name:#pattern}
3347 If the pattern matches the value of name, then substitute the
3348 empty string; otherwise, just substitute the value of name. If
3349 name is an array the matching array elements are removed (use
3350 the `(M)' flag to remove the non-matched elements).
3351
3352 ${name:|arrayname}
3353 If arrayname is the name (N.B., not contents) of an array vari‐
3354 able, then any elements contained in arrayname are removed from
3355 the substitution of name. If the substitution is scalar, either
3356 because name is a scalar variable or the expression is quoted,
3357 the elements of arrayname are instead tested against the entire
3358 expression.
3359
3360 ${name:*arrayname}
3361 Similar to the preceding substitution, but in the opposite
3362 sense, so that entries present in both the original substitution
3363 and as elements of arrayname are retained and others removed.
3364
3365 ${name:^arrayname}
3366 ${name:^^arrayname}
3367 Zips two arrays, such that the output array is twice as long as
3368 the shortest (longest for `:^^') of name and arrayname, with the
3369 elements alternatingly being picked from them. For `:^', if one
3370 of the input arrays is longer, the output will stop when the end
3371 of the shorter array is reached. Thus,
3372
3373 a=(1 2 3 4); b=(a b); print ${a:^b}
3374
3375 will output `1 a 2 b'. For `:^^', then the input is repeated
3376 until all of the longer array has been used up and the above
3377 will output `1 a 2 b 3 a 4 b'.
3378
3379 Either or both inputs may be a scalar, they will be treated as
3380 an array of length 1 with the scalar as the only element. If ei‐
3381 ther array is empty, the other array is output with no extra el‐
3382 ements inserted.
3383
3384 Currently the following code will output `a b' and `1' as two
3385 separate elements, which can be unexpected. The second print
3386 provides a workaround which should continue to work if this is
3387 changed.
3388
3389 a=(a b); b=(1 2); print -l "${a:^b}"; print -l "${${a:^b}}"
3390
3391 ${name:offset}
3392 ${name:offset:length}
3393 This syntax gives effects similar to parameter subscripting in
3394 the form $name[start,end], but is compatible with other shells;
3395 note that both offset and length are interpreted differently
3396 from the components of a subscript.
3397
3398 If offset is non-negative, then if the variable name is a scalar
3399 substitute the contents starting offset characters from the
3400 first character of the string, and if name is an array substi‐
3401 tute elements starting offset elements from the first element.
3402 If length is given, substitute that many characters or elements,
3403 otherwise the entire rest of the scalar or array.
3404
3405 A positive offset is always treated as the offset of a character
3406 or element in name from the first character or element of the
3407 array (this is different from native zsh subscript notation).
3408 Hence 0 refers to the first character or element regardless of
3409 the setting of the option KSH_ARRAYS.
3410
3411 A negative offset counts backwards from the end of the scalar or
3412 array, so that -1 corresponds to the last character or element,
3413 and so on.
3414
3415 When positive, length counts from the offset position toward the
3416 end of the scalar or array. When negative, length counts back
3417 from the end. If this results in a position smaller than off‐
3418 set, a diagnostic is printed and nothing is substituted.
3419
3420 The option MULTIBYTE is obeyed, i.e. the offset and length count
3421 multibyte characters where appropriate.
3422
3423 offset and length undergo the same set of shell substitutions as
3424 for scalar assignment; in addition, they are then subject to
3425 arithmetic evaluation. Hence, for example
3426
3427 print ${foo:3}
3428 print ${foo: 1 + 2}
3429 print ${foo:$(( 1 + 2))}
3430 print ${foo:$(echo 1 + 2)}
3431
3432 all have the same effect, extracting the string starting at the
3433 fourth character of $foo if the substitution would otherwise re‐
3434 turn a scalar, or the array starting at the fourth element if
3435 $foo would return an array. Note that with the option KSH_AR‐
3436 RAYS $foo always returns a scalar (regardless of the use of the
3437 offset syntax) and a form such as ${foo[*]:3} is required to ex‐
3438 tract elements of an array named foo.
3439
3440 If offset is negative, the - may not appear immediately after
3441 the : as this indicates the ${name:-word} form of substitution.
3442 Instead, a space may be inserted before the -. Furthermore,
3443 neither offset nor length may begin with an alphabetic character
3444 or & as these are used to indicate history-style modifiers. To
3445 substitute a value from a variable, the recommended approach is
3446 to precede it with a $ as this signifies the intention (parame‐
3447 ter substitution can easily be rendered unreadable); however, as
3448 arithmetic substitution is performed, the expression ${var:
3449 offs} does work, retrieving the offset from $offs.
3450
3451 For further compatibility with other shells there is a special
3452 case for array offset 0. This usually accesses the first ele‐
3453 ment of the array. However, if the substitution refers to the
3454 positional parameter array, e.g. $@ or $*, then offset 0 instead
3455 refers to $0, offset 1 refers to $1, and so on. In other words,
3456 the positional parameter array is effectively extended by
3457 prepending $0. Hence ${*:0:1} substitutes $0 and ${*:1:1} sub‐
3458 stitutes $1.
3459
3460 ${name/pattern/repl}
3461 ${name//pattern/repl}
3462 ${name:/pattern/repl}
3463 Replace the longest possible match of pattern in the expansion
3464 of parameter name by string repl. The first form replaces just
3465 the first occurrence, the second form all occurrences, and the
3466 third form replaces only if pattern matches the entire string.
3467 Both pattern and repl are subject to double-quoted substitution,
3468 so that expressions like ${name/$opat/$npat} will work, but obey
3469 the usual rule that pattern characters in $opat are not treated
3470 specially unless either the option GLOB_SUBST is set, or $opat
3471 is instead substituted as ${~opat}.
3472
3473 The pattern may begin with a `#', in which case the pattern must
3474 match at the start of the string, or `%', in which case it must
3475 match at the end of the string, or `#%' in which case the pat‐
3476 tern must match the entire string. The repl may be an empty
3477 string, in which case the final `/' may also be omitted. To
3478 quote the final `/' in other cases it should be preceded by a
3479 single backslash; this is not necessary if the `/' occurs inside
3480 a substituted parameter. Note also that the `#', `%' and `#%
3481 are not active if they occur inside a substituted parameter,
3482 even at the start.
3483
3484 If, after quoting rules apply, ${name} expands to an array, the
3485 replacements act on each element individually. Note also the
3486 effect of the I and S parameter expansion flags below; however,
3487 the flags M, R, B, E and N are not useful.
3488
3489 For example,
3490
3491 foo="twinkle twinkle little star" sub="t*e" rep="spy"
3492 print ${foo//${~sub}/$rep}
3493 print ${(S)foo//${~sub}/$rep}
3494
3495 Here, the `~' ensures that the text of $sub is treated as a pat‐
3496 tern rather than a plain string. In the first case, the longest
3497 match for t*e is substituted and the result is `spy star', while
3498 in the second case, the shortest matches are taken and the re‐
3499 sult is `spy spy lispy star'.
3500
3501 ${#spec}
3502 If spec is one of the above substitutions, substitute the length
3503 in characters of the result instead of the result itself. If
3504 spec is an array expression, substitute the number of elements
3505 of the result. This has the side-effect that joining is skipped
3506 even in quoted forms, which may affect other sub-expressions in
3507 spec. Note that `^', `=', and `~', below, must appear to the
3508 left of `#' when these forms are combined.
3509
3510 If the option POSIX_IDENTIFIERS is not set, and spec is a simple
3511 name, then the braces are optional; this is true even for spe‐
3512 cial parameters so e.g. $#- and $#* take the length of the
3513 string $- and the array $* respectively. If POSIX_IDENTIFIERS
3514 is set, then braces are required for the # to be treated in this
3515 fashion.
3516
3517 ${^spec}
3518 ${^^spec}
3519 Turn on the RC_EXPAND_PARAM option for the evaluation of spec;
3520 if the `^' is doubled, turn it off. When this option is set,
3521 array expansions of the form foo${xx}bar, where the parameter xx
3522 is set to (a b c), are substituted with `fooabar foobbar
3523 foocbar' instead of the default `fooa b cbar'. Note that an
3524 empty array will therefore cause all arguments to be removed.
3525
3526 Internally, each such expansion is converted into the equivalent
3527 list for brace expansion. E.g., ${^var} becomes
3528 {$var[1],$var[2],...}, and is processed as described in the sec‐
3529 tion `Brace Expansion' below: note, however, the expansion hap‐
3530 pens immediately, with any explicit brace expansion happening
3531 later. If word splitting is also in effect the $var[N] may
3532 themselves be split into different list elements.
3533
3534 ${=spec}
3535 ${==spec}
3536 Perform word splitting using the rules for SH_WORD_SPLIT during
3537 the evaluation of spec, but regardless of whether the parameter
3538 appears in double quotes; if the `=' is doubled, turn it off.
3539 This forces parameter expansions to be split into separate words
3540 before substitution, using IFS as a delimiter. This is done by
3541 default in most other shells.
3542
3543 Note that splitting is applied to word in the assignment forms
3544 of spec before the assignment to name is performed. This af‐
3545 fects the result of array assignments with the A flag.
3546
3547 ${~spec}
3548 ${~~spec}
3549 Turn on the GLOB_SUBST option for the evaluation of spec; if the
3550 `~' is doubled, turn it off. When this option is set, the
3551 string resulting from the expansion will be interpreted as a
3552 pattern anywhere that is possible, such as in filename expansion
3553 and filename generation and pattern-matching contexts like the
3554 right hand side of the `=' and `!=' operators in conditions.
3555
3556 In nested substitutions, note that the effect of the ~ applies
3557 to the result of the current level of substitution. A surround‐
3558 ing pattern operation on the result may cancel it. Hence, for
3559 example, if the parameter foo is set to *, ${~foo//\*/*.c} is
3560 substituted by the pattern *.c, which may be expanded by file‐
3561 name generation, but ${${~foo}//\*/*.c} substitutes to the
3562 string *.c, which will not be further expanded.
3563
3564 If a ${...} type parameter expression or a $(...) type command substi‐
3565 tution is used in place of name above, it is expanded first and the re‐
3566 sult is used as if it were the value of name. Thus it is possible to
3567 perform nested operations: ${${foo#head}%tail} substitutes the value
3568 of $foo with both `head' and `tail' deleted. The form with $(...) is
3569 often useful in combination with the flags described next; see the ex‐
3570 amples below. Each name or nested ${...} in a parameter expansion may
3571 also be followed by a subscript expression as described in Array Param‐
3572 eters in zshparam(1).
3573
3574 Note that double quotes may appear around nested expressions, in which
3575 case only the part inside is treated as quoted; for example,
3576 ${(f)"$(foo)"} quotes the result of $(foo), but the flag `(f)' (see be‐
3577 low) is applied using the rules for unquoted expansions. Note further
3578 that quotes are themselves nested in this context; for example, in
3579 "${(@f)"$(foo)"}", there are two sets of quotes, one surrounding the
3580 whole expression, the other (redundant) surrounding the $(foo) as be‐
3581 fore.
3582
3583 Parameter Expansion Flags
3584 If the opening brace is directly followed by an opening parenthesis,
3585 the string up to the matching closing parenthesis will be taken as a
3586 list of flags. In cases where repeating a flag is meaningful, the rep‐
3587 etitions need not be consecutive; for example, `(q%q%q)' means the same
3588 thing as the more readable `(%%qqq)'. The following flags are sup‐
3589 ported:
3590
3591 # Evaluate the resulting words as numeric expressions and inter‐
3592 pret these as character codes. Output the corresponding charac‐
3593 ters. Note that this form is entirely distinct from use of the
3594 # without parentheses.
3595
3596 If the MULTIBYTE option is set and the number is greater than
3597 127 (i.e. not an ASCII character) it is treated as a Unicode
3598 character.
3599
3600 % Expand all % escapes in the resulting words in the same way as
3601 in prompts (see EXPANSION OF PROMPT SEQUENCES in zshmisc(1)). If
3602 this flag is given twice, full prompt expansion is done on the
3603 resulting words, depending on the setting of the PROMPT_PERCENT,
3604 PROMPT_SUBST and PROMPT_BANG options.
3605
3606 @ In double quotes, array elements are put into separate words.
3607 E.g., `"${(@)foo}"' is equivalent to `"${foo[@]}"' and
3608 `"${(@)foo[1,2]}"' is the same as `"$foo[1]" "$foo[2]"'. This
3609 is distinct from field splitting by the f, s or z flags, which
3610 still applies within each array element.
3611
3612 A Convert the substitution into an array expression, even if it
3613 otherwise would be scalar. This has lower precedence than sub‐
3614 scripting, so one level of nested expansion is required in order
3615 that subscripts apply to array elements. Thus ${${(A)name}[1]}
3616 yields the full value of name when name is scalar.
3617
3618 This assigns an array parameter with `${...=...}', `${...:=...}'
3619 or `${...::=...}'. If this flag is repeated (as in `AA'), as‐
3620 signs an associative array parameter. Assignment is made before
3621 sorting or padding; if field splitting is active, the word part
3622 is split before assignment. The name part may be a subscripted
3623 range for ordinary arrays; when assigning an associative array,
3624 the word part must be converted to an array, for example by us‐
3625 ing `${(AA)=name=...}' to activate field splitting.
3626
3627 Surrounding context such as additional nesting or use of the
3628 value in a scalar assignment may cause the array to be joined
3629 back into a single string again.
3630
3631 a Sort in array index order; when combined with `O' sort in re‐
3632 verse array index order. Note that `a' is therefore equivalent
3633 to the default but `Oa' is useful for obtaining an array's ele‐
3634 ments in reverse order.
3635
3636 b Quote with backslashes only characters that are special to pat‐
3637 tern matching. This is useful when the contents of the variable
3638 are to be tested using GLOB_SUBST, including the ${~...} switch.
3639
3640 Quoting using one of the q family of flags does not work for
3641 this purpose since quotes are not stripped from non-pattern
3642 characters by GLOB_SUBST. In other words,
3643
3644 pattern=${(q)str}
3645 [[ $str = ${~pattern} ]]
3646
3647 works if $str is `a*b' but not if it is `a b', whereas
3648
3649 pattern=${(b)str}
3650 [[ $str = ${~pattern} ]]
3651
3652 is always true for any possible value of $str.
3653
3654 c With ${#name}, count the total number of characters in an array,
3655 as if the elements were concatenated with spaces between them.
3656 This is not a true join of the array, so other expressions used
3657 with this flag may have an effect on the elements of the array
3658 before it is counted.
3659
3660 C Capitalize the resulting words. `Words' in this case refers to
3661 sequences of alphanumeric characters separated by non-alphanu‐
3662 merics, not to words that result from field splitting.
3663
3664 D Assume the string or array elements contain directories and at‐
3665 tempt to substitute the leading part of these by names. The re‐
3666 mainder of the path (the whole of it if the leading part was not
3667 substituted) is then quoted so that the whole string can be used
3668 as a shell argument. This is the reverse of `~' substitution:
3669 see the section FILENAME EXPANSION below.
3670
3671 e Perform single word shell expansions, namely parameter expan‐
3672 sion, command substitution and arithmetic expansion, on the re‐
3673 sult. Such expansions can be nested but too deep recursion may
3674 have unpredictable effects.
3675
3676 f Split the result of the expansion at newlines. This is a short‐
3677 hand for `ps:\n:'.
3678
3679 F Join the words of arrays together using newline as a separator.
3680 This is a shorthand for `pj:\n:'.
3681
3682 g:opts:
3683 Process escape sequences like the echo builtin when no options
3684 are given (g::). With the o option, octal escapes don't take a
3685 leading zero. With the c option, sequences like `^X' are also
3686 processed. With the e option, processes `\M-t' and similar se‐
3687 quences like the print builtin. With both of the o and e op‐
3688 tions, behaves like the print builtin except that in none of
3689 these modes is `\c' interpreted.
3690
3691 i Sort case-insensitively. May be combined with `n' or `O'.
3692
3693 k If name refers to an associative array, substitute the keys (el‐
3694 ement names) rather than the values of the elements. Used with
3695 subscripts (including ordinary arrays), force indices or keys to
3696 be substituted even if the subscript form refers to values.
3697 However, this flag may not be combined with subscript ranges.
3698 With the KSH_ARRAYS option a subscript `[*]' or `[@]' is needed
3699 to operate on the whole array, as usual.
3700
3701 L Convert all letters in the result to lower case.
3702
3703 n Sort decimal integers numerically; if the first differing char‐
3704 acters of two test strings are not digits, sorting is lexical.
3705 `+' and `-' are not treated specially; they are treated as any
3706 other non-digit. Integers with more initial zeroes are sorted
3707 before those with fewer or none. Hence the array `foo+24 foo1
3708 foo02 foo2 foo3 foo20 foo23' is sorted into the order shown.
3709 May be combined with `i' or `O'.
3710
3711 - As n, but a leading minus sign indicates a negative decimal in‐
3712 teger. A leading minus sign not followed by an integer does not
3713 trigger numeric sorting. Note that `+' signs are not handled
3714 specially (this may change in the future).
3715
3716 o Sort the resulting words in ascending order; if this appears on
3717 its own the sorting is lexical and case-sensitive (unless the
3718 locale renders it case-insensitive). Sorting in ascending order
3719 is the default for other forms of sorting, so this is ignored if
3720 combined with `a', `i', `n' or `-'.
3721
3722 O Sort the resulting words in descending order; `O' without `a',
3723 `i', `n' or `-' sorts in reverse lexical order. May be combined
3724 with `a', `i', `n' or `-' to reverse the order of sorting.
3725
3726 P This forces the value of the parameter name to be interpreted as
3727 a further parameter name, whose value will be used where appro‐
3728 priate. Note that flags set with one of the typeset family of
3729 commands (in particular case transformations) are not applied to
3730 the value of name used in this fashion.
3731
3732 If used with a nested parameter or command substitution, the re‐
3733 sult of that will be taken as a parameter name in the same way.
3734 For example, if you have `foo=bar' and `bar=baz', the strings
3735 ${(P)foo}, ${(P)${foo}}, and ${(P)$(echo bar)} will be expanded
3736 to `baz'.
3737
3738 Likewise, if the reference is itself nested, the expression with
3739 the flag is treated as if it were directly replaced by the pa‐
3740 rameter name. It is an error if this nested substitution pro‐
3741 duces an array with more than one word. For example, if
3742 `name=assoc' where the parameter assoc is an associative array,
3743 then `${${(P)name}[elt]}' refers to the element of the associa‐
3744 tive subscripted `elt'.
3745
3746 q Quote characters that are special to the shell in the resulting
3747 words with backslashes; unprintable or invalid characters are
3748 quoted using the $'\NNN' form, with separate quotes for each
3749 octet.
3750
3751 If this flag is given twice, the resulting words are quoted in
3752 single quotes and if it is given three times, the words are
3753 quoted in double quotes; in these forms no special handling of
3754 unprintable or invalid characters is attempted. If the flag is
3755 given four times, the words are quoted in single quotes preceded
3756 by a $. Note that in all three of these forms quoting is done
3757 unconditionally, even if this does not change the way the re‐
3758 sulting string would be interpreted by the shell.
3759
3760 If a q- is given (only a single q may appear), a minimal form of
3761 single quoting is used that only quotes the string if needed to
3762 protect special characters. Typically this form gives the most
3763 readable output.
3764
3765 If a q+ is given, an extended form of minimal quoting is used
3766 that causes unprintable characters to be rendered using $'...'.
3767 This quoting is similar to that used by the output of values by
3768 the typeset family of commands.
3769
3770 Q Remove one level of quotes from the resulting words.
3771
3772 t Use a string describing the type of the parameter where the
3773 value of the parameter would usually appear. This string con‐
3774 sists of keywords separated by hyphens (`-'). The first keyword
3775 in the string describes the main type, it can be one of
3776 `scalar', `array', `integer', `float' or `association'. The
3777 other keywords describe the type in more detail:
3778
3779 local for local parameters
3780
3781 left for left justified parameters
3782
3783 right_blanks
3784 for right justified parameters with leading blanks
3785
3786 right_zeros
3787 for right justified parameters with leading zeros
3788
3789 lower for parameters whose value is converted to all lower case
3790 when it is expanded
3791
3792 upper for parameters whose value is converted to all upper case
3793 when it is expanded
3794
3795 readonly
3796 for readonly parameters
3797
3798 tag for tagged parameters
3799
3800 tied for parameters tied to another parameter in the manner of
3801 PATH (colon-separated list) and path (array), whether
3802 these are special parameters or user-defined with `type‐
3803 set -T'
3804
3805 export for exported parameters
3806
3807 unique for arrays which keep only the first occurrence of dupli‐
3808 cated values
3809
3810 hide for parameters with the `hide' flag
3811
3812 hideval
3813 for parameters with the `hideval' flag
3814
3815 special
3816 for special parameters defined by the shell
3817
3818 u Expand only the first occurrence of each unique word.
3819
3820 U Convert all letters in the result to upper case.
3821
3822 v Used with k, substitute (as two consecutive words) both the key
3823 and the value of each associative array element. Used with sub‐
3824 scripts, force values to be substituted even if the subscript
3825 form refers to indices or keys.
3826
3827 V Make any special characters in the resulting words visible.
3828
3829 w With ${#name}, count words in arrays or strings; the s flag may
3830 be used to set a word delimiter.
3831
3832 W Similar to w with the difference that empty words between re‐
3833 peated delimiters are also counted.
3834
3835 X With this flag, parsing errors occurring with the Q, e and #
3836 flags or the pattern matching forms such as `${name#pattern}'
3837 are reported. Without the flag, errors are silently ignored.
3838
3839 z Split the result of the expansion into words using shell parsing
3840 to find the words, i.e. taking into account any quoting in the
3841 value. Comments are not treated specially but as ordinary
3842 strings, similar to interactive shells with the INTERACTIVE_COM‐
3843 MENTS option unset (however, see the Z flag below for related
3844 options)
3845
3846 Note that this is done very late, even later than the `(s)'
3847 flag. So to access single words in the result use nested expan‐
3848 sions as in `${${(z)foo}[2]}'. Likewise, to remove the quotes in
3849 the resulting words use `${(Q)${(z)foo}}'.
3850
3851 0 Split the result of the expansion on null bytes. This is a
3852 shorthand for `ps:\0:'.
3853
3854 The following flags (except p) are followed by one or more arguments as
3855 shown. Any character, or the matching pairs `(...)', `{...}', `[...]',
3856 or `<...>', may be used in place of a colon as delimiters, but note
3857 that when a flag takes more than one argument, a matched pair of delim‐
3858 iters must surround each argument.
3859
3860 p Recognize the same escape sequences as the print builtin in
3861 string arguments to any of the flags described below that follow
3862 this argument.
3863
3864 Alternatively, with this option string arguments may be in the
3865 form $var in which case the value of the variable is substi‐
3866 tuted. Note this form is strict; the string argument does not
3867 undergo general parameter expansion.
3868
3869 For example,
3870
3871 sep=:
3872 val=a:b:c
3873 print ${(ps.$sep.)val}
3874
3875 splits the variable on a :.
3876
3877 ~ Strings inserted into the expansion by any of the flags below
3878 are to be treated as patterns. This applies to the string argu‐
3879 ments of flags that follow ~ within the same set of parentheses.
3880 Compare with ~ outside parentheses, which forces the entire sub‐
3881 stituted string to be treated as a pattern. Hence, for example,
3882
3883 [[ "?" = ${(~j.|.)array} ]]
3884
3885 treats `|' as a pattern and succeeds if and only if $array con‐
3886 tains the string `?' as an element. The ~ may be repeated to
3887 toggle the behaviour; its effect only lasts to the end of the
3888 parenthesised group.
3889
3890 j:string:
3891 Join the words of arrays together using string as a separator.
3892 Note that this occurs before field splitting by the s:string:
3893 flag or the SH_WORD_SPLIT option.
3894
3895 l:expr::string1::string2:
3896 Pad the resulting words on the left. Each word will be trun‐
3897 cated if required and placed in a field expr characters wide.
3898
3899 The arguments :string1: and :string2: are optional; neither, the
3900 first, or both may be given. Note that the same pairs of delim‐
3901 iters must be used for each of the three arguments. The space
3902 to the left will be filled with string1 (concatenated as often
3903 as needed) or spaces if string1 is not given. If both string1
3904 and string2 are given, string2 is inserted once directly to the
3905 left of each word, truncated if necessary, before string1 is
3906 used to produce any remaining padding.
3907
3908 If either of string1 or string2 is present but empty, i.e. there
3909 are two delimiters together at that point, the first character
3910 of $IFS is used instead.
3911
3912 If the MULTIBYTE option is in effect, the flag m may also be
3913 given, in which case widths will be used for the calculation of
3914 padding; otherwise individual multibyte characters are treated
3915 as occupying one unit of width.
3916
3917 If the MULTIBYTE option is not in effect, each byte in the
3918 string is treated as occupying one unit of width.
3919
3920 Control characters are always assumed to be one unit wide; this
3921 allows the mechanism to be used for generating repetitions of
3922 control characters.
3923
3924 m Only useful together with one of the flags l or r or with the #
3925 length operator when the MULTIBYTE option is in effect. Use the
3926 character width reported by the system in calculating how much
3927 of the string it occupies or the overall length of the string.
3928 Most printable characters have a width of one unit, however cer‐
3929 tain Asian character sets and certain special effects use wider
3930 characters; combining characters have zero width. Non-printable
3931 characters are arbitrarily counted as zero width; how they would
3932 actually be displayed will vary.
3933
3934 If the m is repeated, the character either counts zero (if it
3935 has zero width), else one. For printable character strings this
3936 has the effect of counting the number of glyphs (visibly sepa‐
3937 rate characters), except for the case where combining characters
3938 themselves have non-zero width (true in certain alphabets).
3939
3940 r:expr::string1::string2:
3941 As l, but pad the words on the right and insert string2 immedi‐
3942 ately to the right of the string to be padded.
3943
3944 Left and right padding may be used together. In this case the
3945 strategy is to apply left padding to the first half width of
3946 each of the resulting words, and right padding to the second
3947 half. If the string to be padded has odd width the extra pad‐
3948 ding is applied on the left.
3949
3950 s:string:
3951 Force field splitting at the separator string. Note that a
3952 string of two or more characters means that all of them must
3953 match in sequence; this differs from the treatment of two or
3954 more characters in the IFS parameter. See also the = flag and
3955 the SH_WORD_SPLIT option. An empty string may also be given in
3956 which case every character will be a separate element.
3957
3958 For historical reasons, the usual behaviour that empty array el‐
3959 ements are retained inside double quotes is disabled for arrays
3960 generated by splitting; hence the following:
3961
3962 line="one::three"
3963 print -l "${(s.:.)line}"
3964
3965 produces two lines of output for one and three and elides the
3966 empty field. To override this behaviour, supply the `(@)' flag
3967 as well, i.e. "${(@s.:.)line}".
3968
3969 Z:opts:
3970 As z but takes a combination of option letters between a follow‐
3971 ing pair of delimiter characters. With no options the effect is
3972 identical to z. The following options are available:
3973
3974 (Z+c+) causes comments to be parsed as a string and retained;
3975 any field in the resulting array beginning with an un‐
3976 quoted comment character is a comment.
3977
3978 (Z+C+) causes comments to be parsed and removed. The rule for
3979 comments is standard: anything between a word starting
3980 with the third character of $HISTCHARS, default #, up to
3981 the next newline is a comment.
3982
3983 (Z+n+) causes unquoted newlines to be treated as ordinary white‐
3984 space, else they are treated as if they are shell code
3985 delimiters and converted to semicolons.
3986
3987 Options are combined within the same set of delimiters, e.g.
3988 (Z+Cn+).
3989
3990 _:flags:
3991 The underscore (_) flag is reserved for future use. As of this
3992 revision of zsh, there are no valid flags; anything following an
3993 underscore, other than an empty pair of delimiters, is treated
3994 as an error, and the flag itself has no effect.
3995
3996 The following flags are meaningful with the ${...#...} or ${...%...}
3997 forms. The S, I, and * flags may also be used with the ${.../...}
3998 forms.
3999
4000 S With # or ##, search for the match that starts closest to the
4001 start of the string (a `substring match'). Of all matches at a
4002 particular position, # selects the shortest and ## the longest:
4003
4004 % str="aXbXc"
4005 % echo ${(S)str#X*}
4006 abXc
4007 % echo ${(S)str##X*}
4008 a
4009 %
4010
4011 With % or %%, search for the match that starts closest to the
4012 end of the string:
4013
4014 % str="aXbXc"
4015 % echo ${(S)str%X*}
4016 aXbc
4017 % echo ${(S)str%%X*}
4018 aXb
4019 %
4020
4021 (Note that % and %% don't search for the match that ends closest
4022 to the end of the string, as one might expect.)
4023
4024 With substitution via ${.../...} or ${...//...}, specifies
4025 non-greedy matching, i.e. that the shortest instead of the long‐
4026 est match should be replaced:
4027
4028 % str="abab"
4029 % echo ${str/*b/_}
4030 _
4031 % echo ${(S)str/*b/_}
4032 _ab
4033 %
4034
4035 I:expr:
4036 Search the exprth match (where expr evaluates to a number).
4037 This only applies when searching for substrings, either with the
4038 S flag, or with ${.../...} (only the exprth match is substi‐
4039 tuted) or ${...//...} (all matches from the exprth on are sub‐
4040 stituted). The default is to take the first match.
4041
4042 The exprth match is counted such that there is either one or
4043 zero matches from each starting position in the string, although
4044 for global substitution matches overlapping previous replace‐
4045 ments are ignored. With the ${...%...} and ${...%%...} forms,
4046 the starting position for the match moves backwards from the end
4047 as the index increases, while with the other forms it moves for‐
4048 ward from the start.
4049
4050 Hence with the string
4051 which switch is the right switch for Ipswich?
4052 substitutions of the form ${(SI:N:)string#w*ch} as N increases
4053 from 1 will match and remove `which', `witch', `witch' and
4054 `wich'; the form using `##' will match and remove `which switch
4055 is the right switch for Ipswich', `witch is the right switch for
4056 Ipswich', `witch for Ipswich' and `wich'. The form using `%'
4057 will remove the same matches as for `#', but in reverse order,
4058 and the form using `%%' will remove the same matches as for `##'
4059 in reverse order.
4060
4061 * Enable EXTENDED_GLOB for substitution via ${.../...} or
4062 ${...//...}. Note that `**' does not disable extendedglob.
4063
4064 B Include the index of the beginning of the match in the result.
4065
4066 E Include the index one character past the end of the match in the
4067 result (note this is inconsistent with other uses of parameter
4068 index).
4069
4070 M Include the matched portion in the result.
4071
4072 N Include the length of the match in the result.
4073
4074 R Include the unmatched portion in the result (the Rest).
4075
4076 Rules
4077 Here is a summary of the rules for substitution; this assumes that
4078 braces are present around the substitution, i.e. ${...}. Some particu‐
4079 lar examples are given below. Note that the Zsh Development Group ac‐
4080 cepts no responsibility for any brain damage which may occur during the
4081 reading of the following rules.
4082
4083 1. Nested substitution
4084 If multiple nested ${...} forms are present, substitution is
4085 performed from the inside outwards. At each level, the substi‐
4086 tution takes account of whether the current value is a scalar or
4087 an array, whether the whole substitution is in double quotes,
4088 and what flags are supplied to the current level of substitu‐
4089 tion, just as if the nested substitution were the outermost.
4090 The flags are not propagated up to enclosing substitutions; the
4091 nested substitution will return either a scalar or an array as
4092 determined by the flags, possibly adjusted for quoting. All the
4093 following steps take place where applicable at all levels of
4094 substitution.
4095
4096 Note that, unless the `(P)' flag is present, the flags and any
4097 subscripts apply directly to the value of the nested substitu‐
4098 tion; for example, the expansion ${${foo}} behaves exactly the
4099 same as ${foo}. When the `(P)' flag is present in a nested sub‐
4100 stitution, the other substitution rules are applied to the value
4101 before it is interpreted as a name, so ${${(P)foo}} may differ
4102 from ${(P)foo}.
4103
4104 At each nested level of substitution, the substituted words un‐
4105 dergo all forms of single-word substitution (i.e. not filename
4106 generation), including command substitution, arithmetic expan‐
4107 sion and filename expansion (i.e. leading ~ and =). Thus, for
4108 example, ${${:-=cat}:h} expands to the directory where the cat
4109 program resides. (Explanation: the internal substitution has no
4110 parameter but a default value =cat, which is expanded by file‐
4111 name expansion to a full path; the outer substitution then ap‐
4112 plies the modifier :h and takes the directory part of the path.)
4113
4114 2. Internal parameter flags
4115 Any parameter flags set by one of the typeset family of com‐
4116 mands, in particular the -L, -R, -Z, -u and -l options for pad‐
4117 ding and capitalization, are applied directly to the parameter
4118 value. Note these flags are options to the command, e.g. `type‐
4119 set -Z'; they are not the same as the flags used within parame‐
4120 ter substitutions.
4121
4122 At the outermost level of substitution, the `(P)' flag (rule 4.)
4123 ignores these transformations and uses the unmodified value of
4124 the parameter as the name to be replaced. This is usually the
4125 desired behavior because padding may make the value syntacti‐
4126 cally illegal as a parameter name, but if capitalization changes
4127 are desired, use the ${${(P)foo}} form (rule 25.).
4128
4129 3. Parameter subscripting
4130 If the value is a raw parameter reference with a subscript, such
4131 as ${var[3]}, the effect of subscripting is applied directly to
4132 the parameter. Subscripts are evaluated left to right; subse‐
4133 quent subscripts apply to the scalar or array value yielded by
4134 the previous subscript. Thus if var is an array, ${var[1][2]}
4135 is the second character of the first word, but ${var[2,4][2]} is
4136 the entire third word (the second word of the range of words two
4137 through four of the original array). Any number of subscripts
4138 may appear. Flags such as `(k)' and `(v)' which alter the re‐
4139 sult of subscripting are applied.
4140
4141 4. Parameter name replacement
4142 At the outermost level of nesting only, the `(P)' flag is ap‐
4143 plied. This treats the value so far as a parameter name (which
4144 may include a subscript expression) and replaces that with the
4145 corresponding value. This replacement occurs later if the `(P)'
4146 flag appears in a nested substitution.
4147
4148 If the value so far names a parameter that has internal flags
4149 (rule 2.), those internal flags are applied to the new value af‐
4150 ter replacement.
4151
4152 5. Double-quoted joining
4153 If the value after this process is an array, and the substitu‐
4154 tion appears in double quotes, and neither an `(@)' flag nor a
4155 `#' length operator is present at the current level, then words
4156 of the value are joined with the first character of the parame‐
4157 ter $IFS, by default a space, between each word (single word ar‐
4158 rays are not modified). If the `(j)' flag is present, that is
4159 used for joining instead of $IFS.
4160
4161 6. Nested subscripting
4162 Any remaining subscripts (i.e. of a nested substitution) are
4163 evaluated at this point, based on whether the value is an array
4164 or a scalar. As with 3., multiple subscripts can appear. Note
4165 that ${foo[2,4][2]} is thus equivalent to ${${foo[2,4]}[2]} and
4166 also to "${${(@)foo[2,4]}[2]}" (the nested substitution returns
4167 an array in both cases), but not to "${${foo[2,4]}[2]}" (the
4168 nested substitution returns a scalar because of the quotes).
4169
4170 7. Modifiers
4171 Any modifiers, as specified by a trailing `#', `%', `/' (possi‐
4172 bly doubled) or by a set of modifiers of the form `:...' (see
4173 the section `Modifiers' in the section `History Expansion'), are
4174 applied to the words of the value at this level.
4175
4176 8. Character evaluation
4177 Any `(#)' flag is applied, evaluating the result so far numeri‐
4178 cally as a character.
4179
4180 9. Length
4181 Any initial `#' modifier, i.e. in the form ${#var}, is used to
4182 evaluate the length of the expression so far.
4183
4184 10. Forced joining
4185 If the `(j)' flag is present, or no `(j)' flag is present but
4186 the string is to be split as given by rule 11., and joining did
4187 not take place at rule 5., any words in the value are joined to‐
4188 gether using the given string or the first character of $IFS if
4189 none. Note that the `(F)' flag implicitly supplies a string for
4190 joining in this manner.
4191
4192 11. Simple word splitting
4193 If one of the `(s)' or `(f)' flags are present, or the `=' spec‐
4194 ifier was present (e.g. ${=var}), the word is split on occur‐
4195 rences of the specified string, or (for = with neither of the
4196 two flags present) any of the characters in $IFS.
4197
4198 If no `(s)', `(f)' or `=' was given, but the word is not quoted
4199 and the option SH_WORD_SPLIT is set, the word is split on occur‐
4200 rences of any of the characters in $IFS. Note this step, too,
4201 takes place at all levels of a nested substitution.
4202
4203 12. Case modification
4204 Any case modification from one of the flags `(L)', `(U)' or
4205 `(C)' is applied.
4206
4207 13. Escape sequence replacement
4208 First any replacements from the `(g)' flag are performed, then
4209 any prompt-style formatting from the `(%)' family of flags is
4210 applied.
4211
4212 14. Quote application
4213 Any quoting or unquoting using `(q)' and `(Q)' and related flags
4214 is applied.
4215
4216 15. Directory naming
4217 Any directory name substitution using `(D)' flag is applied.
4218
4219 16. Visibility enhancement
4220 Any modifications to make characters visible using the `(V)'
4221 flag are applied.
4222
4223 17. Lexical word splitting
4224 If the '(z)' flag or one of the forms of the '(Z)' flag is
4225 present, the word is split as if it were a shell command line,
4226 so that quotation marks and other metacharacters are used to de‐
4227 cide what constitutes a word. Note this form of splitting is
4228 entirely distinct from that described by rule 11.: it does not
4229 use $IFS, and does not cause forced joining.
4230
4231 18. Uniqueness
4232 If the result is an array and the `(u)' flag was present, dupli‐
4233 cate elements are removed from the array.
4234
4235 19. Ordering
4236 If the result is still an array and one of the `(o)' or `(O)'
4237 flags was present, the array is reordered.
4238
4239 20. RC_EXPAND_PARAM
4240 At this point the decision is made whether any resulting array
4241 elements are to be combined element by element with surrounding
4242 text, as given by either the RC_EXPAND_PARAM option or the `^'
4243 flag.
4244
4245 21. Re-evaluation
4246 Any `(e)' flag is applied to the value, forcing it to be re-ex‐
4247 amined for new parameter substitutions, but also for command and
4248 arithmetic substitutions.
4249
4250 22. Padding
4251 Any padding of the value by the `(l.fill.)' or `(r.fill.)' flags
4252 is applied.
4253
4254 23. Semantic joining
4255 In contexts where expansion semantics requires a single word to
4256 result, all words are rejoined with the first character of IFS
4257 between. So in `${(P)${(f)lines}}' the value of ${lines} is
4258 split at newlines, but then must be joined again before the
4259 `(P)' flag can be applied.
4260
4261 If a single word is not required, this rule is skipped.
4262
4263 24. Empty argument removal
4264 If the substitution does not appear in double quotes, any re‐
4265 sulting zero-length argument, whether from a scalar or an ele‐
4266 ment of an array, is elided from the list of arguments inserted
4267 into the command line.
4268
4269 Strictly speaking, the removal happens later as the same happens
4270 with other forms of substitution; the point to note here is sim‐
4271 ply that it occurs after any of the above parameter operations.
4272
4273 25. Nested parameter name replacement
4274 If the `(P)' flag is present and rule 4. has not applied, the
4275 value so far is treated as a parameter name (which may include a
4276 subscript expression) and replaced with the corresponding value,
4277 with internal flags (rule 2.) applied to the new value.
4278
4279 Examples
4280 The flag f is useful to split a double-quoted substitution line by
4281 line. For example, ${(f)"$(<file)"} substitutes the contents of file
4282 divided so that each line is an element of the resulting array. Com‐
4283 pare this with the effect of $(<file) alone, which divides the file up
4284 by words, or the same inside double quotes, which makes the entire con‐
4285 tent of the file a single string.
4286
4287 The following illustrates the rules for nested parameter expansions.
4288 Suppose that $foo contains the array (bar baz):
4289
4290 "${(@)${foo}[1]}"
4291 This produces the result b. First, the inner substitution
4292 "${foo}", which has no array (@) flag, produces a single word
4293 result "bar baz". The outer substitution "${(@)...[1]}" detects
4294 that this is a scalar, so that (despite the `(@)' flag) the sub‐
4295 script picks the first character.
4296
4297 "${${(@)foo}[1]}"
4298 This produces the result `bar'. In this case, the inner substi‐
4299 tution "${(@)foo}" produces the array `(bar baz)'. The outer
4300 substitution "${...[1]}" detects that this is an array and picks
4301 the first word. This is similar to the simple case "${foo[1]}".
4302
4303 As an example of the rules for word splitting and joining, suppose $foo
4304 contains the array `(ax1 bx1)'. Then
4305
4306 ${(s/x/)foo}
4307 produces the words `a', `1 b' and `1'.
4308
4309 ${(j/x/s/x/)foo}
4310 produces `a', `1', `b' and `1'.
4311
4312 ${(s/x/)foo%%1*}
4313 produces `a' and ` b' (note the extra space). As substitution
4314 occurs before either joining or splitting, the operation first
4315 generates the modified array (ax bx), which is joined to give
4316 "ax bx", and then split to give `a', ` b' and `'. The final
4317 empty string will then be elided, as it is not in double quotes.
4318
4320 A command enclosed in parentheses preceded by a dollar sign, like
4321 `$(...)', or quoted with grave accents, like ``...`', is replaced with
4322 its standard output, with any trailing newlines deleted. If the sub‐
4323 stitution is not enclosed in double quotes, the output is broken into
4324 words using the IFS parameter.
4325
4326 The substitution `$(cat foo)' may be replaced by the faster `$(<foo)'.
4327 In this case foo undergoes single word shell expansions (parameter ex‐
4328 pansion, command substitution and arithmetic expansion), but not file‐
4329 name generation.
4330
4331 If the option GLOB_SUBST is set, the result of any unquoted command
4332 substitution, including the special form just mentioned, is eligible
4333 for filename generation.
4334
4336 A string of the form `$[exp]' or `$((exp))' is substituted with the
4337 value of the arithmetic expression exp. exp is subjected to parameter
4338 expansion, command substitution and arithmetic expansion before it is
4339 evaluated. See the section `Arithmetic Evaluation'.
4340
4342 A string of the form `foo{xx,yy,zz}bar' is expanded to the individual
4343 words `fooxxbar', `fooyybar' and `foozzbar'. Left-to-right order is
4344 preserved. This construct may be nested. Commas may be quoted in or‐
4345 der to include them literally in a word.
4346
4347 An expression of the form `{n1..n2}', where n1 and n2 are integers, is
4348 expanded to every number between n1 and n2 inclusive. If either number
4349 begins with a zero, all the resulting numbers will be padded with lead‐
4350 ing zeroes to that minimum width, but for negative numbers the - char‐
4351 acter is also included in the width. If the numbers are in decreasing
4352 order the resulting sequence will also be in decreasing order.
4353
4354 An expression of the form `{n1..n2..n3}', where n1, n2, and n3 are in‐
4355 tegers, is expanded as above, but only every n3th number starting from
4356 n1 is output. If n3 is negative the numbers are output in reverse or‐
4357 der, this is slightly different from simply swapping n1 and n2 in the
4358 case that the step n3 doesn't evenly divide the range. Zero padding
4359 can be specified in any of the three numbers, specifying it in the
4360 third can be useful to pad for example `{-99..100..01}' which is not
4361 possible to specify by putting a 0 on either of the first two numbers
4362 (i.e. pad to two characters).
4363
4364 An expression of the form `{c1..c2}', where c1 and c2 are single char‐
4365 acters (which may be multibyte characters), is expanded to every char‐
4366 acter in the range from c1 to c2 in whatever character sequence is used
4367 internally. For characters with code points below 128 this is US ASCII
4368 (this is the only case most users will need). If any intervening char‐
4369 acter is not printable, appropriate quotation is used to render it
4370 printable. If the character sequence is reversed, the output is in re‐
4371 verse order, e.g. `{d..a}' is substituted as `d c b a'.
4372
4373 If a brace expression matches none of the above forms, it is left un‐
4374 changed, unless the option BRACE_CCL (an abbreviation for `brace char‐
4375 acter class') is set. In that case, it is expanded to a list of the
4376 individual characters between the braces sorted into the order of the
4377 characters in the ASCII character set (multibyte characters are not
4378 currently handled). The syntax is similar to a [...] expression in
4379 filename generation: `-' is treated specially to denote a range of
4380 characters, but `^' or `!' as the first character is treated normally.
4381 For example, `{abcdef0-9}' expands to 16 words 0 1 2 3 4 5 6 7 8 9 a b
4382 c d e f.
4383
4384 Note that brace expansion is not part of filename generation (glob‐
4385 bing); an expression such as */{foo,bar} is split into two separate
4386 words */foo and */bar before filename generation takes place. In par‐
4387 ticular, note that this is liable to produce a `no match' error if ei‐
4388 ther of the two expressions does not match; this is to be contrasted
4389 with */(foo|bar), which is treated as a single pattern but otherwise
4390 has similar effects.
4391
4392 To combine brace expansion with array expansion, see the ${^spec} form
4393 described in the section `Parameter Expansion' above.
4394
4396 Each word is checked to see if it begins with an unquoted `~'. If it
4397 does, then the word up to a `/', or the end of the word if there is no
4398 `/', is checked to see if it can be substituted in one of the ways de‐
4399 scribed here. If so, then the `~' and the checked portion are replaced
4400 with the appropriate substitute value.
4401
4402 A `~' by itself is replaced by the value of $HOME. A `~' followed by a
4403 `+' or a `-' is replaced by current or previous working directory, re‐
4404 spectively.
4405
4406 A `~' followed by a number is replaced by the directory at that posi‐
4407 tion in the directory stack. `~0' is equivalent to `~+', and `~1' is
4408 the top of the stack. `~+' followed by a number is replaced by the di‐
4409 rectory at that position in the directory stack. `~+0' is equivalent
4410 to `~+', and `~+1' is the top of the stack. `~-' followed by a number
4411 is replaced by the directory that many positions from the bottom of the
4412 stack. `~-0' is the bottom of the stack. The PUSHD_MINUS option ex‐
4413 changes the effects of `~+' and `~-' where they are followed by a num‐
4414 ber.
4415
4416 Dynamic named directories
4417 If the function zsh_directory_name exists, or the shell variable
4418 zsh_directory_name_functions exists and contains an array of function
4419 names, then the functions are used to implement dynamic directory nam‐
4420 ing. The functions are tried in order until one returns status zero,
4421 so it is important that functions test whether they can handle the case
4422 in question and return an appropriate status.
4423
4424 A `~' followed by a string namstr in unquoted square brackets is
4425 treated specially as a dynamic directory name. Note that the first un‐
4426 quoted closing square bracket always terminates namstr. The shell
4427 function is passed two arguments: the string n (for name) and namstr.
4428 It should either set the array reply to a single element which is the
4429 directory corresponding to the name and return status zero (executing
4430 an assignment as the last statement is usually sufficient), or it
4431 should return status non-zero. In the former case the element of reply
4432 is used as the directory; in the latter case the substitution is deemed
4433 to have failed. If all functions fail and the option NOMATCH is set,
4434 an error results.
4435
4436 The functions defined as above are also used to see if a directory can
4437 be turned into a name, for example when printing the directory stack or
4438 when expanding %~ in prompts. In this case each function is passed two
4439 arguments: the string d (for directory) and the candidate for dynamic
4440 naming. The function should either return non-zero status, if the di‐
4441 rectory cannot be named by the function, or it should set the array re‐
4442 ply to consist of two elements: the first is the dynamic name for the
4443 directory (as would appear within `~[...]'), and the second is the pre‐
4444 fix length of the directory to be replaced. For example, if the trial
4445 directory is /home/myname/src/zsh and the dynamic name for /home/my‐
4446 name/src (which has 16 characters) is s, then the function sets
4447
4448 reply=(s 16)
4449
4450 The directory name so returned is compared with possible static names
4451 for parts of the directory path, as described below; it is used if the
4452 prefix length matched (16 in the example) is longer than that matched
4453 by any static name.
4454
4455 It is not a requirement that a function implements both n and d calls;
4456 for example, it might be appropriate for certain dynamic forms of ex‐
4457 pansion not to be contracted to names. In that case any call with the
4458 first argument d should cause a non-zero status to be returned.
4459
4460 The completion system calls `zsh_directory_name c' followed by equiva‐
4461 lent calls to elements of the array zsh_directory_name_functions, if it
4462 exists, in order to complete dynamic names for directories. The code
4463 for this should be as for any other completion function as described in
4464 zshcompsys(1).
4465
4466 As a working example, here is a function that expands any dynamic names
4467 beginning with the string p: to directories below /home/pws/perforce.
4468 In this simple case a static name for the directory would be just as
4469 effective.
4470
4471 zsh_directory_name() {
4472 emulate -L zsh
4473 setopt extendedglob
4474 local -a match mbegin mend
4475 if [[ $1 = d ]]; then
4476 # turn the directory into a name
4477 if [[ $2 = (#b)(/home/pws/perforce/)([^/]##)* ]]; then
4478 typeset -ga reply
4479 reply=(p:$match[2] $(( ${#match[1]} + ${#match[2]} )) )
4480 else
4481 return 1
4482 fi
4483 elif [[ $1 = n ]]; then
4484 # turn the name into a directory
4485 [[ $2 != (#b)p:(?*) ]] && return 1
4486 typeset -ga reply
4487 reply=(/home/pws/perforce/$match[1])
4488 elif [[ $1 = c ]]; then
4489 # complete names
4490 local expl
4491 local -a dirs
4492 dirs=(/home/pws/perforce/*(/:t))
4493 dirs=(p:${^dirs})
4494 _wanted dynamic-dirs expl 'dynamic directory' compadd -S\] -a dirs
4495 return
4496 else
4497 return 1
4498 fi
4499 return 0
4500 }
4501
4502 Static named directories
4503 A `~' followed by anything not already covered consisting of any number
4504 of alphanumeric characters or underscore (`_'), hyphen (`-'), or dot
4505 (`.') is looked up as a named directory, and replaced by the value of
4506 that named directory if found. Named directories are typically home
4507 directories for users on the system. They may also be defined if the
4508 text after the `~' is the name of a string shell parameter whose value
4509 begins with a `/'. Note that trailing slashes will be removed from the
4510 path to the directory (though the original parameter is not modified).
4511
4512 It is also possible to define directory names using the -d option to
4513 the hash builtin.
4514
4515 When the shell prints a path (e.g. when expanding %~ in prompts or when
4516 printing the directory stack), the path is checked to see if it has a
4517 named directory as its prefix. If so, then the prefix portion is re‐
4518 placed with a `~' followed by the name of the directory. The shorter
4519 of the two ways of referring to the directory is used, i.e. either the
4520 directory name or the full path; the name is used if they are the same
4521 length. The parameters $PWD and $OLDPWD are never abbreviated in this
4522 fashion.
4523
4524 `=' expansion
4525 If a word begins with an unquoted `=' and the EQUALS option is set, the
4526 remainder of the word is taken as the name of a command. If a command
4527 exists by that name, the word is replaced by the full pathname of the
4528 command.
4529
4530 Notes
4531 Filename expansion is performed on the right hand side of a parameter
4532 assignment, including those appearing after commands of the typeset
4533 family. In this case, the right hand side will be treated as a
4534 colon-separated list in the manner of the PATH parameter, so that a `~'
4535 or an `=' following a `:' is eligible for expansion. All such behav‐
4536 iour can be disabled by quoting the `~', the `=', or the whole expres‐
4537 sion (but not simply the colon); the EQUALS option is also respected.
4538
4539 If the option MAGIC_EQUAL_SUBST is set, any unquoted shell argument in
4540 the form `identifier=expression' becomes eligible for file expansion as
4541 described in the previous paragraph. Quoting the first `=' also in‐
4542 hibits this.
4543
4545 If a word contains an unquoted instance of one of the characters `*',
4546 `(', `|', `<', `[', or `?', it is regarded as a pattern for filename
4547 generation, unless the GLOB option is unset. If the EXTENDED_GLOB op‐
4548 tion is set, the `^' and `#' characters also denote a pattern; other‐
4549 wise they are not treated specially by the shell.
4550
4551 The word is replaced with a list of sorted filenames that match the
4552 pattern. If no matching pattern is found, the shell gives an error
4553 message, unless the NULL_GLOB option is set, in which case the word is
4554 deleted; or unless the NOMATCH option is unset, in which case the word
4555 is left unchanged.
4556
4557 In filename generation, the character `/' must be matched explicitly;
4558 also, a `.' must be matched explicitly at the beginning of a pattern or
4559 after a `/', unless the GLOB_DOTS option is set. No filename genera‐
4560 tion pattern matches the files `.' or `..'. In other instances of pat‐
4561 tern matching, the `/' and `.' are not treated specially.
4562
4563 Glob Operators
4564 * Matches any string, including the null string.
4565
4566 ? Matches any character.
4567
4568 [...] Matches any of the enclosed characters. Ranges of characters
4569 can be specified by separating two characters by a `-'. A `-'
4570 or `]' may be matched by including it as the first character in
4571 the list. There are also several named classes of characters,
4572 in the form `[:name:]' with the following meanings. The first
4573 set use the macros provided by the operating system to test for
4574 the given character combinations, including any modifications
4575 due to local language settings, see ctype(3):
4576
4577 [:alnum:]
4578 The character is alphanumeric
4579
4580 [:alpha:]
4581 The character is alphabetic
4582
4583 [:ascii:]
4584 The character is 7-bit, i.e. is a single-byte character
4585 without the top bit set.
4586
4587 [:blank:]
4588 The character is a blank character
4589
4590 [:cntrl:]
4591 The character is a control character
4592
4593 [:digit:]
4594 The character is a decimal digit
4595
4596 [:graph:]
4597 The character is a printable character other than white‐
4598 space
4599
4600 [:lower:]
4601 The character is a lowercase letter
4602
4603 [:print:]
4604 The character is printable
4605
4606 [:punct:]
4607 The character is printable but neither alphanumeric nor
4608 whitespace
4609
4610 [:space:]
4611 The character is whitespace
4612
4613 [:upper:]
4614 The character is an uppercase letter
4615
4616 [:xdigit:]
4617 The character is a hexadecimal digit
4618
4619 Another set of named classes is handled internally by the shell
4620 and is not sensitive to the locale:
4621
4622 [:IDENT:]
4623 The character is allowed to form part of a shell identi‐
4624 fier, such as a parameter name; this test respects the
4625 POSIX_IDENTIFIERS option
4626
4627 [:IFS:]
4628 The character is used as an input field separator, i.e.
4629 is contained in the IFS parameter
4630
4631 [:IFSSPACE:]
4632 The character is an IFS white space character; see the
4633 documentation for IFS in the zshparam(1) manual page.
4634
4635 [:INCOMPLETE:]
4636 Matches a byte that starts an incomplete multibyte char‐
4637 acter. Note that there may be a sequence of more than
4638 one bytes that taken together form the prefix of a multi‐
4639 byte character. To test for a potentially incomplete
4640 byte sequence, use the pattern `[[:INCOMPLETE:]]*'. This
4641 will never match a sequence starting with a valid multi‐
4642 byte character.
4643
4644 [:INVALID:]
4645 Matches a byte that does not start a valid multibyte
4646 character. Note this may be a continuation byte of an
4647 incomplete multibyte character as any part of a multibyte
4648 string consisting of invalid and incomplete multibyte
4649 characters is treated as single bytes.
4650
4651 [:WORD:]
4652 The character is treated as part of a word; this test is
4653 sensitive to the value of the WORDCHARS parameter
4654
4655 Note that the square brackets are additional to those enclosing
4656 the whole set of characters, so to test for a single alphanu‐
4657 meric character you need `[[:alnum:]]'. Named character sets
4658 can be used alongside other types, e.g. `[[:alpha:]0-9]'.
4659
4660 [^...]
4661 [!...] Like [...], except that it matches any character which is not in
4662 the given set.
4663
4664 <[x]-[y]>
4665 Matches any number in the range x to y, inclusive. Either of
4666 the numbers may be omitted to make the range open-ended; hence
4667 `<->' matches any number. To match individual digits, the [...]
4668 form is more efficient.
4669
4670 Be careful when using other wildcards adjacent to patterns of
4671 this form; for example, <0-9>* will actually match any number
4672 whatsoever at the start of the string, since the `<0-9>' will
4673 match the first digit, and the `*' will match any others. This
4674 is a trap for the unwary, but is in fact an inevitable conse‐
4675 quence of the rule that the longest possible match always suc‐
4676 ceeds. Expressions such as `<0-9>[^[:digit:]]*' can be used in‐
4677 stead.
4678
4679 (...) Matches the enclosed pattern. This is used for grouping. If
4680 the KSH_GLOB option is set, then a `@', `*', `+', `?' or `!' im‐
4681 mediately preceding the `(' is treated specially, as detailed
4682 below. The option SH_GLOB prevents bare parentheses from being
4683 used in this way, though the KSH_GLOB option is still available.
4684
4685 Note that grouping cannot extend over multiple directories: it
4686 is an error to have a `/' within a group (this only applies for
4687 patterns used in filename generation). There is one exception:
4688 a group of the form (pat/)# appearing as a complete path segment
4689 can match a sequence of directories. For example, foo/(a*/)#bar
4690 matches foo/bar, foo/any/bar, foo/any/anyother/bar, and so on.
4691
4692 x|y Matches either x or y. This operator has lower precedence than
4693 any other. The `|' character must be within parentheses, to
4694 avoid interpretation as a pipeline. The alternatives are tried
4695 in order from left to right.
4696
4697 ^x (Requires EXTENDED_GLOB to be set.) Matches anything except the
4698 pattern x. This has a higher precedence than `/', so `^foo/bar'
4699 will search directories in `.' except `./foo' for a file named
4700 `bar'.
4701
4702 x~y (Requires EXTENDED_GLOB to be set.) Match anything that matches
4703 the pattern x but does not match y. This has lower precedence
4704 than any operator except `|', so `*/*~foo/bar' will search for
4705 all files in all directories in `.' and then exclude `foo/bar'
4706 if there was such a match. Multiple patterns can be excluded by
4707 `foo~bar~baz'. In the exclusion pattern (y), `/' and `.' are
4708 not treated specially the way they usually are in globbing.
4709
4710 x# (Requires EXTENDED_GLOB to be set.) Matches zero or more occur‐
4711 rences of the pattern x. This operator has high precedence;
4712 `12#' is equivalent to `1(2#)', rather than `[1m(12)#'. It is an
4713 error for an unquoted `#' to follow something which cannot be
4714 repeated; this includes an empty string, a pattern already fol‐
4715 lowed by `##', or parentheses when part of a KSH_GLOB pattern
4716 (for example, `!(foo)#' is invalid and must be replaced by
4717 `*(!(foo))').
4718
4719 x## (Requires EXTENDED_GLOB to be set.) Matches one or more occur‐
4720 rences of the pattern x. This operator has high precedence;
4721 `12##' is equivalent to `1(2##)', rather than `[1m(12)##'. No more
4722 than two active `#' characters may appear together. (Note the
4723 potential clash with glob qualifiers in the form `1(2##)' which
4724 should therefore be avoided.)
4725
4726 ksh-like Glob Operators
4727 If the KSH_GLOB option is set, the effects of parentheses can be modi‐
4728 fied by a preceding `@', `*', `+', `?' or `!'. This character need not
4729 be unquoted to have special effects, but the `(' must be.
4730
4731 @(...) Match the pattern in the parentheses. (Like `(...)'.)
4732
4733 *(...) Match any number of occurrences. (Like `(...)#', except that
4734 recursive directory searching is not supported.)
4735
4736 +(...) Match at least one occurrence. (Like `(...)##', except that re‐
4737 cursive directory searching is not supported.)
4738
4739 ?(...) Match zero or one occurrence. (Like `(|...)'.)
4740
4741 !(...) Match anything but the expression in parentheses. (Like
4742 `(^(...))'.)
4743
4744 Precedence
4745 The precedence of the operators given above is (highest) `^', `/', `~',
4746 `|' (lowest); the remaining operators are simply treated from left to
4747 right as part of a string, with `#' and `##' applying to the shortest
4748 possible preceding unit (i.e. a character, `?', `[...]', `<...>', or a
4749 parenthesised expression). As mentioned above, a `/' used as a direc‐
4750 tory separator may not appear inside parentheses, while a `|' must do
4751 so; in patterns used in other contexts than filename generation (for
4752 example, in case statements and tests within `[[...]]'), a `/' is not
4753 special; and `/' is also not special after a `~' appearing outside
4754 parentheses in a filename pattern.
4755
4756 Globbing Flags
4757 There are various flags which affect any text to their right up to the
4758 end of the enclosing group or to the end of the pattern; they require
4759 the EXTENDED_GLOB option. All take the form (#X) where X may have one
4760 of the following forms:
4761
4762 i Case insensitive: upper or lower case characters in the pattern
4763 match upper or lower case characters.
4764
4765 l Lower case characters in the pattern match upper or lower case
4766 characters; upper case characters in the pattern still only
4767 match upper case characters.
4768
4769 I Case sensitive: locally negates the effect of i or l from that
4770 point on.
4771
4772 b Activate backreferences for parenthesised groups in the pattern;
4773 this does not work in filename generation. When a pattern with
4774 a set of active parentheses is matched, the strings matched by
4775 the groups are stored in the array $match, the indices of the
4776 beginning of the matched parentheses in the array $mbegin, and
4777 the indices of the end in the array $mend, with the first ele‐
4778 ment of each array corresponding to the first parenthesised
4779 group, and so on. These arrays are not otherwise special to the
4780 shell. The indices use the same convention as does parameter
4781 substitution, so that elements of $mend and $mbegin may be used
4782 in subscripts; the KSH_ARRAYS option is respected. Sets of
4783 globbing flags are not considered parenthesised groups; only the
4784 first nine active parentheses can be referenced.
4785
4786 For example,
4787
4788 foo="a_string_with_a_message"
4789 if [[ $foo = (a|an)_(#b)(*) ]]; then
4790 print ${foo[$mbegin[1],$mend[1]]}
4791 fi
4792
4793 prints `string_with_a_message'. Note that the first set of
4794 parentheses is before the (#b) and does not create a backrefer‐
4795 ence.
4796
4797 Backreferences work with all forms of pattern matching other
4798 than filename generation, but note that when performing matches
4799 on an entire array, such as ${array#pattern}, or a global sub‐
4800 stitution, such as ${param//pat/repl}, only the data for the
4801 last match remains available. In the case of global replace‐
4802 ments this may still be useful. See the example for the m flag
4803 below.
4804
4805 The numbering of backreferences strictly follows the order of
4806 the opening parentheses from left to right in the pattern
4807 string, although sets of parentheses may be nested. There are
4808 special rules for parentheses followed by `#' or `##'. Only the
4809 last match of the parenthesis is remembered: for example, in `[[
4810 abab = (#b)([ab])# ]]', only the final `b' is stored in
4811 match[1]. Thus extra parentheses may be necessary to match the
4812 complete segment: for example, use `X((ab|cd)#)Y' to match a
4813 whole string of either `ab' or `cd' between `X' and `Y', using
4814 the value of $match[1] rather than $match[2].
4815
4816 If the match fails none of the parameters is altered, so in some
4817 cases it may be necessary to initialise them beforehand. If
4818 some of the backreferences fail to match -- which happens if
4819 they are in an alternate branch which fails to match, or if they
4820 are followed by # and matched zero times -- then the matched
4821 string is set to the empty string, and the start and end indices
4822 are set to -1.
4823
4824 Pattern matching with backreferences is slightly slower than
4825 without.
4826
4827 B Deactivate backreferences, negating the effect of the b flag
4828 from that point on.
4829
4830 cN,M The flag (#cN,M) can be used anywhere that the # or ## operators
4831 can be used except in the expressions `(*/)#' and `(*/)##' in
4832 filename generation, where `/' has special meaning; it cannot be
4833 combined with other globbing flags and a bad pattern error oc‐
4834 curs if it is misplaced. It is equivalent to the form {N,M} in
4835 regular expressions. The previous character or group is re‐
4836 quired to match between N and M times, inclusive. The form
4837 (#cN) requires exactly N matches; (#c,M) is equivalent to speci‐
4838 fying N as 0; (#cN,) specifies that there is no maximum limit on
4839 the number of matches.
4840
4841 m Set references to the match data for the entire string matched;
4842 this is similar to backreferencing and does not work in filename
4843 generation. The flag must be in effect at the end of the pat‐
4844 tern, i.e. not local to a group. The parameters $MATCH, $MBEGIN
4845 and $MEND will be set to the string matched and to the indices
4846 of the beginning and end of the string, respectively. This is
4847 most useful in parameter substitutions, as otherwise the string
4848 matched is obvious.
4849
4850 For example,
4851
4852 arr=(veldt jynx grimps waqf zho buck)
4853 print ${arr//(#m)[aeiou]/${(U)MATCH}}
4854
4855 forces all the matches (i.e. all vowels) into uppercase, print‐
4856 ing `vEldt jynx grImps wAqf zhO bUck'.
4857
4858 Unlike backreferences, there is no speed penalty for using match
4859 references, other than the extra substitutions required for the
4860 replacement strings in cases such as the example shown.
4861
4862 M Deactivate the m flag, hence no references to match data will be
4863 created.
4864
4865 anum Approximate matching: num errors are allowed in the string
4866 matched by the pattern. The rules for this are described in the
4867 next subsection.
4868
4869 s, e Unlike the other flags, these have only a local effect, and each
4870 must appear on its own: `(#s)' and `(#e)' are the only valid
4871 forms. The `(#s)' flag succeeds only at the start of the test
4872 string, and the `(#e)' flag succeeds only at the end of the test
4873 string; they correspond to `^' and `$' in standard regular ex‐
4874 pressions. They are useful for matching path segments in pat‐
4875 terns other than those in filename generation (where path seg‐
4876 ments are in any case treated separately). For example,
4877 `*((#s)|/)test((#e)|/)*' matches a path segment `test' in any of
4878 the following strings: test, test/at/start, at/end/test,
4879 in/test/middle.
4880
4881 Another use is in parameter substitution; for example `${ar‐
4882 ray/(#s)A*Z(#e)}' will remove only elements of an array which
4883 match the complete pattern `A*Z'. There are other ways of per‐
4884 forming many operations of this type, however the combination of
4885 the substitution operations `/' and `//' with the `(#s)' and
4886 `(#e)' flags provides a single simple and memorable method.
4887
4888 Note that assertions of the form `(^(#s))' also work, i.e. match
4889 anywhere except at the start of the string, although this actu‐
4890 ally means `anything except a zero-length portion at the start
4891 of the string'; you need to use `(""~(#s))' to match a
4892 zero-length portion of the string not at the start.
4893
4894 q A `q' and everything up to the closing parenthesis of the glob‐
4895 bing flags are ignored by the pattern matching code. This is
4896 intended to support the use of glob qualifiers, see below. The
4897 result is that the pattern `(#b)(*).c(#q.)' can be used both for
4898 globbing and for matching against a string. In the former case,
4899 the `(#q.)' will be treated as a glob qualifier and the `(#b)'
4900 will not be useful, while in the latter case the `(#b)' is use‐
4901 ful for backreferences and the `(#q.)' will be ignored. Note
4902 that colon modifiers in the glob qualifiers are also not applied
4903 in ordinary pattern matching.
4904
4905 u Respect the current locale in determining the presence of multi‐
4906 byte characters in a pattern, provided the shell was compiled
4907 with MULTIBYTE_SUPPORT. This overrides the MULTIBYTE option;
4908 the default behaviour is taken from the option. Compare U.
4909 (Mnemonic: typically multibyte characters are from Unicode in
4910 the UTF-8 encoding, although any extension of ASCII supported by
4911 the system library may be used.)
4912
4913 U All characters are considered to be a single byte long. The op‐
4914 posite of u. This overrides the MULTIBYTE option.
4915
4916 For example, the test string fooxx can be matched by the pattern
4917 (#i)FOOXX, but not by (#l)FOOXX, (#i)FOO(#I)XX or ((#i)FOOX)X. The
4918 string (#ia2)readme specifies case-insensitive matching of readme with
4919 up to two errors.
4920
4921 When using the ksh syntax for grouping both KSH_GLOB and EXTENDED_GLOB
4922 must be set and the left parenthesis should be preceded by @. Note
4923 also that the flags do not affect letters inside [...] groups, in other
4924 words (#i)[a-z] still matches only lowercase letters. Finally, note
4925 that when examining whole paths case-insensitively every directory must
4926 be searched for all files which match, so that a pattern of the form
4927 (#i)/foo/bar/... is potentially slow.
4928
4929 Approximate Matching
4930 When matching approximately, the shell keeps a count of the errors
4931 found, which cannot exceed the number specified in the (#anum) flags.
4932 Four types of error are recognised:
4933
4934 1. Different characters, as in fooxbar and fooybar.
4935
4936 2. Transposition of characters, as in banana and abnana.
4937
4938 3. A character missing in the target string, as with the pattern
4939 road and target string rod.
4940
4941 4. An extra character appearing in the target string, as with stove
4942 and strove.
4943
4944 Thus, the pattern (#a3)abcd matches dcba, with the errors occurring by
4945 using the first rule twice and the second once, grouping the string as
4946 [d][cb][a] and [a][bc][d].
4947
4948 Non-literal parts of the pattern must match exactly, including charac‐
4949 ters in character ranges: hence (#a1)??? matches strings of length
4950 four, by applying rule 4 to an empty part of the pattern, but not
4951 strings of length two, since all the ? must match. Other characters
4952 which must match exactly are initial dots in filenames (unless the
4953 GLOB_DOTS option is set), and all slashes in filenames, so that a/bc is
4954 two errors from ab/c (the slash cannot be transposed with another char‐
4955 acter). Similarly, errors are counted separately for non-contiguous
4956 strings in the pattern, so that (ab|cd)ef is two errors from aebf.
4957
4958 When using exclusion via the ~ operator, approximate matching is
4959 treated entirely separately for the excluded part and must be activated
4960 separately. Thus, (#a1)README~READ_ME matches READ.ME but not READ_ME,
4961 as the trailing READ_ME is matched without approximation. However,
4962 (#a1)README~(#a1)READ_ME does not match any pattern of the form READ?ME
4963 as all such forms are now excluded.
4964
4965 Apart from exclusions, there is only one overall error count; however,
4966 the maximum errors allowed may be altered locally, and this can be de‐
4967 limited by grouping. For example, (#a1)cat((#a0)dog)fox allows one er‐
4968 ror in total, which may not occur in the dog section, and the pattern
4969 (#a1)cat(#a0)dog(#a1)fox is equivalent. Note that the point at which
4970 an error is first found is the crucial one for establishing whether to
4971 use approximation; for example, (#a1)abc(#a0)xyz will not match
4972 abcdxyz, because the error occurs at the `x', where approximation is
4973 turned off.
4974
4975 Entire path segments may be matched approximately, so that
4976 `(#a1)/foo/d/is/available/at/the/bar' allows one error in any path seg‐
4977 ment. This is much less efficient than without the (#a1), however,
4978 since every directory in the path must be scanned for a possible ap‐
4979 proximate match. It is best to place the (#a1) after any path segments
4980 which are known to be correct.
4981
4982 Recursive Globbing
4983 A pathname component of the form `(foo/)#' matches a path consisting of
4984 zero or more directories matching the pattern foo.
4985
4986 As a shorthand, `**/' is equivalent to `(*/)#'; note that this there‐
4987 fore matches files in the current directory as well as subdirectories.
4988 Thus:
4989
4990 ls -ld -- (*/)#bar
4991
4992 or
4993
4994 ls -ld -- **/bar
4995
4996 does a recursive directory search for files named `bar' (potentially
4997 including the file `bar' in the current directory). This form does not
4998 follow symbolic links; the alternative form `***/' does, but is other‐
4999 wise identical. Neither of these can be combined with other forms of
5000 globbing within the same path segment; in that case, the `*' operators
5001 revert to their usual effect.
5002
5003 Even shorter forms are available when the option GLOB_STAR_SHORT is
5004 set. In that case if no / immediately follows a ** or *** they are
5005 treated as if both a / plus a further * are present. Hence:
5006
5007 setopt GLOBSTARSHORT
5008 ls -ld -- **.c
5009
5010 is equivalent to
5011
5012 ls -ld -- **/*.c
5013
5014 Glob Qualifiers
5015 Patterns used for filename generation may end in a list of qualifiers
5016 enclosed in parentheses. The qualifiers specify which filenames that
5017 otherwise match the given pattern will be inserted in the argument
5018 list.
5019
5020 If the option BARE_GLOB_QUAL is set, then a trailing set of parentheses
5021 containing no `|' or `(' characters (or `~' if it is special) is taken
5022 as a set of glob qualifiers. A glob subexpression that would normally
5023 be taken as glob qualifiers, for example `(^x)', can be forced to be
5024 treated as part of the glob pattern by doubling the parentheses, in
5025 this case producing `((^x))'.
5026
5027 If the option EXTENDED_GLOB is set, a different syntax for glob quali‐
5028 fiers is available, namely `(#qx)' where x is any of the same glob
5029 qualifiers used in the other format. The qualifiers must still appear
5030 at the end of the pattern. However, with this syntax multiple glob
5031 qualifiers may be chained together. They are treated as a logical AND
5032 of the individual sets of flags. Also, as the syntax is unambiguous,
5033 the expression will be treated as glob qualifiers just as long any
5034 parentheses contained within it are balanced; appearance of `|', `(' or
5035 `~' does not negate the effect. Note that qualifiers will be recog‐
5036 nised in this form even if a bare glob qualifier exists at the end of
5037 the pattern, for example `*(#q*)(.)' will recognise executable regular
5038 files if both options are set; however, mixed syntax should probably be
5039 avoided for the sake of clarity. Note that within conditions using the
5040 `[[' form the presence of a parenthesised expression (#q...) at the end
5041 of a string indicates that globbing should be performed; the expression
5042 may include glob qualifiers, but it is also valid if it is simply (#q).
5043 This does not apply to the right hand side of pattern match operators
5044 as the syntax already has special significance.
5045
5046 A qualifier may be any one of the following:
5047
5048 / directories
5049
5050 F `full' (i.e. non-empty) directories. Note that the opposite
5051 sense (^F) expands to empty directories and all non-directories.
5052 Use (/^F) for empty directories.
5053
5054 . plain files
5055
5056 @ symbolic links
5057
5058 = sockets
5059
5060 p named pipes (FIFOs)
5061
5062 * executable plain files (0100 or 0010 or 0001)
5063
5064 % device files (character or block special)
5065
5066 %b block special files
5067
5068 %c character special files
5069
5070 r owner-readable files (0400)
5071
5072 w owner-writable files (0200)
5073
5074 x owner-executable files (0100)
5075
5076 A group-readable files (0040)
5077
5078 I group-writable files (0020)
5079
5080 E group-executable files (0010)
5081
5082 R world-readable files (0004)
5083
5084 W world-writable files (0002)
5085
5086 X world-executable files (0001)
5087
5088 s setuid files (04000)
5089
5090 S setgid files (02000)
5091
5092 t files with the sticky bit (01000)
5093
5094 fspec files with access rights matching spec. This spec may be a octal
5095 number optionally preceded by a `=', a `+', or a `-'. If none of
5096 these characters is given, the behavior is the same as for `='.
5097 The octal number describes the mode bits to be expected, if com‐
5098 bined with a `=', the value given must match the file-modes ex‐
5099 actly, with a `+', at least the bits in the given number must be
5100 set in the file-modes, and with a `-', the bits in the number
5101 must not be set. Giving a `?' instead of a octal digit anywhere
5102 in the number ensures that the corresponding bits in the
5103 file-modes are not checked, this is only useful in combination
5104 with `='.
5105
5106 If the qualifier `f' is followed by any other character anything
5107 up to the next matching character (`[', `{', and `<' match `]',
5108 `}', and `>' respectively, any other character matches itself)
5109 is taken as a list of comma-separated sub-specs. Each sub-spec
5110 may be either an octal number as described above or a list of
5111 any of the characters `u', `g', `o', and `a', followed by a `=',
5112 a `+', or a `-', followed by a list of any of the characters
5113 `r', `w', `x', `s', and `t', or an octal digit. The first list
5114 of characters specify which access rights are to be checked. If
5115 a `u' is given, those for the owner of the file are used, if a
5116 `g' is given, those of the group are checked, a `o' means to
5117 test those of other users, and the `a' says to test all three
5118 groups. The `=', `+', and `-' again says how the modes are to be
5119 checked and have the same meaning as described for the first
5120 form above. The second list of characters finally says which ac‐
5121 cess rights are to be expected: `r' for read access, `w' for
5122 write access, `x' for the right to execute the file (or to
5123 search a directory), `s' for the setuid and setgid bits, and `t'
5124 for the sticky bit.
5125
5126 Thus, `*(f70?)' gives the files for which the owner has read,
5127 write, and execute permission, and for which other group members
5128 have no rights, independent of the permissions for other users.
5129 The pattern `*(f-100)' gives all files for which the owner does
5130 not have execute permission, and `*(f:gu+w,o-rx:)' gives the
5131 files for which the owner and the other members of the group
5132 have at least write permission, and for which other users don't
5133 have read or execute permission.
5134
5135 estring
5136 +cmd The string will be executed as shell code. The filename will be
5137 included in the list if and only if the code returns a zero sta‐
5138 tus (usually the status of the last command).
5139
5140 In the first form, the first character after the `e' will be
5141 used as a separator and anything up to the next matching separa‐
5142 tor will be taken as the string; `[', `{', and `<' match `]',
5143 `}', and `>', respectively, while any other character matches
5144 itself. Note that expansions must be quoted in the string to
5145 prevent them from being expanded before globbing is done.
5146 string is then executed as shell code. The string globqual is
5147 appended to the array zsh_eval_context the duration of execu‐
5148 tion.
5149
5150 During the execution of string the filename currently being
5151 tested is available in the parameter REPLY; the parameter may be
5152 altered to a string to be inserted into the list instead of the
5153 original filename. In addition, the parameter reply may be set
5154 to an array or a string, which overrides the value of REPLY. If
5155 set to an array, the latter is inserted into the command line
5156 word by word.
5157
5158 For example, suppose a directory contains a single file
5159 `lonely'. Then the expression `*(e:'reply=(${REPLY}{1,2})':)'
5160 will cause the words `lonely1' and `lonely2' to be inserted into
5161 the command line. Note the quoting of string.
5162
5163 The form +cmd has the same effect, but no delimiters appear
5164 around cmd. Instead, cmd is taken as the longest sequence of
5165 characters following the + that are alphanumeric or underscore.
5166 Typically cmd will be the name of a shell function that contains
5167 the appropriate test. For example,
5168
5169 nt() { [[ $REPLY -nt $NTREF ]] }
5170 NTREF=reffile
5171 ls -ld -- *(+nt)
5172
5173 lists all files in the directory that have been modified more
5174 recently than reffile.
5175
5176 ddev files on the device dev
5177
5178 l[-|+]ct
5179 files having a link count less than ct (-), greater than ct (+),
5180 or equal to ct
5181
5182 U files owned by the effective user ID
5183
5184 G files owned by the effective group ID
5185
5186 uid files owned by user ID id if that is a number. Otherwise, id
5187 specifies a user name: the character after the `u' will be taken
5188 as a separator and the string between it and the next matching
5189 separator will be taken as a user name. The starting separators
5190 `[', `{', and `<' match the final separators `]', `}', and `>',
5191 respectively; any other character matches itself. The selected
5192 files are those owned by this user. For example, `u:foo:' or
5193 `u[foo]' selects files owned by user `foo'.
5194
5195 gid like uid but with group IDs or names
5196
5197 a[Mwhms][-|+]n
5198 files accessed exactly n days ago. Files accessed within the
5199 last n days are selected using a negative value for n (-n).
5200 Files accessed more than n days ago are selected by a positive n
5201 value (+n). Optional unit specifiers `M', `w', `h', `m' or `s'
5202 (e.g. `ah5') cause the check to be performed with months (of 30
5203 days), weeks, hours, minutes or seconds instead of days, respec‐
5204 tively. An explicit `d' for days is also allowed.
5205
5206 Any fractional part of the difference between the access time
5207 and the current part in the appropriate units is ignored in the
5208 comparison. For instance, `echo *(ah-5)' would echo files ac‐
5209 cessed within the last five hours, while `echo *(ah+5)' would
5210 echo files accessed at least six hours ago, as times strictly
5211 between five and six hours are treated as five hours.
5212
5213 m[Mwhms][-|+]n
5214 like the file access qualifier, except that it uses the file
5215 modification time.
5216
5217 c[Mwhms][-|+]n
5218 like the file access qualifier, except that it uses the file in‐
5219 ode change time.
5220
5221 L[+|-]n
5222 files less than n bytes (-), more than n bytes (+), or exactly n
5223 bytes in length.
5224
5225 If this flag is directly followed by a size specifier `k' (`K'),
5226 `m' (`M'), or `p' (`P') (e.g. `Lk-50') the check is performed
5227 with kilobytes, megabytes, or blocks (of 512 bytes) instead.
5228 (On some systems additional specifiers are available for giga‐
5229 bytes, `g' or `G', and terabytes, `t' or `T'.) If a size speci‐
5230 fier is used a file is regarded as "exactly" the size if the
5231 file size rounded up to the next unit is equal to the test size.
5232 Hence `*(Lm1)' matches files from 1 byte up to 1 Megabyte inclu‐
5233 sive. Note also that the set of files "less than" the test size
5234 only includes files that would not match the equality test;
5235 hence `*(Lm-1)' only matches files of zero size.
5236
5237 ^ negates all qualifiers following it
5238
5239 - toggles between making the qualifiers work on symbolic links
5240 (the default) and the files they point to, if any; any symbolic
5241 link for whose target the `stat' system call fails (whatever the
5242 cause of the failure) is treated as a file in its own right
5243
5244 M sets the MARK_DIRS option for the current pattern
5245
5246 T appends a trailing qualifier mark to the filenames, analogous to
5247 the LIST_TYPES option, for the current pattern (overrides M)
5248
5249 N sets the NULL_GLOB option for the current pattern
5250
5251 D sets the GLOB_DOTS option for the current pattern
5252
5253 n sets the NUMERIC_GLOB_SORT option for the current pattern
5254
5255 Yn enables short-circuit mode: the pattern will expand to at most n
5256 filenames. If more than n matches exist, only the first n
5257 matches in directory traversal order will be considered.
5258
5259 Implies oN when no oc qualifier is used.
5260
5261 oc specifies how the names of the files should be sorted. The fol‐
5262 lowing values of c sort in the following ways:
5263
5264 n By name.
5265 L By the size (length) of the files.
5266 l By number of links.
5267 a By time of last access, youngest first.
5268 m By time of last modification, youngest first.
5269 c By time of last inode change, youngest first.
5270 d By directories: files in subdirectories appear before
5271 those in the current directory at each level of the
5272 search -- this is best combined with other criteria, for
5273 example `odon' to sort on names for files within the same
5274 directory.
5275 N No sorting is performed.
5276 estring
5277 +cmd Sort by shell code (see below).
5278
5279 Note that the modifiers ^ and - are used, so `*(^-oL)' gives a
5280 list of all files sorted by file size in descending order, fol‐
5281 lowing any symbolic links. Unless oN is used, multiple order
5282 specifiers may occur to resolve ties.
5283
5284 The default sorting is n (by name) unless the Y glob qualifier
5285 is used, in which case it is N (unsorted).
5286
5287 oe and o+ are special cases; they are each followed by shell
5288 code, delimited as for the e glob qualifier and the + glob qual‐
5289 ifier respectively (see above). The code is executed for each
5290 matched file with the parameter REPLY set to the name of the
5291 file on entry and globsort appended to zsh_eval_context. The
5292 code should modify the parameter REPLY in some fashion. On re‐
5293 turn, the value of the parameter is used instead of the file
5294 name as the string on which to sort. Unlike other sort opera‐
5295 tors, oe and o+ may be repeated, but note that the maximum num‐
5296 ber of sort operators of any kind that may appear in any glob
5297 expression is 12.
5298
5299 Oc like `o', but sorts in descending order; i.e. `*(^oc)' is the
5300 same as `*(Oc)' and `*(^Oc)' is the same as `*(oc)'; `Od' puts
5301 files in the current directory before those in subdirectories at
5302 each level of the search.
5303
5304 [beg[,end]]
5305 specifies which of the matched filenames should be included in
5306 the returned list. The syntax is the same as for array sub‐
5307 scripts. beg and the optional end may be mathematical expres‐
5308 sions. As in parameter subscripting they may be negative to make
5309 them count from the last match backward. E.g.: `*(-OL[1,3])'
5310 gives a list of the names of the three largest files.
5311
5312 Pstring
5313 The string will be prepended to each glob match as a separate
5314 word. string is delimited in the same way as arguments to the e
5315 glob qualifier described above. The qualifier can be repeated;
5316 the words are prepended separately so that the resulting command
5317 line contains the words in the same order they were given in the
5318 list of glob qualifiers.
5319
5320 A typical use for this is to prepend an option before all occur‐
5321 rences of a file name; for example, the pattern `*(P:-f:)' pro‐
5322 duces the command line arguments `-f file1 -f file2 ...'
5323
5324 If the modifier ^ is active, then string will be appended in‐
5325 stead of prepended. Prepending and appending is done indepen‐
5326 dently so both can be used on the same glob expression; for ex‐
5327 ample by writing `*(P:foo:^P:bar:^P:baz:)' which produces the
5328 command line arguments `foo baz file1 bar ...'
5329
5330 More than one of these lists can be combined, separated by commas. The
5331 whole list matches if at least one of the sublists matches (they are
5332 `or'ed, the qualifiers in the sublists are `and'ed). Some qualifiers,
5333 however, affect all matches generated, independent of the sublist in
5334 which they are given. These are the qualifiers `M', `T', `N', `D',
5335 `n', `o', `O' and the subscripts given in brackets (`[...]').
5336
5337 If a `:' appears in a qualifier list, the remainder of the expression
5338 in parenthesis is interpreted as a modifier (see the section `Modi‐
5339 fiers' in the section `History Expansion'). Each modifier must be in‐
5340 troduced by a separate `:'. Note also that the result after modifica‐
5341 tion does not have to be an existing file. The name of any existing
5342 file can be followed by a modifier of the form `(:...)' even if no ac‐
5343 tual filename generation is performed, although note that the presence
5344 of the parentheses causes the entire expression to be subjected to any
5345 global pattern matching options such as NULL_GLOB. Thus:
5346
5347 ls -ld -- *(-/)
5348
5349 lists all directories and symbolic links that point to directories, and
5350
5351 ls -ld -- *(-@)
5352
5353 lists all broken symbolic links, and
5354
5355 ls -ld -- *(%W)
5356
5357 lists all world-writable device files in the current directory, and
5358
5359 ls -ld -- *(W,X)
5360
5361 lists all files in the current directory that are world-writable or
5362 world-executable, and
5363
5364 print -rC1 /tmp/foo*(u0^@:t)
5365
5366 outputs the basename of all root-owned files beginning with the string
5367 `foo' in /tmp, ignoring symlinks, and
5368
5369 ls -ld -- *.*~(lex|parse).[ch](^D^l1)
5370
5371 lists all files having a link count of one whose names contain a dot
5372 (but not those starting with a dot, since GLOB_DOTS is explicitly
5373 switched off) except for lex.c, lex.h, parse.c and parse.h.
5374
5375 print -rC1 b*.pro(#q:s/pro/shmo/)(#q.:s/builtin/shmiltin/)
5376
5377 demonstrates how colon modifiers and other qualifiers may be chained
5378 together. The ordinary qualifier `.' is applied first, then the colon
5379 modifiers in order from left to right. So if EXTENDED_GLOB is set and
5380 the base pattern matches the regular file builtin.pro, the shell will
5381 print `shmiltin.shmo'.
5382
5383
5384
5385ZSHPARAM(1) General Commands Manual ZSHPARAM(1)
5386
5387
5388
5390 zshparam - zsh parameters
5391
5393 A parameter has a name, a value, and a number of attributes. A name
5394 may be any sequence of alphanumeric characters and underscores, or the
5395 single characters `*', `@', `#', `?', `-', `$', or `!'. A parameter
5396 whose name begins with an alphanumeric or underscore is also referred
5397 to as a variable.
5398
5399 The attributes of a parameter determine the type of its value, often
5400 referred to as the parameter type or variable type, and also control
5401 other processing that may be applied to the value when it is refer‐
5402 enced. The value type may be a scalar (a string, an integer, or a
5403 floating point number), an array (indexed numerically), or an associa‐
5404 tive array (an unordered set of name-value pairs, indexed by name, also
5405 referred to as a hash).
5406
5407 Named scalar parameters may have the exported, -x, attribute, to copy
5408 them into the process environment, which is then passed from the shell
5409 to any new processes that it starts. Exported parameters are called
5410 environment variables. The shell also imports environment variables at
5411 startup time and automatically marks the corresponding parameters as
5412 exported. Some environment variables are not imported for reasons of
5413 security or because they would interfere with the correct operation of
5414 other shell features.
5415
5416 Parameters may also be special, that is, they have a predetermined
5417 meaning to the shell. Special parameters cannot have their type
5418 changed or their readonly attribute turned off, and if a special param‐
5419 eter is unset, then later recreated, the special properties will be re‐
5420 tained.
5421
5422 To declare the type of a parameter, or to assign a string or numeric
5423 value to a scalar parameter, use the typeset builtin.
5424
5425 The value of a scalar parameter may also be assigned by writing:
5426
5427 name=value
5428
5429 In scalar assignment, value is expanded as a single string, in which
5430 the elements of arrays are joined together; filename expansion is not
5431 performed unless the option GLOB_ASSIGN is set.
5432
5433 When the integer attribute, -i, or a floating point attribute, -E or
5434 -F, is set for name, the value is subject to arithmetic evaluation.
5435 Furthermore, by replacing `=' with `+=', a parameter can be incremented
5436 or appended to. See the section `Array Parameters' and Arithmetic
5437 Evaluation (in zshmisc(1)) for additional forms of assignment.
5438
5439 Note that assignment may implicitly change the attributes of a parame‐
5440 ter. For example, assigning a number to a variable in arithmetic eval‐
5441 uation may change its type to integer or float, and with GLOB_ASSIGN
5442 assigning a pattern to a variable may change its type to an array.
5443
5444 To reference the value of a parameter, write `$name' or `${name}'. See
5445 Parameter Expansion in zshexpn(1) for complete details. That section
5446 also explains the effect of the difference between scalar and array as‐
5447 signment on parameter expansion.
5448
5450 To assign an array value, write one of:
5451
5452 set -A name value ...
5453 name=(value ...)
5454 name=([key]=value ...)
5455
5456 If no parameter name exists, an ordinary array parameter is created.
5457 If the parameter name exists and is a scalar, it is replaced by a new
5458 array.
5459
5460 In the third form, key is an expression that will be evaluated in
5461 arithmetic context (in its simplest form, an integer) that gives the
5462 index of the element to be assigned with value. In this form any ele‐
5463 ments not explicitly mentioned that come before the largest index to
5464 which a value is assigned are assigned an empty string. The indices
5465 may be in any order. Note that this syntax is strict: [ and ]= must
5466 not be quoted, and key may not consist of the unquoted string ]=, but
5467 is otherwise treated as a simple string. The enhanced forms of sub‐
5468 script expression that may be used when directly subscripting a vari‐
5469 able name, described in the section `Array Subscripts' below, are not
5470 available.
5471
5472 The syntaxes with and without the explicit key may be mixed. An im‐
5473 plicit key is deduced by incrementing the index from the previously as‐
5474 signed element. Note that it is not treated as an error if latter as‐
5475 signments in this form overwrite earlier assignments.
5476
5477 For example, assuming the option KSH_ARRAYS is not set, the following:
5478
5479 array=(one [3]=three four)
5480
5481 causes the array variable array to contain four elements one, an empty
5482 string, three and four, in that order.
5483
5484 In the forms where only value is specified, full command line expansion
5485 is performed.
5486
5487 In the [key]=value form, both key and value undergo all forms of expan‐
5488 sion allowed for single word shell expansions (this does not include
5489 filename generation); these are as performed by the parameter expansion
5490 flag (e) as described in zshexpn(1). Nested parentheses may surround
5491 value and are included as part of the value, which is joined into a
5492 plain string; this differs from ksh which allows the values themselves
5493 to be arrays. A future version of zsh may support that. To cause the
5494 brackets to be interpreted as a character class for filename genera‐
5495 tion, and therefore to treat the resulting list of files as a set of
5496 values, quote the equal sign using any form of quoting. Example:
5497
5498 name=([a-z]'='*)
5499
5500 To append to an array without changing the existing values, use one of
5501 the following:
5502
5503 name+=(value ...)
5504 name+=([key]=value ...)
5505
5506 In the second form key may specify an existing index as well as an in‐
5507 dex off the end of the old array; any existing value is overwritten by
5508 value. Also, it is possible to use [key]+=value to append to the ex‐
5509 isting value at that index.
5510
5511 Within the parentheses on the right hand side of either form of the as‐
5512 signment, newlines and semicolons are treated the same as white space,
5513 separating individual values. Any consecutive sequence of such charac‐
5514 ters has the same effect.
5515
5516 Ordinary array parameters may also be explicitly declared with:
5517
5518 typeset -a name
5519
5520 Associative arrays must be declared before assignment, by using:
5521
5522 typeset -A name
5523
5524 When name refers to an associative array, the list in an assignment is
5525 interpreted as alternating keys and values:
5526
5527 set -A name key value ...
5528 name=(key value ...)
5529 name=([key]=value ...)
5530
5531 Note that only one of the two syntaxes above may be used in any given
5532 assignment; the forms may not be mixed. This is unlike the case of nu‐
5533 merically indexed arrays.
5534
5535 Every key must have a value in this case. Note that this assigns to
5536 the entire array, deleting any elements that do not appear in the list.
5537 The append syntax may also be used with an associative array:
5538
5539 name+=(key value ...)
5540 name+=([key]=value ...)
5541
5542 This adds a new key/value pair if the key is not already present, and
5543 replaces the value for the existing key if it is. In the second form
5544 it is also possible to use [key]+=value to append to the existing value
5545 at that key. Expansion is performed identically to the corresponding
5546 forms for normal arrays, as described above.
5547
5548 To create an empty array (including associative arrays), use one of:
5549
5550 set -A name
5551 name=()
5552
5553 Array Subscripts
5554 Individual elements of an array may be selected using a subscript. A
5555 subscript of the form `[exp]' selects the single element exp, where exp
5556 is an arithmetic expression which will be subject to arithmetic expan‐
5557 sion as if it were surrounded by `$((...))'. The elements are numbered
5558 beginning with 1, unless the KSH_ARRAYS option is set in which case
5559 they are numbered from zero.
5560
5561 Subscripts may be used inside braces used to delimit a parameter name,
5562 thus `${foo[2]}' is equivalent to `$foo[2]'. If the KSH_ARRAYS option
5563 is set, the braced form is the only one that works, as bracketed ex‐
5564 pressions otherwise are not treated as subscripts.
5565
5566 If the KSH_ARRAYS option is not set, then by default accesses to an ar‐
5567 ray element with a subscript that evaluates to zero return an empty
5568 string, while an attempt to write such an element is treated as an er‐
5569 ror. For backward compatibility the KSH_ZERO_SUBSCRIPT option can be
5570 set to cause subscript values 0 and 1 to be equivalent; see the de‐
5571 scription of the option in zshoptions(1).
5572
5573 The same subscripting syntax is used for associative arrays, except
5574 that no arithmetic expansion is applied to exp. However, the parsing
5575 rules for arithmetic expressions still apply, which affects the way
5576 that certain special characters must be protected from interpretation.
5577 See Subscript Parsing below for details.
5578
5579 A subscript of the form `[*]' or `[@]' evaluates to all elements of an
5580 array; there is no difference between the two except when they appear
5581 within double quotes. `"$foo[*]"' evaluates to `"$foo[1] $foo[2]
5582 ..."', whereas `"$foo[@]"' evaluates to `"$foo[1]" "$foo[2]" ...'. For
5583 associative arrays, `[*]' or `[@]' evaluate to all the values, in no
5584 particular order. Note that this does not substitute the keys; see the
5585 documentation for the `k' flag under Parameter Expansion Flags in zsh‐
5586 expn(1) for complete details. When an array parameter is referenced as
5587 `$name' (with no subscript) it evaluates to `$name[*]', unless the
5588 KSH_ARRAYS option is set in which case it evaluates to `${name[0]}'
5589 (for an associative array, this means the value of the key `0', which
5590 may not exist even if there are values for other keys).
5591
5592 A subscript of the form `[exp1,exp2]' selects all elements in the range
5593 exp1 to exp2, inclusive. (Associative arrays are unordered, and so do
5594 not support ranges.) If one of the subscripts evaluates to a negative
5595 number, say -n, then the nth element from the end of the array is used.
5596 Thus `$foo[-3]' is the third element from the end of the array foo, and
5597 `$foo[1,-1]' is the same as `$foo[*]'.
5598
5599 Subscripting may also be performed on non-array values, in which case
5600 the subscripts specify a substring to be extracted. For example, if
5601 FOO is set to `foobar', then `echo $FOO[2,5]' prints `ooba'. Note that
5602 some forms of subscripting described below perform pattern matching,
5603 and in that case the substring extends from the start of the match of
5604 the first subscript to the end of the match of the second subscript.
5605 For example,
5606
5607 string="abcdefghijklm"
5608 print ${string[(r)d?,(r)h?]}
5609
5610 prints `defghi'. This is an obvious generalisation of the rule for
5611 single-character matches. For a single subscript, only a single char‐
5612 acter is referenced (not the range of characters covered by the match).
5613
5614 Note that in substring operations the second subscript is handled dif‐
5615 ferently by the r and R subscript flags: the former takes the shortest
5616 match as the length and the latter the longest match. Hence in the
5617 former case a * at the end is redundant while in the latter case it
5618 matches the whole remainder of the string. This does not affect the
5619 result of the single subscript case as here the length of the match is
5620 irrelevant.
5621
5622 Array Element Assignment
5623 A subscript may be used on the left side of an assignment like so:
5624
5625 name[exp]=value
5626
5627 In this form of assignment the element or range specified by exp is re‐
5628 placed by the expression on the right side. An array (but not an asso‐
5629 ciative array) may be created by assignment to a range or element. Ar‐
5630 rays do not nest, so assigning a parenthesized list of values to an el‐
5631 ement or range changes the number of elements in the array, shifting
5632 the other elements to accommodate the new values. (This is not sup‐
5633 ported for associative arrays.)
5634
5635 This syntax also works as an argument to the typeset command:
5636
5637 typeset "name[exp]"=value
5638
5639 The value may not be a parenthesized list in this case; only single-el‐
5640 ement assignments may be made with typeset. Note that quotes are nec‐
5641 essary in this case to prevent the brackets from being interpreted as
5642 filename generation operators. The noglob precommand modifier could be
5643 used instead.
5644
5645 To delete an element of an ordinary array, assign `()' to that element.
5646 To delete an element of an associative array, use the unset command:
5647
5648 unset "name[exp]"
5649
5650 Subscript Flags
5651 If the opening bracket, or the comma in a range, in any subscript ex‐
5652 pression is directly followed by an opening parenthesis, the string up
5653 to the matching closing one is considered to be a list of flags, as in
5654 `name[(flags)exp]'.
5655
5656 The flags s, n and b take an argument; the delimiter is shown below as
5657 `:', but any character, or the matching pairs `(...)', `{...}',
5658 `[...]', or `<...>', may be used, but note that `<...>' can only be
5659 used if the subscript is inside a double quoted expression or a parame‐
5660 ter substitution enclosed in braces as otherwise the expression is in‐
5661 terpreted as a redirection.
5662
5663 The flags currently understood are:
5664
5665 w If the parameter subscripted is a scalar then this flag makes
5666 subscripting work on words instead of characters. The default
5667 word separator is whitespace. When combined with the i or I
5668 flag, the effect is to produce the index of the first character
5669 of the first/last word which matches the given pattern; note
5670 that a failed match in this case always yields 0.
5671
5672 s:string:
5673 This gives the string that separates words (for use with the w
5674 flag). The delimiter character : is arbitrary; see above.
5675
5676 p Recognize the same escape sequences as the print builtin in the
5677 string argument of a subsequent `s' flag.
5678
5679 f If the parameter subscripted is a scalar then this flag makes
5680 subscripting work on lines instead of characters, i.e. with ele‐
5681 ments separated by newlines. This is a shorthand for `pws:\n:'.
5682
5683 r Reverse subscripting: if this flag is given, the exp is taken as
5684 a pattern and the result is the first matching array element,
5685 substring or word (if the parameter is an array, if it is a
5686 scalar, or if it is a scalar and the `w' flag is given, respec‐
5687 tively). The subscript used is the number of the matching ele‐
5688 ment, so that pairs of subscripts such as `$foo[(r)??,3]' and
5689 `$foo[(r)??,(r)f*]' are possible if the parameter is not an as‐
5690 sociative array. If the parameter is an associative array, only
5691 the value part of each pair is compared to the pattern, and the
5692 result is that value.
5693
5694 If a search through an ordinary array failed, the search sets
5695 the subscript to one past the end of the array, and hence ${ar‐
5696 ray[(r)pattern]} will substitute the empty string. Thus the
5697 success of a search can be tested by using the (i) flag, for ex‐
5698 ample (assuming the option KSH_ARRAYS is not in effect):
5699
5700 [[ ${array[(i)pattern]} -le ${#array} ]]
5701
5702 If KSH_ARRAYS is in effect, the -le should be replaced by -lt.
5703
5704 R Like `r', but gives the last match. For associative arrays,
5705 gives all possible matches. May be used for assigning to ordi‐
5706 nary array elements, but not for assigning to associative ar‐
5707 rays. On failure, for normal arrays this has the effect of re‐
5708 turning the element corresponding to subscript 0; this is empty
5709 unless one of the options KSH_ARRAYS or KSH_ZERO_SUBSCRIPT is in
5710 effect.
5711
5712 Note that in subscripts with both `r' and `R' pattern characters
5713 are active even if they were substituted for a parameter (re‐
5714 gardless of the setting of GLOB_SUBST which controls this fea‐
5715 ture in normal pattern matching). The flag `e' can be added to
5716 inhibit pattern matching. As this flag does not inhibit other
5717 forms of substitution, care is still required; using a parameter
5718 to hold the key has the desired effect:
5719
5720 key2='original key'
5721 print ${array[(Re)$key2]}
5722
5723 i Like `r', but gives the index of the match instead; this may not
5724 be combined with a second argument. On the left side of an as‐
5725 signment, behaves like `r'. For associative arrays, the key
5726 part of each pair is compared to the pattern, and the first
5727 matching key found is the result. On failure substitutes the
5728 length of the array plus one, as discussed under the description
5729 of `r', or the empty string for an associative array.
5730
5731 Note: Although `i' may be applied to a scalar substitution to
5732 find the offset of a substring, the results are likely to be
5733 misleading when searching within substitutions that yield an
5734 empty string, or when searching for the empty substring.
5735
5736 I Like `i', but gives the index of the last match, or all possible
5737 matching keys in an associative array. On failure substitutes
5738 0, or the empty string for an associative array. This flag is
5739 best when testing for values or keys that do not exist.
5740
5741 Note: If the option KSH_ARRAYS is in effect and no match is
5742 found, the result is indistinguishable from the case when the
5743 first element of the array matches.
5744
5745 k If used in a subscript on an associative array, this flag causes
5746 the keys to be interpreted as patterns, and returns the value
5747 for the first key found where exp is matched by the key. Note
5748 this could be any such key as no ordering of associative arrays
5749 is defined. This flag does not work on the left side of an as‐
5750 signment to an associative array element. If used on another
5751 type of parameter, this behaves like `r'.
5752
5753 K On an associative array this is like `k' but returns all values
5754 where exp is matched by the keys. On other types of parameters
5755 this has the same effect as `R'.
5756
5757 n:expr:
5758 If combined with `r', `R', `i' or `I', makes them give the nth
5759 or nth last match (if expr evaluates to n). This flag is ig‐
5760 nored when the array is associative. The delimiter character :
5761 is arbitrary; see above.
5762
5763 b:expr:
5764 If combined with `r', `R', `i' or `I', makes them begin at the
5765 nth or nth last element, word, or character (if expr evaluates
5766 to n). This flag is ignored when the array is associative. The
5767 delimiter character : is arbitrary; see above.
5768
5769 e This flag causes any pattern matching that would be performed on
5770 the subscript to use plain string matching instead. Hence
5771 `${array[(re)*]}' matches only the array element whose value is
5772 *. Note that other forms of substitution such as parameter sub‐
5773 stitution are not inhibited.
5774
5775 This flag can also be used to force * or @ to be interpreted as
5776 a single key rather than as a reference to all values. It may
5777 be used for either purpose on the left side of an assignment.
5778
5779 See Parameter Expansion Flags (zshexpn(1)) for additional ways to ma‐
5780 nipulate the results of array subscripting.
5781
5782 Subscript Parsing
5783 This discussion applies mainly to associative array key strings and to
5784 patterns used for reverse subscripting (the `r', `R', `i', etc. flags),
5785 but it may also affect parameter substitutions that appear as part of
5786 an arithmetic expression in an ordinary subscript.
5787
5788 To avoid subscript parsing limitations in assignments to associative
5789 array elements, use the append syntax:
5790
5791 aa+=('key with "*strange*" characters' 'value string')
5792
5793 The basic rule to remember when writing a subscript expression is that
5794 all text between the opening `[' and the closing `]' is interpreted as
5795 if it were in double quotes (see zshmisc(1)). However, unlike double
5796 quotes which normally cannot nest, subscript expressions may appear in‐
5797 side double-quoted strings or inside other subscript expressions (or
5798 both!), so the rules have two important differences.
5799
5800 The first difference is that brackets (`[' and `]') must appear as bal‐
5801 anced pairs in a subscript expression unless they are preceded by a
5802 backslash (`\'). Therefore, within a subscript expression (and unlike
5803 true double-quoting) the sequence `\[' becomes `[', and similarly `\]'
5804 becomes `]'. This applies even in cases where a backslash is not nor‐
5805 mally required; for example, the pattern `[^[]' (to match any character
5806 other than an open bracket) should be written `[^\[]' in a reverse-sub‐
5807 script pattern. However, note that `\[^\[\]' and even `\[^[]' mean the
5808 same thing, because backslashes are always stripped when they appear
5809 before brackets!
5810
5811 The same rule applies to parentheses (`(' and `)') and braces (`{' and
5812 `}'): they must appear either in balanced pairs or preceded by a back‐
5813 slash, and backslashes that protect parentheses or braces are removed
5814 during parsing. This is because parameter expansions may be surrounded
5815 by balanced braces, and subscript flags are introduced by balanced
5816 parentheses.
5817
5818 The second difference is that a double-quote (`"') may appear as part
5819 of a subscript expression without being preceded by a backslash, and
5820 therefore that the two characters `\"' remain as two characters in the
5821 subscript (in true double-quoting, `\"' becomes `"'). However, because
5822 of the standard shell quoting rules, any double-quotes that appear must
5823 occur in balanced pairs unless preceded by a backslash. This makes it
5824 more difficult to write a subscript expression that contains an odd
5825 number of double-quote characters, but the reason for this difference
5826 is so that when a subscript expression appears inside true dou‐
5827 ble-quotes, one can still write `\"' (rather than `\\\"') for `"'.
5828
5829 To use an odd number of double quotes as a key in an assignment, use
5830 the typeset builtin and an enclosing pair of double quotes; to refer to
5831 the value of that key, again use double quotes:
5832
5833 typeset -A aa
5834 typeset "aa[one\"two\"three\"quotes]"=QQQ
5835 print "$aa[one\"two\"three\"quotes]"
5836
5837 It is important to note that the quoting rules do not change when a pa‐
5838 rameter expansion with a subscript is nested inside another subscript
5839 expression. That is, it is not necessary to use additional backslashes
5840 within the inner subscript expression; they are removed only once, from
5841 the innermost subscript outwards. Parameters are also expanded from
5842 the innermost subscript first, as each expansion is encountered left to
5843 right in the outer expression.
5844
5845 A further complication arises from a way in which subscript parsing is
5846 not different from double quote parsing. As in true double-quoting,
5847 the sequences `\*', and `\@' remain as two characters when they appear
5848 in a subscript expression. To use a literal `*' or `@' as an associa‐
5849 tive array key, the `e' flag must be used:
5850
5851 typeset -A aa
5852 aa[(e)*]=star
5853 print $aa[(e)*]
5854
5855 A last detail must be considered when reverse subscripting is per‐
5856 formed. Parameters appearing in the subscript expression are first ex‐
5857 panded and then the complete expression is interpreted as a pattern.
5858 This has two effects: first, parameters behave as if GLOB_SUBST were on
5859 (and it cannot be turned off); second, backslashes are interpreted
5860 twice, once when parsing the array subscript and again when parsing the
5861 pattern. In a reverse subscript, it's necessary to use four back‐
5862 slashes to cause a single backslash to match literally in the pattern.
5863 For complex patterns, it is often easiest to assign the desired pattern
5864 to a parameter and then refer to that parameter in the subscript, be‐
5865 cause then the backslashes, brackets, parentheses, etc., are seen only
5866 when the complete expression is converted to a pattern. To match the
5867 value of a parameter literally in a reverse subscript, rather than as a
5868 pattern, use `${(q)name}' (see zshexpn(1)) to quote the expanded value.
5869
5870 Note that the `k' and `K' flags are reverse subscripting for an ordi‐
5871 nary array, but are not reverse subscripting for an associative array!
5872 (For an associative array, the keys in the array itself are interpreted
5873 as patterns by those flags; the subscript is a plain string in that
5874 case.)
5875
5876 One final note, not directly related to subscripting: the numeric names
5877 of positional parameters (described below) are parsed specially, so for
5878 example `$2foo' is equivalent to `${2}foo'. Therefore, to use sub‐
5879 script syntax to extract a substring from a positional parameter, the
5880 expansion must be surrounded by braces; for example, `${2[3,5]}' evalu‐
5881 ates to the third through fifth characters of the second positional pa‐
5882 rameter, but `$2[3,5]' is the entire second parameter concatenated with
5883 the filename generation pattern `[3,5]'.
5884
5886 The positional parameters provide access to the command-line arguments
5887 of a shell function, shell script, or the shell itself; see the section
5888 `Invocation', and also the section `Functions'. The parameter n, where
5889 n is a number, is the nth positional parameter. The parameter `$0' is
5890 a special case, see the section `Parameters Set By The Shell'.
5891
5892 The parameters *, @ and argv are arrays containing all the positional
5893 parameters; thus `$argv[n]', etc., is equivalent to simply `$n'. Note
5894 that the options KSH_ARRAYS or KSH_ZERO_SUBSCRIPT apply to these arrays
5895 as well, so with either of those options set, `${argv[0]}' is equiva‐
5896 lent to `$1' and so on.
5897
5898 Positional parameters may be changed after the shell or function starts
5899 by using the set builtin, by assigning to the argv array, or by direct
5900 assignment of the form `n=value' where n is the number of the posi‐
5901 tional parameter to be changed. This also creates (with empty values)
5902 any of the positions from 1 to n that do not already have values. Note
5903 that, because the positional parameters form an array, an array assign‐
5904 ment of the form `n=(value ...)' is allowed, and has the effect of
5905 shifting all the values at positions greater than n by as many posi‐
5906 tions as necessary to accommodate the new values.
5907
5909 Shell function executions delimit scopes for shell parameters. (Param‐
5910 eters are dynamically scoped.) The typeset builtin, and its alterna‐
5911 tive forms declare, integer, local and readonly (but not export), can
5912 be used to declare a parameter as being local to the innermost scope.
5913
5914 When a parameter is read or assigned to, the innermost existing parame‐
5915 ter of that name is used. (That is, the local parameter hides any
5916 less-local parameter.) However, assigning to a non-existent parameter,
5917 or declaring a new parameter with export, causes it to be created in
5918 the outermost scope.
5919
5920 Local parameters disappear when their scope ends. unset can be used to
5921 delete a parameter while it is still in scope; any outer parameter of
5922 the same name remains hidden.
5923
5924 Special parameters may also be made local; they retain their special
5925 attributes unless either the existing or the newly-created parameter
5926 has the -h (hide) attribute. This may have unexpected effects: there
5927 is no default value, so if there is no assignment at the point the
5928 variable is made local, it will be set to an empty value (or zero in
5929 the case of integers). The following:
5930
5931 typeset PATH=/new/directory:$PATH
5932
5933 is valid for temporarily allowing the shell or programmes called from
5934 it to find the programs in /new/directory inside a function.
5935
5936 Note that the restriction in older versions of zsh that local parame‐
5937 ters were never exported has been removed.
5938
5940 In the parameter lists that follow, the mark `<S>' indicates that the
5941 parameter is special. `<Z>' indicates that the parameter does not ex‐
5942 ist when the shell initializes in sh or ksh emulation mode.
5943
5944 The parameters `!', `#', `*', `-', `?', `@', `$', `ARGC', `HISTCMD',
5945 `LINENO', `PPID', `status', `TTYIDLE', `zsh_eval_context',
5946 `ZSH_EVAL_CONTEXT', and `ZSH_SUBSHELL' are read-only and thus cannot be
5947 restored by the user, so they are not output by `typeset -p'. This
5948 also applies to many read-only parameters loaded from modules.
5949
5950 The following parameters are automatically set by the shell:
5951
5952 ! <S> The process ID of the last command started in the background
5953 with &, put into the background with the bg builtin, or spawned
5954 with coproc.
5955
5956 # <S> The number of positional parameters in decimal. Note that some
5957 confusion may occur with the syntax $#param which substitutes
5958 the length of param. Use ${#} to resolve ambiguities. In par‐
5959 ticular, the sequence `$#-...' in an arithmetic expression is
5960 interpreted as the length of the parameter -, q.v.
5961
5962 ARGC <S> <Z>
5963 Same as #.
5964
5965 $ <S> The process ID of this shell, set when the shell initializes.
5966 Processes forked from the shell without executing a new program,
5967 such as command substitutions and commands grouped with (...),
5968 are subshells that duplicate the current shell, and thus substi‐
5969 tute the same value for $$ as their parent shell.
5970
5971 - <S> Flags supplied to the shell on invocation or by the set or se‐
5972 topt commands.
5973
5974 * <S> An array containing the positional parameters.
5975
5976 argv <S> <Z>
5977 Same as *. Assigning to argv changes the local positional pa‐
5978 rameters, but argv is not itself a local parameter. Deleting
5979 argv with unset in any function deletes it everywhere, although
5980 only the innermost positional parameter array is deleted (so *
5981 and @ in other scopes are not affected).
5982
5983 @ <S> Same as argv[@], even when argv is not set.
5984
5985 ? <S> The exit status returned by the last command.
5986
5987 0 <S> The name used to invoke the current shell, or as set by the -c
5988 command line option upon invocation. If the FUNCTION_ARGZERO
5989 option is set, $0 is set upon entry to a shell function to the
5990 name of the function, and upon entry to a sourced script to the
5991 name of the script, and reset to its previous value when the
5992 function or script returns.
5993
5994 status <S> <Z>
5995 Same as ?.
5996
5997 pipestatus <S> <Z>
5998 An array containing the exit statuses returned by all commands
5999 in the last pipeline.
6000
6001 _ <S> The last argument of the previous command. Also, this parameter
6002 is set in the environment of every command executed to the full
6003 pathname of the command.
6004
6005 CPUTYPE
6006 The machine type (microprocessor class or machine model), as de‐
6007 termined at run time.
6008
6009 EGID <S>
6010 The effective group ID of the shell process. If you have suffi‐
6011 cient privileges, you may change the effective group ID of the
6012 shell process by assigning to this parameter. Also (assuming
6013 sufficient privileges), you may start a single command with a
6014 different effective group ID by `(EGID=gid; command)'
6015
6016 If this is made local, it is not implicitly set to 0, but may be
6017 explicitly set locally.
6018
6019 EUID <S>
6020 The effective user ID of the shell process. If you have suffi‐
6021 cient privileges, you may change the effective user ID of the
6022 shell process by assigning to this parameter. Also (assuming
6023 sufficient privileges), you may start a single command with a
6024 different effective user ID by `(EUID=uid; command)'
6025
6026 If this is made local, it is not implicitly set to 0, but may be
6027 explicitly set locally.
6028
6029 ERRNO <S>
6030 The value of errno (see errno(3)) as set by the most recently
6031 failed system call. This value is system dependent and is in‐
6032 tended for debugging purposes. It is also useful with the
6033 zsh/system module which allows the number to be turned into a
6034 name or message.
6035
6036 To use this parameter, it must first be assigned a value (typi‐
6037 cally 0 (zero)). It is initially unset for scripting compati‐
6038 bility.
6039
6040 FUNCNEST <S>
6041 Integer. If greater than or equal to zero, the maximum nesting
6042 depth of shell functions. When it is exceeded, an error is
6043 raised at the point where a function is called. The default
6044 value is determined when the shell is configured, but is typi‐
6045 cally 500. Increasing the value increases the danger of a run‐
6046 away function recursion causing the shell to crash. Setting a
6047 negative value turns off the check.
6048
6049 GID <S>
6050 The real group ID of the shell process. If you have sufficient
6051 privileges, you may change the group ID of the shell process by
6052 assigning to this parameter. Also (assuming sufficient privi‐
6053 leges), you may start a single command under a different group
6054 ID by `(GID=gid; command)'
6055
6056 If this is made local, it is not implicitly set to 0, but may be
6057 explicitly set locally.
6058
6059 HISTCMD
6060 The current history event number in an interactive shell, in
6061 other words the event number for the command that caused
6062 $HISTCMD to be read. If the current history event modifies the
6063 history, HISTCMD changes to the new maximum history event num‐
6064 ber.
6065
6066 HOST The current hostname.
6067
6068 LINENO <S>
6069 The line number of the current line within the current script,
6070 sourced file, or shell function being executed, whichever was
6071 started most recently. Note that in the case of shell functions
6072 the line number refers to the function as it appeared in the
6073 original definition, not necessarily as displayed by the func‐
6074 tions builtin.
6075
6076 LOGNAME
6077 If the corresponding variable is not set in the environment of
6078 the shell, it is initialized to the login name corresponding to
6079 the current login session. This parameter is exported by default
6080 but this can be disabled using the typeset builtin. The value
6081 is set to the string returned by the getlogin(3) system call if
6082 that is available.
6083
6084 MACHTYPE
6085 The machine type (microprocessor class or machine model), as de‐
6086 termined at compile time.
6087
6088 OLDPWD The previous working directory. This is set when the shell ini‐
6089 tializes and whenever the directory changes.
6090
6091 OPTARG <S>
6092 The value of the last option argument processed by the getopts
6093 command.
6094
6095 OPTIND <S>
6096 The index of the last option argument processed by the getopts
6097 command.
6098
6099 OSTYPE The operating system, as determined at compile time.
6100
6101 PPID <S>
6102 The process ID of the parent of the shell, set when the shell
6103 initializes. As with $$, the value does not change in subshells
6104 created as a duplicate of the current shell.
6105
6106 PWD The present working directory. This is set when the shell ini‐
6107 tializes and whenever the directory changes.
6108
6109 RANDOM <S>
6110 A pseudo-random integer from 0 to 32767, newly generated each
6111 time this parameter is referenced. The random number generator
6112 can be seeded by assigning a numeric value to RANDOM.
6113
6114 The values of RANDOM form an intentionally-repeatable
6115 pseudo-random sequence; subshells that reference RANDOM will re‐
6116 sult in identical pseudo-random values unless the value of RAN‐
6117 DOM is referenced or seeded in the parent shell in between sub‐
6118 shell invocations.
6119
6120 SECONDS <S>
6121 The number of seconds since shell invocation. If this parameter
6122 is assigned a value, then the value returned upon reference will
6123 be the value that was assigned plus the number of seconds since
6124 the assignment.
6125
6126 Unlike other special parameters, the type of the SECONDS parame‐
6127 ter can be changed using the typeset command. The type may be
6128 changed only to one of the floating point types or back to inte‐
6129 ger. For example, `typeset -F SECONDS' causes the value to be
6130 reported as a floating point number. The value is available to
6131 microsecond accuracy, although the shell may show more or fewer
6132 digits depending on the use of typeset. See the documentation
6133 for the builtin typeset in zshbuiltins(1) for more details.
6134
6135 SHLVL <S>
6136 Incremented by one each time a new shell is started.
6137
6138 signals
6139 An array containing the names of the signals. Note that with
6140 the standard zsh numbering of array indices, where the first el‐
6141 ement has index 1, the signals are offset by 1 from the signal
6142 number used by the operating system. For example, on typical
6143 Unix-like systems HUP is signal number 1, but is referred to as
6144 $signals[2]. This is because of EXIT at position 1 in the ar‐
6145 ray, which is used internally by zsh but is not known to the op‐
6146 erating system.
6147
6148 TRY_BLOCK_ERROR <S>
6149 In an always block, indicates whether the preceding list of code
6150 caused an error. The value is 1 to indicate an error, 0 other‐
6151 wise. It may be reset, clearing the error condition. See Com‐
6152 plex Commands in zshmisc(1)
6153
6154 TRY_BLOCK_INTERRUPT <S>
6155 This variable works in a similar way to TRY_BLOCK_ERROR, but
6156 represents the status of an interrupt from the signal SIGINT,
6157 which typically comes from the keyboard when the user types ^C.
6158 If set to 0, any such interrupt will be reset; otherwise, the
6159 interrupt is propagated after the always block.
6160
6161 Note that it is possible that an interrupt arrives during the
6162 execution of the always block; this interrupt is also propa‐
6163 gated.
6164
6165 TTY The name of the tty associated with the shell, if any.
6166
6167 TTYIDLE <S>
6168 The idle time of the tty associated with the shell in seconds or
6169 -1 if there is no such tty.
6170
6171 UID <S>
6172 The real user ID of the shell process. If you have sufficient
6173 privileges, you may change the user ID of the shell by assigning
6174 to this parameter. Also (assuming sufficient privileges), you
6175 may start a single command under a different user ID by
6176 `(UID=uid; command)'
6177
6178 If this is made local, it is not implicitly set to 0, but may be
6179 explicitly set locally.
6180
6181 USERNAME <S>
6182 The username corresponding to the real user ID of the shell
6183 process. If you have sufficient privileges, you may change the
6184 username (and also the user ID and group ID) of the shell by as‐
6185 signing to this parameter. Also (assuming sufficient privi‐
6186 leges), you may start a single command under a different user‐
6187 name (and user ID and group ID) by `(USERNAME=username; com‐
6188 mand)'
6189
6190 VENDOR The vendor, as determined at compile time.
6191
6192 zsh_eval_context <S> <Z> (ZSH_EVAL_CONTEXT <S>)
6193 An array (colon-separated list) indicating the context of shell
6194 code that is being run. Each time a piece of shell code that is
6195 stored within the shell is executed a string is temporarily ap‐
6196 pended to the array to indicate the type of operation that is
6197 being performed. Read in order the array gives an indication of
6198 the stack of operations being performed with the most immediate
6199 context last.
6200
6201 Note that the variable does not give information on syntactic
6202 context such as pipelines or subshells. Use $ZSH_SUBSHELL to
6203 detect subshells.
6204
6205 The context is one of the following:
6206 cmdarg Code specified by the -c option to the command line that
6207 invoked the shell.
6208
6209 cmdsubst
6210 Command substitution using the `...` or $(...) construct.
6211
6212 equalsubst
6213 File substitution using the =(...) construct.
6214
6215 eval Code executed by the eval builtin.
6216
6217 evalautofunc
6218 Code executed with the KSH_AUTOLOAD mechanism in order to
6219 define an autoloaded function.
6220
6221 fc Code from the shell history executed by the -e option to
6222 the fc builtin.
6223
6224 file Lines of code being read directly from a file, for exam‐
6225 ple by the source builtin.
6226
6227 filecode
6228 Lines of code being read from a .zwc file instead of di‐
6229 rectly from the source file.
6230
6231 globqual
6232 Code executed by the e or + glob qualifier.
6233
6234 globsort
6235 Code executed to order files by the o glob qualifier.
6236
6237 insubst
6238 File substitution using the <(...) construct.
6239
6240 loadautofunc
6241 Code read directly from a file to define an autoloaded
6242 function.
6243
6244 outsubst
6245 File substitution using the >(...) construct.
6246
6247 sched Code executed by the sched builtin.
6248
6249 shfunc A shell function.
6250
6251 stty Code passed to stty by the STTY environment variable.
6252 Normally this is passed directly to the system's stty
6253 command, so this value is unlikely to be seen in prac‐
6254 tice.
6255
6256 style Code executed as part of a style retrieved by the zstyle
6257 builtin from the zsh/zutil module.
6258
6259 toplevel
6260 The highest execution level of a script or interactive
6261 shell.
6262
6263 trap Code executed as a trap defined by the trap builtin.
6264 Traps defined as functions have the context shfunc. As
6265 traps are asynchronous they may have a different hierar‐
6266 chy from other code.
6267
6268 zpty Code executed by the zpty builtin from the zsh/zpty mod‐
6269 ule.
6270
6271 zregexparse-guard
6272 Code executed as a guard by the zregexparse command from
6273 the zsh/zutil module.
6274
6275 zregexparse-action
6276 Code executed as an action by the zregexparse command
6277 from the zsh/zutil module.
6278
6279 ZSH_ARGZERO
6280 If zsh was invoked to run a script, this is the name of the
6281 script. Otherwise, it is the name used to invoke the current
6282 shell. This is the same as the value of $0 when the
6283 POSIX_ARGZERO option is set, but is always available.
6284
6285 ZSH_EXECUTION_STRING
6286 If the shell was started with the option -c, this contains the
6287 argument passed to the option. Otherwise it is not set.
6288
6289 ZSH_NAME
6290 Expands to the basename of the command used to invoke this in‐
6291 stance of zsh.
6292
6293 ZSH_PATCHLEVEL
6294 The output of `git describe --tags --long' for the zsh reposi‐
6295 tory used to build the shell. This is most useful in order to
6296 keep track of versions of the shell during development between
6297 releases; hence most users should not use it and should instead
6298 rely on $ZSH_VERSION.
6299
6300 zsh_scheduled_events
6301 See the section `The zsh/sched Module' in zshmodules(1).
6302
6303 ZSH_SCRIPT
6304 If zsh was invoked to run a script, this is the name of the
6305 script, otherwise it is unset.
6306
6307 ZSH_SUBSHELL
6308 Readonly integer. Initially zero, incremented each time the
6309 shell forks to create a subshell for executing code. Hence
6310 `(print $ZSH_SUBSHELL)' and `print $(print $ZSH_SUBSHELL)' out‐
6311 put 1, while `( (print $ZSH_SUBSHELL) )' outputs 2.
6312
6313 ZSH_VERSION
6314 The version number of the release of zsh.
6315
6317 The following parameters are used by the shell. Again, `<S>' indicates
6318 that the parameter is special and `<Z>' indicates that the parameter
6319 does not exist when the shell initializes in sh or ksh emulation mode.
6320
6321 In cases where there are two parameters with an upper- and lowercase
6322 form of the same name, such as path and PATH, the lowercase form is an
6323 array and the uppercase form is a scalar with the elements of the array
6324 joined together by colons. These are similar to tied parameters cre‐
6325 ated via `typeset -T'. The normal use for the colon-separated form is
6326 for exporting to the environment, while the array form is easier to ma‐
6327 nipulate within the shell. Note that unsetting either of the pair will
6328 unset the other; they retain their special properties when recreated,
6329 and recreating one of the pair will recreate the other.
6330
6331 ARGV0 If exported, its value is used as the argv[0] of external com‐
6332 mands. Usually used in constructs like `ARGV0=emacs nethack'.
6333
6334 BAUD The rate in bits per second at which data reaches the terminal.
6335 The line editor will use this value in order to compensate for a
6336 slow terminal by delaying updates to the display until neces‐
6337 sary. If the parameter is unset or the value is zero the com‐
6338 pensation mechanism is turned off. The parameter is not set by
6339 default.
6340
6341 This parameter may be profitably set in some circumstances, e.g.
6342 for slow modems dialing into a communications server, or on a
6343 slow wide area network. It should be set to the baud rate of
6344 the slowest part of the link for best performance.
6345
6346 cdpath <S> <Z> (CDPATH <S>)
6347 An array (colon-separated list) of directories specifying the
6348 search path for the cd command.
6349
6350 COLUMNS <S>
6351 The number of columns for this terminal session. Used for
6352 printing select lists and for the line editor.
6353
6354 CORRECT_IGNORE
6355 If set, is treated as a pattern during spelling correction. Any
6356 potential correction that matches the pattern is ignored. For
6357 example, if the value is `_*' then completion functions (which,
6358 by convention, have names beginning with `_') will never be of‐
6359 fered as spelling corrections. The pattern does not apply to
6360 the correction of file names, as applied by the CORRECT_ALL op‐
6361 tion (so with the example just given files beginning with `_' in
6362 the current directory would still be completed).
6363
6364 CORRECT_IGNORE_FILE
6365 If set, is treated as a pattern during spelling correction of
6366 file names. Any file name that matches the pattern is never of‐
6367 fered as a correction. For example, if the value is `.*' then
6368 dot file names will never be offered as spelling corrections.
6369 This is useful with the CORRECT_ALL option.
6370
6371 DIRSTACKSIZE
6372 The maximum size of the directory stack, by default there is no
6373 limit. If the stack gets larger than this, it will be truncated
6374 automatically. This is useful with the AUTO_PUSHD option.
6375
6376 ENV If the ENV environment variable is set when zsh is invoked as sh
6377 or ksh, $ENV is sourced after the profile scripts. The value of
6378 ENV is subjected to parameter expansion, command substitution,
6379 and arithmetic expansion before being interpreted as a pathname.
6380 Note that ENV is not used unless the shell is interactive and
6381 zsh is emulating sh or ksh.
6382
6383 FCEDIT The default editor for the fc builtin. If FCEDIT is not set,
6384 the parameter EDITOR is used; if that is not set either, a
6385 builtin default, usually vi, is used.
6386
6387 fignore <S> <Z> (FIGNORE <S>)
6388 An array (colon separated list) containing the suffixes of files
6389 to be ignored during filename completion. However, if comple‐
6390 tion only generates files with suffixes in this list, then these
6391 files are completed anyway.
6392
6393 fpath <S> <Z> (FPATH <S>)
6394 An array (colon separated list) of directories specifying the
6395 search path for function definitions. This path is searched
6396 when a function with the -u attribute is referenced. If an exe‐
6397 cutable file is found, then it is read and executed in the cur‐
6398 rent environment.
6399
6400 histchars <S>
6401 Three characters used by the shell's history and lexical analy‐
6402 sis mechanism. The first character signals the start of a his‐
6403 tory expansion (default `!'). The second character signals the
6404 start of a quick history substitution (default `^'). The third
6405 character is the comment character (default `#').
6406
6407 The characters must be in the ASCII character set; any attempt
6408 to set histchars to characters with a locale-dependent meaning
6409 will be rejected with an error message.
6410
6411 HISTCHARS <S> <Z>
6412 Same as histchars. (Deprecated.)
6413
6414 HISTFILE
6415 The file to save the history in when an interactive shell exits.
6416 If unset, the history is not saved.
6417
6418 HISTORY_IGNORE
6419 If set, is treated as a pattern at the time history files are
6420 written. Any potential history entry that matches the pattern
6421 is skipped. For example, if the value is `fc *' then commands
6422 that invoke the interactive history editor are never written to
6423 the history file.
6424
6425 Note that HISTORY_IGNORE defines a single pattern: to specify
6426 alternatives use the `(first|second|...)' syntax.
6427
6428 Compare the HIST_NO_STORE option or the zshaddhistory hook, ei‐
6429 ther of which would prevent such commands from being added to
6430 the interactive history at all. If you wish to use HISTORY_IG‐
6431 NORE to stop history being added in the first place, you can de‐
6432 fine the following hook:
6433
6434 zshaddhistory() {
6435 emulate -L zsh
6436 ## uncomment if HISTORY_IGNORE
6437 ## should use EXTENDED_GLOB syntax
6438 # setopt extendedglob
6439 [[ $1 != ${~HISTORY_IGNORE} ]]
6440 }
6441
6442 HISTSIZE <S>
6443 The maximum number of events stored in the internal history
6444 list. If you use the HIST_EXPIRE_DUPS_FIRST option, setting
6445 this value larger than the SAVEHIST size will give you the dif‐
6446 ference as a cushion for saving duplicated history events.
6447
6448 If this is made local, it is not implicitly set to 0, but may be
6449 explicitly set locally.
6450
6451 HOME <S>
6452 The default argument for the cd command. This is not set auto‐
6453 matically by the shell in sh, ksh or csh emulation, but it is
6454 typically present in the environment anyway, and if it becomes
6455 set it has its usual special behaviour.
6456
6457 IFS <S>
6458 Internal field separators (by default space, tab, newline and
6459 NUL), that are used to separate words which result from command
6460 or parameter expansion and words read by the read builtin. Any
6461 characters from the set space, tab and newline that appear in
6462 the IFS are called IFS white space. One or more IFS white space
6463 characters or one non-IFS white space character together with
6464 any adjacent IFS white space character delimit a field. If an
6465 IFS white space character appears twice consecutively in the
6466 IFS, this character is treated as if it were not an IFS white
6467 space character.
6468
6469 If the parameter is unset, the default is used. Note this has a
6470 different effect from setting the parameter to an empty string.
6471
6472 KEYBOARD_HACK
6473 This variable defines a character to be removed from the end of
6474 the command line before interpreting it (interactive shells
6475 only). It is intended to fix the problem with keys placed annoy‐
6476 ingly close to return and replaces the SUNKEYBOARDHACK option
6477 which did this for backquotes only. Should the chosen character
6478 be one of singlequote, doublequote or backquote, there must also
6479 be an odd number of them on the command line for the last one to
6480 be removed.
6481
6482 For backward compatibility, if the SUNKEYBOARDHACK option is ex‐
6483 plicitly set, the value of KEYBOARD_HACK reverts to backquote.
6484 If the option is explicitly unset, this variable is set to
6485 empty.
6486
6487 KEYTIMEOUT
6488 The time the shell waits, in hundredths of seconds, for another
6489 key to be pressed when reading bound multi-character sequences.
6490
6491 LANG <S>
6492 This variable determines the locale category for any category
6493 not specifically selected via a variable starting with `LC_'.
6494
6495 LC_ALL <S>
6496 This variable overrides the value of the `LANG' variable and the
6497 value of any of the other variables starting with `LC_'.
6498
6499 LC_COLLATE <S>
6500 This variable determines the locale category for character col‐
6501 lation information within ranges in glob brackets and for sort‐
6502 ing.
6503
6504 LC_CTYPE <S>
6505 This variable determines the locale category for character han‐
6506 dling functions. If the MULTIBYTE option is in effect this
6507 variable or LANG should contain a value that reflects the char‐
6508 acter set in use, even if it is a single-byte character set, un‐
6509 less only the 7-bit subset (ASCII) is used. For example, if the
6510 character set is ISO-8859-1, a suitable value might be
6511 en_US.iso88591 (certain Linux distributions) or en_US.ISO8859-1
6512 (MacOS).
6513
6514 LC_MESSAGES <S>
6515 This variable determines the language in which messages should
6516 be written. Note that zsh does not use message catalogs.
6517
6518 LC_NUMERIC <S>
6519 This variable affects the decimal point character and thousands
6520 separator character for the formatted input/output functions and
6521 string conversion functions. Note that zsh ignores this setting
6522 when parsing floating point mathematical expressions.
6523
6524 LC_TIME <S>
6525 This variable determines the locale category for date and time
6526 formatting in prompt escape sequences.
6527
6528 LINES <S>
6529 The number of lines for this terminal session. Used for print‐
6530 ing select lists and for the line editor.
6531
6532 LISTMAX
6533 In the line editor, the number of matches to list without asking
6534 first. If the value is negative, the list will be shown if it
6535 spans at most as many lines as given by the absolute value. If
6536 set to zero, the shell asks only if the top of the listing would
6537 scroll off the screen.
6538
6539 MAIL If this parameter is set and mailpath is not set, the shell
6540 looks for mail in the specified file.
6541
6542 MAILCHECK
6543 The interval in seconds between checks for new mail.
6544
6545 mailpath <S> <Z> (MAILPATH <S>)
6546 An array (colon-separated list) of filenames to check for new
6547 mail. Each filename can be followed by a `?' and a message that
6548 will be printed. The message will undergo parameter expansion,
6549 command substitution and arithmetic expansion with the variable
6550 $_ defined as the name of the file that has changed. The de‐
6551 fault message is `You have new mail'. If an element is a direc‐
6552 tory instead of a file the shell will recursively check every
6553 file in every subdirectory of the element.
6554
6555 manpath <S> <Z> (MANPATH <S> <Z>)
6556 An array (colon-separated list) whose value is not used by the
6557 shell. The manpath array can be useful, however, since setting
6558 it also sets MANPATH, and vice versa.
6559
6560 match
6561 mbegin
6562 mend Arrays set by the shell when the b globbing flag is used in pat‐
6563 tern matches. See the subsection Globbing flags in the documen‐
6564 tation for Filename Generation in zshexpn(1).
6565
6566 MATCH
6567 MBEGIN
6568 MEND Set by the shell when the m globbing flag is used in pattern
6569 matches. See the subsection Globbing flags in the documentation
6570 for Filename Generation in zshexpn(1).
6571
6572 module_path <S> <Z> (MODULE_PATH <S>)
6573 An array (colon-separated list) of directories that zmodload
6574 searches for dynamically loadable modules. This is initialized
6575 to a standard pathname, usually `/usr/local/lib/zsh/$ZSH_VER‐
6576 SION'. (The `/usr/local/lib' part varies from installation to
6577 installation.) For security reasons, any value set in the envi‐
6578 ronment when the shell is started will be ignored.
6579
6580 These parameters only exist if the installation supports dynamic
6581 module loading.
6582
6583 NULLCMD <S>
6584 The command name to assume if a redirection is specified with no
6585 command. Defaults to cat. For sh/ksh behavior, change this to
6586 :. For csh-like behavior, unset this parameter; the shell will
6587 print an error message if null commands are entered.
6588
6589 path <S> <Z> (PATH <S>)
6590 An array (colon-separated list) of directories to search for
6591 commands. When this parameter is set, each directory is scanned
6592 and all files found are put in a hash table.
6593
6594 POSTEDIT <S>
6595 This string is output whenever the line editor exits. It usu‐
6596 ally contains termcap strings to reset the terminal.
6597
6598 PROMPT <S> <Z>
6599 PROMPT2 <S> <Z>
6600 PROMPT3 <S> <Z>
6601 PROMPT4 <S> <Z>
6602 Same as PS1, PS2, PS3 and PS4, respectively.
6603
6604 prompt <S> <Z>
6605 Same as PS1.
6606
6607 PROMPT_EOL_MARK
6608 When the PROMPT_CR and PROMPT_SP options are set, the
6609 PROMPT_EOL_MARK parameter can be used to customize how the end
6610 of partial lines are shown. This parameter undergoes prompt ex‐
6611 pansion, with the PROMPT_PERCENT option set. If not set, the
6612 default behavior is equivalent to the value `%B%S%#%s%b'.
6613
6614 PS1 <S>
6615 The primary prompt string, printed before a command is read. It
6616 undergoes a special form of expansion before being displayed;
6617 see EXPANSION OF PROMPT SEQUENCES in zshmisc(1). The default is
6618 `%m%# '.
6619
6620 PS2 <S>
6621 The secondary prompt, printed when the shell needs more informa‐
6622 tion to complete a command. It is expanded in the same way as
6623 PS1. The default is `%_> ', which displays any shell constructs
6624 or quotation marks which are currently being processed.
6625
6626 PS3 <S>
6627 Selection prompt used within a select loop. It is expanded in
6628 the same way as PS1. The default is `?# '.
6629
6630 PS4 <S>
6631 The execution trace prompt. Default is `+%N:%i> ', which dis‐
6632 plays the name of the current shell structure and the line num‐
6633 ber within it. In sh or ksh emulation, the default is `+ '.
6634
6635 psvar <S> <Z> (PSVAR <S>)
6636 An array (colon-separated list) whose elements can be used in
6637 PROMPT strings. Setting psvar also sets PSVAR, and vice versa.
6638
6639 READNULLCMD <S>
6640 The command name to assume if a single input redirection is
6641 specified with no command. Defaults to more.
6642
6643 REPORTMEMORY
6644 If nonnegative, commands whose maximum resident set size
6645 (roughly speaking, main memory usage) in kilobytes is greater
6646 than this value have timing statistics reported. The format
6647 used to output statistics is the value of the TIMEFMT parameter,
6648 which is the same as for the REPORTTIME variable and the time
6649 builtin; note that by default this does not output memory usage.
6650 Appending " max RSS %M" to the value of TIMEFMT causes it to
6651 output the value that triggered the report. If REPORTTIME is
6652 also in use, at most a single report is printed for both trig‐
6653 gers. This feature requires the getrusage() system call, com‐
6654 monly supported by modern Unix-like systems.
6655
6656 REPORTTIME
6657 If nonnegative, commands whose combined user and system execu‐
6658 tion times (measured in seconds) are greater than this value
6659 have timing statistics printed for them. Output is suppressed
6660 for commands executed within the line editor, including comple‐
6661 tion; commands explicitly marked with the time keyword still
6662 cause the summary to be printed in this case.
6663
6664 REPLY This parameter is reserved by convention to pass string values
6665 between shell scripts and shell builtins in situations where a
6666 function call or redirection are impossible or undesirable. The
6667 read builtin and the select complex command may set REPLY, and
6668 filename generation both sets and examines its value when evalu‐
6669 ating certain expressions. Some modules also employ REPLY for
6670 similar purposes.
6671
6672 reply As REPLY, but for array values rather than strings.
6673
6674 RPROMPT <S>
6675 RPS1 <S>
6676 This prompt is displayed on the right-hand side of the screen
6677 when the primary prompt is being displayed on the left. This
6678 does not work if the SINGLE_LINE_ZLE option is set. It is ex‐
6679 panded in the same way as PS1.
6680
6681 RPROMPT2 <S>
6682 RPS2 <S>
6683 This prompt is displayed on the right-hand side of the screen
6684 when the secondary prompt is being displayed on the left. This
6685 does not work if the SINGLE_LINE_ZLE option is set. It is ex‐
6686 panded in the same way as PS2.
6687
6688 SAVEHIST
6689 The maximum number of history events to save in the history
6690 file.
6691
6692 If this is made local, it is not implicitly set to 0, but may be
6693 explicitly set locally.
6694
6695 SPROMPT <S>
6696 The prompt used for spelling correction. The sequence `%R' ex‐
6697 pands to the string which presumably needs spelling correction,
6698 and `%r' expands to the proposed correction. All other prompt
6699 escapes are also allowed.
6700
6701 The actions available at the prompt are [nyae]:
6702 n (`no') (default)
6703 Discard the correction and run the command.
6704 y (`yes')
6705 Make the correction and run the command.
6706 a (`abort')
6707 Discard the entire command line without running it.
6708 e (`edit')
6709 Resume editing the command line.
6710
6711 STTY If this parameter is set in a command's environment, the shell
6712 runs the stty command with the value of this parameter as argu‐
6713 ments in order to set up the terminal before executing the com‐
6714 mand. The modes apply only to the command, and are reset when it
6715 finishes or is suspended. If the command is suspended and con‐
6716 tinued later with the fg or wait builtins it will see the modes
6717 specified by STTY, as if it were not suspended. This (inten‐
6718 tionally) does not apply if the command is continued via `kill
6719 -CONT'. STTY is ignored if the command is run in the back‐
6720 ground, or if it is in the environment of the shell but not ex‐
6721 plicitly assigned to in the input line. This avoids running stty
6722 at every external command by accidentally exporting it. Also
6723 note that STTY should not be used for window size specifica‐
6724 tions; these will not be local to the command.
6725
6726 If the parameter is set and empty, all of the above applies ex‐
6727 cept that stty is not run. This can be useful as a way to freeze
6728 the tty around a single command, blocking its changes to tty
6729 settings, similar to the ttyctl builtin.
6730
6731 TERM <S>
6732 The type of terminal in use. This is used when looking up term‐
6733 cap sequences. An assignment to TERM causes zsh to re-initial‐
6734 ize the terminal, even if the value does not change (e.g.,
6735 `TERM=$TERM'). It is necessary to make such an assignment upon
6736 any change to the terminal definition database or terminal type
6737 in order for the new settings to take effect.
6738
6739 TERMINFO <S>
6740 A reference to your terminfo database, used by the `terminfo'
6741 library when the system has it; see terminfo(5). If set, this
6742 causes the shell to reinitialise the terminal, making the work‐
6743 around `TERM=$TERM' unnecessary.
6744
6745 TERMINFO_DIRS <S>
6746 A colon-seprarated list of terminfo databases, used by the `ter‐
6747 minfo' library when the system has it; see terminfo(5). This
6748 variable is only used by certain terminal libraries, in particu‐
6749 lar ncurses; see terminfo(5) to check support on your system.
6750 If set, this causes the shell to reinitialise the terminal, mak‐
6751 ing the workaround `TERM=$TERM' unnecessary. Note that unlike
6752 other colon-separated arrays this is not tied to a zsh array.
6753
6754 TIMEFMT
6755 The format of process time reports with the time keyword. The
6756 default is `%J %U user %S system %P cpu %*E total'. Recognizes
6757 the following escape sequences, although not all may be avail‐
6758 able on all systems, and some that are available may not be use‐
6759 ful:
6760
6761 %% A `%'.
6762 %U CPU seconds spent in user mode.
6763 %S CPU seconds spent in kernel mode.
6764 %E Elapsed time in seconds.
6765 %P The CPU percentage, computed as 100*(%U+%S)/%E.
6766 %W Number of times the process was swapped.
6767 %X The average amount in (shared) text space used in kilo‐
6768 bytes.
6769 %D The average amount in (unshared) data/stack space used in
6770 kilobytes.
6771 %K The total space used (%X+%D) in kilobytes.
6772 %M The maximum memory the process had in use at any time in
6773 kilobytes.
6774 %F The number of major page faults (page needed to be
6775 brought from disk).
6776 %R The number of minor page faults.
6777 %I The number of input operations.
6778 %O The number of output operations.
6779 %r The number of socket messages received.
6780 %s The number of socket messages sent.
6781 %k The number of signals received.
6782 %w Number of voluntary context switches (waits).
6783 %c Number of involuntary context switches.
6784 %J The name of this job.
6785
6786 A star may be inserted between the percent sign and flags print‐
6787 ing time (e.g., `%*E'); this causes the time to be printed in
6788 `hh:mm:ss.ttt' format (hours and minutes are only printed if
6789 they are not zero). Alternatively, `m' or `u' may be used
6790 (e.g., `%mE') to produce time output in milliseconds or mi‐
6791 croseconds, respectively.
6792
6793 TMOUT If this parameter is nonzero, the shell will receive an ALRM
6794 signal if a command is not entered within the specified number
6795 of seconds after issuing a prompt. If there is a trap on
6796 SIGALRM, it will be executed and a new alarm is scheduled using
6797 the value of the TMOUT parameter after executing the trap. If
6798 no trap is set, and the idle time of the terminal is not less
6799 than the value of the TMOUT parameter, zsh terminates. Other‐
6800 wise a new alarm is scheduled to TMOUT seconds after the last
6801 keypress.
6802
6803 TMPPREFIX
6804 A pathname prefix which the shell will use for all temporary
6805 files. Note that this should include an initial part for the
6806 file name as well as any directory names. The default is
6807 `/tmp/zsh'.
6808
6809 TMPSUFFIX
6810 A filename suffix which the shell will use for temporary files
6811 created by process substitutions (e.g., `=(list)'). Note that
6812 the value should include a leading dot `.' if intended to be in‐
6813 terpreted as a file extension. The default is not to append any
6814 suffix, thus this parameter should be assigned only when needed
6815 and then unset again.
6816
6817 WORDCHARS <S>
6818 A list of non-alphanumeric characters considered part of a word
6819 by the line editor.
6820
6821 ZBEEP If set, this gives a string of characters, which can use all the
6822 same codes as the bindkey command as described in the zsh/zle
6823 module entry in zshmodules(1), that will be output to the termi‐
6824 nal instead of beeping. This may have a visible instead of an
6825 audible effect; for example, the string `\e[?5h\e[?5l' on a
6826 vt100 or xterm will have the effect of flashing reverse video on
6827 and off (if you usually use reverse video, you should use the
6828 string `\e[?5l\e[?5h' instead). This takes precedence over the
6829 NOBEEP option.
6830
6831 ZDOTDIR
6832 The directory to search for shell startup files (.zshrc, etc),
6833 if not $HOME.
6834
6835 zle_bracketed_paste
6836 Many terminal emulators have a feature that allows applications
6837 to identify when text is pasted into the terminal rather than
6838 being typed normally. For ZLE, this means that special charac‐
6839 ters such as tabs and newlines can be inserted instead of invok‐
6840 ing editor commands. Furthermore, pasted text forms a single
6841 undo event and if the region is active, pasted text will replace
6842 the region.
6843
6844 This two-element array contains the terminal escape sequences
6845 for enabling and disabling the feature. These escape sequences
6846 are used to enable bracketed paste when ZLE is active and dis‐
6847 able it at other times. Unsetting the parameter has the effect
6848 of ensuring that bracketed paste remains disabled.
6849
6850 zle_highlight
6851 An array describing contexts in which ZLE should highlight the
6852 input text. See Character Highlighting in zshzle(1).
6853
6854 ZLE_LINE_ABORTED
6855 This parameter is set by the line editor when an error occurs.
6856 It contains the line that was being edited at the point of the
6857 error. `print -zr -- $ZLE_LINE_ABORTED' can be used to recover
6858 the line. Only the most recent line of this kind is remembered.
6859
6860 ZLE_REMOVE_SUFFIX_CHARS
6861 ZLE_SPACE_SUFFIX_CHARS
6862 These parameters are used by the line editor. In certain cir‐
6863 cumstances suffixes (typically space or slash) added by the com‐
6864 pletion system will be removed automatically, either because the
6865 next editing command was not an insertable character, or because
6866 the character was marked as requiring the suffix to be removed.
6867
6868 These variables can contain the sets of characters that will
6869 cause the suffix to be removed. If ZLE_REMOVE_SUFFIX_CHARS is
6870 set, those characters will cause the suffix to be removed; if
6871 ZLE_SPACE_SUFFIX_CHARS is set, those characters will cause the
6872 suffix to be removed and replaced by a space.
6873
6874 If ZLE_REMOVE_SUFFIX_CHARS is not set, the default behaviour is
6875 equivalent to:
6876
6877 ZLE_REMOVE_SUFFIX_CHARS=$' \t\n;&|'
6878
6879 If ZLE_REMOVE_SUFFIX_CHARS is set but is empty, no characters
6880 have this behaviour. ZLE_SPACE_SUFFIX_CHARS takes precedence,
6881 so that the following:
6882
6883 ZLE_SPACE_SUFFIX_CHARS=$'&|'
6884
6885 causes the characters `&' and `|' to remove the suffix but to
6886 replace it with a space.
6887
6888 To illustrate the difference, suppose that the option AUTO_RE‐
6889 MOVE_SLASH is in effect and the directory DIR has just been com‐
6890 pleted, with an appended /, following which the user types `&'.
6891 The default result is `DIR&'. With ZLE_REMOVE_SUFFIX_CHARS set
6892 but without including `&' the result is `DIR/&'. With
6893 ZLE_SPACE_SUFFIX_CHARS set to include `&' the result is `DIR &'.
6894
6895 Note that certain completions may provide their own suffix re‐
6896 moval or replacement behaviour which overrides the values de‐
6897 scribed here. See the completion system documentation in zsh‐
6898 compsys(1).
6899
6900 ZLE_RPROMPT_INDENT <S>
6901 If set, used to give the indentation between the right hand side
6902 of the right prompt in the line editor as given by RPS1 or
6903 RPROMPT and the right hand side of the screen. If not set, the
6904 value 1 is used.
6905
6906 Typically this will be used to set the value to 0 so that the
6907 prompt appears flush with the right hand side of the screen.
6908 This is not the default as many terminals do not handle this
6909 correctly, in particular when the prompt appears at the extreme
6910 bottom right of the screen. Recent virtual terminals are more
6911 likely to handle this case correctly. Some experimentation is
6912 necessary.
6913
6914
6915
6916ZSHOPTIONS(1) General Commands Manual ZSHOPTIONS(1)
6917
6918
6919
6921 zshoptions - zsh options
6922
6924 Options are primarily referred to by name. These names are case insen‐
6925 sitive and underscores are ignored. For example, `allexport' is equiv‐
6926 alent to `A__lleXP_ort'.
6927
6928 The sense of an option name may be inverted by preceding it with `no',
6929 so `setopt No_Beep' is equivalent to `unsetopt beep'. This inversion
6930 can only be done once, so `nonobeep' is not a synonym for `beep'. Sim‐
6931 ilarly, `tify' is not a synonym for `nonotify' (the inversion of `no‐
6932 tify').
6933
6934 Some options also have one or more single letter names. There are two
6935 sets of single letter options: one used by default, and another used to
6936 emulate sh/ksh (used when the SH_OPTION_LETTERS option is set). The
6937 single letter options can be used on the shell command line, or with
6938 the set, setopt and unsetopt builtins, as normal Unix options preceded
6939 by `-'.
6940
6941 The sense of the single letter options may be inverted by using `+' in‐
6942 stead of `-'. Some of the single letter option names refer to an op‐
6943 tion being off, in which case the inversion of that name refers to the
6944 option being on. For example, `+n' is the short name of `exec', and
6945 `-n' is the short name of its inversion, `noexec'.
6946
6947 In strings of single letter options supplied to the shell at startup,
6948 trailing whitespace will be ignored; for example the string `-f '
6949 will be treated just as `-f', but the string `-f i' is an error. This
6950 is because many systems which implement the `#!' mechanism for calling
6951 scripts do not strip trailing whitespace.
6952
6953 It is possible for options to be set within a function scope. See the
6954 description of the option LOCAL_OPTIONS below.
6955
6957 In the following list, options set by default in all emulations are
6958 marked <D>; those set by default only in csh, ksh, sh, or zsh emula‐
6959 tions are marked <C>, <K>, <S>, <Z> as appropriate. When listing op‐
6960 tions (by `setopt', `unsetopt', `set -o' or `set +o'), those turned on
6961 by default appear in the list prefixed with `no'. Hence (unless
6962 KSH_OPTION_PRINT is set), `setopt' shows all options whose settings are
6963 changed from the default.
6964
6965 Changing Directories
6966 AUTO_CD (-J)
6967 If a command is issued that can't be executed as a normal com‐
6968 mand, and the command is the name of a directory, perform the cd
6969 command to that directory. This option is only applicable if
6970 the option SHIN_STDIN is set, i.e. if commands are being read
6971 from standard input. The option is designed for interactive
6972 use; it is recommended that cd be used explicitly in scripts to
6973 avoid ambiguity.
6974
6975 AUTO_PUSHD (-N)
6976 Make cd push the old directory onto the directory stack.
6977
6978 CDABLE_VARS (-T)
6979 If the argument to a cd command (or an implied cd with the
6980 AUTO_CD option set) is not a directory, and does not begin with
6981 a slash, try to expand the expression as if it were preceded by
6982 a `~' (see the section `Filename Expansion').
6983
6984 CD_SILENT
6985 Never print the working directory after a cd (whether explicit
6986 or implied with the AUTO_CD option set). cd normally prints the
6987 working directory when the argument given to it was -, a stack
6988 entry, or the name of a directory found under CDPATH. Note that
6989 this is distinct from pushd's stack-printing behaviour, which is
6990 controlled by PUSHD_SILENT. This option overrides the print‐
6991 ing-related effects of POSIX_CD.
6992
6993 CHASE_DOTS
6994 When changing to a directory containing a path segment `..'
6995 which would otherwise be treated as canceling the previous seg‐
6996 ment in the path (in other words, `foo/..' would be removed from
6997 the path, or if `..' is the first part of the path, the last
6998 part of the current working directory would be removed), instead
6999 resolve the path to the physical directory. This option is
7000 overridden by CHASE_LINKS.
7001
7002 For example, suppose /foo/bar is a link to the directory
7003 /alt/rod. Without this option set, `cd /foo/bar/..' changes to
7004 /foo; with it set, it changes to /alt. The same applies if the
7005 current directory is /foo/bar and `cd ..' is used. Note that
7006 all other symbolic links in the path will also be resolved.
7007
7008 CHASE_LINKS (-w)
7009 Resolve symbolic links to their true values when changing direc‐
7010 tory. This also has the effect of CHASE_DOTS, i.e. a `..' path
7011 segment will be treated as referring to the physical parent,
7012 even if the preceding path segment is a symbolic link.
7013
7014 POSIX_CD <K> <S>
7015 Modifies the behaviour of cd, chdir and pushd commands to make
7016 them more compatible with the POSIX standard. The behaviour with
7017 the option unset is described in the documentation for the cd
7018 builtin in zshbuiltins(1). If the option is set, the shell does
7019 not test for directories beneath the local directory (`.') until
7020 after all directories in cdpath have been tested, and the cd and
7021 chdir commands do not recognise arguments of the form `{+|-}n'
7022 as directory stack entries.
7023
7024 Also, if the option is set, the conditions under which the shell
7025 prints the new directory after changing to it are modified. It
7026 is no longer restricted to interactive shells (although printing
7027 of the directory stack with pushd is still limited to interac‐
7028 tive shells); and any use of a component of CDPATH, including a
7029 `.' but excluding an empty component that is otherwise treated
7030 as `.', causes the directory to be printed.
7031
7032 PUSHD_IGNORE_DUPS
7033 Don't push multiple copies of the same directory onto the direc‐
7034 tory stack.
7035
7036 PUSHD_MINUS
7037 Exchanges the meanings of `+' and `-' when used with a number to
7038 specify a directory in the stack.
7039
7040 PUSHD_SILENT (-E)
7041 Do not print the directory stack after pushd or popd.
7042
7043 PUSHD_TO_HOME (-D)
7044 Have pushd with no arguments act like `pushd $HOME'.
7045
7046 Completion
7047 ALWAYS_LAST_PROMPT <D>
7048 If unset, key functions that list completions try to return to
7049 the last prompt if given a numeric argument. If set these func‐
7050 tions try to return to the last prompt if given no numeric argu‐
7051 ment.
7052
7053 ALWAYS_TO_END
7054 If a completion is performed with the cursor within a word, and
7055 a full completion is inserted, the cursor is moved to the end of
7056 the word. That is, the cursor is moved to the end of the word
7057 if either a single match is inserted or menu completion is per‐
7058 formed.
7059
7060 AUTO_LIST (-9) <D>
7061 Automatically list choices on an ambiguous completion.
7062
7063 AUTO_MENU <D>
7064 Automatically use menu completion after the second consecutive
7065 request for completion, for example by pressing the tab key re‐
7066 peatedly. This option is overridden by MENU_COMPLETE.
7067
7068 AUTO_NAME_DIRS
7069 Any parameter that is set to the absolute name of a directory
7070 immediately becomes a name for that directory, that will be used
7071 by the `%~' and related prompt sequences, and will be available
7072 when completion is performed on a word starting with `~'. (Oth‐
7073 erwise, the parameter must be used in the form `~param' first.)
7074
7075 AUTO_PARAM_KEYS <D>
7076 If a parameter name was completed and a following character
7077 (normally a space) automatically inserted, and the next charac‐
7078 ter typed is one of those that have to come directly after the
7079 name (like `}', `:', etc.), the automatically added character is
7080 deleted, so that the character typed comes immediately after the
7081 parameter name. Completion in a brace expansion is affected
7082 similarly: the added character is a `,', which will be removed
7083 if `}' is typed next.
7084
7085 AUTO_PARAM_SLASH <D>
7086 If a parameter is completed whose content is the name of a di‐
7087 rectory, then add a trailing slash instead of a space.
7088
7089 AUTO_REMOVE_SLASH <D>
7090 When the last character resulting from a completion is a slash
7091 and the next character typed is a word delimiter, a slash, or a
7092 character that ends a command (such as a semicolon or an amper‐
7093 sand), remove the slash.
7094
7095 BASH_AUTO_LIST
7096 On an ambiguous completion, automatically list choices when the
7097 completion function is called twice in succession. This takes
7098 precedence over AUTO_LIST. The setting of LIST_AMBIGUOUS is re‐
7099 spected. If AUTO_MENU is set, the menu behaviour will then
7100 start with the third press. Note that this will not work with
7101 MENU_COMPLETE, since repeated completion calls immediately cycle
7102 through the list in that case.
7103
7104 COMPLETE_ALIASES
7105 Prevents aliases on the command line from being internally sub‐
7106 stituted before completion is attempted. The effect is to make
7107 the alias a distinct command for completion purposes.
7108
7109 COMPLETE_IN_WORD
7110 If unset, the cursor is set to the end of the word if completion
7111 is started. Otherwise it stays there and completion is done from
7112 both ends.
7113
7114 GLOB_COMPLETE
7115 When the current word has a glob pattern, do not insert all the
7116 words resulting from the expansion but generate matches as for
7117 completion and cycle through them like MENU_COMPLETE. The
7118 matches are generated as if a `*' was added to the end of the
7119 word, or inserted at the cursor when COMPLETE_IN_WORD is set.
7120 This actually uses pattern matching, not globbing, so it works
7121 not only for files but for any completion, such as options, user
7122 names, etc.
7123
7124 Note that when the pattern matcher is used, matching control
7125 (for example, case-insensitive or anchored matching) cannot be
7126 used. This limitation only applies when the current word con‐
7127 tains a pattern; simply turning on the GLOB_COMPLETE option does
7128 not have this effect.
7129
7130 HASH_LIST_ALL <D>
7131 Whenever a command completion or spelling correction is at‐
7132 tempted, make sure the entire command path is hashed first.
7133 This makes the first completion slower but avoids false reports
7134 of spelling errors.
7135
7136 LIST_AMBIGUOUS <D>
7137 This option works when AUTO_LIST or BASH_AUTO_LIST is also set.
7138 If there is an unambiguous prefix to insert on the command line,
7139 that is done without a completion list being displayed; in other
7140 words, auto-listing behaviour only takes place when nothing
7141 would be inserted. In the case of BASH_AUTO_LIST, this means
7142 that the list will be delayed to the third call of the function.
7143
7144 LIST_BEEP <D>
7145 Beep on an ambiguous completion. More accurately, this forces
7146 the completion widgets to return status 1 on an ambiguous com‐
7147 pletion, which causes the shell to beep if the option BEEP is
7148 also set; this may be modified if completion is called from a
7149 user-defined widget.
7150
7151 LIST_PACKED
7152 Try to make the completion list smaller (occupying less lines)
7153 by printing the matches in columns with different widths.
7154
7155 LIST_ROWS_FIRST
7156 Lay out the matches in completion lists sorted horizontally,
7157 that is, the second match is to the right of the first one, not
7158 under it as usual.
7159
7160 LIST_TYPES (-X) <D>
7161 When listing files that are possible completions, show the type
7162 of each file with a trailing identifying mark.
7163
7164 MENU_COMPLETE (-Y)
7165 On an ambiguous completion, instead of listing possibilities or
7166 beeping, insert the first match immediately. Then when comple‐
7167 tion is requested again, remove the first match and insert the
7168 second match, etc. When there are no more matches, go back to
7169 the first one again. reverse-menu-complete may be used to loop
7170 through the list in the other direction. This option overrides
7171 AUTO_MENU.
7172
7173 REC_EXACT (-S)
7174 If the string on the command line exactly matches one of the
7175 possible completions, it is accepted, even if there is another
7176 completion (i.e. that string with something else added) that
7177 also matches.
7178
7179 Expansion and Globbing
7180 BAD_PATTERN (+2) <C> <Z>
7181 If a pattern for filename generation is badly formed, print an
7182 error message. (If this option is unset, the pattern will be
7183 left unchanged.)
7184
7185 BARE_GLOB_QUAL <Z>
7186 In a glob pattern, treat a trailing set of parentheses as a
7187 qualifier list, if it contains no `|', `(' or (if special) `~'
7188 characters. See the section `Filename Generation'.
7189
7190 BRACE_CCL
7191 Expand expressions in braces which would not otherwise undergo
7192 brace expansion to a lexically ordered list of all the charac‐
7193 ters. See the section `Brace Expansion'.
7194
7195 CASE_GLOB <D>
7196 Make globbing (filename generation) sensitive to case. Note
7197 that other uses of patterns are always sensitive to case. If
7198 the option is unset, the presence of any character which is spe‐
7199 cial to filename generation will cause case-insensitive match‐
7200 ing. For example, cvs(/) can match the directory CVS owing to
7201 the presence of the globbing flag (unless the option
7202 BARE_GLOB_QUAL is unset).
7203
7204 CASE_MATCH <D>
7205 Make regular expressions using the zsh/regex module (including
7206 matches with =~) sensitive to case.
7207
7208 CASE_PATHS
7209 If CASE_PATHS is not set (the default), CASE_GLOB affects the
7210 interpretation of every path component, whenever a special char‐
7211 acter appears in any component. When CASE_PATHS is set, file
7212 path components that do not contain special filename generation
7213 characters are always sensitive to case, thus restricting
7214 NO_CASE_GLOB to components that contain globbing characters.
7215
7216 Note that if the filesystem itself is not sensitive to case,
7217 then CASE_PATHS has no effect.
7218
7219 CSH_NULL_GLOB <C>
7220 If a pattern for filename generation has no matches, delete the
7221 pattern from the argument list; do not report an error unless
7222 all the patterns in a command have no matches. Overrides NO‐
7223 MATCH.
7224
7225 EQUALS <Z>
7226 Perform = filename expansion. (See the section `Filename Expan‐
7227 sion'.)
7228
7229 EXTENDED_GLOB
7230 Treat the `#', `~' and `^' characters as part of patterns for
7231 filename generation, etc. (An initial unquoted `~' always pro‐
7232 duces named directory expansion.)
7233
7234 FORCE_FLOAT
7235 Constants in arithmetic evaluation will be treated as floating
7236 point even without the use of a decimal point; the values of in‐
7237 teger variables will be converted to floating point when used in
7238 arithmetic expressions. Integers in any base will be converted.
7239
7240 GLOB (+F, ksh: +f) <D>
7241 Perform filename generation (globbing). (See the section `File‐
7242 name Generation'.)
7243
7244 GLOB_ASSIGN <C>
7245 If this option is set, filename generation (globbing) is per‐
7246 formed on the right hand side of scalar parameter assignments of
7247 the form `name=pattern (e.g. `foo=*'). If the result has more
7248 than one word the parameter will become an array with those
7249 words as arguments. This option is provided for backwards com‐
7250 patibility only: globbing is always performed on the right hand
7251 side of array assignments of the form `name=(value)' (e.g.
7252 `foo=(*)') and this form is recommended for clarity; with this
7253 option set, it is not possible to predict whether the result
7254 will be an array or a scalar.
7255
7256 GLOB_DOTS (-4)
7257 Do not require a leading `.' in a filename to be matched explic‐
7258 itly.
7259
7260 GLOB_STAR_SHORT
7261 When this option is set and the default zsh-style globbing is in
7262 effect, the pattern `**/*' can be abbreviated to `**' and the
7263 pattern `***/*' can be abbreviated to ***. Hence `**.c' finds a
7264 file ending in .c in any subdirectory, and `***.c' does the same
7265 while also following symbolic links. A / immediately after the
7266 `**' or `***' forces the pattern to be treated as the unabbrevi‐
7267 ated form.
7268
7269 GLOB_SUBST <C> <K> <S>
7270 Treat any characters resulting from parameter expansion as being
7271 eligible for filename expansion and filename generation, and any
7272 characters resulting from command substitution as being eligible
7273 for filename generation. Braces (and commas in between) do not
7274 become eligible for expansion.
7275
7276 HIST_SUBST_PATTERN
7277 Substitutions using the :s and :& history modifiers are per‐
7278 formed with pattern matching instead of string matching. This
7279 occurs wherever history modifiers are valid, including glob
7280 qualifiers and parameters. See the section `Modifiers' in zsh‐
7281 expn(1).
7282
7283 IGNORE_BRACES (-I) <S>
7284 Do not perform brace expansion. For historical reasons this
7285 also includes the effect of the IGNORE_CLOSE_BRACES option.
7286
7287 IGNORE_CLOSE_BRACES
7288 When neither this option nor IGNORE_BRACES is set, a sole close
7289 brace character `}' is syntactically significant at any point on
7290 a command line. This has the effect that no semicolon or new‐
7291 line is necessary before the brace terminating a function or
7292 current shell construct. When either option is set, a closing
7293 brace is syntactically significant only in command position.
7294 Unlike IGNORE_BRACES, this option does not disable brace expan‐
7295 sion.
7296
7297 For example, with both options unset a function may be defined
7298 in the following fashion:
7299
7300 args() { echo $# }
7301
7302 while if either option is set, this does not work and something
7303 equivalent to the following is required:
7304
7305 args() { echo $#; }
7306
7307 KSH_GLOB <K>
7308 In pattern matching, the interpretation of parentheses is af‐
7309 fected by a preceding `@', `*', `+', `?' or `!'. See the sec‐
7310 tion `Filename Generation'.
7311
7312 MAGIC_EQUAL_SUBST
7313 All unquoted arguments of the form `anything=expression' appear‐
7314 ing after the command name have filename expansion (that is,
7315 where expression has a leading `~' or `=') performed on expres‐
7316 sion as if it were a parameter assignment. The argument is not
7317 otherwise treated specially; it is passed to the command as a
7318 single argument, and not used as an actual parameter assignment.
7319 For example, in echo foo=~/bar:~/rod, both occurrences of ~
7320 would be replaced. Note that this happens anyway with typeset
7321 and similar statements.
7322
7323 This option respects the setting of the KSH_TYPESET option. In
7324 other words, if both options are in effect, arguments looking
7325 like assignments will not undergo word splitting.
7326
7327 MARK_DIRS (-8, ksh: -X)
7328 Append a trailing `/' to all directory names resulting from
7329 filename generation (globbing).
7330
7331 MULTIBYTE <D>
7332 Respect multibyte characters when found in strings. When this
7333 option is set, strings are examined using the system library to
7334 determine how many bytes form a character, depending on the cur‐
7335 rent locale. This affects the way characters are counted in
7336 pattern matching, parameter values and various delimiters.
7337
7338 The option is on by default if the shell was compiled with
7339 MULTIBYTE_SUPPORT; otherwise it is off by default and has no ef‐
7340 fect if turned on.
7341
7342 If the option is off a single byte is always treated as a single
7343 character. This setting is designed purely for examining
7344 strings known to contain raw bytes or other values that may not
7345 be characters in the current locale. It is not necessary to un‐
7346 set the option merely because the character set for the current
7347 locale does not contain multibyte characters.
7348
7349 The option does not affect the shell's editor, which always
7350 uses the locale to determine multibyte characters. This is be‐
7351 cause the character set displayed by the terminal emulator is
7352 independent of shell settings.
7353
7354 NOMATCH (+3) <C> <Z>
7355 If a pattern for filename generation has no matches, print an
7356 error, instead of leaving it unchanged in the argument list.
7357 This also applies to file expansion of an initial `~' or `='.
7358
7359 NULL_GLOB (-G)
7360 If a pattern for filename generation has no matches, delete the
7361 pattern from the argument list instead of reporting an error.
7362 Overrides NOMATCH.
7363
7364 NUMERIC_GLOB_SORT
7365 If numeric filenames are matched by a filename generation pat‐
7366 tern, sort the filenames numerically rather than lexicographi‐
7367 cally.
7368
7369 RC_EXPAND_PARAM (-P)
7370 Array expansions of the form `foo${xx}bar', where the parameter
7371 xx is set to (a b c), are substituted with `fooabar foobbar
7372 foocbar' instead of the default `fooa b cbar'. Note that an
7373 empty array will therefore cause all arguments to be removed.
7374
7375 REMATCH_PCRE
7376 If set, regular expression matching with the =~ operator will
7377 use Perl-Compatible Regular Expressions from the PCRE library.
7378 (The zsh/pcre module must be available.) If not set, regular
7379 expressions will use the extended regexp syntax provided by the
7380 system libraries.
7381
7382 SH_GLOB <K> <S>
7383 Disables the special meaning of `(', `|', `)' and '<' for glob‐
7384 bing the result of parameter and command substitutions, and in
7385 some other places where the shell accepts patterns. If SH_GLOB
7386 is set but KSH_GLOB is not, the shell allows the interpretation
7387 of subshell expressions enclosed in parentheses in some cases
7388 where there is no space before the opening parenthesis, e.g.
7389 !(true) is interpreted as if there were a space after the !.
7390 This option is set by default if zsh is invoked as sh or ksh.
7391
7392 UNSET (+u, ksh: +u) <K> <S> <Z>
7393 Treat unset parameters as if they were empty when substituting,
7394 and as if they were zero when reading their values in arithmetic
7395 expansion and arithmetic commands. Otherwise they are treated
7396 as an error.
7397
7398 WARN_CREATE_GLOBAL
7399 Print a warning message when a global parameter is created in a
7400 function by an assignment or in math context. This often indi‐
7401 cates that a parameter has not been declared local when it
7402 should have been. Parameters explicitly declared global from
7403 within a function using typeset -g do not cause a warning. Note
7404 that there is no warning when a local parameter is assigned to
7405 in a nested function, which may also indicate an error.
7406
7407 WARN_NESTED_VAR
7408 Print a warning message when an existing parameter from an en‐
7409 closing function scope, or global, is set in a function by an
7410 assignment or in math context. Assignment to shell special pa‐
7411 rameters does not cause a warning. This is the companion to
7412 WARN_CREATE_GLOBAL as in this case the warning is only printed
7413 when a parameter is not created. Where possible, use of typeset
7414 -g to set the parameter suppresses the error, but note that this
7415 needs to be used every time the parameter is set. To restrict
7416 the effect of this option to a single function scope, use `func‐
7417 tions -W'.
7418
7419 For example, the following code produces a warning for the as‐
7420 signment inside the function nested as that overrides the value
7421 within toplevel
7422
7423 toplevel() {
7424 local foo="in fn"
7425 nested
7426 }
7427 nested() {
7428 foo="in nested"
7429 }
7430 setopt warn_nested_var
7431 toplevel
7432
7433 History
7434 APPEND_HISTORY <D>
7435 If this is set, zsh sessions will append their history list to
7436 the history file, rather than replace it. Thus, multiple paral‐
7437 lel zsh sessions will all have the new entries from their his‐
7438 tory lists added to the history file, in the order that they
7439 exit. The file will still be periodically re-written to trim it
7440 when the number of lines grows 20% beyond the value specified by
7441 $SAVEHIST (see also the HIST_SAVE_BY_COPY option).
7442
7443 BANG_HIST (+K) <C> <Z>
7444 Perform textual history expansion, csh-style, treating the char‐
7445 acter `!' specially.
7446
7447 EXTENDED_HISTORY <C>
7448 Save each command's beginning timestamp (in seconds since the
7449 epoch) and the duration (in seconds) to the history file. The
7450 format of this prefixed data is:
7451
7452 `: <beginning time>:<elapsed seconds>;<command>'.
7453
7454 HIST_ALLOW_CLOBBER
7455 Add `|' to output redirections in the history. This allows his‐
7456 tory references to clobber files even when CLOBBER is unset.
7457
7458 HIST_BEEP <D>
7459 Beep in ZLE when a widget attempts to access a history entry
7460 which isn't there.
7461
7462 HIST_EXPIRE_DUPS_FIRST
7463 If the internal history needs to be trimmed to add the current
7464 command line, setting this option will cause the oldest history
7465 event that has a duplicate to be lost before losing a unique
7466 event from the list. You should be sure to set the value of
7467 HISTSIZE to a larger number than SAVEHIST in order to give you
7468 some room for the duplicated events, otherwise this option will
7469 behave just like HIST_IGNORE_ALL_DUPS once the history fills up
7470 with unique events.
7471
7472 HIST_FCNTL_LOCK
7473 When writing out the history file, by default zsh uses ad-hoc
7474 file locking to avoid known problems with locking on some oper‐
7475 ating systems. With this option locking is done by means of the
7476 system's fcntl call, where this method is available. On recent
7477 operating systems this may provide better performance, in par‐
7478 ticular avoiding history corruption when files are stored on
7479 NFS.
7480
7481 HIST_FIND_NO_DUPS
7482 When searching for history entries in the line editor, do not
7483 display duplicates of a line previously found, even if the du‐
7484 plicates are not contiguous.
7485
7486 HIST_IGNORE_ALL_DUPS
7487 If a new command line being added to the history list duplicates
7488 an older one, the older command is removed from the list (even
7489 if it is not the previous event).
7490
7491 HIST_IGNORE_DUPS (-h)
7492 Do not enter command lines into the history list if they are du‐
7493 plicates of the previous event.
7494
7495 HIST_IGNORE_SPACE (-g)
7496 Remove command lines from the history list when the first char‐
7497 acter on the line is a space, or when one of the expanded
7498 aliases contains a leading space. Only normal aliases (not
7499 global or suffix aliases) have this behaviour. Note that the
7500 command lingers in the internal history until the next command
7501 is entered before it vanishes, allowing you to briefly reuse or
7502 edit the line. If you want to make it vanish right away without
7503 entering another command, type a space and press return.
7504
7505 HIST_LEX_WORDS
7506 By default, shell history that is read in from files is split
7507 into words on all white space. This means that arguments with
7508 quoted whitespace are not correctly handled, with the conse‐
7509 quence that references to words in history lines that have been
7510 read from a file may be inaccurate. When this option is set,
7511 words read in from a history file are divided up in a similar
7512 fashion to normal shell command line handling. Although this
7513 produces more accurately delimited words, if the size of the
7514 history file is large this can be slow. Trial and error is nec‐
7515 essary to decide.
7516
7517 HIST_NO_FUNCTIONS
7518 Remove function definitions from the history list. Note that
7519 the function lingers in the internal history until the next com‐
7520 mand is entered before it vanishes, allowing you to briefly re‐
7521 use or edit the definition.
7522
7523 HIST_NO_STORE
7524 Remove the history (fc -l) command from the history list when
7525 invoked. Note that the command lingers in the internal history
7526 until the next command is entered before it vanishes, allowing
7527 you to briefly reuse or edit the line.
7528
7529 HIST_REDUCE_BLANKS
7530 Remove superfluous blanks from each command line being added to
7531 the history list.
7532
7533 HIST_SAVE_BY_COPY <D>
7534 When the history file is re-written, we normally write out a
7535 copy of the file named $HISTFILE.new and then rename it over the
7536 old one. However, if this option is unset, we instead truncate
7537 the old history file and write out the new version in-place. If
7538 one of the history-appending options is enabled, this option
7539 only has an effect when the enlarged history file needs to be
7540 re-written to trim it down to size. Disable this only if you
7541 have special needs, as doing so makes it possible to lose his‐
7542 tory entries if zsh gets interrupted during the save.
7543
7544 When writing out a copy of the history file, zsh preserves the
7545 old file's permissions and group information, but will refuse to
7546 write out a new file if it would change the history file's
7547 owner.
7548
7549 HIST_SAVE_NO_DUPS
7550 When writing out the history file, older commands that duplicate
7551 newer ones are omitted.
7552
7553 HIST_VERIFY
7554 Whenever the user enters a line with history expansion, don't
7555 execute the line directly; instead, perform history expansion
7556 and reload the line into the editing buffer.
7557
7558 INC_APPEND_HISTORY
7559 This option works like APPEND_HISTORY except that new history
7560 lines are added to the $HISTFILE incrementally (as soon as they
7561 are entered), rather than waiting until the shell exits. The
7562 file will still be periodically re-written to trim it when the
7563 number of lines grows 20% beyond the value specified by $SAVE‐
7564 HIST (see also the HIST_SAVE_BY_COPY option).
7565
7566 INC_APPEND_HISTORY_TIME
7567 This option is a variant of INC_APPEND_HISTORY in which, where
7568 possible, the history entry is written out to the file after the
7569 command is finished, so that the time taken by the command is
7570 recorded correctly in the history file in EXTENDED_HISTORY for‐
7571 mat. This means that the history entry will not be available
7572 immediately from other instances of the shell that are using the
7573 same history file.
7574
7575 This option is only useful if INC_APPEND_HISTORY and SHARE_HIS‐
7576 TORY are turned off. The three options should be considered mu‐
7577 tually exclusive.
7578
7579 SHARE_HISTORY <K>
7580
7581 This option both imports new commands from the history file, and
7582 also causes your typed commands to be appended to the history
7583 file (the latter is like specifying INC_APPEND_HISTORY, which
7584 should be turned off if this option is in effect). The history
7585 lines are also output with timestamps ala EXTENDED_HISTORY
7586 (which makes it easier to find the spot where we left off read‐
7587 ing the file after it gets re-written).
7588
7589 By default, history movement commands visit the imported lines
7590 as well as the local lines, but you can toggle this on and off
7591 with the set-local-history zle binding. It is also possible to
7592 create a zle widget that will make some commands ignore imported
7593 commands, and some include them.
7594
7595 If you find that you want more control over when commands get
7596 imported, you may wish to turn SHARE_HISTORY off, INC_AP‐
7597 PEND_HISTORY or INC_APPEND_HISTORY_TIME (see above) on, and then
7598 manually import commands whenever you need them using `fc -RI'.
7599
7600 Initialisation
7601 ALL_EXPORT (-a, ksh: -a)
7602 All parameters subsequently defined are automatically exported.
7603
7604 GLOBAL_EXPORT <Z>
7605 If this option is set, passing the -x flag to the builtins de‐
7606 clare, float, integer, readonly and typeset (but not local) will
7607 also set the -g flag; hence parameters exported to the environ‐
7608 ment will not be made local to the enclosing function, unless
7609 they were already or the flag +g is given explicitly. If the
7610 option is unset, exported parameters will be made local in just
7611 the same way as any other parameter.
7612
7613 This option is set by default for backward compatibility; it is
7614 not recommended that its behaviour be relied upon. Note that
7615 the builtin export always sets both the -x and -g flags, and
7616 hence its effect extends beyond the scope of the enclosing func‐
7617 tion; this is the most portable way to achieve this behaviour.
7618
7619 GLOBAL_RCS (+d) <D>
7620 If this option is unset, the startup files /etc/zprofile,
7621 /etc/zshrc, /etc/zlogin and /etc/zlogout will not be run. It
7622 can be disabled and re-enabled at any time, including inside lo‐
7623 cal startup files (.zshrc, etc.).
7624
7625 RCS (+f) <D>
7626 After /etc/zshenv is sourced on startup, source the .zshenv,
7627 /etc/zprofile, .zprofile, /etc/zshrc, .zshrc, /etc/zlogin, .zlo‐
7628 gin, and .zlogout files, as described in the section `Files'.
7629 If this option is unset, the /etc/zshenv file is still sourced,
7630 but any of the others will not be; it can be set at any time to
7631 prevent the remaining startup files after the currently execut‐
7632 ing one from being sourced.
7633
7634 Input/Output
7635 ALIASES <D>
7636 Expand aliases.
7637
7638 CLOBBER (+C, ksh: +C) <D>
7639 Allows `>' redirection to truncate existing files. Otherwise
7640 `>!' or `>|' must be used to truncate a file.
7641
7642 If the option is not set, and the option APPEND_CREATE is also
7643 not set, `>>!' or `>>|' must be used to create a file. If ei‐
7644 ther option is set, `>>' may be used.
7645
7646 CLOBBER_EMPTY
7647 This option is only used if the option CLOBBER is not set: note
7648 that it is set by default.
7649
7650 If this option is set, then regular files of zero length may be
7651 ovewritten (`clobbered'). Note that it is possible another
7652 process has written to the file between this test and use of the
7653 file by the current process. This option should therefore not
7654 be used in cases where files to be clobbered may be written to
7655 asynchronously.
7656
7657 CORRECT (-0)
7658 Try to correct the spelling of commands. Note that, when the
7659 HASH_LIST_ALL option is not set or when some directories in the
7660 path are not readable, this may falsely report spelling errors
7661 the first time some commands are used.
7662
7663 The shell variable CORRECT_IGNORE may be set to a pattern to
7664 match words that will never be offered as corrections.
7665
7666 CORRECT_ALL (-O)
7667 Try to correct the spelling of all arguments in a line.
7668
7669 The shell variable CORRECT_IGNORE_FILE may be set to a pattern
7670 to match file names that will never be offered as corrections.
7671
7672 DVORAK Use the Dvorak keyboard instead of the standard qwerty keyboard
7673 as a basis for examining spelling mistakes for the CORRECT and
7674 CORRECT_ALL options and the spell-word editor command.
7675
7676 FLOW_CONTROL <D>
7677 If this option is unset, output flow control via start/stop
7678 characters (usually assigned to ^S/^Q) is disabled in the
7679 shell's editor.
7680
7681 IGNORE_EOF (-7)
7682 Do not exit on end-of-file. Require the use of exit or logout
7683 instead. However, ten consecutive EOFs will cause the shell to
7684 exit anyway, to avoid the shell hanging if its tty goes away.
7685
7686 Also, if this option is set and the Zsh Line Editor is used,
7687 widgets implemented by shell functions can be bound to EOF (nor‐
7688 mally Control-D) without printing the normal warning message.
7689 This works only for normal widgets, not for completion widgets.
7690
7691 INTERACTIVE_COMMENTS (-k) <K> <S>
7692 Allow comments even in interactive shells.
7693
7694 HASH_CMDS <D>
7695 Note the location of each command the first time it is executed.
7696 Subsequent invocations of the same command will use the saved
7697 location, avoiding a path search. If this option is unset, no
7698 path hashing is done at all. However, when CORRECT is set, com‐
7699 mands whose names do not appear in the functions or aliases hash
7700 tables are hashed in order to avoid reporting them as spelling
7701 errors.
7702
7703 HASH_DIRS <D>
7704 Whenever a command name is hashed, hash the directory containing
7705 it, as well as all directories that occur earlier in the path.
7706 Has no effect if neither HASH_CMDS nor CORRECT is set.
7707
7708 HASH_EXECUTABLES_ONLY
7709 When hashing commands because of HASH_CMDS, check that the file
7710 to be hashed is actually an executable. This option is unset by
7711 default as if the path contains a large number of commands, or
7712 consists of many remote files, the additional tests can take a
7713 long time. Trial and error is needed to show if this option is
7714 beneficial.
7715
7716 MAIL_WARNING (-U)
7717 Print a warning message if a mail file has been accessed since
7718 the shell last checked.
7719
7720 PATH_DIRS (-Q)
7721 Perform a path search even on command names with slashes in
7722 them. Thus if `/usr/local/bin' is in the user's path, and he or
7723 she types `X11/xinit', the command `/usr/local/bin/X11/xinit'
7724 will be executed (assuming it exists). Commands explicitly be‐
7725 ginning with `/', `./' or `../' are not subject to the path
7726 search. This also applies to the `.' and source builtins.
7727
7728 Note that subdirectories of the current directory are always
7729 searched for executables specified in this form. This takes
7730 place before any search indicated by this option, and regardless
7731 of whether `.' or the current directory appear in the command
7732 search path.
7733
7734 PATH_SCRIPT <K> <S>
7735 If this option is not set, a script passed as the first non-op‐
7736 tion argument to the shell must contain the name of the file to
7737 open. If this option is set, and the script does not specify a
7738 directory path, the script is looked for first in the current
7739 directory, then in the command path. See the section INVOCATION
7740 in zsh(1).
7741
7742 PRINT_EIGHT_BIT
7743 Print eight bit characters literally in completion lists, etc.
7744 This option is not necessary if your system correctly returns
7745 the printability of eight bit characters (see ctype(3)).
7746
7747 PRINT_EXIT_VALUE (-1)
7748 Print the exit value of programs with non-zero exit status.
7749 This is only available at the command line in interactive
7750 shells.
7751
7752 RC_QUOTES
7753 Allow the character sequence `''' to signify a single quote
7754 within singly quoted strings. Note this does not apply in
7755 quoted strings using the format $'...', where a backslashed sin‐
7756 gle quote can be used.
7757
7758 RM_STAR_SILENT (-H) <K> <S>
7759 Do not query the user before executing `rm *' or `rm path/*'.
7760
7761 RM_STAR_WAIT
7762 If querying the user before executing `rm *' or `rm path/*',
7763 first wait ten seconds and ignore anything typed in that time.
7764 This avoids the problem of reflexively answering `yes' to the
7765 query when one didn't really mean it. The wait and query can
7766 always be avoided by expanding the `*' in ZLE (with tab).
7767
7768 SHORT_LOOPS <C> <Z>
7769 Allow the short forms of for, repeat, select, if, and function
7770 constructs.
7771
7772 SHORT_REPEAT
7773 Allow the short form repeat as SHORT_LOOPS but without enabling
7774 it for the other constructs.
7775
7776 SUN_KEYBOARD_HACK (-L)
7777 If a line ends with a backquote, and there are an odd number of
7778 backquotes on the line, ignore the trailing backquote. This is
7779 useful on some keyboards where the return key is too small, and
7780 the backquote key lies annoyingly close to it. As an alterna‐
7781 tive the variable KEYBOARD_HACK lets you choose the character to
7782 be removed.
7783
7784 Job Control
7785 AUTO_CONTINUE
7786 With this option set, stopped jobs that are removed from the job
7787 table with the disown builtin command are automatically sent a
7788 CONT signal to make them running.
7789
7790 AUTO_RESUME (-W)
7791 Treat single word simple commands without redirection as candi‐
7792 dates for resumption of an existing job.
7793
7794 BG_NICE (-6) <C> <Z>
7795 Run all background jobs at a lower priority. This option is set
7796 by default.
7797
7798 CHECK_JOBS <Z>
7799 Report the status of background and suspended jobs before exit‐
7800 ing a shell with job control; a second attempt to exit the shell
7801 will succeed. NO_CHECK_JOBS is best used only in combination
7802 with NO_HUP, else such jobs will be killed automatically.
7803
7804 The check is omitted if the commands run from the previous com‐
7805 mand line included a `jobs' command, since it is assumed the
7806 user is aware that there are background or suspended jobs. A
7807 `jobs' command run from one of the hook functions defined in the
7808 section SPECIAL FUNCTIONS in zshmisc(1) is not counted for this
7809 purpose.
7810
7811 CHECK_RUNNING_JOBS <Z>
7812 Check for both running and suspended jobs when CHECK_JOBS is en‐
7813 abled. When this option is disabled, zsh checks only for sus‐
7814 pended jobs, which matches the default behavior of bash.
7815
7816 This option has no effect unless CHECK_JOBS is set.
7817
7818 HUP <Z>
7819 Send the HUP signal to running jobs when the shell exits.
7820
7821 LONG_LIST_JOBS (-R)
7822 Print job notifications in the long format by default.
7823
7824 MONITOR (-m, ksh: -m)
7825 Allow job control. Set by default in interactive shells.
7826
7827 NOTIFY (-5, ksh: -b) <Z>
7828 Report the status of background jobs immediately, rather than
7829 waiting until just before printing a prompt.
7830
7831 POSIX_JOBS <K> <S>
7832 This option makes job control more compliant with the POSIX
7833 standard.
7834
7835 When the option is not set, the MONITOR option is unset on entry
7836 to subshells, so that job control is no longer active. When the
7837 option is set, the MONITOR option and job control remain active
7838 in the subshell, but note that the subshell has no access to
7839 jobs in the parent shell.
7840
7841 When the option is not set, jobs put in the background or fore‐
7842 ground with bg or fg are displayed with the same information
7843 that would be reported by jobs. When the option is set, only
7844 the text is printed. The output from jobs itself is not af‐
7845 fected by the option.
7846
7847 When the option is not set, job information from the parent
7848 shell is saved for output within a subshell (for example, within
7849 a pipeline). When the option is set, the output of jobs is
7850 empty until a job is started within the subshell.
7851
7852 In previous versions of the shell, it was necessary to enable
7853 POSIX_JOBS in order for the builtin command wait to return the
7854 status of background jobs that had already exited. This is no
7855 longer the case.
7856
7857 Prompting
7858 PROMPT_BANG <K>
7859 If set, `!' is treated specially in prompt expansion. See EX‐
7860 PANSION OF PROMPT SEQUENCES in zshmisc(1).
7861
7862 PROMPT_CR (+V) <D>
7863 Print a carriage return just before printing a prompt in the
7864 line editor. This is on by default as multi-line editing is
7865 only possible if the editor knows where the start of the line
7866 appears.
7867
7868 PROMPT_SP <D>
7869 Attempt to preserve a partial line (i.e. a line that did not end
7870 with a newline) that would otherwise be covered up by the com‐
7871 mand prompt due to the PROMPT_CR option. This works by out‐
7872 putting some cursor-control characters, including a series of
7873 spaces, that should make the terminal wrap to the next line when
7874 a partial line is present (note that this is only successful if
7875 your terminal has automatic margins, which is typical).
7876
7877 When a partial line is preserved, by default you will see an in‐
7878 verse+bold character at the end of the partial line: a `%' for
7879 a normal user or a `#' for root. If set, the shell parameter
7880 PROMPT_EOL_MARK can be used to customize how the end of partial
7881 lines are shown.
7882
7883 NOTE: if the PROMPT_CR option is not set, enabling this option
7884 will have no effect. This option is on by default.
7885
7886 PROMPT_PERCENT <C> <Z>
7887 If set, `%' is treated specially in prompt expansion. See EX‐
7888 PANSION OF PROMPT SEQUENCES in zshmisc(1).
7889
7890 PROMPT_SUBST <K> <S>
7891 If set, parameter expansion, command substitution and arithmetic
7892 expansion are performed in prompts. Substitutions within
7893 prompts do not affect the command status.
7894
7895 TRANSIENT_RPROMPT
7896 Remove any right prompt from display when accepting a command
7897 line. This may be useful with terminals with other cut/paste
7898 methods.
7899
7900 Scripts and Functions
7901 ALIAS_FUNC_DEF <S>
7902 By default, zsh does not allow the definition of functions using
7903 the `name ()' syntax if name was expanded as an alias: this
7904 causes an error. This is usually the desired behaviour, as oth‐
7905 erwise the combination of an alias and a function based on the
7906 same definition can easily cause problems.
7907
7908 When this option is set, aliases can be used for defining func‐
7909 tions.
7910
7911 For example, consider the following definitions as they might
7912 occur in a startup file.
7913
7914 alias foo=bar
7915 foo() {
7916 print This probably does not do what you expect.
7917 }
7918
7919 Here, foo is expanded as an alias to bar before the () is en‐
7920 countered, so the function defined would be named bar. By de‐
7921 fault this is instead an error in native mode. Note that quot‐
7922 ing any part of the function name, or using the keyword func‐
7923 tion, avoids the problem, so is recommended when the function
7924 name can also be an alias.
7925
7926 C_BASES
7927 Output hexadecimal numbers in the standard C format, for example
7928 `0xFF' instead of the usual `16#FF'. If the option OCTAL_ZEROES
7929 is also set (it is not by default), octal numbers will be
7930 treated similarly and hence appear as `077' instead of `8#77'.
7931 This option has no effect on the choice of the output base, nor
7932 on the output of bases other than hexadecimal and octal. Note
7933 that these formats will be understood on input irrespective of
7934 the setting of C_BASES.
7935
7936 C_PRECEDENCES
7937 This alters the precedence of arithmetic operators to be more
7938 like C and other programming languages; the section ARITHMETIC
7939 EVALUATION in zshmisc(1) has an explicit list.
7940
7941 DEBUG_BEFORE_CMD <D>
7942 Run the DEBUG trap before each command; otherwise it is run af‐
7943 ter each command. Setting this option mimics the behaviour of
7944 ksh 93; with the option unset the behaviour is that of ksh 88.
7945
7946 ERR_EXIT (-e, ksh: -e)
7947 If a command has a non-zero exit status, execute the ZERR trap,
7948 if set, and exit. This is disabled while running initialization
7949 scripts.
7950
7951 The behaviour is also disabled inside DEBUG traps. In this case
7952 the option is handled specially: it is unset on entry to the
7953 trap. If the option DEBUG_BEFORE_CMD is set, as it is by de‐
7954 fault, and the option ERR_EXIT is found to have been set on
7955 exit, then the command for which the DEBUG trap is being exe‐
7956 cuted is skipped. The option is restored after the trap exits.
7957
7958 Non-zero status in a command list containing && or || is ignored
7959 for commands not at the end of the list. Hence
7960
7961 false && true
7962
7963 does not trigger exit.
7964
7965 Exiting due to ERR_EXIT has certain interactions with asynchro‐
7966 nous jobs noted in the section JOBS in zshmisc(1).
7967
7968 ERR_RETURN
7969 If a command has a non-zero exit status, return immediately from
7970 the enclosing function. The logic is similar to that for
7971 ERR_EXIT, except that an implicit return statement is executed
7972 instead of an exit. This will trigger an exit at the outermost
7973 level of a non-interactive script.
7974
7975 Normally this option inherits the behaviour of ERR_EXIT that
7976 code followed by `&&' `||' does not trigger a return. Hence in
7977 the following:
7978
7979 summit || true
7980
7981 no return is forced as the combined effect always has a zero re‐
7982 turn status.
7983
7984 Note. however, that if summit in the above example is itself a
7985 function, code inside it is considered separately: it may force
7986 a return from summit (assuming the option remains set within
7987 summit), but not from the enclosing context. This behaviour is
7988 different from ERR_EXIT which is unaffected by function scope.
7989
7990 EVAL_LINENO <Z>
7991 If set, line numbers of expressions evaluated using the builtin
7992 eval are tracked separately of the enclosing environment. This
7993 applies both to the parameter LINENO and the line number output
7994 by the prompt escape %i. If the option is set, the prompt es‐
7995 cape %N will output the string `(eval)' instead of the script or
7996 function name as an indication. (The two prompt escapes are
7997 typically used in the parameter PS4 to be output when the option
7998 XTRACE is set.) If EVAL_LINENO is unset, the line number of the
7999 surrounding script or function is retained during the evalua‐
8000 tion.
8001
8002 EXEC (+n, ksh: +n) <D>
8003 Do execute commands. Without this option, commands are read and
8004 checked for syntax errors, but not executed. This option cannot
8005 be turned off in an interactive shell, except when `-n' is sup‐
8006 plied to the shell at startup.
8007
8008 FUNCTION_ARGZERO <C> <Z>
8009 When executing a shell function or sourcing a script, set $0
8010 temporarily to the name of the function/script. Note that tog‐
8011 gling FUNCTION_ARGZERO from on to off (or off to on) does not
8012 change the current value of $0. Only the state upon entry to
8013 the function or script has an effect. Compare POSIX_ARGZERO.
8014
8015 LOCAL_LOOPS
8016 When this option is not set, the effect of break and continue
8017 commands may propagate outside function scope, affecting loops
8018 in calling functions. When the option is set in a calling func‐
8019 tion, a break or a continue that is not caught within a called
8020 function (regardless of the setting of the option within that
8021 function) produces a warning and the effect is cancelled.
8022
8023 LOCAL_OPTIONS <K>
8024 If this option is set at the point of return from a shell func‐
8025 tion, most options (including this one) which were in force upon
8026 entry to the function are restored; options that are not re‐
8027 stored are PRIVILEGED and RESTRICTED. Otherwise, only this op‐
8028 tion, and the LOCAL_LOOPS, XTRACE and PRINT_EXIT_VALUE options
8029 are restored. Hence if this is explicitly unset by a shell
8030 function the other options in force at the point of return will
8031 remain so. A shell function can also guarantee itself a known
8032 shell configuration with a formulation like `emulate -L zsh';
8033 the -L activates LOCAL_OPTIONS.
8034
8035 LOCAL_PATTERNS
8036 If this option is set at the point of return from a shell func‐
8037 tion, the state of pattern disables, as set with the builtin
8038 command `disable -p', is restored to what it was when the func‐
8039 tion was entered. The behaviour of this option is similar to
8040 the effect of LOCAL_OPTIONS on options; hence `emulate -L sh'
8041 (or indeed any other emulation with the -L option) activates LO‐
8042 CAL_PATTERNS.
8043
8044 LOCAL_TRAPS <K>
8045 If this option is set when a signal trap is set inside a func‐
8046 tion, then the previous status of the trap for that signal will
8047 be restored when the function exits. Note that this option must
8048 be set prior to altering the trap behaviour in a function; un‐
8049 like LOCAL_OPTIONS, the value on exit from the function is ir‐
8050 relevant. However, it does not need to be set before any global
8051 trap for that to be correctly restored by a function. For exam‐
8052 ple,
8053
8054 unsetopt localtraps
8055 trap - INT
8056 fn() { setopt localtraps; trap '' INT; sleep 3; }
8057
8058 will restore normal handling of SIGINT after the function exits.
8059
8060 MULTI_FUNC_DEF <Z>
8061 Allow definitions of multiple functions at once in the form `fn1
8062 fn2...()'; if the option is not set, this causes a parse error.
8063 Definition of multiple functions with the function keyword is
8064 always allowed. Multiple function definitions are not often
8065 used and can cause obscure errors.
8066
8067 MULTIOS <Z>
8068 Perform implicit tees or cats when multiple redirections are at‐
8069 tempted (see the section `Redirection').
8070
8071 OCTAL_ZEROES <S>
8072 Interpret any integer constant beginning with a 0 as octal, per
8073 IEEE Std 1003.2-1992 (ISO 9945-2:1993). This is not enabled by
8074 default as it causes problems with parsing of, for example, date
8075 and time strings with leading zeroes.
8076
8077 Sequences of digits indicating a numeric base such as the `08'
8078 component in `08#77' are always interpreted as decimal, regard‐
8079 less of leading zeroes.
8080
8081 PIPE_FAIL
8082 By default, when a pipeline exits the exit status recorded by
8083 the shell and returned by the shell variable $? reflects that of
8084 the rightmost element of a pipeline. If this option is set, the
8085 exit status instead reflects the status of the rightmost element
8086 of the pipeline that was non-zero, or zero if all elements ex‐
8087 ited with zero status.
8088
8089 SOURCE_TRACE
8090 If set, zsh will print an informational message announcing the
8091 name of each file it loads. The format of the output is similar
8092 to that for the XTRACE option, with the message <sourcetrace>.
8093 A file may be loaded by the shell itself when it starts up and
8094 shuts down (Startup/Shutdown Files) or by the use of the
8095 `source' and `dot' builtin commands.
8096
8097 TYPESET_SILENT
8098 If this is unset, executing any of the `typeset' family of com‐
8099 mands with no options and a list of parameters that have no val‐
8100 ues to be assigned but already exist will display the value of
8101 the parameter. If the option is set, they will only be shown
8102 when parameters are selected with the `-m' option. The option
8103 `-p' is available whether or not the option is set.
8104
8105 TYPESET_TO_UNSET <K> <S>
8106 When declaring a new parameter with any of the `typeset' family
8107 of related commands, the parameter remains unset unless and un‐
8108 til a value is explicity assigned to it, either in the `typeset'
8109 command itself or as a later assignment statement.
8110
8111 VERBOSE (-v, ksh: -v)
8112 Print shell input lines as they are read.
8113
8114 XTRACE (-x, ksh: -x)
8115 Print commands and their arguments as they are executed. The
8116 output is preceded by the value of $PS4, formatted as described
8117 in the section EXPANSION OF PROMPT SEQUENCES in zshmisc(1).
8118
8119 Shell Emulation
8120 APPEND_CREATE <K> <S>
8121 This option only applies when NO_CLOBBER (-C) is in effect.
8122
8123 If this option is not set, the shell will report an error when a
8124 append redirection (>>) is used on a file that does not already
8125 exists (the traditional zsh behaviour of NO_CLOBBER). If the
8126 option is set, no error is reported (POSIX behaviour).
8127
8128 BASH_REMATCH
8129 When set, matches performed with the =~ operator will set the
8130 BASH_REMATCH array variable, instead of the default MATCH and
8131 match variables. The first element of the BASH_REMATCH array
8132 will contain the entire matched text and subsequent elements
8133 will contain extracted substrings. This option makes more sense
8134 when KSH_ARRAYS is also set, so that the entire matched portion
8135 is stored at index 0 and the first substring is at index 1.
8136 Without this option, the MATCH variable contains the entire
8137 matched text and the match array variable contains substrings.
8138
8139 BSD_ECHO <S>
8140 Make the echo builtin compatible with the BSD echo(1) command.
8141 This disables backslashed escape sequences in echo strings un‐
8142 less the -e option is specified.
8143
8144 CONTINUE_ON_ERROR
8145 If a fatal error is encountered (see the section ERRORS in zsh‐
8146 misc(1)), and the code is running in a script, the shell will
8147 resume execution at the next statement in the script at the top
8148 level, in other words outside all functions or shell constructs
8149 such as loops and conditions. This mimics the behaviour of in‐
8150 teractive shells, where the shell returns to the line editor to
8151 read a new command; it was the normal behaviour in versions of
8152 zsh before 5.0.1.
8153
8154 CSH_JUNKIE_HISTORY <C>
8155 A history reference without an event specifier will always refer
8156 to the previous command. Without this option, such a history
8157 reference refers to the same event as the previous history ref‐
8158 erence on the current command line, defaulting to the previous
8159 command.
8160
8161 CSH_JUNKIE_LOOPS <C>
8162 Allow loop bodies to take the form `list; end' instead of `do
8163 list; done'.
8164
8165 CSH_JUNKIE_QUOTES <C>
8166 Changes the rules for single- and double-quoted text to match
8167 that of csh. These require that embedded newlines be preceded
8168 by a backslash; unescaped newlines will cause an error message.
8169 In double-quoted strings, it is made impossible to escape `$',
8170 ``' or `"' (and `\' itself no longer needs escaping). Command
8171 substitutions are only expanded once, and cannot be nested.
8172
8173 CSH_NULLCMD <C>
8174 Do not use the values of NULLCMD and READNULLCMD when running
8175 redirections with no command. This make such redirections fail
8176 (see the section `Redirection').
8177
8178 KSH_ARRAYS <K> <S>
8179 Emulate ksh array handling as closely as possible. If this op‐
8180 tion is set, array elements are numbered from zero, an array pa‐
8181 rameter without subscript refers to the first element instead of
8182 the whole array, and braces are required to delimit a subscript
8183 (`${path[2]}' rather than just `$path[2]') or to apply modifiers
8184 to any parameter (`${PWD:h}' rather than `$PWD:h').
8185
8186 KSH_AUTOLOAD <K> <S>
8187 Emulate ksh function autoloading. This means that when a func‐
8188 tion is autoloaded, the corresponding file is merely executed,
8189 and must define the function itself. (By default, the function
8190 is defined to the contents of the file. However, the most com‐
8191 mon ksh-style case - of the file containing only a simple defi‐
8192 nition of the function - is always handled in the ksh-compatible
8193 manner.)
8194
8195 KSH_OPTION_PRINT <K>
8196 Alters the way options settings are printed: instead of separate
8197 lists of set and unset options, all options are shown, marked
8198 `on' if they are in the non-default state, `off' otherwise.
8199
8200 KSH_TYPESET
8201 This option is now obsolete: a better appropximation to the be‐
8202 haviour of other shells is obtained with the reserved word in‐
8203 terface to declare, export, float, integer, local, readonly and
8204 typeset. Note that the option is only applied when the reserved
8205 word interface is not in use.
8206
8207 Alters the way arguments to the typeset family of commands, in‐
8208 cluding declare, export, float, integer, local and readonly, are
8209 processed. Without this option, zsh will perform normal word
8210 splitting after command and parameter expansion in arguments of
8211 an assignment; with it, word splitting does not take place in
8212 those cases.
8213
8214 KSH_ZERO_SUBSCRIPT
8215 Treat use of a subscript of value zero in array or string ex‐
8216 pressions as a reference to the first element, i.e. the element
8217 that usually has the subscript 1. Ignored if KSH_ARRAYS is also
8218 set.
8219
8220 If neither this option nor KSH_ARRAYS is set, accesses to an el‐
8221 ement of an array or string with subscript zero return an empty
8222 element or string, while attempts to set element zero of an ar‐
8223 ray or string are treated as an error. However, attempts to set
8224 an otherwise valid subscript range that includes zero will suc‐
8225 ceed. For example, if KSH_ZERO_SUBSCRIPT is not set,
8226
8227 array[0]=(element)
8228
8229 is an error, while
8230
8231 array[0,1]=(element)
8232
8233 is not and will replace the first element of the array.
8234
8235 This option is for compatibility with older versions of the
8236 shell and is not recommended in new code.
8237
8238 POSIX_ALIASES <K> <S>
8239 When this option is set, reserved words are not candidates for
8240 alias expansion: it is still possible to declare any of them as
8241 an alias, but the alias will never be expanded. Reserved words
8242 are described in the section RESERVED WORDS in zshmisc(1).
8243
8244 Alias expansion takes place while text is being read; hence when
8245 this option is set it does not take effect until the end of any
8246 function or other piece of shell code parsed as one unit. Note
8247 this may cause differences from other shells even when the op‐
8248 tion is in effect. For example, when running a command with
8249 `zsh -c', or even `zsh -o posixaliases -c', the entire command
8250 argument is parsed as one unit, so aliases defined within the
8251 argument are not available even in later lines. If in doubt,
8252 avoid use of aliases in non-interactive code.
8253
8254 POSIX_ARGZERO
8255 This option may be used to temporarily disable FUNCTION_ARGZERO
8256 and thereby restore the value of $0 to the name used to invoke
8257 the shell (or as set by the -c command line option). For com‐
8258 patibility with previous versions of the shell, emulations use
8259 NO_FUNCTION_ARGZERO instead of POSIX_ARGZERO, which may result
8260 in unexpected scoping of $0 if the emulation mode is changed in‐
8261 side a function or script. To avoid this, explicitly enable
8262 POSIX_ARGZERO in the emulate command:
8263
8264 emulate sh -o POSIX_ARGZERO
8265
8266 Note that NO_POSIX_ARGZERO has no effect unless FUNCTION_ARGZERO
8267 was already enabled upon entry to the function or script.
8268
8269 POSIX_BUILTINS <K> <S>
8270 When this option is set the command builtin can be used to exe‐
8271 cute shell builtin commands. Parameter assignments specified
8272 before shell functions and special builtins are kept after the
8273 command completes unless the special builtin is prefixed with
8274 the command builtin. Special builtins are ., :, break, con‐
8275 tinue, declare, eval, exit, export, integer, local, readonly,
8276 return, set, shift, source, times, trap and unset.
8277
8278 In addition, various error conditions associated with the above
8279 builtins or exec cause a non-interactive shell to exit and an
8280 interactive shell to return to its top-level processing.
8281
8282 Furthermore, functions and shell builtins are not executed after
8283 an exec prefix; the command to be executed must be an external
8284 command found in the path.
8285
8286 Furthermore, the getopts builtin behaves in a POSIX-compatible
8287 fashion in that the associated variable OPTIND is not made local
8288 to functions, and its value is calculated differently to match
8289 other shells.
8290
8291 Moreover, the warning and special exit code from [[ -o non_exis‐
8292 tent_option ]] are suppressed.
8293
8294 POSIX_IDENTIFIERS <K> <S>
8295 When this option is set, only the ASCII characters a to z, A to
8296 Z, 0 to 9 and _ may be used in identifiers (names of shell pa‐
8297 rameters and modules).
8298
8299 In addition, setting this option limits the effect of parameter
8300 substitution with no braces, so that the expression $# is
8301 treated as the parameter $# even if followed by a valid parame‐
8302 ter name. When it is unset, zsh allows expressions of the form
8303 $#name to refer to the length of $name, even for special vari‐
8304 ables, for example in expressions such as $#- and $#*.
8305
8306 Another difference is that with the option set assignment to an
8307 unset variable in arithmetic context causes the variable to be
8308 created as a scalar rather than a numeric type. So after `unset
8309 t; (( t = 3 ))'. without POSIX_IDENTIFIERS set t has integer
8310 type, while with it set it has scalar type.
8311
8312 When the option is unset and multibyte character support is en‐
8313 abled (i.e. it is compiled in and the option MULTIBYTE is set),
8314 then additionally any alphanumeric characters in the local char‐
8315 acter set may be used in identifiers. Note that scripts and
8316 functions written with this feature are not portable, and also
8317 that both options must be set before the script or function is
8318 parsed; setting them during execution is not sufficient as the
8319 syntax variable=value has already been parsed as a command
8320 rather than an assignment.
8321
8322 If multibyte character support is not compiled into the shell
8323 this option is ignored; all octets with the top bit set may be
8324 used in identifiers. This is non-standard but is the tradi‐
8325 tional zsh behaviour.
8326
8327 POSIX_STRINGS <K> <S>
8328 This option affects processing of quoted strings. Currently it
8329 only affects the behaviour of null characters, i.e. character 0
8330 in the portable character set corresponding to US ASCII.
8331
8332 When this option is not set, null characters embedded within
8333 strings of the form $'...' are treated as ordinary characters.
8334 The entire string is maintained within the shell and output to
8335 files where necessary, although owing to restrictions of the li‐
8336 brary interface the string is truncated at the null character in
8337 file names, environment variables, or in arguments to external
8338 programs.
8339
8340 When this option is set, the $'...' expression is truncated at
8341 the null character. Note that remaining parts of the same
8342 string beyond the termination of the quotes are not truncated.
8343
8344 For example, the command line argument a$'b\0c'd is treated with
8345 the option off as the characters a, b, null, c, d, and with the
8346 option on as the characters a, b, d.
8347
8348 POSIX_TRAPS <K> <S>
8349 When this option is set, the usual zsh behaviour of executing
8350 traps for EXIT on exit from shell functions is suppressed. In
8351 that case, manipulating EXIT traps always alters the global trap
8352 for exiting the shell; the LOCAL_TRAPS option is ignored for the
8353 EXIT trap.
8354
8355 Also, a return statement executed in a trap with no argument
8356 passes back from the function the value from the surrounding
8357 context, not from code executed within the trap.
8358
8359 Furthermore, if a trap is set to be ignored, this state persists
8360 when a subshell is entered. Without the option, the trap would
8361 be reset to its default state at this point.
8362
8363 SH_FILE_EXPANSION <K> <S>
8364 Perform filename expansion (e.g., ~ expansion) before parameter
8365 expansion, command substitution, arithmetic expansion and brace
8366 expansion. If this option is unset, it is performed after brace
8367 expansion, so things like `~$USERNAME' and `~{pfalstad,rc}' will
8368 work.
8369
8370 SH_NULLCMD <K> <S>
8371 Do not use the values of NULLCMD and READNULLCMD when doing
8372 redirections, use `:' instead (see the section `Redirection').
8373
8374 SH_OPTION_LETTERS <K> <S>
8375 If this option is set the shell tries to interpret single letter
8376 options (which are used with set and setopt) like ksh does.
8377 This also affects the value of the - special parameter.
8378
8379 SH_WORD_SPLIT (-y) <K> <S>
8380 Causes field splitting to be performed on unquoted parameter ex‐
8381 pansions. Note that this option has nothing to do with word
8382 splitting. (See zshexpn(1).)
8383
8384 TRAPS_ASYNC
8385 While waiting for a program to exit, handle signals and run
8386 traps immediately. Otherwise the trap is run after a child
8387 process has exited. Note this does not affect the point at
8388 which traps are run for any case other than when the shell is
8389 waiting for a child process.
8390
8391 Shell State
8392 INTERACTIVE (-i, ksh: -i)
8393 This is an interactive shell. This option is set upon initiali‐
8394 sation if the standard input is a tty and commands are being
8395 read from standard input. (See the discussion of SHIN_STDIN.)
8396 This heuristic may be overridden by specifying a state for this
8397 option on the command line. The value of this option can only
8398 be changed via flags supplied at invocation of the shell. It
8399 cannot be changed once zsh is running.
8400
8401 LOGIN (-l, ksh: -l)
8402 This is a login shell. If this option is not explicitly set,
8403 the shell becomes a login shell if the first character of the
8404 argv[0] passed to the shell is a `-'.
8405
8406 PRIVILEGED (-p, ksh: -p)
8407 Turn on privileged mode. Typically this is used when script is
8408 to be run with elevated privileges. This should be done as fol‐
8409 lows directly with the -p option to zsh so that it takes effect
8410 during startup.
8411
8412 #!/bin/zsh -p
8413
8414 The option is enabled automatically on startup if the effective
8415 user (group) ID is not equal to the real user (group) ID. In
8416 this case, turning the option off causes the effective user and
8417 group IDs to be set to the real user and group IDs. Be aware
8418 that if that fails the shell may be running with different IDs
8419 than was intended so a script should check for failure and act
8420 accordingly, for example:
8421
8422 unsetopt privileged || exit
8423
8424 The PRIVILEGED option disables sourcing user startup files. If
8425 zsh is invoked as `sh' or `ksh' with this option set,
8426 /etc/suid_profile is sourced (after /etc/profile on interactive
8427 shells). Sourcing ~/.profile is disabled and the contents of the
8428 ENV variable is ignored. This option cannot be changed using the
8429 -m option of setopt and unsetopt, and changing it inside a func‐
8430 tion always changes it globally regardless of the LOCAL_OPTIONS
8431 option.
8432
8433 RESTRICTED (-r)
8434 Enables restricted mode. This option cannot be changed using
8435 unsetopt, and setting it inside a function always changes it
8436 globally regardless of the LOCAL_OPTIONS option. See the sec‐
8437 tion `Restricted Shell'.
8438
8439 SHIN_STDIN (-s, ksh: -s)
8440 Commands are being read from the standard input. Commands are
8441 read from standard input if no command is specified with -c and
8442 no file of commands is specified. If SHIN_STDIN is set explic‐
8443 itly on the command line, any argument that would otherwise have
8444 been taken as a file to run will instead be treated as a normal
8445 positional parameter. Note that setting or unsetting this op‐
8446 tion on the command line does not necessarily affect the state
8447 the option will have while the shell is running - that is purely
8448 an indicator of whether or not commands are actually being read
8449 from standard input. The value of this option can only be
8450 changed via flags supplied at invocation of the shell. It can‐
8451 not be changed once zsh is running.
8452
8453 SINGLE_COMMAND (-t, ksh: -t)
8454 If the shell is reading from standard input, it exits after a
8455 single command has been executed. This also makes the shell
8456 non-interactive, unless the INTERACTIVE option is explicitly set
8457 on the command line. The value of this option can only be
8458 changed via flags supplied at invocation of the shell. It can‐
8459 not be changed once zsh is running.
8460
8461 Zle
8462 BEEP (+B) <D>
8463 Beep on error in ZLE.
8464
8465 COMBINING_CHARS
8466 Assume that the terminal displays combining characters cor‐
8467 rectly. Specifically, if a base alphanumeric character is fol‐
8468 lowed by one or more zero-width punctuation characters, assume
8469 that the zero-width characters will be displayed as modifica‐
8470 tions to the base character within the same width. Not all ter‐
8471 minals handle this. If this option is not set, zero-width char‐
8472 acters are displayed separately with special mark-up.
8473
8474 If this option is set, the pattern test [[:WORD:]] matches a
8475 zero-width punctuation character on the assumption that it will
8476 be used as part of a word in combination with a word character.
8477 Otherwise the base shell does not handle combining characters
8478 specially.
8479
8480 EMACS If ZLE is loaded, turning on this option has the equivalent ef‐
8481 fect of `bindkey -e'. In addition, the VI option is unset.
8482 Turning it off has no effect. The option setting is not guaran‐
8483 teed to reflect the current keymap. This option is provided for
8484 compatibility; bindkey is the recommended interface.
8485
8486 OVERSTRIKE
8487 Start up the line editor in overstrike mode.
8488
8489 SINGLE_LINE_ZLE (-M) <K>
8490 Use single-line command line editing instead of multi-line.
8491
8492 Note that although this is on by default in ksh emulation it
8493 only provides superficial compatibility with the ksh line editor
8494 and reduces the effectiveness of the zsh line editor. As it has
8495 no effect on shell syntax, many users may wish to disable this
8496 option when using ksh emulation interactively.
8497
8498 VI If ZLE is loaded, turning on this option has the equivalent ef‐
8499 fect of `bindkey -v'. In addition, the EMACS option is unset.
8500 Turning it off has no effect. The option setting is not guaran‐
8501 teed to reflect the current keymap. This option is provided for
8502 compatibility; bindkey is the recommended interface.
8503
8504 ZLE (-Z)
8505 Use the zsh line editor. Set by default in interactive shells
8506 connected to a terminal.
8507
8509 Some options have alternative names. These aliases are never used for
8510 output, but can be used just like normal option names when specifying
8511 options to the shell.
8512
8513 BRACE_EXPAND
8514 NO_IGNORE_BRACES (ksh and bash compatibility)
8515
8516 DOT_GLOB
8517 GLOB_DOTS (bash compatibility)
8518
8519 HASH_ALL
8520 HASH_CMDS (bash compatibility)
8521
8522 HIST_APPEND
8523 APPEND_HISTORY (bash compatibility)
8524
8525 HIST_EXPAND
8526 BANG_HIST (bash compatibility)
8527
8528 LOG NO_HIST_NO_FUNCTIONS (ksh compatibility)
8529
8530 MAIL_WARN
8531 MAIL_WARNING (bash compatibility)
8532
8533 ONE_CMD
8534 SINGLE_COMMAND (bash compatibility)
8535
8536 PHYSICAL
8537 CHASE_LINKS (ksh and bash compatibility)
8538
8539 PROMPT_VARS
8540 PROMPT_SUBST (bash compatibility)
8541
8542 STDIN SHIN_STDIN (ksh compatibility)
8543
8544 TRACK_ALL
8545 HASH_CMDS (ksh compatibility)
8546
8548 Default set
8549 -0 CORRECT
8550 -1 PRINT_EXIT_VALUE
8551 -2 NO_BAD_PATTERN
8552 -3 NO_NOMATCH
8553 -4 GLOB_DOTS
8554 -5 NOTIFY
8555 -6 BG_NICE
8556 -7 IGNORE_EOF
8557 -8 MARK_DIRS
8558 -9 AUTO_LIST
8559 -B NO_BEEP
8560 -C NO_CLOBBER
8561 -D PUSHD_TO_HOME
8562 -E PUSHD_SILENT
8563 -F NO_GLOB
8564 -G NULL_GLOB
8565 -H RM_STAR_SILENT
8566 -I IGNORE_BRACES
8567 -J AUTO_CD
8568 -K NO_BANG_HIST
8569 -L SUN_KEYBOARD_HACK
8570 -M SINGLE_LINE_ZLE
8571 -N AUTO_PUSHD
8572 -O CORRECT_ALL
8573 -P RC_EXPAND_PARAM
8574 -Q PATH_DIRS
8575 -R LONG_LIST_JOBS
8576 -S REC_EXACT
8577 -T CDABLE_VARS
8578 -U MAIL_WARNING
8579 -V NO_PROMPT_CR
8580 -W AUTO_RESUME
8581 -X LIST_TYPES
8582 -Y MENU_COMPLETE
8583 -Z ZLE
8584 -a ALL_EXPORT
8585 -e ERR_EXIT
8586 -f NO_RCS
8587 -g HIST_IGNORE_SPACE
8588 -h HIST_IGNORE_DUPS
8589 -i INTERACTIVE
8590 -k INTERACTIVE_COMMENTS
8591 -l LOGIN
8592 -m MONITOR
8593 -n NO_EXEC
8594 -p PRIVILEGED
8595 -r RESTRICTED
8596 -s SHIN_STDIN
8597 -t SINGLE_COMMAND
8598 -u NO_UNSET
8599 -v VERBOSE
8600 -w CHASE_LINKS
8601 -x XTRACE
8602 -y SH_WORD_SPLIT
8603
8604 sh/ksh emulation set
8605 -C NO_CLOBBER
8606 -T TRAPS_ASYNC
8607 -X MARK_DIRS
8608 -a ALL_EXPORT
8609 -b NOTIFY
8610 -e ERR_EXIT
8611 -f NO_GLOB
8612 -i INTERACTIVE
8613 -l LOGIN
8614 -m MONITOR
8615 -n NO_EXEC
8616 -p PRIVILEGED
8617 -r RESTRICTED
8618 -s SHIN_STDIN
8619 -t SINGLE_COMMAND
8620 -u NO_UNSET
8621 -v VERBOSE
8622 -x XTRACE
8623
8624 Also note
8625 -A Used by set for setting arrays
8626 -b Used on the command line to specify end of option processing
8627 -c Used on the command line to specify a single command
8628 -m Used by setopt for pattern-matching option setting
8629 -o Used in all places to allow use of long option names
8630 -s Used by set to sort positional parameters
8631
8632ZSHBUILTINS(1) General Commands Manual ZSHBUILTINS(1)
8633
8634
8635
8637 zshbuiltins - zsh built-in commands
8638
8640 Some shell builtin commands take options as described in individual en‐
8641 tries; these are often referred to in the list below as `flags' to
8642 avoid confusion with shell options, which may also have an effect on
8643 the behaviour of builtin commands. In this introductory section, `op‐
8644 tion' always has the meaning of an option to a command that should be
8645 familiar to most command line users.
8646
8647 Typically, options are single letters preceded by a hyphen (-). Op‐
8648 tions that take an argument accept it either immediately following the
8649 option letter or after white space, for example `print -C3 {1..9}' or
8650 `print -C 3 {1..9}' are equivalent. Arguments to options are not the
8651 same as arguments to the command; the documentation indicates which is
8652 which. Options that do not take an argument may be combined in a sin‐
8653 gle word, for example `print -rca -- *' and `print -r -c -a -- *' are
8654 equivalent.
8655
8656 Some shell builtin commands also take options that begin with `+' in‐
8657 stead of `-'. The list below makes clear which commands these are.
8658
8659 Options (together with their individual arguments, if any) must appear
8660 in a group before any non-option arguments; once the first non-option
8661 argument has been found, option processing is terminated.
8662
8663 All builtin commands other than `echo' and precommand modifiers, even
8664 those that have no options, can be given the argument `--' to terminate
8665 option processing. This indicates that the following words are non-op‐
8666 tion arguments, but is otherwise ignored. This is useful in cases
8667 where arguments to the command may begin with `-'. For historical rea‐
8668 sons, most builtin commands (including `echo') also recognize a single
8669 `-' in a separate word for this purpose; note that this is less stan‐
8670 dard and use of `--' is recommended.
8671
8672 - simple command
8673 See the section `Precommand Modifiers' in zshmisc(1).
8674
8675 . file [ arg ... ]
8676 Read commands from file and execute them in the current shell
8677 environment.
8678
8679 If file does not contain a slash, or if PATH_DIRS is set, the
8680 shell looks in the components of $path to find the directory
8681 containing file. Files in the current directory are not read
8682 unless `.' appears somewhere in $path. If a file named
8683 `file.zwc' is found, is newer than file, and is the compiled
8684 form (created with the zcompile builtin) of file, then commands
8685 are read from that file instead of file.
8686
8687 If any arguments arg are given, they become the positional pa‐
8688 rameters; the old positional parameters are restored when the
8689 file is done executing. However, if no arguments are given, the
8690 positional parameters remain those of the calling context, and
8691 no restoring is done.
8692
8693 If file was not found the return status is 127; if file was
8694 found but contained a syntax error the return status is 126;
8695 else the return status is the exit status of the last command
8696 executed.
8697
8698 : [ arg ... ]
8699 This command does nothing, although normal argument expansions
8700 is performed which may have effects on shell parameters. A zero
8701 exit status is returned.
8702
8703 alias [ {+|-}gmrsL ] [ name[=value] ... ]
8704 For each name with a corresponding value, define an alias with
8705 that value. A trailing space in value causes the next word to
8706 be checked for alias expansion. If the -g flag is present, de‐
8707 fine a global alias; global aliases are expanded even if they do
8708 not occur in command position:
8709
8710 % perldoc --help 2>&1 | grep 'built-in functions'
8711 -f Search Perl built-in functions
8712 % alias -g HG='--help 2>&1 | grep'
8713 % perldoc HG 'built-in functions'
8714 -f Search Perl built-in functions
8715
8716 If the -s flag is present, define a suffix alias: if the command
8717 word on a command line is in the form `text.name', where text is
8718 any non-empty string, it is replaced by the text `value
8719 text.name'. Note that name is treated as a literal string, not
8720 a pattern. A trailing space in value is not special in this
8721 case. For example,
8722
8723 alias -s ps='gv --'
8724
8725 will cause the command `*.ps' to be expanded to `gv -- *.ps'.
8726 As alias expansion is carried out earlier than globbing, the
8727 `*.ps' will then be expanded. Suffix aliases constitute a dif‐
8728 ferent name space from other aliases (so in the above example it
8729 is still possible to create an alias for the command ps) and the
8730 two sets are never listed together.
8731
8732 For each name with no value, print the value of name, if any.
8733 With no arguments, print all currently defined aliases other
8734 than suffix aliases. If the -m flag is given the arguments are
8735 taken as patterns (they should be quoted to preserve them from
8736 being interpreted as glob patterns), and the aliases matching
8737 these patterns are printed. When printing aliases and one of
8738 the -g, -r or -s flags is present, restrict the printing to
8739 global, regular or suffix aliases, respectively; a regular alias
8740 is one which is neither a global nor a suffix alias. Using `+'
8741 instead of `-', or ending the option list with a single `+',
8742 prevents the values of the aliases from being printed.
8743
8744 If the -L flag is present, then print each alias in a manner
8745 suitable for putting in a startup script. The exit status is
8746 nonzero if a name (with no value) is given for which no alias
8747 has been defined.
8748
8749 For more on aliases, include common problems, see the section
8750 ALIASING in zshmisc(1).
8751
8752 autoload [ {+|-}RTUXdkmrtWz ] [ -w ] [ name ... ]
8753 See the section `Autoloading Functions' in zshmisc(1) for full
8754 details. The fpath parameter will be searched to find the func‐
8755 tion definition when the function is first referenced.
8756
8757 If name consists of an absolute path, the function is defined to
8758 load from the file given (searching as usual for dump files in
8759 the given location). The name of the function is the basename
8760 (non-directory part) of the file. It is normally an error if
8761 the function is not found in the given location; however, if the
8762 option -d is given, searching for the function defaults to
8763 $fpath. If a function is loaded by absolute path, any functions
8764 loaded from it that are marked for autoload without an absolute
8765 path have the load path of the parent function temporarily
8766 prepended to $fpath.
8767
8768 If the option -r or -R is given, the function is searched for
8769 immediately and the location is recorded internally for use when
8770 the function is executed; a relative path is expanded using the
8771 value of $PWD. This protects against a change to $fpath after
8772 the call to autoload. With -r, if the function is not found, it
8773 is silently left unresolved until execution; with -R, an error
8774 message is printed and command processing aborted immediately
8775 the search fails, i.e. at the autoload command rather than at
8776 function execution..
8777
8778 The flag -X may be used only inside a shell function. It causes
8779 the calling function to be marked for autoloading and then imme‐
8780 diately loaded and executed, with the current array of posi‐
8781 tional parameters as arguments. This replaces the previous def‐
8782 inition of the function. If no function definition is found, an
8783 error is printed and the function remains undefined and marked
8784 for autoloading. If an argument is given, it is used as a di‐
8785 rectory (i.e. it does not include the name of the function) in
8786 which the function is to be found; this may be combined with the
8787 -d option to allow the function search to default to $fpath if
8788 it is not in the given location.
8789
8790 The flag +X attempts to load each name as an autoloaded func‐
8791 tion, but does not execute it. The exit status is zero (suc‐
8792 cess) if the function was not previously defined and a defini‐
8793 tion for it was found. This does not replace any existing defi‐
8794 nition of the function. The exit status is nonzero (failure) if
8795 the function was already defined or when no definition was
8796 found. In the latter case the function remains undefined and
8797 marked for autoloading. If ksh-style autoloading is enabled,
8798 the function created will contain the contents of the file plus
8799 a call to the function itself appended to it, thus giving normal
8800 ksh autoloading behaviour on the first call to the function. If
8801 the -m flag is also given each name is treated as a pattern and
8802 all functions already marked for autoload that match the pattern
8803 are loaded.
8804
8805 With the -t flag, turn on execution tracing; with -T, turn on
8806 execution tracing only for the current function, turning it off
8807 on entry to any called functions that do not also have tracing
8808 enabled.
8809
8810 With the -U flag, alias expansion is suppressed when the func‐
8811 tion is loaded.
8812
8813 With the -w flag, the names are taken as names of files compiled
8814 with the zcompile builtin, and all functions defined in them are
8815 marked for autoloading.
8816
8817 The flags -z and -k mark the function to be autoloaded using the
8818 zsh or ksh style, as if the option KSH_AUTOLOAD were unset or
8819 were set, respectively. The flags override the setting of the
8820 option at the time the function is loaded.
8821
8822 Note that the autoload command makes no attempt to ensure the
8823 shell options set during the loading or execution of the file
8824 have any particular value. For this, the emulate command can be
8825 used:
8826
8827 emulate zsh -c 'autoload -Uz func'
8828
8829 arranges that when func is loaded the shell is in native zsh em‐
8830 ulation, and this emulation is also applied when func is run.
8831
8832 Some of the functions of autoload are also provided by functions
8833 -u or functions -U, but autoload is a more comprehensive inter‐
8834 face.
8835
8836 bg [ job ... ]
8837 job ... &
8838 Put each specified job in the background, or the current job if
8839 none is specified.
8840
8841 bindkey
8842 See the section `Zle Builtins' in zshzle(1).
8843
8844 break [ n ]
8845 Exit from an enclosing for, while, until, select or repeat loop.
8846 If an arithmetic expression n is specified, then break n levels
8847 instead of just one.
8848
8849 builtin name [ args ... ]
8850 Executes the builtin name, with the given args.
8851
8852 bye Same as exit.
8853
8854 cap See the section `The zsh/cap Module' in zshmodules(1).
8855
8856 cd [ -qsLP ] [ arg ]
8857 cd [ -qsLP ] old new
8858 cd [ -qsLP ] {+|-}n
8859 Change the current directory. In the first form, change the
8860 current directory to arg, or to the value of $HOME if arg is not
8861 specified. If arg is `-', change to the previous directory.
8862
8863 Otherwise, if arg begins with a slash, attempt to change to the
8864 directory given by arg.
8865
8866 If arg does not begin with a slash, the behaviour depends on
8867 whether the current directory `.' occurs in the list of directo‐
8868 ries contained in the shell parameter cdpath. If it does not,
8869 first attempt to change to the directory arg under the current
8870 directory, and if that fails but cdpath is set and contains at
8871 least one element attempt to change to the directory arg under
8872 each component of cdpath in turn until successful. If `.' oc‐
8873 curs in cdpath, then cdpath is searched strictly in order so
8874 that `.' is only tried at the appropriate point.
8875
8876 The order of testing cdpath is modified if the option POSIX_CD
8877 is set, as described in the documentation for the option.
8878
8879 If no directory is found, the option CDABLE_VARS is set, and a
8880 parameter named arg exists whose value begins with a slash,
8881 treat its value as the directory. In that case, the parameter
8882 is added to the named directory hash table.
8883
8884 The second form of cd substitutes the string new for the string
8885 old in the name of the current directory, and tries to change to
8886 this new directory.
8887
8888 The third form of cd extracts an entry from the directory stack,
8889 and changes to that directory. An argument of the form `+n'
8890 identifies a stack entry by counting from the left of the list
8891 shown by the dirs command, starting with zero. An argument of
8892 the form `-n' counts from the right. If the PUSHD_MINUS option
8893 is set, the meanings of `+' and `-' in this context are swapped.
8894 If the POSIX_CD option is set, this form of cd is not recognised
8895 and will be interpreted as the first form.
8896
8897 If the -q (quiet) option is specified, the hook function chpwd
8898 and the functions in the array chpwd_functions are not called.
8899 This is useful for calls to cd that do not change the environ‐
8900 ment seen by an interactive user.
8901
8902 If the -s option is specified, cd refuses to change the current
8903 directory if the given pathname contains symlinks. If the -P
8904 option is given or the CHASE_LINKS option is set, symbolic links
8905 are resolved to their true values. If the -L option is given
8906 symbolic links are retained in the directory (and not resolved)
8907 regardless of the state of the CHASE_LINKS option.
8908
8909 chdir Same as cd.
8910
8911 clone See the section `The zsh/clone Module' in zshmodules(1).
8912
8913 command [ -pvV ] simple command
8914 The simple command argument is taken as an external command in‐
8915 stead of a function or builtin and is executed. If the
8916 POSIX_BUILTINS option is set, builtins will also be executed but
8917 certain special properties of them are suppressed. The -p flag
8918 causes a default path to be searched instead of that in $path.
8919 With the -v flag, command is similar to whence and with -V, it
8920 is equivalent to whence -v.
8921
8922 See also the section `Precommand Modifiers' in zshmisc(1).
8923
8924 comparguments
8925 See the section `The zsh/computil Module' in zshmodules(1).
8926
8927 compcall
8928 See the section `The zsh/compctl Module' in zshmodules(1).
8929
8930 compctl
8931 See the section `The zsh/compctl Module' in zshmodules(1).
8932
8933 compdescribe
8934 See the section `The zsh/computil Module' in zshmodules(1).
8935
8936 compfiles
8937 See the section `The zsh/computil Module' in zshmodules(1).
8938
8939 compgroups
8940 See the section `The zsh/computil Module' in zshmodules(1).
8941
8942 compquote
8943 See the section `The zsh/computil Module' in zshmodules(1).
8944
8945 comptags
8946 See the section `The zsh/computil Module' in zshmodules(1).
8947
8948 comptry
8949 See the section `The zsh/computil Module' in zshmodules(1).
8950
8951 compvalues
8952 See the section `The zsh/computil Module' in zshmodules(1).
8953
8954 continue [ n ]
8955 Resume the next iteration of the enclosing for, while, until,
8956 select or repeat loop. If an arithmetic expression n is speci‐
8957 fied, break out of n-1 loops and resume at the nth enclosing
8958 loop.
8959
8960 declare
8961 Same as typeset.
8962
8963 dirs [ -c ] [ arg ... ]
8964 dirs [ -lpv ]
8965 With no arguments, print the contents of the directory stack.
8966 Directories are added to this stack with the pushd command, and
8967 removed with the cd or popd commands. If arguments are speci‐
8968 fied, load them onto the directory stack, replacing anything
8969 that was there, and push the current directory onto the stack.
8970
8971 -c clear the directory stack.
8972
8973 -l print directory names in full instead of using of using ~
8974 expressions (see Dynamic and Static named directories in
8975 zshexpn(1)).
8976
8977 -p print directory entries one per line.
8978
8979 -v number the directories in the stack when printing.
8980
8981 disable [ -afmprs ] name ...
8982 Temporarily disable the named hash table elements or patterns.
8983 The default is to disable builtin commands. This allows you to
8984 use an external command with the same name as a builtin command.
8985 The -a option causes disable to act on regular or global
8986 aliases. The -s option causes disable to act on suffix aliases.
8987 The -f option causes disable to act on shell functions. The -r
8988 options causes disable to act on reserved words. Without argu‐
8989 ments all disabled hash table elements from the corresponding
8990 hash table are printed. With the -m flag the arguments are
8991 taken as patterns (which should be quoted to prevent them from
8992 undergoing filename expansion), and all hash table elements from
8993 the corresponding hash table matching these patterns are dis‐
8994 abled. Disabled objects can be enabled with the enable command.
8995
8996 With the option -p, name ... refer to elements of the shell's
8997 pattern syntax as described in the section `Filename Genera‐
8998 tion'. Certain elements can be disabled separately, as given
8999 below.
9000
9001 Note that patterns not allowed by the current settings for the
9002 options EXTENDED_GLOB, KSH_GLOB and SH_GLOB are never enabled,
9003 regardless of the setting here. For example, if EXTENDED_GLOB
9004 is not active, the pattern ^ is ineffective even if `disable -p
9005 "^"' has not been issued. The list below indicates any option
9006 settings that restrict the use of the pattern. It should be
9007 noted that setting SH_GLOB has a wider effect than merely dis‐
9008 abling patterns as certain expressions, in particular those in‐
9009 volving parentheses, are parsed differently.
9010
9011 The following patterns may be disabled; all the strings need
9012 quoting on the command line to prevent them from being inter‐
9013 preted immediately as patterns and the patterns are shown below
9014 in single quotes as a reminder.
9015
9016 '?' The pattern character ? wherever it occurs, including
9017 when preceding a parenthesis with KSH_GLOB.
9018
9019 '*' The pattern character * wherever it occurs, including re‐
9020 cursive globbing and when preceding a parenthesis with
9021 KSH_GLOB.
9022
9023 '[' Character classes.
9024
9025 '<' (NO_SH_GLOB)
9026 Numeric ranges.
9027
9028 '|' (NO_SH_GLOB)
9029 Alternation in grouped patterns, case statements, or
9030 KSH_GLOB parenthesised expressions.
9031
9032 '(' (NO_SH_GLOB)
9033 Grouping using single parentheses. Disabling this does
9034 not disable the use of parentheses for KSH_GLOB where
9035 they are introduced by a special character, nor for glob
9036 qualifiers (use `setopt NO_BARE_GLOB_QUAL' to disable
9037 glob qualifiers that use parentheses only).
9038
9039 '~' (EXTENDED_GLOB)
9040 Exclusion in the form A~B.
9041
9042 '^' (EXTENDED_GLOB)
9043 Exclusion in the form A^B.
9044
9045 '#' (EXTENDED_GLOB)
9046 The pattern character # wherever it occurs, both for rep‐
9047 etition of a previous pattern and for indicating globbing
9048 flags.
9049
9050 '?(' (KSH_GLOB)
9051 The grouping form ?(...). Note this is also disabled if
9052 '?' is disabled.
9053
9054 '*(' (KSH_GLOB)
9055 The grouping form *(...). Note this is also disabled if
9056 '*' is disabled.
9057
9058 '+(' (KSH_GLOB)
9059 The grouping form +(...).
9060
9061 '!(' (KSH_GLOB)
9062 The grouping form !(...).
9063
9064 '@(' (KSH_GLOB)
9065 The grouping form @(...).
9066
9067 disown [ job ... ]
9068 job ... &|
9069 job ... &!
9070 Remove the specified jobs from the job table; the shell will no
9071 longer report their status, and will not complain if you try to
9072 exit an interactive shell with them running or stopped. If no
9073 job is specified, disown the current job.
9074
9075 If the jobs are currently stopped and the AUTO_CONTINUE option
9076 is not set, a warning is printed containing information about
9077 how to make them running after they have been disowned. If one
9078 of the latter two forms is used, the jobs will automatically be
9079 made running, independent of the setting of the AUTO_CONTINUE
9080 option.
9081
9082 echo [ -neE ] [ arg ... ]
9083 Write each arg on the standard output, with a space separating
9084 each one. If the -n flag is not present, print a newline at the
9085 end. echo recognizes the following escape sequences:
9086
9087 \a bell character
9088 \b backspace
9089 \c suppress subsequent characters and final newline
9090 \e escape
9091 \f form feed
9092 \n linefeed (newline)
9093 \r carriage return
9094 \t horizontal tab
9095 \v vertical tab
9096 \\ backslash
9097 \0NNN character code in octal
9098 \xNN character code in hexadecimal
9099 \uNNNN unicode character code in hexadecimal
9100 \UNNNNNNNN
9101 unicode character code in hexadecimal
9102
9103 The -E flag, or the BSD_ECHO option, can be used to disable
9104 these escape sequences. In the latter case, -e flag can be used
9105 to enable them.
9106
9107 Note that for standards compliance a double dash does not termi‐
9108 nate option processing; instead, it is printed directly. How‐
9109 ever, a single dash does terminate option processing, so the
9110 first dash, possibly following options, is not printed, but ev‐
9111 erything following it is printed as an argument. The single
9112 dash behaviour is different from other shells. For a more por‐
9113 table way of printing text, see printf, and for a more control‐
9114 lable way of printing text within zsh, see print.
9115
9116 echotc See the section `The zsh/termcap Module' in zshmodules(1).
9117
9118 echoti See the section `The zsh/terminfo Module' in zshmodules(1).
9119
9120 emulate [ -lLR ] [ {zsh|sh|ksh|csh} [ flags ... ] ]
9121 Without any argument print current emulation mode.
9122
9123 With single argument set up zsh options to emulate the specified
9124 shell as much as possible. csh will never be fully emulated.
9125 If the argument is not one of the shells listed above, zsh will
9126 be used as a default; more precisely, the tests performed on the
9127 argument are the same as those used to determine the emulation
9128 at startup based on the shell name, see the section COMPATIBIL‐
9129 ITY in zsh(1) . In addition to setting shell options, the com‐
9130 mand also restores the pristine state of pattern enables, as if
9131 all patterns had been enabled using enable -p.
9132
9133 If the emulate command occurs inside a function that has been
9134 marked for execution tracing with functions -t then the xtrace
9135 option will be turned on regardless of emulation mode or other
9136 options. Note that code executed inside the function by the .,
9137 source, or eval commands is not considered to be running di‐
9138 rectly from the function, hence does not provoke this behaviour.
9139
9140 If the -R switch is given, all settable options are reset to
9141 their default value corresponding to the specified emulation
9142 mode, except for certain options describing the interactive en‐
9143 vironment; otherwise, only those options likely to cause porta‐
9144 bility problems in scripts and functions are altered. If the -L
9145 switch is given, the options LOCAL_OPTIONS, LOCAL_PATTERNS and
9146 LOCAL_TRAPS will be set as well, causing the effects of the emu‐
9147 late command and any setopt, disable -p or enable -p, and trap
9148 commands to be local to the immediately surrounding shell func‐
9149 tion, if any; normally these options are turned off in all emu‐
9150 lation modes except ksh. The -L switch is mutually exclusive
9151 with the use of -c in flags.
9152
9153 If there is a single argument and the -l switch is given, the
9154 options that would be set or unset (the latter indicated with
9155 the prefix `no') are listed. -l can be combined with -L or -R
9156 and the list will be modified in the appropriate way. Note the
9157 list does not depend on the current setting of options, i.e. it
9158 includes all options that may in principle change, not just
9159 those that would actually change.
9160
9161 The flags may be any of the invocation-time flags described in
9162 the section INVOCATION in zsh(1), except that `-o EMACS' and `-o
9163 VI' may not be used. Flags such as `+r'/`+o RESTRICTED' may be
9164 prohibited in some circumstances.
9165
9166 If -c arg appears in flags, arg is evaluated while the requested
9167 emulation is temporarily in effect. In this case the emulation
9168 mode and all options are restored to their previous values be‐
9169 fore emulate returns. The -R switch may precede the name of the
9170 shell to emulate; note this has a meaning distinct from includ‐
9171 ing -R in flags.
9172
9173 Use of -c enables `sticky' emulation mode for functions defined
9174 within the evaluated expression: the emulation mode is associ‐
9175 ated thereafter with the function so that whenever the function
9176 is executed the emulation (respecting the -R switch, if present)
9177 and all options are set (and pattern disables cleared) before
9178 entry to the function, and the state is restored after exit. If
9179 the function is called when the sticky emulation is already in
9180 effect, either within an `emulate shell -c' expression or within
9181 another function with the same sticky emulation, entry and exit
9182 from the function do not cause options to be altered (except due
9183 to standard processing such as the LOCAL_OPTIONS option). This
9184 also applies to functions marked for autoload within the sticky
9185 emulation; the appropriate set of options will be applied at the
9186 point the function is loaded as well as when it is run.
9187
9188 For example:
9189
9190 emulate sh -c 'fni() { setopt cshnullglob; }
9191 fno() { fni; }'
9192 fno
9193
9194 The two functions fni and fno are defined with sticky sh emula‐
9195 tion. fno is then executed, causing options associated with em‐
9196 ulations to be set to their values in sh. fno then calls fni;
9197 because fni is also marked for sticky sh emulation, no option
9198 changes take place on entry to or exit from it. Hence the op‐
9199 tion cshnullglob, turned off by sh emulation, will be turned on
9200 within fni and remain on return to fno. On exit from fno, the
9201 emulation mode and all options will be restored to the state
9202 they were in before entry to the temporary emulation.
9203
9204 The documentation above is typically sufficient for the intended
9205 purpose of executing code designed for other shells in a suit‐
9206 able environment. More detailed rules follow.
9207 1. The sticky emulation environment provided by `emulate
9208 shell -c' is identical to that provided by entry to a
9209 function marked for sticky emulation as a consequence of
9210 being defined in such an environment. Hence, for exam‐
9211 ple, the sticky emulation is inherited by subfunctions
9212 defined within functions with sticky emulation.
9213 2. No change of options takes place on entry to or exit from
9214 functions that are not marked for sticky emulation, other
9215 than those that would normally take place, even if those
9216 functions are called within sticky emulation.
9217 3. No special handling is provided for functions marked for
9218 autoload nor for functions present in wordcode created by
9219 the zcompile command.
9220 4. The presence or absence of the -R switch to emulate cor‐
9221 responds to different sticky emulation modes, so for ex‐
9222 ample `emulate sh -c', `emulate -R sh -c' and `emulate
9223 csh -c' are treated as three distinct sticky emulations.
9224 5. Difference in shell options supplied in addition to the
9225 basic emulation also mean the sticky emulations are dif‐
9226 ferent, so for example `emulate zsh -c' and `emulate zsh
9227 -o cbases -c' are treated as distinct sticky emulations.
9228
9229 enable [ -afmprs ] name ...
9230 Enable the named hash table elements, presumably disabled ear‐
9231 lier with disable. The default is to enable builtin commands.
9232 The -a option causes enable to act on regular or global aliases.
9233 The -s option causes enable to act on suffix aliases. The -f
9234 option causes enable to act on shell functions. The -r option
9235 causes enable to act on reserved words. Without arguments all
9236 enabled hash table elements from the corresponding hash table
9237 are printed. With the -m flag the arguments are taken as pat‐
9238 terns (should be quoted) and all hash table elements from the
9239 corresponding hash table matching these patterns are enabled.
9240 Enabled objects can be disabled with the disable builtin com‐
9241 mand.
9242
9243 enable -p reenables patterns disabled with disable -p. Note
9244 that it does not override globbing options; for example, `enable
9245 -p "~"' does not cause the pattern character ~ to be active un‐
9246 less the EXTENDED_GLOB option is also set. To enable all possi‐
9247 ble patterns (so that they may be individually disabled with
9248 disable -p), use `setopt EXTENDED_GLOB KSH_GLOB NO_SH_GLOB'.
9249
9250 eval [ arg ... ]
9251 Read the arguments as input to the shell and execute the result‐
9252 ing command(s) in the current shell process. The return status
9253 is the same as if the commands had been executed directly by the
9254 shell; if there are no args or they contain no commands (i.e.
9255 are an empty string or whitespace) the return status is zero.
9256
9257 exec [ -cl ] [ -a argv0 ] [ command [ arg ... ] ]
9258 Replace the current shell with command rather than forking. If
9259 command is a shell builtin command or a shell function, the
9260 shell executes it, and exits when the command is complete.
9261
9262 With -c clear the environment; with -l prepend - to the argv[0]
9263 string of the command executed (to simulate a login shell); with
9264 -a argv0 set the argv[0] string of the command executed. See
9265 the section `Precommand Modifiers' in zshmisc(1).
9266
9267 If the option POSIX_BUILTINS is set, command is never inter‐
9268 preted as a shell builtin command or shell function. This means
9269 further precommand modifiers such as builtin and noglob are also
9270 not interpreted within the shell. Hence command is always found
9271 by searching the command path.
9272
9273 If command is omitted but any redirections are specified, then
9274 the redirections will take effect in the current shell.
9275
9276 exit [ n ]
9277 Exit the shell with the exit status specified by an arithmetic
9278 expression n; if none is specified, use the exit status from the
9279 last command executed. An EOF condition will also cause the
9280 shell to exit, unless the IGNORE_EOF option is set.
9281
9282 See notes at the end of the section JOBS in zshmisc(1) for some
9283 possibly unexpected interactions of the exit command with jobs.
9284
9285 export [ name[=value] ... ]
9286 The specified names are marked for automatic export to the envi‐
9287 ronment of subsequently executed commands. Equivalent to type‐
9288 set -gx. If a parameter specified does not already exist, it is
9289 created in the global scope.
9290
9291 false [ arg ... ]
9292 Do nothing and return an exit status of 1.
9293
9294
9295 fc [ -e ename ] [ -s ] [ -LI ] [ -m match ] [ old=new ... ] [ first [
9296 last ] ]
9297 fc -l [ -LI ] [ -nrdfEiD ] [ -t timefmt ] [ -m match ]
9298 [ old=new ... ] [ first [ last ] ]
9299 fc -p [ -a ] [ filename [ histsize [ savehistsize ] ] ]
9300 fc -P
9301 fc -ARWI [ filename ]
9302 The fc command controls the interactive history mechanism. Note
9303 that reading and writing of history options is only performed if
9304 the shell is interactive. Usually this is detected automati‐
9305 cally, but it can be forced by setting the interactive option
9306 when starting the shell.
9307
9308 The first two forms of this command select a range of events
9309 from first to last from the history list. The arguments first
9310 and last may be specified as a number or as a string. A nega‐
9311 tive number is used as an offset to the current history event
9312 number. A string specifies the most recent event beginning with
9313 the given string. All substitutions old=new, if any, are then
9314 performed on the text of the events.
9315
9316 The range of events selected by numbers can be narrowed further
9317 by the following flags.
9318 -I restricts to only internal events (not from $HISTFILE)
9319 -L restricts to only local events (not from other shells,
9320 see SHARE_HISTORY in zshoptions(1) -- note that $HISTFILE
9321 is considered local when read at startup)
9322 -m takes the first argument as a pattern (which should be
9323 quoted) and only the history events matching this pattern
9324 are considered
9325
9326 If first is not specified, it will be set to -1 (the most recent
9327 event), or to -16 if the -l flag is given. If last is not spec‐
9328 ified, it will be set to first, or to -1 if the -l flag is
9329 given. However, if the current event has added entries to the
9330 history with `print -s' or `fc -R', then the default last for -l
9331 includes all new history entries since the current event began.
9332
9333 When the -l flag is given, the resulting events are listed on
9334 standard output. Otherwise the editor program specified by -e
9335 ename is invoked on a file containing these history events. If
9336 -e is not given, the value of the parameter FCEDIT is used; if
9337 that is not set the value of the parameter EDITOR is used; if
9338 that is not set a builtin default, usually `vi' is used. If
9339 ename is `-', no editor is invoked. When editing is complete,
9340 the edited command is executed.
9341
9342 The flag `-s' is equivalent to `-e -'. The flag -r reverses the
9343 order of the events and the flag -n suppresses event numbers
9344 when listing.
9345
9346 Also when listing,
9347 -d prints timestamps for each event
9348 -f prints full time-date stamps in the US `MM/DD/YY hh:mm'
9349 format
9350 -E prints full time-date stamps in the European `dd.mm.yyyy
9351 hh:mm' format
9352 -i prints full time-date stamps in ISO8601 `yyyy-mm-dd
9353 hh:mm' format
9354 -t fmt prints time and date stamps in the given format; fmt is
9355 formatted with the strftime function with the zsh exten‐
9356 sions described for the %D{string} prompt format in the
9357 section EXPANSION OF PROMPT SEQUENCES in zshmisc(1). The
9358 resulting formatted string must be no more than 256 char‐
9359 acters or will not be printed
9360 -D prints elapsed times; may be combined with one of the op‐
9361 tions above
9362
9363 `fc -p' pushes the current history list onto a stack and
9364 switches to a new history list. If the -a option is also speci‐
9365 fied, this history list will be automatically popped when the
9366 current function scope is exited, which is a much better solu‐
9367 tion than creating a trap function to call `fc -P' manually. If
9368 no arguments are specified, the history list is left empty,
9369 $HISTFILE is unset, and $HISTSIZE & $SAVEHIST are set to their
9370 default values. If one argument is given, $HISTFILE is set to
9371 that filename, $HISTSIZE & $SAVEHIST are left unchanged, and the
9372 history file is read in (if it exists) to initialize the new
9373 list. If a second argument is specified, $HISTSIZE & $SAVEHIST
9374 are instead set to the single specified numeric value. Finally,
9375 if a third argument is specified, $SAVEHIST is set to a separate
9376 value from $HISTSIZE. You are free to change these environment
9377 values for the new history list however you desire in order to
9378 manipulate the new history list.
9379
9380 `fc -P' pops the history list back to an older list saved by `fc
9381 -p'. The current list is saved to its $HISTFILE before it is
9382 destroyed (assuming that $HISTFILE and $SAVEHIST are set appro‐
9383 priately, of course). The values of $HISTFILE, $HISTSIZE, and
9384 $SAVEHIST are restored to the values they had when `fc -p' was
9385 called. Note that this restoration can conflict with making
9386 these variables "local", so your best bet is to avoid local dec‐
9387 larations for these variables in functions that use `fc -p'.
9388 The one other guaranteed-safe combination is declaring these
9389 variables to be local at the top of your function and using the
9390 automatic option (-a) with `fc -p'. Finally, note that it is
9391 legal to manually pop a push marked for automatic popping if you
9392 need to do so before the function exits.
9393
9394 `fc -R' reads the history from the given file, `fc -W' writes
9395 the history out to the given file, and `fc -A' appends the his‐
9396 tory out to the given file. If no filename is specified, the
9397 $HISTFILE is assumed. If the -I option is added to -R, only
9398 those events that are not already contained within the internal
9399 history list are added. If the -I option is added to -A or -W,
9400 only those events that are new since last incremental ap‐
9401 pend/write to the history file are appended/written. In any
9402 case, the created file will have no more than $SAVEHIST entries.
9403
9404 fg [ job ... ]
9405 job ...
9406 Bring each specified job in turn to the foreground. If no job
9407 is specified, resume the current job.
9408
9409 float [ {+|-}Hghlprtux ] [ {+|-}EFLRZ [ n ] ] [ name[=value] ... ]
9410 Equivalent to typeset -E, except that options irrelevant to
9411 floating point numbers are not permitted.
9412
9413 functions [ {+|-}UkmtTuWz ] [ -x num ] [ name ... ]
9414 functions -c oldfn newfn
9415 functions -M [-s] mathfn [ min [ max [ shellfn ] ] ]
9416 functions -M [ -m pattern ... ]
9417 functions +M [ -m ] mathfn ...
9418 Equivalent to typeset -f, with the exception of the -c, -x, -M
9419 and -W options. For functions -u and functions -U, see au‐
9420 toload, which provides additional options. For functions -t and
9421 functions -T, see typeset -f.
9422
9423 The -x option indicates that any functions output will have each
9424 leading tab for indentation, added by the shell to show syntac‐
9425 tic structure, expanded to the given number num of spaces. num
9426 can also be 0 to suppress all indentation.
9427
9428 The -W option turns on the option WARN_NESTED_VAR for the named
9429 function or functions only. The option is turned off at the
9430 start of nested functions (apart from anonoymous functions) un‐
9431 less the called function also has the -W attribute.
9432
9433 The -c option causes oldfn to be copied to newfn. The copy is
9434 efficiently handled internally by reference counting. If oldfn
9435 was marked for autoload it is first loaded and if this fails the
9436 copy fails. Either function may subsequently be redefined with‐
9437 out affecting the other. A typical idiom is that oldfn is the
9438 name of a library shell function which is then redefined to call
9439 newfn, thereby installing a modified version of the function.
9440
9441 The -M and +M flags
9442
9443 Use of the -M option may not be combined with any of the options
9444 handled by typeset -f.
9445
9446 functions -M mathfn defines mathfn as the name of a mathematical
9447 function recognised in all forms of arithmetical expressions;
9448 see the section `Arithmetic Evaluation' in zshmisc(1). By de‐
9449 fault mathfn may take any number of comma-separated arguments.
9450 If min is given, it must have exactly min args; if min and max
9451 are both given, it must have at least min and at most max args.
9452 max may be -1 to indicate that there is no upper limit.
9453
9454 By default the function is implemented by a shell function of
9455 the same name; if shellfn is specified it gives the name of the
9456 corresponding shell function while mathfn remains the name used
9457 in arithmetical expressions. The name of the function in $0 is
9458 mathfn (not shellfn as would usually be the case), provided the
9459 option FUNCTION_ARGZERO is in effect. The positional parameters
9460 in the shell function correspond to the arguments of the mathe‐
9461 matical function call.
9462
9463 The result of the last arithmetical expression evaluated inside
9464 the shell function gives the result of the mathematical func‐
9465 tion. This is not limited to arithmetic substitutions of the
9466 form $((...)), but also includes arithmetical expressions evalu‐
9467 ated in any other way, including by the let builtin, by ((...))
9468 statements, and even by the return builtin and by array sub‐
9469 scripts. Therefore, care must be taken not to use syntactical
9470 constructs that perform arithmetic evaluation after evaluating
9471 what is to be the result of the function. For example:
9472
9473 # WRONG
9474 zmath_cube() {
9475 (( $1 * $1 * $1 ))
9476 return 0
9477 }
9478 functions -M cube 1 1 zmath_cube
9479 print $(( cube(3) ))
9480
9481 This will print `0' because of the return.
9482
9483 Commenting the return out would lead to a different problem: the
9484 ((...)) statement would become the last statement in the func‐
9485 tion, so the return status ($?) of the function would be
9486 non-zero (indicating failure) whenever the arithmetic result of
9487 the function would happen to be zero (numerically):
9488
9489 # WRONG
9490 zmath_cube() {
9491 (( $1 * $1 * $1 ))
9492 }
9493 functions -M cube 1 1 zmath_cube
9494 print $(( cube(0) ))
9495
9496 Instead, the true builtin can be used:
9497
9498 # RIGHT
9499 zmath_cube() {
9500 (( $1 * $1 * $1 ))
9501 true
9502 }
9503 functions -M cube 1 1 zmath_cube
9504 print $(( cube(3) ))
9505
9506 If the additional option -s is given to functions -M, the argu‐
9507 ment to the function is a single string: anything between the
9508 opening and matching closing parenthesis is passed to the func‐
9509 tion as a single argument, even if it includes commas or white
9510 space. The minimum and maximum argument specifiers must there‐
9511 fore be 1 if given. An empty argument list is passed as a
9512 zero-length string. Thus, the following string function takes a
9513 single argument, including the commas, and prints 11:
9514
9515 stringfn() { (( $#1 )); true }
9516 functions -Ms stringfn
9517 print $(( stringfn(foo,bar,rod) ))
9518
9519 functions -M with no arguments lists all such user-defined func‐
9520 tions in the same form as a definition. With the additional op‐
9521 tion -m and a list of arguments, all functions whose mathfn
9522 matches one of the pattern arguments are listed.
9523
9524 function +M removes the list of mathematical functions; with the
9525 additional option -m the arguments are treated as patterns and
9526 all functions whose mathfn matches the pattern are removed.
9527 Note that the shell function implementing the behaviour is not
9528 removed (regardless of whether its name coincides with mathfn).
9529
9530 getcap See the section `The zsh/cap Module' in zshmodules(1).
9531
9532 getln [ -AclneE ] name ...
9533 Read the top value from the buffer stack and put it in the shell
9534 parameter name. Equivalent to read -zr.
9535
9536 getopts optstring name [ arg ... ]
9537 Checks the args for legal options. If the args are omitted, use
9538 the positional parameters. A valid option argument begins with
9539 a `+' or a `-'. An argument not beginning with a `+' or a `-',
9540 or the argument `--', ends the options. Note that a single `-'
9541 is not considered a valid option argument. optstring contains
9542 the letters that getopts recognizes. If a letter is followed by
9543 a `:', that option requires an argument. The options can be
9544 separated from the argument by blanks.
9545
9546 Each time it is invoked, getopts places the option letter it
9547 finds in the shell parameter name, prepended with a `+' when arg
9548 begins with a `+'. The index of the next arg is stored in
9549 OPTIND. The option argument, if any, is stored in OPTARG.
9550
9551 The first option to be examined may be changed by explicitly as‐
9552 signing to OPTIND. OPTIND has an initial value of 1, and is
9553 normally set to 1 upon entry to a shell function and restored
9554 upon exit. (The POSIX_BUILTINS option disables this, and also
9555 changes the way the value is calculated to match other shells.)
9556 OPTARG is not reset and retains its value from the most recent
9557 call to getopts. If either of OPTIND or OPTARG is explicitly
9558 unset, it remains unset, and the index or option argument is not
9559 stored. The option itself is still stored in name in this case.
9560
9561 A leading `:' in optstring causes getopts to store the letter of
9562 any invalid option in OPTARG, and to set name to `?' for an un‐
9563 known option and to `:' when a required argument is missing.
9564 Otherwise, getopts sets name to `?' and prints an error message
9565 when an option is invalid. The exit status is nonzero when
9566 there are no more options.
9567
9568 hash [ -Ldfmrv ] [ name[=value] ] ...
9569 hash can be used to directly modify the contents of the command
9570 hash table, and the named directory hash table. Normally one
9571 would modify these tables by modifying one's PATH (for the com‐
9572 mand hash table) or by creating appropriate shell parameters
9573 (for the named directory hash table). The choice of hash table
9574 to work on is determined by the -d option; without the option
9575 the command hash table is used, and with the option the named
9576 directory hash table is used.
9577
9578 A command name starting with a / is never hashed, whether by ex‐
9579 plicit use of the hash command or otherwise. Such a command is
9580 always found by direct look up in the file system.
9581
9582 Given no arguments, and neither the -r or -f options, the se‐
9583 lected hash table will be listed in full.
9584
9585 The -r option causes the selected hash table to be emptied. It
9586 will be subsequently rebuilt in the normal fashion. The -f op‐
9587 tion causes the selected hash table to be fully rebuilt immedi‐
9588 ately. For the command hash table this hashes all the absolute
9589 directories in the PATH, and for the named directory hash table
9590 this adds all users' home directories. These two options cannot
9591 be used with any arguments.
9592
9593 The -m option causes the arguments to be taken as patterns
9594 (which should be quoted) and the elements of the hash table
9595 matching those patterns are printed. This is the only way to
9596 display a limited selection of hash table elements.
9597
9598 For each name with a corresponding value, put `name' in the se‐
9599 lected hash table, associating it with the pathname `value'. In
9600 the command hash table, this means that whenever `name' is used
9601 as a command argument, the shell will try to execute the file
9602 given by `value'. In the named directory hash table, this means
9603 that `value' may be referred to as `~name'.
9604
9605 For each name with no corresponding value, attempt to add name
9606 to the hash table, checking what the appropriate value is in the
9607 normal manner for that hash table. If an appropriate value
9608 can't be found, then the hash table will be unchanged.
9609
9610 The -v option causes hash table entries to be listed as they are
9611 added by explicit specification. If has no effect if used with
9612 -f.
9613
9614 If the -L flag is present, then each hash table entry is printed
9615 in the form of a call to hash.
9616
9617 history
9618 Same as fc -l.
9619
9620 integer [ {+|-}Hghlprtux ] [ {+|-}LRZi [ n ] ] [ name[=value] ... ]
9621 Equivalent to typeset -i, except that options irrelevant to in‐
9622 tegers are not permitted.
9623
9624 jobs [ -dlprs ] [ job ... ]
9625 jobs -Z string
9626 Lists information about each given job, or all jobs if job is
9627 omitted. The -l flag lists process IDs, and the -p flag lists
9628 process groups. If the -r flag is specified only running jobs
9629 will be listed and if the -s flag is given only stopped jobs are
9630 shown. If the -d flag is given, the directory from which the
9631 job was started (which may not be the current directory of the
9632 job) will also be shown.
9633
9634 The -Z option replaces the shell's argument and environment
9635 space with the given string, truncated if necessary to fit.
9636 This will normally be visible in ps (ps(1)) listings. This fea‐
9637 ture is typically used by daemons, to indicate their state.
9638
9639 Full job control is only available in the top-level interactive
9640 shell, not in commands run in the left hand side of pipelines or
9641 within the (...) construct. However, a snapshot of the job
9642 state at that point is taken, so it is still possible to use the
9643 jobs builtin, or any parameter providing job information. This
9644 gives information about the state of jobs at the point the sub‐
9645 shell was created. If background processes are created within
9646 the subshell, then instead information about those processes is
9647 provided.
9648
9649 For example,
9650
9651 sleep 10 & # Job in background
9652 ( # Shell forks
9653 jobs # Shows information about "sleep 10 &"
9654 sleep 5 & # Process in background (no job control)
9655 jobs # Shows information about "sleep 5 &"
9656 )
9657
9658 kill [ -s signal_name | -n signal_number | -sig ] job ...
9659 kill -l [ sig ... ]
9660 Sends either SIGTERM or the specified signal to the given jobs
9661 or processes. Signals are given by number or by names, with or
9662 without the `SIG' prefix. If the signal being sent is not
9663 `KILL' or `CONT', then the job will be sent a `CONT' signal if
9664 it is stopped. The argument job can be the process ID of a job
9665 not in the job list. In the second form, kill -l, if sig is not
9666 specified the signal names are listed. Otherwise, for each sig
9667 that is a name, the corresponding signal number is listed. For
9668 each sig that is a signal number or a number representing the
9669 exit status of a process which was terminated or stopped by a
9670 signal the name of the signal is printed.
9671
9672 On some systems, alternative signal names are allowed for a few
9673 signals. Typical examples are SIGCHLD and SIGCLD or SIGPOLL and
9674 SIGIO, assuming they correspond to the same signal number. kill
9675 -l will only list the preferred form, however kill -l alt will
9676 show if the alternative form corresponds to a signal number.
9677 For example, under Linux kill -l IO and kill -l POLL both output
9678 29, hence kill -IO and kill -POLL have the same effect.
9679
9680 Many systems will allow process IDs to be negative to kill a
9681 process group or zero to kill the current process group.
9682
9683 let arg ...
9684 Evaluate each arg as an arithmetic expression. See the section
9685 `Arithmetic Evaluation' in zshmisc(1) for a description of
9686 arithmetic expressions. The exit status is 0 if the value of
9687 the last expression is nonzero, 1 if it is zero, and 2 if an er‐
9688 ror occurred.
9689
9690 limit [ -hs ] [ resource [ limit ] ] ...
9691 Set or display resource limits. Unless the -s flag is given,
9692 the limit applies only the children of the shell. If -s is
9693 given without other arguments, the resource limits of the cur‐
9694 rent shell is set to the previously set resource limits of the
9695 children.
9696
9697 If limit is not specified, print the current limit placed on re‐
9698 source, otherwise set the limit to the specified value. If the
9699 -h flag is given, use hard limits instead of soft limits. If no
9700 resource is given, print all limits.
9701
9702 When looping over multiple resources, the shell will abort imme‐
9703 diately if it detects a badly formed argument. However, if it
9704 fails to set a limit for some other reason it will continue try‐
9705 ing to set the remaining limits.
9706
9707 resource can be one of:
9708
9709 addressspace
9710 Maximum amount of address space used.
9711 aiomemorylocked
9712 Maximum amount of memory locked in RAM for AIO opera‐
9713 tions.
9714 aiooperations
9715 Maximum number of AIO operations.
9716 cachedthreads
9717 Maximum number of cached threads.
9718 coredumpsize
9719 Maximum size of a core dump.
9720 cputime
9721 Maximum CPU seconds per process.
9722 datasize
9723 Maximum data size (including stack) for each process.
9724 descriptors
9725 Maximum value for a file descriptor.
9726 filesize
9727 Largest single file allowed.
9728 kqueues
9729 Maximum number of kqueues allocated.
9730 maxproc
9731 Maximum number of processes.
9732 maxpthreads
9733 Maximum number of threads per process.
9734 memorylocked
9735 Maximum amount of memory locked in RAM.
9736 memoryuse
9737 Maximum resident set size.
9738 msgqueue
9739 Maximum number of bytes in POSIX message queues.
9740 posixlocks
9741 Maximum number of POSIX locks per user.
9742 pseudoterminals
9743 Maximum number of pseudo-terminals.
9744 resident
9745 Maximum resident set size.
9746 sigpending
9747 Maximum number of pending signals.
9748 sockbufsize
9749 Maximum size of all socket buffers.
9750 stacksize
9751 Maximum stack size for each process.
9752 swapsize
9753 Maximum amount of swap used.
9754 vmemorysize
9755 Maximum amount of virtual memory.
9756
9757 Which of these resource limits are available depends on the sys‐
9758 tem. resource can be abbreviated to any unambiguous prefix. It
9759 can also be an integer, which corresponds to the integer defined
9760 for the resource by the operating system.
9761
9762 If argument corresponds to a number which is out of the range of
9763 the resources configured into the shell, the shell will try to
9764 read or write the limit anyway, and will report an error if this
9765 fails. As the shell does not store such resources internally,
9766 an attempt to set the limit will fail unless the -s option is
9767 present.
9768
9769 limit is a number, with an optional scaling factor, as follows:
9770
9771 nh hours
9772 nk kilobytes (default)
9773 nm megabytes or minutes
9774 ng gigabytes
9775 [mm:]ss
9776 minutes and seconds
9777
9778 The limit command is not made available by default when the
9779 shell starts in a mode emulating another shell. It can be made
9780 available with the command `zmodload -F zsh/rlimits b:limit'.
9781
9782 local [ {+|-}AHUahlprtux ] [ {+|-}EFLRZi [ n ] ] [ name[=value] ... ]
9783 Same as typeset, except that the options -g, and -f are not per‐
9784 mitted. In this case the -x option does not force the use of
9785 -g, i.e. exported variables will be local to functions.
9786
9787 logout [ n ]
9788 Same as exit, except that it only works in a login shell.
9789
9790 noglob simple command
9791 See the section `Precommand Modifiers' in zshmisc(1).
9792
9793 popd [ -q ] [ {+|-}n ]
9794 Remove an entry from the directory stack, and perform a cd to
9795 the new top directory. With no argument, the current top entry
9796 is removed. An argument of the form `+n' identifies a stack en‐
9797 try by counting from the left of the list shown by the dirs com‐
9798 mand, starting with zero. An argument of the form -n counts
9799 from the right. If the PUSHD_MINUS option is set, the meanings
9800 of `+' and `-' in this context are swapped.
9801
9802 If the -q (quiet) option is specified, the hook function chpwd
9803 and the functions in the array $chpwd_functions are not called,
9804 and the new directory stack is not printed. This is useful for
9805 calls to popd that do not change the environment seen by an in‐
9806 teractive user.
9807
9808 print [ -abcDilmnNoOpPrsSz ] [ -u n ] [ -f format ] [ -C cols ]
9809 [ -v name ] [ -xX tabstop ] [ -R [ -en ]] [ arg ... ]
9810 With the `-f' option the arguments are printed as described by
9811 printf. With no flags or with the flag `-', the arguments are
9812 printed on the standard output as described by echo, with the
9813 following differences: the escape sequence `\M-x' (or `\Mx')
9814 metafies the character x (sets the highest bit), `\C-x' (or
9815 `\Cx') produces a control character (`\C-@' and `\C-?' give the
9816 characters NULL and delete), a character code in octal is repre‐
9817 sented by `\NNN' (instead of `\0NNN'), and `\E' is a synonym for
9818 `\e'. Finally, if not in an escape sequence, `\' escapes the
9819 following character and is not printed.
9820
9821 -a Print arguments with the column incrementing first. Only
9822 useful with the -c and -C options.
9823
9824 -b Recognize all the escape sequences defined for the bind‐
9825 key command, see the section `Zle Builtins' in zshzle(1).
9826
9827 -c Print the arguments in columns. Unless -a is also given,
9828 arguments are printed with the row incrementing first.
9829
9830 -C cols
9831 Print the arguments in cols columns. Unless -a is also
9832 given, arguments are printed with the row incrementing
9833 first.
9834
9835 -D Treat the arguments as paths, replacing directory pre‐
9836 fixes with ~ expressions corresponding to directory
9837 names, as appropriate.
9838
9839 -i If given together with -o or -O, sorting is performed
9840 case-independently.
9841
9842 -l Print the arguments separated by newlines instead of spa‐
9843 ces. Note: if the list of arguments is empty, print -l
9844 will still output one empty line. To print a possi‐
9845 bly-empty list of arguments one per line, use print -C1,
9846 as in `print -rC1 -- "$list[@]"'.
9847
9848 -m Take the first argument as a pattern (should be quoted),
9849 and remove it from the argument list together with subse‐
9850 quent arguments that do not match this pattern.
9851
9852 -n Do not add a newline to the output.
9853
9854 -N Print the arguments separated and terminated by nulls.
9855 Again, print -rNC1 -- "$list[@]" is a canonical way to
9856 print an arbitrary list as null-delimited records.
9857
9858 -o Print the arguments sorted in ascending order.
9859
9860 -O Print the arguments sorted in descending order.
9861
9862 -p Print the arguments to the input of the coprocess.
9863
9864 -P Perform prompt expansion (see EXPANSION OF PROMPT SE‐
9865 QUENCES in zshmisc(1)). In combination with `-f', prompt
9866 escape sequences are parsed only within interpolated ar‐
9867 guments, not within the format string.
9868
9869 -r Ignore the escape conventions of echo.
9870
9871 -R Emulate the BSD echo command, which does not process es‐
9872 cape sequences unless the -e flag is given. The -n flag
9873 suppresses the trailing newline. Only the -e and -n
9874 flags are recognized after -R; all other arguments and
9875 options are printed.
9876
9877 -s Place the results in the history list instead of on the
9878 standard output. Each argument to the print command is
9879 treated as a single word in the history, regardless of
9880 its content.
9881
9882 -S Place the results in the history list instead of on the
9883 standard output. In this case only a single argument is
9884 allowed; it will be split into words as if it were a full
9885 shell command line. The effect is similar to reading the
9886 line from a history file with the HIST_LEX_WORDS option
9887 active.
9888
9889 -u n Print the arguments to file descriptor n.
9890
9891 -v name
9892 Store the printed arguments as the value of the parameter
9893 name.
9894
9895 -x tab-stop
9896 Expand leading tabs on each line of output in the printed
9897 string assuming a tab stop every tab-stop characters.
9898 This is appropriate for formatting code that may be in‐
9899 dented with tabs. Note that leading tabs of any argument
9900 to print, not just the first, are expanded, even if print
9901 is using spaces to separate arguments (the column count
9902 is maintained across arguments but may be incorrect on
9903 output owing to previous unexpanded tabs).
9904
9905 The start of the output of each print command is assumed
9906 to be aligned with a tab stop. Widths of multibyte char‐
9907 acters are handled if the option MULTIBYTE is in effect.
9908 This option is ignored if other formatting options are in
9909 effect, namely column alignment or printf style, or if
9910 output is to a special location such as shell history or
9911 the command line editor.
9912
9913 -X tab-stop
9914 This is similar to -x, except that all tabs in the
9915 printed string are expanded. This is appropriate if tabs
9916 in the arguments are being used to produce a table for‐
9917 mat.
9918
9919 -z Push the arguments onto the editing buffer stack, sepa‐
9920 rated by spaces.
9921
9922 If any of `-m', `-o' or `-O' are used in combination with `-f'
9923 and there are no arguments (after the removal process in the
9924 case of `-m') then nothing is printed.
9925
9926 printf [ -v name ] format [ arg ... ]
9927 Print the arguments according to the format specification. For‐
9928 matting rules are the same as used in C. The same escape se‐
9929 quences as for echo are recognised in the format. All C conver‐
9930 sion specifications ending in one of csdiouxXeEfgGn are handled.
9931 In addition to this, `%b' can be used instead of `%s' to cause
9932 escape sequences in the argument to be recognised and `%q' can
9933 be used to quote the argument in such a way that allows it to be
9934 reused as shell input. With the numeric format specifiers, if
9935 the corresponding argument starts with a quote character, the
9936 numeric value of the following character is used as the number
9937 to print; otherwise the argument is evaluated as an arithmetic
9938 expression. See the section `Arithmetic Evaluation' in zsh‐
9939 misc(1) for a description of arithmetic expressions. With `%n',
9940 the corresponding argument is taken as an identifier which is
9941 created as an integer parameter.
9942
9943 Normally, conversion specifications are applied to each argument
9944 in order but they can explicitly specify the nth argument is to
9945 be used by replacing `%' by `%n$' and `*' by `*n$'. It is rec‐
9946 ommended that you do not mix references of this explicit style
9947 with the normal style and the handling of such mixed styles may
9948 be subject to future change.
9949
9950 If arguments remain unused after formatting, the format string
9951 is reused until all arguments have been consumed. With the print
9952 builtin, this can be suppressed by using the -r option. If more
9953 arguments are required by the format than have been specified,
9954 the behaviour is as if zero or an empty string had been speci‐
9955 fied as the argument.
9956
9957 The -v option causes the output to be stored as the value of the
9958 parameter name, instead of printed. If name is an array and the
9959 format string is reused when consuming arguments then one array
9960 element will be used for each use of the format string.
9961
9962 pushd [ -qsLP ] [ arg ]
9963 pushd [ -qsLP ] old new
9964 pushd [ -qsLP ] {+|-}n
9965 Change the current directory, and push the old current directory
9966 onto the directory stack. In the first form, change the current
9967 directory to arg. If arg is not specified, change to the second
9968 directory on the stack (that is, exchange the top two entries),
9969 or change to $HOME if the PUSHD_TO_HOME option is set or if
9970 there is only one entry on the stack. Otherwise, arg is inter‐
9971 preted as it would be by cd. The meaning of old and new in the
9972 second form is also the same as for cd.
9973
9974 The third form of pushd changes directory by rotating the direc‐
9975 tory list. An argument of the form `+n' identifies a stack en‐
9976 try by counting from the left of the list shown by the dirs com‐
9977 mand, starting with zero. An argument of the form `-n' counts
9978 from the right. If the PUSHD_MINUS option is set, the meanings
9979 of `+' and `-' in this context are swapped.
9980
9981 If the -q (quiet) option is specified, the hook function chpwd
9982 and the functions in the array $chpwd_functions are not called,
9983 and the new directory stack is not printed. This is useful for
9984 calls to pushd that do not change the environment seen by an in‐
9985 teractive user.
9986
9987 If the option -q is not specified and the shell option
9988 PUSHD_SILENT is not set, the directory stack will be printed af‐
9989 ter a pushd is performed.
9990
9991 The options -s, -L and -P have the same meanings as for the cd
9992 builtin.
9993
9994 pushln [ arg ... ]
9995 Equivalent to print -nz.
9996
9997 pwd [ -rLP ]
9998 Print the absolute pathname of the current working directory.
9999 If the -r or the -P flag is specified, or the CHASE_LINKS option
10000 is set and the -L flag is not given, the printed path will not
10001 contain symbolic links.
10002
10003 r Same as fc -e -.
10004
10005
10006 read [ -rszpqAclneE ] [ -t [ num ] ] [ -k [ num ] ] [ -d delim ]
10007 [ -u n ] [ [name][?prompt] ] [ name ... ]
10008 Read one line and break it into fields using the characters in
10009 $IFS as separators, except as noted below. The first field is
10010 assigned to the first name, the second field to the second name,
10011 etc., with leftover fields assigned to the last name. If name
10012 is omitted then REPLY is used for scalars and reply for arrays.
10013
10014 -r Raw mode: a `\' at the end of a line does not signify
10015 line continuation and backslashes in the line don't quote
10016 the following character and are not removed.
10017
10018 -s Don't echo back characters if reading from the terminal.
10019
10020 -q Read only one character from the terminal and set name to
10021 `y' if this character was `y' or `Y' and to `n' other‐
10022 wise. With this flag set the return status is zero only
10023 if the character was `y' or `Y'. This option may be used
10024 with a timeout (see -t); if the read times out, or en‐
10025 counters end of file, status 2 is returned. Input is
10026 read from the terminal unless one of -u or -p is present.
10027 This option may also be used within zle widgets.
10028
10029 -k [ num ]
10030 Read only one (or num) characters. All are assigned to
10031 the first name, without word splitting. This flag is ig‐
10032 nored when -q is present. Input is read from the termi‐
10033 nal unless one of -u or -p is present. This option may
10034 also be used within zle widgets.
10035
10036 Note that despite the mnemonic `key' this option does
10037 read full characters, which may consist of multiple bytes
10038 if the option MULTIBYTE is set.
10039
10040 -z Read one entry from the editor buffer stack and assign it
10041 to the first name, without word splitting. Text is
10042 pushed onto the stack with `print -z' or with push-line
10043 from the line editor (see zshzle(1)). This flag is ig‐
10044 nored when the -k or -q flags are present.
10045
10046 -e
10047 -E The input read is printed (echoed) to the standard out‐
10048 put. If the -e flag is used, no input is assigned to the
10049 parameters.
10050
10051 -A The first name is taken as the name of an array and all
10052 words are assigned to it.
10053
10054 -c
10055 -l These flags are allowed only if called inside a function
10056 used for completion (specified with the -K flag to com‐
10057 pctl). If the -c flag is given, the words of the current
10058 command are read. If the -l flag is given, the whole line
10059 is assigned as a scalar. If both flags are present, -l
10060 is used and -c is ignored.
10061
10062 -n Together with -c, the number of the word the cursor is on
10063 is read. With -l, the index of the character the cursor
10064 is on is read. Note that the command name is word number
10065 1, not word 0, and that when the cursor is at the end of
10066 the line, its character index is the length of the line
10067 plus one.
10068
10069 -u n Input is read from file descriptor n.
10070
10071 -p Input is read from the coprocess.
10072
10073 -d delim
10074 Input is terminated by the first character of delim in‐
10075 stead of by newline.
10076
10077 -t [ num ]
10078 Test if input is available before attempting to read. If
10079 num is present, it must begin with a digit and will be
10080 evaluated to give a number of seconds, which may be a
10081 floating point number; in this case the read times out if
10082 input is not available within this time. If num is not
10083 present, it is taken to be zero, so that read returns im‐
10084 mediately if no input is available. If no input is
10085 available, return status 1 and do not set any variables.
10086
10087 This option is not available when reading from the editor
10088 buffer with -z, when called from within completion with
10089 -c or -l, with -q which clears the input queue before
10090 reading, or within zle where other mechanisms should be
10091 used to test for input.
10092
10093 Note that read does not attempt to alter the input pro‐
10094 cessing mode. The default mode is canonical input, in
10095 which an entire line is read at a time, so usually `read
10096 -t' will not read anything until an entire line has been
10097 typed. However, when reading from the terminal with -k
10098 input is processed one key at a time; in this case, only
10099 availability of the first character is tested, so that
10100 e.g. `read -t -k 2' can still block on the second charac‐
10101 ter. Use two instances of `read -t -k' if this is not
10102 what is wanted.
10103
10104 If the first argument contains a `?', the remainder of this word
10105 is used as a prompt on standard error when the shell is interac‐
10106 tive.
10107
10108 The value (exit status) of read is 1 when an end-of-file is en‐
10109 countered, or when -c or -l is present and the command is not
10110 called from a compctl function, or as described for -q. Other‐
10111 wise the value is 0.
10112
10113 The behavior of some combinations of the -k, -p, -q, -u and -z
10114 flags is undefined. Presently -q cancels all the others, -p
10115 cancels -u, -k cancels -z, and otherwise -z cancels both -p and
10116 -u.
10117
10118 The -c or -l flags cancel any and all of -kpquz.
10119
10120 readonly
10121 Same as typeset -r. With the POSIX_BUILTINS option set, same as
10122 typeset -gr.
10123
10124 rehash Same as hash -r.
10125
10126 return [ n ]
10127 Causes a shell function or `.' script to return to the invoking
10128 script with the return status specified by an arithmetic expres‐
10129 sion n. For example, the following prints `42':
10130
10131 () { integer foo=40; return "foo + 2" }
10132 echo $?
10133
10134 If n is omitted, the return status is that of the last command
10135 executed.
10136
10137 If return was executed from a trap in a TRAPNAL function, the
10138 effect is different for zero and non-zero return status. With
10139 zero status (or after an implicit return at the end of the
10140 trap), the shell will return to whatever it was previously pro‐
10141 cessing; with a non-zero status, the shell will behave as inter‐
10142 rupted except that the return status of the trap is retained.
10143 Note that the numeric value of the signal which caused the trap
10144 is passed as the first argument, so the statement `return
10145 "128+$1"' will return the same status as if the signal had not
10146 been trapped.
10147
10148 sched See the section `The zsh/sched Module' in zshmodules(1).
10149
10150
10151 set [ {+|-}options | {+|-}o [ option_name ] ] ... [ {+|-}A [ name ] ]
10152 [ arg ... ]
10153 Set the options for the shell and/or set the positional parame‐
10154 ters, or declare and set an array. If the -s option is given,
10155 it causes the specified arguments to be sorted before assigning
10156 them to the positional parameters (or to the array name if -A is
10157 used). With +s sort arguments in descending order. For the
10158 meaning of the other flags, see zshoptions(1). Flags may be
10159 specified by name using the -o option. If no option name is sup‐
10160 plied with -o, the current option states are printed: see the
10161 description of setopt below for more information on the format.
10162 With +o they are printed in a form that can be used as input to
10163 the shell.
10164
10165 If the -A flag is specified, name is set to an array containing
10166 the given args; if no name is specified, all arrays are printed
10167 together with their values.
10168
10169 If +A is used and name is an array, the given arguments will re‐
10170 place the initial elements of that array; if no name is speci‐
10171 fied, all arrays are printed without their values.
10172
10173 The behaviour of arguments after -A name or +A name depends on
10174 whether the option KSH_ARRAYS is set. If it is not set, all ar‐
10175 guments following name are treated as values for the array, re‐
10176 gardless of their form. If the option is set, normal option
10177 processing continues at that point; only regular arguments are
10178 treated as values for the array. This means that
10179
10180 set -A array -x -- foo
10181
10182 sets array to `-x -- foo' if KSH_ARRAYS is not set, but sets the
10183 array to foo and turns on the option `-x' if it is set.
10184
10185 If the -A flag is not present, but there are arguments beyond
10186 the options, the positional parameters are set. If the option
10187 list (if any) is terminated by `--', and there are no further
10188 arguments, the positional parameters will be unset.
10189
10190 If no arguments and no `--' are given, then the names and values
10191 of all parameters are printed on the standard output. If the
10192 only argument is `+', the names of all parameters are printed.
10193
10194 For historical reasons, `set -' is treated as `set +xv' and `set
10195 - args' as `set +xv -- args' when in any other emulation mode
10196 than zsh's native mode.
10197
10198 setcap See the section `The zsh/cap Module' in zshmodules(1).
10199
10200 setopt [ {+|-}options | {+|-}o option_name ] [ -m ] [ name ... ]
10201 Set the options for the shell. All options specified either
10202 with flags or by name are set.
10203
10204 If no arguments are supplied, the names of all options currently
10205 set are printed. The form is chosen so as to minimize the dif‐
10206 ferences from the default options for the current emulation (the
10207 default emulation being native zsh, shown as <Z> in zshop‐
10208 tions(1)). Options that are on by default for the emulation are
10209 shown with the prefix no only if they are off, while other op‐
10210 tions are shown without the prefix no and only if they are on.
10211 In addition to options changed from the default state by the
10212 user, any options activated automatically by the shell (for ex‐
10213 ample, SHIN_STDIN or INTERACTIVE) will be shown in the list.
10214 The format is further modified by the option KSH_OPTION_PRINT,
10215 however the rationale for choosing options with or without the
10216 no prefix remains the same in this case.
10217
10218 If the -m flag is given the arguments are taken as patterns
10219 (which should be quoted to protect them from filename expan‐
10220 sion), and all options with names matching these patterns are
10221 set.
10222
10223 Note that a bad option name does not cause execution of subse‐
10224 quent shell code to be aborted; this is behaviour is different
10225 from that of `set -o'. This is because set is regarded as a
10226 special builtin by the POSIX standard, but setopt is not.
10227
10228 shift [ -p ] [ n ] [ name ... ]
10229 The positional parameters ${n+1} ... are renamed to $1 ...,
10230 where n is an arithmetic expression that defaults to 1. If any
10231 names are given then the arrays with these names are shifted in‐
10232 stead of the positional parameters.
10233
10234 If the option -p is given arguments are instead removed (popped)
10235 from the end rather than the start of the array.
10236
10237 source file [ arg ... ]
10238 Same as `.', except that the current directory is always
10239 searched and is always searched first, before directories in
10240 $path.
10241
10242 stat See the section `The zsh/stat Module' in zshmodules(1).
10243
10244 suspend [ -f ]
10245 Suspend the execution of the shell (send it a SIGTSTP) until it
10246 receives a SIGCONT. Unless the -f option is given, this will
10247 refuse to suspend a login shell.
10248
10249 test [ arg ... ]
10250 [ [ arg ... ] ]
10251 Like the system version of test. Added for compatibility; use
10252 conditional expressions instead (see the section `Conditional
10253 Expressions'). The main differences between the conditional ex‐
10254 pression syntax and the test and [ builtins are: these commands
10255 are not handled syntactically, so for example an empty variable
10256 expansion may cause an argument to be omitted; syntax errors
10257 cause status 2 to be returned instead of a shell error; and
10258 arithmetic operators expect integer arguments rather than arith‐
10259 metic expressions.
10260
10261 The command attempts to implement POSIX and its extensions where
10262 these are specified. Unfortunately there are intrinsic ambigui‐
10263 ties in the syntax; in particular there is no distinction be‐
10264 tween test operators and strings that resemble them. The stan‐
10265 dard attempts to resolve these for small numbers of arguments
10266 (up to four); for five or more arguments compatibility cannot be
10267 relied on. Users are urged wherever possible to use the `[['
10268 test syntax which does not have these ambiguities.
10269
10270 times Print the accumulated user and system times for the shell and
10271 for processes run from the shell.
10272
10273 trap [ arg ] [ sig ... ]
10274 arg is a series of commands (usually quoted to protect it from
10275 immediate evaluation by the shell) to be read and executed when
10276 the shell receives any of the signals specified by one or more
10277 sig args. Each sig can be given as a number, or as the name of
10278 a signal either with or without the string SIG in front (e.g. 1,
10279 HUP, and SIGHUP are all the same signal).
10280
10281 If arg is `-', then the specified signals are reset to their de‐
10282 faults, or, if no sig args are present, all traps are reset.
10283
10284 If arg is an empty string, then the specified signals are ig‐
10285 nored by the shell (and by the commands it invokes).
10286
10287 If arg is omitted but one or more sig args are provided (i.e.
10288 the first argument is a valid signal number or name), the effect
10289 is the same as if arg had been specified as `-'.
10290
10291 The trap command with no arguments prints a list of commands as‐
10292 sociated with each signal.
10293
10294 If sig is ZERR then arg will be executed after each command with
10295 a nonzero exit status. ERR is an alias for ZERR on systems that
10296 have no SIGERR signal (this is the usual case).
10297
10298 If sig is DEBUG then arg will be executed before each command if
10299 the option DEBUG_BEFORE_CMD is set (as it is by default), else
10300 after each command. Here, a `command' is what is described as a
10301 `sublist' in the shell grammar, see the section SIMPLE COMMANDS
10302 & PIPELINES in zshmisc(1). If DEBUG_BEFORE_CMD is set various
10303 additional features are available. First, it is possible to
10304 skip the next command by setting the option ERR_EXIT; see the
10305 description of the ERR_EXIT option in zshoptions(1). Also, the
10306 shell parameter ZSH_DEBUG_CMD is set to the string corresponding
10307 to the command to be executed following the trap. Note that
10308 this string is reconstructed from the internal format and may
10309 not be formatted the same way as the original text. The parame‐
10310 ter is unset after the trap is executed.
10311
10312 If sig is 0 or EXIT and the trap statement is executed inside
10313 the body of a function, then the command arg is executed after
10314 the function completes. The value of $? at the start of execu‐
10315 tion is the exit status of the shell or the return status of the
10316 function exiting. If sig is 0 or EXIT and the trap statement is
10317 not executed inside the body of a function, then the command arg
10318 is executed when the shell terminates; the trap runs before any
10319 zshexit hook functions.
10320
10321 ZERR, DEBUG, and EXIT traps are not executed inside other traps.
10322 ZERR and DEBUG traps are kept within subshells, while other
10323 traps are reset.
10324
10325 Note that traps defined with the trap builtin are slightly dif‐
10326 ferent from those defined as `TRAPNAL () { ... }', as the latter
10327 have their own function environment (line numbers, local vari‐
10328 ables, etc.) while the former use the environment of the command
10329 in which they were called. For example,
10330
10331 trap 'print $LINENO' DEBUG
10332
10333 will print the line number of a command executed after it has
10334 run, while
10335
10336 TRAPDEBUG() { print $LINENO; }
10337
10338 will always print the number zero.
10339
10340 Alternative signal names are allowed as described under kill
10341 above. Defining a trap under either name causes any trap under
10342 an alternative name to be removed. However, it is recommended
10343 that for consistency users stick exclusively to one name or an‐
10344 other.
10345
10346 true [ arg ... ]
10347 Do nothing and return an exit status of 0.
10348
10349 ttyctl [ -fu ]
10350 The -f option freezes the tty (i.e. terminal or terminal emula‐
10351 tor), and -u unfreezes it. When the tty is frozen, no changes
10352 made to the tty settings by external programs will be honored by
10353 the shell, except for changes in the size of the screen; the
10354 shell will simply reset the settings to their previous values as
10355 soon as each command exits or is suspended. Thus, stty and sim‐
10356 ilar programs have no effect when the tty is frozen. Freezing
10357 the tty does not cause the current state to be remembered: in‐
10358 stead, it causes future changes to the state to be blocked.
10359
10360 Without options it reports whether the terminal is frozen or
10361 not.
10362
10363 Note that, regardless of whether the tty is frozen or not, the
10364 shell needs to change the settings when the line editor starts,
10365 so unfreezing the tty does not guarantee settings made on the
10366 command line are preserved. Strings of commands run between
10367 editing the command line will see a consistent tty state. See
10368 also the shell variable STTY for a means of initialising the tty
10369 before running external commands and/or freezing the tty around
10370 a single command.
10371
10372 type [ -wfpamsS ] name ...
10373 Equivalent to whence -v.
10374
10375
10376 typeset [ {+|-}AHUaghlmrtux ] [ {+|-}EFLRZip [ n ] ]
10377 [ + ] [ name[=value] ... ]
10378 typeset -T [ {+|-}Uglrux ] [ {+|-}LRZp [ n ] ]
10379 [ + | SCALAR[=value] array[=(value ...)] [ sep ] ]
10380 typeset -f [ {+|-}TUkmtuz ] [ + ] [ name ... ]
10381 Set or display attributes and values for shell parameters.
10382
10383 Except as noted below for control flags that change the behav‐
10384 ior, a parameter is created for each name that does not already
10385 refer to one. When inside a function, a new parameter is cre‐
10386 ated for every name (even those that already exist), and is un‐
10387 set again when the function completes. See `Local Parameters'
10388 in zshparam(1). The same rules apply to special shell parame‐
10389 ters, which retain their special attributes when made local.
10390
10391 For each name=value assignment, the parameter name is set to
10392 value. If the assignment is omitted and name does not refer to
10393 an existing parameter, a new parameter is intialized to empty
10394 string, zero, or empty array (as appropriate), unless the shell
10395 option TYPESET_TO_UNSET is set. When that option is set, the
10396 parameter attributes are recorded but the parameter remains un‐
10397 set.
10398
10399 If the shell option TYPESET_SILENT is not set, for each remain‐
10400 ing name that refers to a parameter that is already set, the
10401 name and value of the parameter are printed in the form of an
10402 assignment. Nothing is printed for newly-created parameters, or
10403 when any attribute flags listed below are given along with the
10404 name. Using `+' instead of minus to introduce an attribute
10405 turns it off.
10406
10407 If no name is present, the names and values of all parameters
10408 are printed. In this case the attribute flags restrict the dis‐
10409 play to only those parameters that have the specified at‐
10410 tributes, and using `+' rather than `-' to introduce the flag
10411 suppresses printing of the values of parameters when there is no
10412 parameter name.
10413
10414 All forms of the command handle scalar assignment. Array as‐
10415 signment is possible if any of the reserved words declare, ex‐
10416 port, float, integer, local, readonly or typeset is matched when
10417 the line is parsed (N.B. not when it is executed). In this case
10418 the arguments are parsed as assignments, except that the `+='
10419 syntax and the GLOB_ASSIGN option are not supported, and scalar
10420 values after = are not split further into words, even if ex‐
10421 panded (regardless of the setting of the KSH_TYPESET option;
10422 this option is obsolete).
10423
10424 Examples of the differences between command and reserved word
10425 parsing:
10426
10427 # Reserved word parsing
10428 typeset svar=$(echo one word) avar=(several words)
10429
10430 The above creates a scalar parameter svar and an array parameter
10431 avar as if the assignments had been
10432
10433 svar="one word"
10434 avar=(several words)
10435
10436 On the other hand:
10437
10438 # Normal builtin interface
10439 builtin typeset svar=$(echo two words)
10440
10441 The builtin keyword causes the above to use the standard builtin
10442 interface to typeset in which argument parsing is performed in
10443 the same way as for other commands. This example creates a
10444 scalar svar containing the value two and another scalar parame‐
10445 ter words with no value. An array value in this case would ei‐
10446 ther cause an error or be treated as an obscure set of glob
10447 qualifiers.
10448
10449 Arbitrary arguments are allowed if they take the form of assign‐
10450 ments after command line expansion; however, these only perform
10451 scalar assignment:
10452
10453 var='svar=val'
10454 typeset $var
10455
10456 The above sets the scalar parameter svar to the value val.
10457 Parentheses around the value within var would not cause array
10458 assignment as they will be treated as ordinary characters when
10459 $var is substituted. Any non-trivial expansion in the name part
10460 of the assignment causes the argument to be treated in this
10461 fashion:
10462
10463 typeset {var1,var2,var3}=name
10464
10465 The above syntax is valid, and has the expected effect of set‐
10466 ting the three parameters to the same value, but the command
10467 line is parsed as a set of three normal command line arguments
10468 to typeset after expansion. Hence it is not possible to assign
10469 to multiple arrays by this means.
10470
10471 Note that each interface to any of the commands may be disabled
10472 separately. For example, `disable -r typeset' disables the re‐
10473 served word interface to typeset, exposing the builtin inter‐
10474 face, while `disable typeset' disables the builtin. Note that
10475 disabling the reserved word interface for typeset may cause
10476 problems with the output of `typeset -p', which assumes the re‐
10477 served word interface is available in order to restore array and
10478 associative array values.
10479
10480 Unlike parameter assignment statements, typeset's exit status on
10481 an assignment that involves a command substitution does not re‐
10482 flect the exit status of the command substitution. Therefore,
10483 to test for an error in a command substitution, separate the
10484 declaration of the parameter from its initialization:
10485
10486 # WRONG
10487 typeset var1=$(exit 1) || echo "Trouble with var1"
10488
10489 # RIGHT
10490 typeset var1 && var1=$(exit 1) || echo "Trouble with var1"
10491
10492 To initialize a parameter param to a command output and mark it
10493 readonly, use typeset -r param or readonly param after the pa‐
10494 rameter assignment statement.
10495
10496 If no attribute flags are given, and either no name arguments
10497 are present or the flag +m is used, then each parameter name
10498 printed is preceded by a list of the attributes of that parame‐
10499 ter (array, association, exported, float, integer, readonly, or
10500 undefined for autoloaded parameters not yet loaded). If +m is
10501 used with attribute flags, and all those flags are introduced
10502 with +, the matching parameter names are printed but their val‐
10503 ues are not.
10504
10505 The following control flags change the behavior of typeset:
10506
10507 + If `+' appears by itself in a separate word as the last
10508 option, then the names of all parameters (functions with
10509 -f) are printed, but the values (function bodies) are
10510 not. No name arguments may appear, and it is an error
10511 for any other options to follow `+'. The effect of `+'
10512 is as if all attribute flags which precede it were given
10513 with a `+' prefix. For example, `typeset -U +' is equiv‐
10514 alent to `typeset +U' and displays the names of all ar‐
10515 rays having the uniqueness attribute, whereas `typeset -f
10516 -U +' displays the names of all autoloadable functions.
10517 If + is the only option, then type information (array,
10518 readonly, etc.) is also printed for each parameter, in
10519 the same manner as `typeset +m "*"'.
10520
10521 -g The -g (global) means that any resulting parameter will
10522 not be restricted to local scope. Note that this does
10523 not necessarily mean that the parameter will be global,
10524 as the flag will apply to any existing parameter (even if
10525 unset) from an enclosing function. This flag does not
10526 affect the parameter after creation, hence it has no ef‐
10527 fect when listing existing parameters, nor does the flag
10528 +g have any effect except in combination with -m (see be‐
10529 low).
10530
10531 -m If the -m flag is given the name arguments are taken as
10532 patterns (use quoting to prevent these from being inter‐
10533 preted as file patterns). With no attribute flags, all
10534 parameters (or functions with the -f flag) with matching
10535 names are printed (the shell option TYPESET_SILENT is not
10536 used in this case).
10537
10538 If the +g flag is combined with -m, a new local parameter
10539 is created for every matching parameter that is not al‐
10540 ready local. Otherwise -m applies all other flags or as‐
10541 signments to the existing parameters.
10542
10543 Except when assignments are made with name=value, using
10544 +m forces the matching parameters and their attributes to
10545 be printed, even inside a function. Note that -m is ig‐
10546 nored if no patterns are given, so `typeset -m' displays
10547 attributes but `typeset -a +m' does not.
10548
10549 -p [ n ]
10550 If the -p option is given, parameters and values are
10551 printed in the form of a typeset command with an assign‐
10552 ment, regardless of other flags and options. Note that
10553 the -H flag on parameters is respected; no value will be
10554 shown for these parameters.
10555
10556 -p may be followed by an optional integer argument. Cur‐
10557 rently only the value 1 is supported. In this case ar‐
10558 rays and associative arrays are printed with newlines be‐
10559 tween indented elements for readability.
10560
10561 -T [ scalar[=value] array[=(value ...)] [ sep ] ]
10562 This flag has a different meaning when used with -f; see
10563 below. Otherwise the -T option requires zero, two, or
10564 three arguments to be present. With no arguments, the
10565 list of parameters created in this fashion is shown.
10566 With two or three arguments, the first two are the name
10567 of a scalar and of an array parameter (in that order)
10568 that will be tied together in the manner of $PATH and
10569 $path. The optional third argument is a single-character
10570 separator which will be used to join the elements of the
10571 array to form the scalar; if absent, a colon is used, as
10572 with $PATH. Only the first character of the separator is
10573 significant; any remaining characters are ignored.
10574 Multibyte characters are not yet supported.
10575
10576 Only one of the scalar and array parameters may be as‐
10577 signed an initial value (the restrictions on assignment
10578 forms described above also apply).
10579
10580 Both the scalar and the array may be manipulated as nor‐
10581 mal. If one is unset, the other will automatically be
10582 unset too. There is no way of untying the variables
10583 without unsetting them, nor of converting the type of one
10584 of them with another typeset command; +T does not work,
10585 assigning an array to scalar is an error, and assigning a
10586 scalar to array sets it to be a single-element array.
10587
10588 Note that both `typeset -xT ...' and `export -T ...'
10589 work, but only the scalar will be marked for export.
10590 Setting the value using the scalar version causes a split
10591 on all separators (which cannot be quoted). It is possi‐
10592 ble to apply -T to two previously tied variables but with
10593 a different separator character, in which case the vari‐
10594 ables remain joined as before but the separator is
10595 changed.
10596
10597 When an existing scalar is tied to a new array, the value
10598 of the scalar is preserved but no attribute other than
10599 export will be preserved.
10600
10601 Attribute flags that transform the final value (-L, -R, -Z, -l,
10602 -u) are only applied to the expanded value at the point of a pa‐
10603 rameter expansion expression using `$'. They are not applied
10604 when a parameter is retrieved internally by the shell for any
10605 purpose.
10606
10607 The following attribute flags may be specified:
10608
10609 -A The names refer to associative array parameters; see `Ar‐
10610 ray Parameters' in zshparam(1).
10611
10612 -L [ n ]
10613 Left justify and remove leading blanks from the value
10614 when the parameter is expanded. If n is nonzero, it de‐
10615 fines the width of the field. If n is zero, the width is
10616 determined by the width of the value of the first assign‐
10617 ment. In the case of numeric parameters, the length of
10618 the complete value assigned to the parameter is used to
10619 determine the width, not the value that would be output.
10620
10621 The width is the count of characters, which may be multi‐
10622 byte characters if the MULTIBYTE option is in effect.
10623 Note that the screen width of the character is not taken
10624 into account; if this is required, use padding with pa‐
10625 rameter expansion flags ${(ml...)...} as described in
10626 `Parameter Expansion Flags' in zshexpn(1).
10627
10628 When the parameter is expanded, it is filled on the right
10629 with blanks or truncated if necessary to fit the field.
10630 Note truncation can lead to unexpected results with nu‐
10631 meric parameters. Leading zeros are removed if the -Z
10632 flag is also set.
10633
10634 -R [ n ]
10635 Similar to -L, except that right justification is used;
10636 when the parameter is expanded, the field is left filled
10637 with blanks or truncated from the end. May not be com‐
10638 bined with the -Z flag.
10639
10640 -U For arrays (but not for associative arrays), keep only
10641 the first occurrence of each duplicated value. This may
10642 also be set for tied parameters (see -T) or colon-sepa‐
10643 rated special parameters like PATH or FIGNORE, etc. Note
10644 the flag takes effect on assignment, and the type of the
10645 variable being assigned to is determinative; for vari‐
10646 ables with shared values it is therefore recommended to
10647 set the flag for all interfaces, e.g. `typeset -U PATH
10648 path'.
10649
10650 This flag has a different meaning when used with -f; see
10651 below.
10652
10653 -Z [ n ]
10654 Specially handled if set along with the -L flag. Other‐
10655 wise, similar to -R, except that leading zeros are used
10656 for padding instead of blanks if the first non-blank
10657 character is a digit. Numeric parameters are specially
10658 handled: they are always eligible for padding with ze‐
10659 roes, and the zeroes are inserted at an appropriate place
10660 in the output.
10661
10662 -a The names refer to array parameters. An array parameter
10663 may be created this way, but it may be assigned to in the
10664 typeset statement only if the reserved word form of type‐
10665 set is enabled (as it is by default). When displaying,
10666 both normal and associative arrays are shown.
10667
10668 -f The names refer to functions rather than parameters. No
10669 assignments can be made, and the only other valid flags
10670 are -t, -T, -k, -u, -U and -z. The flag -t turns on exe‐
10671 cution tracing for this function; the flag -T does the
10672 same, but turns off tracing for any named (not anonymous)
10673 function called from the present one, unless that func‐
10674 tion also has the -t or -T flag. The -u and -U flags
10675 cause the function to be marked for autoloading; -U also
10676 causes alias expansion to be suppressed when the function
10677 is loaded. See the description of the `autoload' builtin
10678 for details.
10679
10680 Note that the builtin functions provides the same basic
10681 capabilities as typeset -f but gives access to a few ex‐
10682 tra options; autoload gives further additional options
10683 for the case typeset -fu and typeset -fU.
10684
10685 -h Hide: only useful for special parameters (those marked
10686 `<S>' in the table in zshparam(1)), and for local parame‐
10687 ters with the same name as a special parameter, though
10688 harmless for others. A special parameter with this at‐
10689 tribute will not retain its special effect when made lo‐
10690 cal. Thus after `typeset -h PATH', a function containing
10691 `typeset PATH' will create an ordinary local parameter
10692 without the usual behaviour of PATH. Alternatively, the
10693 local parameter may itself be given this attribute; hence
10694 inside a function `typeset -h PATH' creates an ordinary
10695 local parameter and the special PATH parameter is not al‐
10696 tered in any way. It is also possible to create a local
10697 parameter using `typeset +h special', where the local
10698 copy of special will retain its special properties re‐
10699 gardless of having the -h attribute. Global special pa‐
10700 rameters loaded from shell modules (currently those in
10701 zsh/mapfile and zsh/parameter) are automatically given
10702 the -h attribute to avoid name clashes.
10703
10704 -H Hide value: specifies that typeset will not display the
10705 value of the parameter when listing parameters; the dis‐
10706 play for such parameters is always as if the `+' flag had
10707 been given. Use of the parameter is in other respects
10708 normal, and the option does not apply if the parameter is
10709 specified by name, or by pattern with the -m option.
10710 This is on by default for the parameters in the zsh/pa‐
10711 rameter and zsh/mapfile modules. Note, however, that un‐
10712 like the -h flag this is also useful for non-special pa‐
10713 rameters.
10714
10715 -i [ n ]
10716 Use an internal integer representation. If n is nonzero
10717 it defines the output arithmetic base, otherwise it is
10718 determined by the first assignment. Bases from 2 to 36
10719 inclusive are allowed.
10720
10721 -E [ n ]
10722 Use an internal double-precision floating point represen‐
10723 tation. On output the variable will be converted to sci‐
10724 entific notation. If n is nonzero it defines the number
10725 of significant figures to display; the default is ten.
10726
10727 -F [ n ]
10728 Use an internal double-precision floating point represen‐
10729 tation. On output the variable will be converted to
10730 fixed-point decimal notation. If n is nonzero it defines
10731 the number of digits to display after the decimal point;
10732 the default is ten.
10733
10734 -l Convert the result to lower case whenever the parameter
10735 is expanded. The value is not converted when assigned.
10736
10737 -r The given names are marked readonly. Note that if name
10738 is a special parameter, the readonly attribute can be
10739 turned on, but cannot then be turned off.
10740
10741 If the POSIX_BUILTINS option is set, the readonly attri‐
10742 bute is more restrictive: unset variables can be marked
10743 readonly and cannot then be set; furthermore, the read‐
10744 only attribute cannot be removed from any variable.
10745
10746 It is still possible to change other attributes of the
10747 variable though, some of which like -U or -Z would affect
10748 the value. More generally, the readonly attribute should
10749 not be relied on as a security mechanism.
10750
10751 Note that in zsh (like in pdksh but unlike most other
10752 shells) it is still possible to create a local variable
10753 of the same name as this is considered a different vari‐
10754 able (though this variable, too, can be marked readonly).
10755 Special variables that have been made readonly retain
10756 their value and readonly attribute when made local.
10757
10758 -t Tags the named parameters. Tags have no special meaning
10759 to the shell. This flag has a different meaning when
10760 used with -f; see above.
10761
10762 -u Convert the result to upper case whenever the parameter
10763 is expanded. The value is not converted when assigned.
10764 This flag has a different meaning when used with -f; see
10765 above.
10766
10767 -x Mark for automatic export to the environment of subse‐
10768 quently executed commands. If the option GLOBAL_EXPORT
10769 is set, this implies the option -g, unless +g is also ex‐
10770 plicitly given; in other words the parameter is not made
10771 local to the enclosing function. This is for compatibil‐
10772 ity with previous versions of zsh.
10773
10774 ulimit [ -HSa ] [ { -bcdfiklmnpqrsTtvwx | -N resource } [ limit ] ... ]
10775 Set or display resource limits of the shell and the processes
10776 started by the shell. The value of limit can be a number in the
10777 unit specified below or one of the values `unlimited', which re‐
10778 moves the limit on the resource, or `hard', which uses the cur‐
10779 rent value of the hard limit on the resource.
10780
10781 By default, only soft limits are manipulated. If the -H flag is
10782 given use hard limits instead of soft limits. If the -S flag is
10783 given together with the -H flag set both hard and soft limits.
10784
10785 If no options are used, the file size limit (-f) is assumed.
10786
10787 If limit is omitted the current value of the specified resources
10788 are printed. When more than one resource value is printed, the
10789 limit name and unit is printed before each value.
10790
10791 When looping over multiple resources, the shell will abort imme‐
10792 diately if it detects a badly formed argument. However, if it
10793 fails to set a limit for some other reason it will continue try‐
10794 ing to set the remaining limits.
10795
10796 Not all the following resources are supported on all systems.
10797 Running ulimit -a will show which are supported.
10798
10799 -a Lists all of the current resource limits.
10800 -b Socket buffer size in bytes (N.B. not kilobytes)
10801 -c 512-byte blocks on the size of core dumps.
10802 -d Kilobytes on the size of the data segment.
10803 -f 512-byte blocks on the size of files written.
10804 -i The number of pending signals.
10805 -k The number of kqueues allocated.
10806 -l Kilobytes on the size of locked-in memory.
10807 -m Kilobytes on the size of physical memory.
10808 -n open file descriptors.
10809 -p The number of pseudo-terminals.
10810 -q Bytes in POSIX message queues.
10811 -r Maximum real time priority. On some systems where this
10812 is not available, such as NetBSD, this has the same ef‐
10813 fect as -T for compatibility with sh.
10814 -s Kilobytes on the size of the stack.
10815 -T The number of simultaneous threads available to the user.
10816 -t CPU seconds to be used.
10817 -u The number of processes available to the user.
10818 -v Kilobytes on the size of virtual memory. On some systems
10819 this refers to the limit called `address space'.
10820 -w Kilobytes on the size of swapped out memory.
10821 -x The number of locks on files.
10822
10823 A resource may also be specified by integer in the form `-N re‐
10824 source', where resource corresponds to the integer defined for
10825 the resource by the operating system. This may be used to set
10826 the limits for resources known to the shell which do not corre‐
10827 spond to option letters. Such limits will be shown by number in
10828 the output of `ulimit -a'.
10829
10830 The number may alternatively be out of the range of limits com‐
10831 piled into the shell. The shell will try to read or write the
10832 limit anyway, and will report an error if this fails.
10833
10834 umask [ -S ] [ mask ]
10835 The umask is set to mask. mask can be either an octal number or
10836 a symbolic value as described in the chmod(1) man page. If mask
10837 is omitted, the current value is printed. The -S option causes
10838 the mask to be printed as a symbolic value. Otherwise, the mask
10839 is printed as an octal number. Note that in the symbolic form
10840 the permissions you specify are those which are to be allowed
10841 (not denied) to the users specified.
10842
10843 unalias [ -ams ] name ...
10844 Removes aliases. This command works the same as unhash -a, ex‐
10845 cept that the -a option removes all regular or global aliases,
10846 or with -s all suffix aliases: in this case no name arguments
10847 may appear. The options -m (remove by pattern) and -s without
10848 -a (remove listed suffix aliases) behave as for unhash -a. Note
10849 that the meaning of -a is different between unalias and unhash.
10850
10851 unfunction
10852 Same as unhash -f.
10853
10854 unhash [ -adfms ] name ...
10855 Remove the element named name from an internal hash table. The
10856 default is remove elements from the command hash table. The -a
10857 option causes unhash to remove regular or global aliases; note
10858 when removing a global aliases that the argument must be quoted
10859 to prevent it from being expanded before being passed to the
10860 command. The -s option causes unhash to remove suffix aliases.
10861 The -f option causes unhash to remove shell functions. The -d
10862 options causes unhash to remove named directories. If the -m
10863 flag is given the arguments are taken as patterns (should be
10864 quoted) and all elements of the corresponding hash table with
10865 matching names will be removed.
10866
10867 unlimit [ -hs ] resource ...
10868 The resource limit for each resource is set to the hard limit.
10869 If the -h flag is given and the shell has appropriate privi‐
10870 leges, the hard resource limit for each resource is removed.
10871 The resources of the shell process are only changed if the -s
10872 flag is given.
10873
10874 The unlimit command is not made available by default when the
10875 shell starts in a mode emulating another shell. It can be made
10876 available with the command `zmodload -F zsh/rlimits b:unlimit'.
10877
10878 unset [ -fmv ] name ...
10879 Each named parameter is unset. Local parameters remain local
10880 even if unset; they appear unset within scope, but the previous
10881 value will still reappear when the scope ends.
10882
10883 Individual elements of associative array parameters may be unset
10884 by using subscript syntax on name, which should be quoted (or
10885 the entire command prefixed with noglob) to protect the sub‐
10886 script from filename generation.
10887
10888 If the -m flag is specified the arguments are taken as patterns
10889 (should be quoted) and all parameters with matching names are
10890 unset. Note that this cannot be used when unsetting associative
10891 array elements, as the subscript will be treated as part of the
10892 pattern.
10893
10894 The -v flag specifies that name refers to parameters. This is
10895 the default behaviour.
10896
10897 unset -f is equivalent to unfunction.
10898
10899 unsetopt [ {+|-}options | {+|-}o option_name ] [ name ... ]
10900 Unset the options for the shell. All options specified either
10901 with flags or by name are unset. If no arguments are supplied,
10902 the names of all options currently unset are printed. If the -m
10903 flag is given the arguments are taken as patterns (which should
10904 be quoted to preserve them from being interpreted as glob pat‐
10905 terns), and all options with names matching these patterns are
10906 unset.
10907
10908 vared See the section `Zle Builtins' in zshzle(1).
10909
10910 wait [ job ... ]
10911 Wait for the specified jobs or processes. If job is not given
10912 then all currently active child processes are waited for. Each
10913 job can be either a job specification or the process ID of a job
10914 in the job table. The exit status from this command is that of
10915 the job waited for. If job represents an unknown job or process
10916 ID, a warning is printed (unless the POSIX_BUILTINS option is
10917 set) and the exit status is 127.
10918
10919 It is possible to wait for recent processes (specified by
10920 process ID, not by job) that were running in the background even
10921 if the process has exited. Typically the process ID will be
10922 recorded by capturing the value of the variable $! immediately
10923 after the process has been started. There is a limit on the
10924 number of process IDs remembered by the shell; this is given by
10925 the value of the system configuration parameter CHILD_MAX. When
10926 this limit is reached, older process IDs are discarded, least
10927 recently started processes first.
10928
10929 Note there is no protection against the process ID wrapping,
10930 i.e. if the wait is not executed soon enough there is a chance
10931 the process waited for is the wrong one. A conflict implies
10932 both process IDs have been generated by the shell, as other pro‐
10933 cesses are not recorded, and that the user is potentially inter‐
10934 ested in both, so this problem is intrinsic to process IDs.
10935
10936 whence [ -vcwfpamsS ] [ -x num ] name ...
10937 For each name, indicate how it would be interpreted if used as a
10938 command name.
10939
10940 If name is not an alias, built-in command, external command,
10941 shell function, hashed command, or a reserved word, the exit
10942 status shall be non-zero, and -- if -v, -c, or -w was passed --
10943 a message will be written to standard output. (This is differ‐
10944 ent from other shells that write that message to standard er‐
10945 ror.)
10946
10947 whence is most useful when name is only the last path component
10948 of a command, i.e. does not include a `/'; in particular, pat‐
10949 tern matching only succeeds if just the non-directory component
10950 of the command is passed.
10951
10952 -v Produce a more verbose report.
10953
10954 -c Print the results in a csh-like format. This takes
10955 precedence over -v.
10956
10957 -w For each name, print `name: word' where word is one of
10958 alias, builtin, command, function, hashed, reserved or
10959 none, according as name corresponds to an alias, a
10960 built-in command, an external command, a shell function,
10961 a command defined with the hash builtin, a reserved word,
10962 or is not recognised. This takes precedence over -v and
10963 -c.
10964
10965 -f Causes the contents of a shell function to be displayed,
10966 which would otherwise not happen unless the -c flag were
10967 used.
10968
10969 -p Do a path search for name even if it is an alias, re‐
10970 served word, shell function or builtin.
10971
10972 -a Do a search for all occurrences of name throughout the
10973 command path. Normally only the first occurrence is
10974 printed.
10975
10976 -m The arguments are taken as patterns (pattern characters
10977 should be quoted), and the information is displayed for
10978 each command matching one of these patterns.
10979
10980 -s If a pathname contains symlinks, print the symlink-free
10981 pathname as well.
10982
10983 -S As -s, but if the pathname had to be resolved by follow‐
10984 ing multiple symlinks, the intermediate steps are
10985 printed, too. The symlink resolved at each step might be
10986 anywhere in the path.
10987
10988 -x num Expand tabs when outputting shell functions using the -c
10989 option. This has the same effect as the -x option to the
10990 functions builtin.
10991
10992 where [ -wpmsS ] [ -x num ] name ...
10993 Equivalent to whence -ca.
10994
10995 which [ -wpamsS ] [ -x num ] name ...
10996 Equivalent to whence -c.
10997
10998 zcompile [ -U ] [ -z | -k ] [ -R | -M ] file [ name ... ]
10999 zcompile -ca [ -m ] [ -R | -M ] file [ name ... ]
11000 zcompile -t file [ name ... ]
11001 This builtin command can be used to compile functions or
11002 scripts, storing the compiled form in a file, and to examine
11003 files containing the compiled form. This allows faster au‐
11004 toloading of functions and sourcing of scripts by avoiding pars‐
11005 ing of the text when the files are read.
11006
11007 The first form (without the -c, -a or -t options) creates a com‐
11008 piled file. If only the file argument is given, the output file
11009 has the name `file.zwc' and will be placed in the same directory
11010 as the file. The shell will load the compiled file instead of
11011 the normal function file when the function is autoloaded; see
11012 the section `Autoloading Functions' in zshmisc(1) for a descrip‐
11013 tion of how autoloaded functions are searched. The extension
11014 .zwc stands for `zsh word code'.
11015
11016 If there is at least one name argument, all the named files are
11017 compiled into the output file given as the first argument. If
11018 file does not end in .zwc, this extension is automatically ap‐
11019 pended. Files containing multiple compiled functions are called
11020 `digest' files, and are intended to be used as elements of the
11021 FPATH/fpath special array.
11022
11023 The second form, with the -c or -a options, writes the compiled
11024 definitions for all the named functions into file. For -c, the
11025 names must be functions currently defined in the shell, not
11026 those marked for autoloading. Undefined functions that are
11027 marked for autoloading may be written by using the -a option, in
11028 which case the fpath is searched and the contents of the defini‐
11029 tion files for those functions, if found, are compiled into
11030 file. If both -c and -a are given, names of both defined func‐
11031 tions and functions marked for autoloading may be given. In ei‐
11032 ther case, the functions in files written with the -c or -a op‐
11033 tion will be autoloaded as if the KSH_AUTOLOAD option were un‐
11034 set.
11035
11036 The reason for handling loaded and not-yet-loaded functions with
11037 different options is that some definition files for autoloading
11038 define multiple functions, including the function with the same
11039 name as the file, and, at the end, call that function. In such
11040 cases the output of `zcompile -c' does not include the addi‐
11041 tional functions defined in the file, and any other initializa‐
11042 tion code in the file is lost. Using `zcompile -a' captures all
11043 this extra information.
11044
11045 If the -m option is combined with -c or -a, the names are used
11046 as patterns and all functions whose names match one of these
11047 patterns will be written. If no name is given, the definitions
11048 of all functions currently defined or marked as autoloaded will
11049 be written.
11050
11051 Note the second form cannot be used for compiling functions that
11052 include redirections as part of the definition rather than
11053 within the body of the function; for example
11054
11055 fn1() { { ... } >~/logfile }
11056
11057 can be compiled but
11058
11059 fn1() { ... } >~/logfile
11060
11061 cannot. It is possible to use the first form of zcompile to
11062 compile autoloadable functions that include the full function
11063 definition instead of just the body of the function.
11064
11065 The third form, with the -t option, examines an existing com‐
11066 piled file. Without further arguments, the names of the origi‐
11067 nal files compiled into it are listed. The first line of output
11068 shows the version of the shell which compiled the file and how
11069 the file will be used (i.e. by reading it directly or by mapping
11070 it into memory). With arguments, nothing is output and the re‐
11071 turn status is set to zero if definitions for all names were
11072 found in the compiled file, and non-zero if the definition for
11073 at least one name was not found.
11074
11075 Other options:
11076
11077 -U Aliases are not expanded when compiling the named files.
11078
11079 -R When the compiled file is read, its contents are copied
11080 into the shell's memory, rather than memory-mapped (see
11081 -M). This happens automatically on systems that do not
11082 support memory mapping.
11083
11084 When compiling scripts instead of autoloadable functions,
11085 it is often desirable to use this option; otherwise the
11086 whole file, including the code to define functions which
11087 have already been defined, will remain mapped, conse‐
11088 quently wasting memory.
11089
11090 -M The compiled file is mapped into the shell's memory when
11091 read. This is done in such a way that multiple instances
11092 of the shell running on the same host will share this
11093 mapped file. If neither -R nor -M is given, the zcompile
11094 builtin decides what to do based on the size of the com‐
11095 piled file.
11096
11097 -k
11098 -z These options are used when the compiled file contains
11099 functions which are to be autoloaded. If -z is given, the
11100 function will be autoloaded as if the KSH_AUTOLOAD option
11101 is not set, even if it is set at the time the compiled
11102 file is read, while if the -k is given, the function will
11103 be loaded as if KSH_AUTOLOAD is set. These options also
11104 take precedence over any -k or -z options specified to
11105 the autoload builtin. If neither of these options is
11106 given, the function will be loaded as determined by the
11107 setting of the KSH_AUTOLOAD option at the time the com‐
11108 piled file is read.
11109
11110 These options may also appear as many times as necessary
11111 between the listed names to specify the loading style of
11112 all following functions, up to the next -k or -z.
11113
11114 The created file always contains two versions of the com‐
11115 piled format, one for big-endian machines and one for
11116 small-endian machines. The upshot of this is that the
11117 compiled file is machine independent and if it is read or
11118 mapped, only one half of the file is actually used (and
11119 mapped).
11120
11121 zformat
11122 See the section `The zsh/zutil Module' in zshmodules(1).
11123
11124 zftp See the section `The zsh/zftp Module' in zshmodules(1).
11125
11126 zle See the section `Zle Builtins' in zshzle(1).
11127
11128 zmodload [ -dL ] [ -s ] [ ... ]
11129 zmodload -F [ -alLme -P param ] module [ [+-]feature ... ]
11130 zmodload -e [ -A ] [ ... ]
11131 zmodload [ -a [ -bcpf [ -I ] ] ] [ -iL ] ...
11132 zmodload -u [ -abcdpf [ -I ] ] [ -iL ] ...
11133 zmodload -A [ -L ] [ modalias[=module] ... ]
11134 zmodload -R modalias ...
11135 Performs operations relating to zsh's loadable modules. Loading
11136 of modules while the shell is running (`dynamical loading') is
11137 not available on all operating systems, or on all installations
11138 on a particular operating system, although the zmodload command
11139 itself is always available and can be used to manipulate modules
11140 built into versions of the shell executable without dynamical
11141 loading.
11142
11143 Without arguments the names of all currently loaded binary mod‐
11144 ules are printed. The -L option causes this list to be in the
11145 form of a series of zmodload commands. Forms with arguments
11146 are:
11147
11148 zmodload [ -is ] name ...
11149 zmodload -u [ -i ] name ...
11150 In the simplest case, zmodload loads a binary module.
11151 The module must be in a file with a name consisting of
11152 the specified name followed by a standard suffix, usually
11153 `.so' (`.sl' on HPUX). If the module to be loaded is al‐
11154 ready loaded the duplicate module is ignored. If zmod‐
11155 load detects an inconsistency, such as an invalid module
11156 name or circular dependency list, the current code block
11157 is aborted. If it is available, the module is loaded if
11158 necessary, while if it is not available, non-zero status
11159 is silently returned. The option -i is accepted for com‐
11160 patibility but has no effect.
11161
11162 The named module is searched for in the same way a com‐
11163 mand is, using $module_path instead of $path. However,
11164 the path search is performed even when the module name
11165 contains a `/', which it usually does. There is no way
11166 to prevent the path search.
11167
11168 If the module supports features (see below), zmodload
11169 tries to enable all features when loading a module. If
11170 the module was successfully loaded but not all features
11171 could be enabled, zmodload returns status 2.
11172
11173 If the option -s is given, no error is printed if the
11174 module was not available (though other errors indicating
11175 a problem with the module are printed). The return sta‐
11176 tus indicates if the module was loaded. This is appro‐
11177 priate if the caller considers the module optional.
11178
11179 With -u, zmodload unloads modules. The same name must be
11180 given that was given when the module was loaded, but it
11181 is not necessary for the module to exist in the file sys‐
11182 tem. The -i option suppresses the error if the module is
11183 already unloaded (or was never loaded).
11184
11185 Each module has a boot and a cleanup function. The mod‐
11186 ule will not be loaded if its boot function fails. Simi‐
11187 larly a module can only be unloaded if its cleanup func‐
11188 tion runs successfully.
11189
11190 zmodload -F [ -almLe -P param ] module [ [+-]feature ... ]
11191 zmodload -F allows more selective control over the fea‐
11192 tures provided by modules. With no options apart from
11193 -F, the module named module is loaded, if it was not al‐
11194 ready loaded, and the list of features is set to the re‐
11195 quired state. If no features are specified, the module
11196 is loaded, if it was not already loaded, but the state of
11197 features is unchanged. Each feature may be preceded by a
11198 + to turn the feature on, or - to turn it off; the + is
11199 assumed if neither character is present. Any feature not
11200 explicitly mentioned is left in its current state; if the
11201 module was not previously loaded this means any such fea‐
11202 tures will remain disabled. The return status is zero if
11203 all features were set, 1 if the module failed to load,
11204 and 2 if some features could not be set (for example, a
11205 parameter couldn't be added because there was a different
11206 parameter of the same name) but the module was loaded.
11207
11208 The standard features are builtins, conditions, parame‐
11209 ters and math functions; these are indicated by the pre‐
11210 fix `b:', `c:' (`C:' for an infix condition), `p:' and
11211 `f:', respectively, followed by the name that the corre‐
11212 sponding feature would have in the shell. For example,
11213 `b:strftime' indicates a builtin named strftime and
11214 p:EPOCHSECONDS indicates a parameter named EPOCHSECONDS.
11215 The module may provide other (`abstract') features of its
11216 own as indicated by its documentation; these have no pre‐
11217 fix.
11218
11219 With -l or -L, features provided by the module are
11220 listed. With -l alone, a list of features together with
11221 their states is shown, one feature per line. With -L
11222 alone, a zmodload -F command that would cause enabled
11223 features of the module to be turned on is shown. With
11224 -lL, a zmodload -F command that would cause all the fea‐
11225 tures to be set to their current state is shown. If one
11226 of these combinations is given with the option -P param
11227 then the parameter param is set to an array of features,
11228 either features together with their state or (if -L alone
11229 is given) enabled features.
11230
11231 With the option -L the module name may be omitted; then a
11232 list of all enabled features for all modules providing
11233 features is printed in the form of zmodload -F commands.
11234 If -l is also given, the state of both enabled and dis‐
11235 abled features is output in that form.
11236
11237 A set of features may be provided together with -l or -L
11238 and a module name; in that case only the state of those
11239 features is considered. Each feature may be preceded by
11240 + or - but the character has no effect. If no set of
11241 features is provided, all features are considered.
11242
11243 With -e, the command first tests that the module is
11244 loaded; if it is not, status 1 is returned. If the mod‐
11245 ule is loaded, the list of features given as an argument
11246 is examined. Any feature given with no prefix is simply
11247 tested to see if the module provides it; any feature
11248 given with a prefix + or - is tested to see if is pro‐
11249 vided and in the given state. If the tests on all fea‐
11250 tures in the list succeed, status 0 is returned, else
11251 status 1.
11252
11253 With -m, each entry in the given list of features is
11254 taken as a pattern to be matched against the list of fea‐
11255 tures provided by the module. An initial + or - must be
11256 given explicitly. This may not be combined with the -a
11257 option as autoloads must be specified explicitly.
11258
11259 With -a, the given list of features is marked for au‐
11260 toload from the specified module, which may not yet be
11261 loaded. An optional + may appear before the feature
11262 name. If the feature is prefixed with -, any existing
11263 autoload is removed. The options -l and -L may be used
11264 to list autoloads. Autoloading is specific to individual
11265 features; when the module is loaded only the requested
11266 feature is enabled. Autoload requests are preserved if
11267 the module is subsequently unloaded until an explicit
11268 `zmodload -Fa module -feature' is issued. It is not an
11269 error to request an autoload for a feature of a module
11270 that is already loaded.
11271
11272 When the module is loaded each autoload is checked
11273 against the features actually provided by the module; if
11274 the feature is not provided the autoload request is
11275 deleted. A warning message is output; if the module is
11276 being loaded to provide a different feature, and that au‐
11277 toload is successful, there is no effect on the status of
11278 the current command. If the module is already loaded at
11279 the time when zmodload -Fa is run, an error message is
11280 printed and status 1 returned.
11281
11282 zmodload -Fa can be used with the -l, -L, -e and -P op‐
11283 tions for listing and testing the existence of autoload‐
11284 able features. In this case -l is ignored if -L is spec‐
11285 ified. zmodload -FaL with no module name lists autoloads
11286 for all modules.
11287
11288 Note that only standard features as described above can
11289 be autoloaded; other features require the module to be
11290 loaded before enabling.
11291
11292 zmodload -d [ -L ] [ name ]
11293 zmodload -d name dep ...
11294 zmodload -ud name [ dep ... ]
11295 The -d option can be used to specify module dependencies.
11296 The modules named in the second and subsequent arguments
11297 will be loaded before the module named in the first argu‐
11298 ment.
11299
11300 With -d and one argument, all dependencies for that mod‐
11301 ule are listed. With -d and no arguments, all module de‐
11302 pendencies are listed. This listing is by default in a
11303 Makefile-like format. The -L option changes this format
11304 to a list of zmodload -d commands.
11305
11306 If -d and -u are both used, dependencies are removed. If
11307 only one argument is given, all dependencies for that
11308 module are removed.
11309
11310 zmodload -ab [ -L ]
11311 zmodload -ab [ -i ] name [ builtin ... ]
11312 zmodload -ub [ -i ] builtin ...
11313 The -ab option defines autoloaded builtins. It defines
11314 the specified builtins. When any of those builtins is
11315 called, the module specified in the first argument is
11316 loaded and all its features are enabled (for selective
11317 control of features use `zmodload -F -a' as described
11318 above). If only the name is given, one builtin is de‐
11319 fined, with the same name as the module. -i suppresses
11320 the error if the builtin is already defined or au‐
11321 toloaded, but not if another builtin of the same name is
11322 already defined.
11323
11324 With -ab and no arguments, all autoloaded builtins are
11325 listed, with the module name (if different) shown in
11326 parentheses after the builtin name. The -L option
11327 changes this format to a list of zmodload -a commands.
11328
11329 If -b is used together with the -u option, it removes
11330 builtins previously defined with -ab. This is only pos‐
11331 sible if the builtin is not yet loaded. -i suppresses
11332 the error if the builtin is already removed (or never ex‐
11333 isted).
11334
11335 Autoload requests are retained if the module is subse‐
11336 quently unloaded until an explicit `zmodload -ub builtin'
11337 is issued.
11338
11339 zmodload -ac [ -IL ]
11340 zmodload -ac [ -iI ] name [ cond ... ]
11341 zmodload -uc [ -iI ] cond ...
11342 The -ac option is used to define autoloaded condition
11343 codes. The cond strings give the names of the conditions
11344 defined by the module. The optional -I option is used to
11345 define infix condition names. Without this option prefix
11346 condition names are defined.
11347
11348 If given no condition names, all defined names are listed
11349 (as a series of zmodload commands if the -L option is
11350 given).
11351
11352 The -uc option removes definitions for autoloaded condi‐
11353 tions.
11354
11355 zmodload -ap [ -L ]
11356 zmodload -ap [ -i ] name [ parameter ... ]
11357 zmodload -up [ -i ] parameter ...
11358 The -p option is like the -b and -c options, but makes
11359 zmodload work on autoloaded parameters instead.
11360
11361 zmodload -af [ -L ]
11362 zmodload -af [ -i ] name [ function ... ]
11363 zmodload -uf [ -i ] function ...
11364 The -f option is like the -b, -p, and -c options, but
11365 makes zmodload work on autoloaded math functions instead.
11366
11367 zmodload -a [ -L ]
11368 zmodload -a [ -i ] name [ builtin ... ]
11369 zmodload -ua [ -i ] builtin ...
11370 Equivalent to -ab and -ub.
11371
11372 zmodload -e [ -A ] [ string ... ]
11373 The -e option without arguments lists all loaded modules;
11374 if the -A option is also given, module aliases corre‐
11375 sponding to loaded modules are also shown. If arguments
11376 are provided, nothing is printed; the return status is
11377 set to zero if all strings given as arguments are names
11378 of loaded modules and to one if at least on string is not
11379 the name of a loaded module. This can be used to test
11380 for the availability of things implemented by modules.
11381 In this case, any aliases are automatically resolved and
11382 the -A flag is not used.
11383
11384 zmodload -A [ -L ] [ modalias[=module] ... ]
11385 For each argument, if both modalias and module are given,
11386 define modalias to be an alias for the module module. If
11387 the module modalias is ever subsequently requested, ei‐
11388 ther via a call to zmodload or implicitly, the shell will
11389 attempt to load module instead. If module is not given,
11390 show the definition of modalias. If no arguments are
11391 given, list all defined module aliases. When listing, if
11392 the -L flag was also given, list the definition as a
11393 zmodload command to recreate the alias.
11394
11395 The existence of aliases for modules is completely inde‐
11396 pendent of whether the name resolved is actually loaded
11397 as a module: while the alias exists, loading and unload‐
11398 ing the module under any alias has exactly the same ef‐
11399 fect as using the resolved name, and does not affect the
11400 connection between the alias and the resolved name which
11401 can be removed either by zmodload -R or by redefining the
11402 alias. Chains of aliases (i.e. where the first resolved
11403 name is itself an alias) are valid so long as these are
11404 not circular. As the aliases take the same format as
11405 module names, they may include path separators: in this
11406 case, there is no requirement for any part of the path
11407 named to exist as the alias will be resolved first. For
11408 example, `any/old/alias' is always a valid alias.
11409
11410 Dependencies added to aliased modules are actually added
11411 to the resolved module; these remain if the alias is re‐
11412 moved. It is valid to create an alias whose name is one
11413 of the standard shell modules and which resolves to a
11414 different module. However, if a module has dependencies,
11415 it will not be possible to use the module name as an
11416 alias as the module will already be marked as a loadable
11417 module in its own right.
11418
11419 Apart from the above, aliases can be used in the zmodload
11420 command anywhere module names are required. However,
11421 aliases will not be shown in lists of loaded modules with
11422 a bare `zmodload'.
11423
11424 zmodload -R modalias ...
11425 For each modalias argument that was previously defined as
11426 a module alias via zmodload -A, delete the alias. If any
11427 was not defined, an error is caused and the remainder of
11428 the line is ignored.
11429
11430 Note that zsh makes no distinction between modules that were
11431 linked into the shell and modules that are loaded dynamically.
11432 In both cases this builtin command has to be used to make avail‐
11433 able the builtins and other things defined by modules (unless
11434 the module is autoloaded on these definitions). This is true
11435 even for systems that don't support dynamic loading of modules.
11436
11437 zparseopts
11438 See the section `The zsh/zutil Module' in zshmodules(1).
11439
11440 zprof See the section `The zsh/zprof Module' in zshmodules(1).
11441
11442 zpty See the section `The zsh/zpty Module' in zshmodules(1).
11443
11444 zregexparse
11445 See the section `The zsh/zutil Module' in zshmodules(1).
11446
11447 zsocket
11448 See the section `The zsh/net/socket Module' in zshmodules(1).
11449
11450 zstyle See the section `The zsh/zutil Module' in zshmodules(1).
11451
11452 ztcp See the section `The zsh/net/tcp Module' in zshmodules(1).
11453
11454
11455
11456ZSHZLE(1) General Commands Manual ZSHZLE(1)
11457
11458
11459
11461 zshzle - zsh command line editor
11462
11464 If the ZLE option is set (which it is by default in interactive shells)
11465 and the shell input is attached to the terminal, the user is able to
11466 edit command lines.
11467
11468 There are two display modes. The first, multiline mode, is the de‐
11469 fault. It only works if the TERM parameter is set to a valid terminal
11470 type that can move the cursor up. The second, single line mode, is
11471 used if TERM is invalid or incapable of moving the cursor up, or if the
11472 SINGLE_LINE_ZLE option is set. This mode is similar to ksh, and uses
11473 no termcap sequences. If TERM is "emacs", the ZLE option will be unset
11474 by default.
11475
11476 The parameters BAUD, COLUMNS, and LINES are also used by the line edi‐
11477 tor. See Parameters Used By The Shell in zshparam(1).
11478
11479 The parameter zle_highlight is also used by the line editor; see Char‐
11480 acter Highlighting below. Highlighting of special characters and the
11481 region between the cursor and the mark (as set with set-mark-command in
11482 Emacs mode, or by visual-mode in Vi mode) is enabled by default; con‐
11483 sult this reference for more information. Irascible conservatives will
11484 wish to know that all highlighting may be disabled by the following
11485 setting:
11486
11487 zle_highlight=(none)
11488
11489 In many places, references are made to the numeric argument. This can
11490 by default be entered in emacs mode by holding the alt key and typing a
11491 number, or pressing escape before each digit, and in vi command mode by
11492 typing the number before entering a command. Generally the numeric ar‐
11493 gument causes the next command entered to be repeated the specified
11494 number of times, unless otherwise noted below; this is implemented by
11495 the digit-argument widget. See also the Arguments subsection of the
11496 Widgets section for some other ways the numeric argument can be modi‐
11497 fied.
11498
11500 A keymap in ZLE contains a set of bindings between key sequences and
11501 ZLE commands. The empty key sequence cannot be bound.
11502
11503 There can be any number of keymaps at any time, and each keymap has one
11504 or more names. If all of a keymap's names are deleted, it disappears.
11505 bindkey can be used to manipulate keymap names.
11506
11507 Initially, there are eight keymaps:
11508
11509 emacs EMACS emulation
11510 viins vi emulation - insert mode
11511 vicmd vi emulation - command mode
11512 viopp vi emulation - operator pending
11513 visual vi emulation - selection active
11514 isearch
11515 incremental search mode
11516 command
11517 read a command name
11518 .safe fallback keymap
11519
11520 The `.safe' keymap is special. It can never be altered, and the name
11521 can never be removed. However, it can be linked to other names, which
11522 can be removed. In the future other special keymaps may be added;
11523 users should avoid using names beginning with `.' for their own
11524 keymaps.
11525
11526 In addition to these names, either `emacs' or `viins' is also linked to
11527 the name `main'. If one of the VISUAL or EDITOR environment variables
11528 contain the string `vi' when the shell starts up then it will be `vi‐
11529 ins', otherwise it will be `emacs'. bindkey's -e and -v options pro‐
11530 vide a convenient way to override this default choice.
11531
11532 When the editor starts up, it will select the `main' keymap. If that
11533 keymap doesn't exist, it will use `.safe' instead.
11534
11535 In the `.safe' keymap, each single key is bound to self-insert, except
11536 for ^J (line feed) and ^M (return) which are bound to accept-line.
11537 This is deliberately not pleasant to use; if you are using it, it means
11538 you deleted the main keymap, and you should put it back.
11539
11540 Reading Commands
11541 When ZLE is reading a command from the terminal, it may read a sequence
11542 that is bound to some command and is also a prefix of a longer bound
11543 string. In this case ZLE will wait a certain time to see if more char‐
11544 acters are typed, and if not (or they don't match any longer string) it
11545 will execute the binding. This timeout is defined by the KEYTIMEOUT
11546 parameter; its default is 0.4 sec. There is no timeout if the prefix
11547 string is not itself bound to a command.
11548
11549 The key timeout is also applied when ZLE is reading the bytes from a
11550 multibyte character string when it is in the appropriate mode. (This
11551 requires that the shell was compiled with multibyte mode enabled; typi‐
11552 cally also the locale has characters with the UTF-8 encoding, although
11553 any multibyte encoding known to the operating system is supported.) If
11554 the second or a subsequent byte is not read within the timeout period,
11555 the shell acts as if ? were typed and resets the input state.
11556
11557 As well as ZLE commands, key sequences can be bound to other strings,
11558 by using `bindkey -s'. When such a sequence is read, the replacement
11559 string is pushed back as input, and the command reading process starts
11560 again using these fake keystrokes. This input can itself invoke fur‐
11561 ther replacement strings, but in order to detect loops the process will
11562 be stopped if there are twenty such replacements without a real command
11563 being read.
11564
11565 A key sequence typed by the user can be turned into a command name for
11566 use in user-defined widgets with the read-command widget, described in
11567 the subsection `Miscellaneous' of the section `Standard Widgets' below.
11568
11569 Local Keymaps
11570 While for normal editing a single keymap is used exclusively, in many
11571 modes a local keymap allows for some keys to be customised. For exam‐
11572 ple, in an incremental search mode, a binding in the isearch keymap
11573 will override a binding in the main keymap but all keys that are not
11574 overridden can still be used.
11575
11576 If a key sequence is defined in a local keymap, it will hide a key se‐
11577 quence in the global keymap that is a prefix of that sequence. An exam‐
11578 ple of this occurs with the binding of iw in viopp as this hides the
11579 binding of i in vicmd. However, a longer sequence in the global keymap
11580 that shares the same prefix can still apply so for example the binding
11581 of ^Xa in the global keymap will be unaffected by the binding of ^Xb in
11582 the local keymap.
11583
11585 The ZLE module contains three related builtin commands. The bindkey
11586 command manipulates keymaps and key bindings; the vared command invokes
11587 ZLE on the value of a shell parameter; and the zle command manipulates
11588 editing widgets and allows command line access to ZLE commands from
11589 within shell functions.
11590
11591 bindkey [ options ] -l [ -L ] [ keymap ... ]
11592 bindkey [ options ] -d
11593 bindkey [ options ] -D keymap ...
11594 bindkey [ options ] -A old-keymap new-keymap
11595 bindkey [ options ] -N new-keymap [ old-keymap ]
11596 bindkey [ options ] -m
11597 bindkey [ options ] -r in-string ...
11598 bindkey [ options ] -s in-string out-string ...
11599 bindkey [ options ] in-string command ...
11600 bindkey [ options ] [ in-string ]
11601 bindkey's options can be divided into three categories: keymap
11602 selection for the current command, operation selection, and oth‐
11603 ers. The keymap selection options are:
11604
11605 -e Selects keymap `emacs' for any operations by the current
11606 command, and also links `emacs' to `main' so that it is
11607 selected by default the next time the editor starts.
11608
11609 -v Selects keymap `viins' for any operations by the current
11610 command, and also links `viins' to `main' so that it is
11611 selected by default the next time the editor starts.
11612
11613 -a Selects keymap `vicmd' for any operations by the current
11614 command.
11615
11616 -M keymap
11617 The keymap specifies a keymap name that is selected for
11618 any operations by the current command.
11619
11620 If a keymap selection is required and none of the options above
11621 are used, the `main' keymap is used. Some operations do not
11622 permit a keymap to be selected, namely:
11623
11624 -l List all existing keymap names; if any arguments are
11625 given, list just those keymaps.
11626
11627 If the -L option is also used, list in the form of bind‐
11628 key commands to create or link the keymaps. `bindkey -lL
11629 main' shows which keymap is linked to `main', if any, and
11630 hence if the standard emacs or vi emulation is in effect.
11631 This option does not show the .safe keymap because it
11632 cannot be created in that fashion; however, neither is
11633 `bindkey -lL .safe' reported as an error, it simply out‐
11634 puts nothing.
11635
11636 -d Delete all existing keymaps and reset to the default
11637 state.
11638
11639 -D keymap ...
11640 Delete the named keymaps.
11641
11642 -A old-keymap new-keymap
11643 Make the new-keymap name an alias for old-keymap, so that
11644 both names refer to the same keymap. The names have
11645 equal standing; if either is deleted, the other remains.
11646 If there is already a keymap with the new-keymap name, it
11647 is deleted.
11648
11649 -N new-keymap [ old-keymap ]
11650 Create a new keymap, named new-keymap. If a keymap al‐
11651 ready has that name, it is deleted. If an old-keymap
11652 name is given, the new keymap is initialized to be a du‐
11653 plicate of it, otherwise the new keymap will be empty.
11654
11655 To use a newly created keymap, it should be linked to main.
11656 Hence the sequence of commands to create and use a new keymap
11657 `mymap' initialized from the emacs keymap (which remains un‐
11658 changed) is:
11659
11660 bindkey -N mymap emacs
11661 bindkey -A mymap main
11662
11663 Note that while `bindkey -A newmap main' will work when newmap
11664 is emacs or viins, it will not work for vicmd, as switching from
11665 vi insert to command mode becomes impossible.
11666
11667 The following operations act on the `main' keymap if no keymap
11668 selection option was given:
11669
11670 -m Add the built-in set of meta-key bindings to the selected
11671 keymap. Only keys that are unbound or bound to self-in‐
11672 sert are affected.
11673
11674 -r in-string ...
11675 Unbind the specified in-strings in the selected keymap.
11676 This is exactly equivalent to binding the strings to un‐
11677 defined-key.
11678
11679 When -R is also used, interpret the in-strings as ranges.
11680
11681 When -p is also used, the in-strings specify prefixes.
11682 Any binding that has the given in-string as a prefix, not
11683 including the binding for the in-string itself, if any,
11684 will be removed. For example,
11685
11686 bindkey -rpM viins '^['
11687
11688 will remove all bindings in the vi-insert keymap begin‐
11689 ning with an escape character (probably cursor keys), but
11690 leave the binding for the escape character itself (proba‐
11691 bly vi-cmd-mode). This is incompatible with the option
11692 -R.
11693
11694 -s in-string out-string ...
11695 Bind each in-string to each out-string. When in-string
11696 is typed, out-string will be pushed back and treated as
11697 input to the line editor. When -R is also used, inter‐
11698 pret the in-strings as ranges.
11699
11700 Note that both in-string and out-string are subject to
11701 the same form of interpretation, as described below.
11702
11703 in-string command ...
11704 Bind each in-string to each command. When -R is used,
11705 interpret the in-strings as ranges.
11706
11707 [ in-string ]
11708 List key bindings. If an in-string is specified, the
11709 binding of that string in the selected keymap is dis‐
11710 played. Otherwise, all key bindings in the selected
11711 keymap are displayed. (As a special case, if the -e or
11712 -v option is used alone, the keymap is not displayed -
11713 the implicit linking of keymaps is the only thing that
11714 happens.)
11715
11716 When the option -p is used, the in-string must be
11717 present. The listing shows all bindings which have the
11718 given key sequence as a prefix, not including any bind‐
11719 ings for the key sequence itself.
11720
11721 When the -L option is used, the list is in the form of
11722 bindkey commands to create the key bindings.
11723
11724 When the -R option is used as noted above, a valid range con‐
11725 sists of two characters, with an optional `-' between them. All
11726 characters between the two specified, inclusive, are bound as
11727 specified.
11728
11729 For either in-string or out-string, the following escape se‐
11730 quences are recognised:
11731
11732 \a bell character
11733 \b backspace
11734 \e, \E escape
11735 \f form feed
11736 \n linefeed (newline)
11737 \r carriage return
11738 \t horizontal tab
11739 \v vertical tab
11740 \NNN character code in octal
11741 \xNN character code in hexadecimal
11742 \uNNNN unicode character code in hexadecimal
11743 \UNNNNNNNN
11744 unicode character code in hexadecimal
11745 \M[-]X character with meta bit set
11746 \C[-]X control character
11747 ^X control character
11748
11749 In all other cases, `\' escapes the following character. Delete
11750 is written as `^?'. Note that `\M^?' and `^\M?' are not the
11751 same, and that (unlike emacs), the bindings `\M-X' and `\eX' are
11752 entirely distinct, although they are initialized to the same
11753 bindings by `bindkey -m'.
11754
11755
11756 vared [ -Aacghe ] [ -p prompt ] [ -r rprompt ]
11757 [ -M main-keymap ] [ -m vicmd-keymap ]
11758 [ -i init-widget ] [ -f finish-widget ]
11759 [ -t tty ] name
11760 The value of the parameter name is loaded into the edit buffer,
11761 and the line editor is invoked. When the editor exits, name is
11762 set to the string value returned by the editor. When the -c
11763 flag is given, the parameter is created if it doesn't already
11764 exist. The -a flag may be given with -c to create an array pa‐
11765 rameter, or the -A flag to create an associative array. If the
11766 type of an existing parameter does not match the type to be cre‐
11767 ated, the parameter is unset and recreated. The -g flag may be
11768 given to suppress warnings from the WARN_CREATE_GLOBAL and
11769 WARN_NESTED_VAR options.
11770
11771 If an array or array slice is being edited, separator characters
11772 as defined in $IFS will be shown quoted with a backslash, as
11773 will backslashes themselves. Conversely, when the edited text
11774 is split into an array, a backslash quotes an immediately fol‐
11775 lowing separator character or backslash; no other special han‐
11776 dling of backslashes, or any handling of quotes, is performed.
11777
11778 Individual elements of existing array or associative array pa‐
11779 rameters may be edited by using subscript syntax on name. New
11780 elements are created automatically, even without -c.
11781
11782 If the -p flag is given, the following string will be taken as
11783 the prompt to display at the left. If the -r flag is given, the
11784 following string gives the prompt to display at the right. If
11785 the -h flag is specified, the history can be accessed from ZLE.
11786 If the -e flag is given, typing ^D (Control-D) on an empty line
11787 causes vared to exit immediately with a non-zero return value.
11788
11789 The -M option gives a keymap to link to the main keymap during
11790 editing, and the -m option gives a keymap to link to the vicmd
11791 keymap during editing. For vi-style editing, this allows a pair
11792 of keymaps to override viins and vicmd. For emacs-style edit‐
11793 ing, only -M is normally needed but the -m option may still be
11794 used. On exit, the previous keymaps will be restored.
11795
11796 Vared calls the usual `zle-line-init' and `zle-line-finish'
11797 hooks before and after it takes control. Using the -i and -f op‐
11798 tions, it is possible to replace these with other custom wid‐
11799 gets.
11800
11801 If `-t tty' is given, tty is the name of a terminal device to be
11802 used instead of the default /dev/tty. If tty does not refer to
11803 a terminal an error is reported.
11804
11805 zle
11806 zle -l [ -L | -a ] [ string ... ]
11807 zle -D widget ...
11808 zle -A old-widget new-widget
11809 zle -N widget [ function ]
11810 zle -f flag [ flag... ]
11811 zle -C widget completion-widget function
11812 zle -R [ -c ] [ display-string ] [ string ... ]
11813 zle -M string
11814 zle -U string
11815 zle -K keymap
11816 zle -F [ -L | -w ] [ fd [ handler ] ]
11817 zle -I
11818 zle -T [ tc function | -r tc | -L ]
11819 zle widget [ -n num ] [ -f flag ] [ -Nw ] [ -K keymap ] args ...
11820 The zle builtin performs a number of different actions concern‐
11821 ing ZLE.
11822
11823 With no options and no arguments, only the return status will be
11824 set. It is zero if ZLE is currently active and widgets could be
11825 invoked using this builtin command and non-zero otherwise. Note
11826 that even if non-zero status is returned, zle may still be ac‐
11827 tive as part of the completion system; this does not allow di‐
11828 rect calls to ZLE widgets.
11829
11830 Otherwise, which operation it performs depends on its options:
11831
11832 -l [ -L | -a ] [ string ]
11833 List all existing user-defined widgets. If the -L option
11834 is used, list in the form of zle commands to create the
11835 widgets.
11836
11837 When combined with the -a option, all widget names are
11838 listed, including the builtin ones. In this case the -L
11839 option is ignored.
11840
11841 If at least one string is given, and -a is present or -L
11842 is not used, nothing will be printed. The return status
11843 will be zero if all strings are names of existing widgets
11844 and non-zero if at least one string is not a name of a
11845 defined widget. If -a is also present, all widget names
11846 are used for the comparison including builtin widgets,
11847 else only user-defined widgets are used.
11848
11849 If at least one string is present and the -L option is
11850 used, user-defined widgets matching any string are listed
11851 in the form of zle commands to create the widgets.
11852
11853 -D widget ...
11854 Delete the named widgets.
11855
11856 -A old-widget new-widget
11857 Make the new-widget name an alias for old-widget, so that
11858 both names refer to the same widget. The names have
11859 equal standing; if either is deleted, the other remains.
11860 If there is already a widget with the new-widget name, it
11861 is deleted.
11862
11863 -N widget [ function ]
11864 Create a user-defined widget. If there is already a wid‐
11865 get with the specified name, it is overwritten. When the
11866 new widget is invoked from within the editor, the speci‐
11867 fied shell function is called. If no function name is
11868 specified, it defaults to the same name as the widget.
11869 For further information, see the section `Widgets' below.
11870
11871 -f flag [ flag... ]
11872 Set various flags on the running widget. Possible values
11873 for flag are:
11874
11875 yank for indicating that the widget has yanked text into
11876 the buffer. If the widget is wrapping an existing inter‐
11877 nal widget, no further action is necessary, but if it has
11878 inserted the text manually, then it should also take care
11879 to set YANK_START and YANK_END correctly. yankbefore
11880 does the same but is used when the yanked text appears
11881 after the cursor.
11882
11883 kill for indicating that text has been killed into the
11884 cutbuffer. When repeatedly invoking a kill widget, text
11885 is appended to the cutbuffer instead of replacing it, but
11886 when wrapping such widgets, it is necessary to call `zle
11887 -f kill' to retain this effect.
11888
11889 vichange for indicating that the widget represents a vi
11890 change that can be repeated as a whole with `vi-re‐
11891 peat-change'. The flag should be set early in the func‐
11892 tion before inspecting the value of NUMERIC or invoking
11893 other widgets. This has no effect for a widget invoked
11894 from insert mode. If insert mode is active when the wid‐
11895 get finishes, the change extends until next returning to
11896 command mode.
11897
11898 -C widget completion-widget function
11899 Create a user-defined completion widget named widget. The
11900 completion widget will behave like the built-in comple‐
11901 tion-widget whose name is given as completion-widget. To
11902 generate the completions, the shell function function
11903 will be called. For further information, see zshcomp‐
11904 wid(1).
11905
11906 -R [ -c ] [ display-string ] [ string ... ]
11907 Redisplay the command line. If a display-string is given
11908 and not empty, this is shown in the status line (immedi‐
11909 ately below the line being edited).
11910
11911 If the optional strings are given they are listed below
11912 the prompt in the same way as completion lists are
11913 printed. If no strings are given but the -c option is
11914 used such a list is cleared.
11915
11916 Note that immediately after returning from running wid‐
11917 gets, the command line will be redisplayed and the
11918 strings displayed will be erased. Therefore, this option
11919 is only useful for widgets that do not exit immediately
11920 after using it.
11921
11922 This command can safely be called outside user defined
11923 widgets; if zle is active, the display will be refreshed,
11924 while if zle is not active, the command has no effect.
11925 In this case there will usually be no other arguments.
11926
11927 The status is zero if zle was active, else one.
11928
11929 -M string
11930 As with the -R option, the string will be displayed below
11931 the command line; unlike the -R option, the string will
11932 not be put into the status line but will instead be
11933 printed normally below the prompt. This means that the
11934 string will still be displayed after the widget returns
11935 (until it is overwritten by subsequent commands).
11936
11937 -U string
11938 This pushes the characters in the string onto the input
11939 stack of ZLE. After the widget currently executed fin‐
11940 ishes ZLE will behave as if the characters in the string
11941 were typed by the user.
11942
11943 As ZLE uses a stack, if this option is used repeatedly
11944 the last string pushed onto the stack will be processed
11945 first. However, the characters in each string will be
11946 processed in the order in which they appear in the
11947 string.
11948
11949 -K keymap
11950 Selects the keymap named keymap. An error message will
11951 be displayed if there is no such keymap.
11952
11953 This keymap selection affects the interpretation of fol‐
11954 lowing keystrokes within this invocation of ZLE. Any
11955 following invocation (e.g., the next command line) will
11956 start as usual with the `main' keymap selected.
11957
11958 -F [ -L | -w ] [ fd [ handler ] ]
11959 Only available if your system supports one of the `poll'
11960 or `select' system calls; most modern systems do.
11961
11962 Installs handler (the name of a shell function) to handle
11963 input from file descriptor fd. Installing a handler for
11964 an fd which is already handled causes the existing han‐
11965 dler to be replaced. Any number of handlers for any num‐
11966 ber of readable file descriptors may be installed. Note
11967 that zle makes no attempt to check whether this fd is ac‐
11968 tually readable when installing the handler. The user
11969 must make their own arrangements for handling the file
11970 descriptor when zle is not active.
11971
11972 When zle is attempting to read data, it will examine both
11973 the terminal and the list of handled fd's. If data be‐
11974 comes available on a handled fd, zle calls handler with
11975 the fd which is ready for reading as the first argument.
11976 Under normal circumstances this is the only argument, but
11977 if an error was detected, a second argument provides de‐
11978 tails: `hup' for a disconnect, `nval' for a closed or
11979 otherwise invalid descriptor, or `err' for any other con‐
11980 dition. Systems that support only the `select' system
11981 call always use `err'.
11982
11983 If the option -w is also given, the handler is instead a
11984 line editor widget, typically a shell function made into
11985 a widget using `zle -N'. In that case handler can use
11986 all the facilities of zle to update the current editing
11987 line. Note, however, that as handling fd takes place at
11988 a low level changes to the display will not automatically
11989 appear; the widget should call `zle -R' to force redis‐
11990 play. As of this writing, widget handlers only support a
11991 single argument and thus are never passed a string for
11992 error state, so widgets must be prepared to test the de‐
11993 scriptor themselves.
11994
11995 If either type of handler produces output to the termi‐
11996 nal, it should call `zle -I' before doing so (see below).
11997 Handlers should not attempt to read from the terminal.
11998
11999 If no handler is given, but an fd is present, any handler
12000 for that fd is removed. If there is none, an error mes‐
12001 sage is printed and status 1 is returned.
12002
12003 If no arguments are given, or the -L option is supplied,
12004 a list of handlers is printed in a form which can be
12005 stored for later execution.
12006
12007 An fd (but not a handler) may optionally be given with
12008 the -L option; in this case, the function will list the
12009 handler if any, else silently return status 1.
12010
12011 Note that this feature should be used with care. Activ‐
12012 ity on one of the fd's which is not properly handled can
12013 cause the terminal to become unusable. Removing an fd
12014 handler from within a signal trap may cause unpredictable
12015 behavior.
12016
12017 Here is a simple example of using this feature. A con‐
12018 nection to a remote TCP port is created using the ztcp
12019 command; see the description of the zsh/net/tcp module in
12020 zshmodules(1). Then a handler is installed which simply
12021 prints out any data which arrives on this connection.
12022 Note that `select' will indicate that the file descriptor
12023 needs handling if the remote side has closed the connec‐
12024 tion; we handle that by testing for a failed read.
12025
12026 if ztcp pwspc 2811; then
12027 tcpfd=$REPLY
12028 handler() {
12029 zle -I
12030 local line
12031 if ! read -r line <&$1; then
12032 # select marks this fd if we reach EOF,
12033 # so handle this specially.
12034 print "[Read on fd $1 failed, removing.]" >&2
12035 zle -F $1
12036 return 1
12037 fi
12038 print -r - $line
12039 }
12040 zle -F $tcpfd handler
12041 fi
12042
12043 -I Unusually, this option is most useful outside ordinary
12044 widget functions, though it may be used within if normal
12045 output to the terminal is required. It invalidates the
12046 current zle display in preparation for output; typically
12047 this will be from a trap function. It has no effect if
12048 zle is not active. When a trap exits, the shell checks
12049 to see if the display needs restoring, hence the follow‐
12050 ing will print output in such a way as not to disturb the
12051 line being edited:
12052
12053 TRAPUSR1() {
12054 # Invalidate zle display
12055 [[ -o zle ]] && zle -I
12056 # Show output
12057 print Hello
12058 }
12059
12060 In general, the trap function may need to test whether
12061 zle is active before using this method (as shown in the
12062 example), since the zsh/zle module may not even be
12063 loaded; if it is not, the command can be skipped.
12064
12065 It is possible to call `zle -I' several times before con‐
12066 trol is returned to the editor; the display will only be
12067 invalidated the first time to minimise disruption.
12068
12069 Note that there are normally better ways of manipulating
12070 the display from within zle widgets; see, for example,
12071 `zle -R' above.
12072
12073 The returned status is zero if zle was invalidated, even
12074 though this may have been by a previous call to `zle -I'
12075 or by a system notification. To test if a zle widget may
12076 be called at this point, execute zle with no arguments
12077 and examine the return status.
12078
12079 -T This is used to add, list or remove internal transforma‐
12080 tions on the processing performed by the line editor. It
12081 is typically used only for debugging or testing and is
12082 therefore of little interest to the general user.
12083
12084 `zle -T transformation func' specifies that the given
12085 transformation (see below) is effected by shell function
12086 func.
12087
12088 `zle -Tr transformation' removes the given transformation
12089 if it was present (it is not an error if none was).
12090
12091 `zle -TL' can be used to list all transformations cur‐
12092 rently in operation.
12093
12094 Currently the only transformation is tc. This is used
12095 instead of outputting termcap codes to the terminal.
12096 When the transformation is in operation the shell func‐
12097 tion is passed the termcap code that would be output as
12098 its first argument; if the operation required a numeric
12099 argument, that is passed as a second argument. The func‐
12100 tion should set the shell variable REPLY to the trans‐
12101 formed termcap code. Typically this is used to produce
12102 some simply formatted version of the code and optional
12103 argument for debugging or testing. Note that this trans‐
12104 formation is not applied to other non-printing characters
12105 such as carriage returns and newlines.
12106
12107 widget [ -n num ] [ -f flag ] [ -Nw ] [ -K keymap ] args ...
12108 Invoke the specified widget. This can only be done when
12109 ZLE is active; normally this will be within a user-de‐
12110 fined widget.
12111
12112 With the options -n and -N, the current numeric argument
12113 will be saved and then restored after the call to widget;
12114 `-n num' sets the numeric argument temporarily to num,
12115 while `-N' sets it to the default, i.e. as if there were
12116 none.
12117
12118 With the option -K, keymap will be used as the current
12119 keymap during the execution of the widget. The previous
12120 keymap will be restored when the widget exits.
12121
12122 Normally, calling a widget in this way does not set the
12123 special parameter WIDGET and related parameters, so that
12124 the environment appears as if the top-level widget called
12125 by the user were still active. With the option -w, WID‐
12126 GET and related parameters are set to reflect the widget
12127 being executed by the zle call.
12128
12129 Normally, when widget returns the special parameter LAST‐
12130 WIDGET will point to it. This can be inhibited by pass‐
12131 ing the option -f nolast.
12132
12133 Any further arguments will be passed to the widget; note
12134 that as standard argument handling is performed, any gen‐
12135 eral argument list should be preceded by --. If it is a
12136 shell function, these are passed down as positional pa‐
12137 rameters; for builtin widgets it is up to the widget in
12138 question what it does with them. Currently arguments are
12139 only handled by the incremental-search commands, the his‐
12140 tory-search-forward and -backward and the corresponding
12141 functions prefixed by vi-, and by universal-argument. No
12142 error is flagged if the command does not use the argu‐
12143 ments, or only uses some of them.
12144
12145 The return status reflects the success or failure of the
12146 operation carried out by the widget, or if it is a
12147 user-defined widget the return status of the shell func‐
12148 tion.
12149
12150 A non-zero return status causes the shell to beep when
12151 the widget exits, unless the BEEP options was unset or
12152 the widget was called via the zle command. Thus if a
12153 user defined widget requires an immediate beep, it should
12154 call the beep widget directly.
12155
12157 All actions in the editor are performed by `widgets'. A widget's job
12158 is simply to perform some small action. The ZLE commands that key se‐
12159 quences in keymaps are bound to are in fact widgets. Widgets can be
12160 user-defined or built in.
12161
12162 The standard widgets built into ZLE are listed in the section `Standard
12163 Widgets' below. Other built-in widgets can be defined by other modules
12164 (see zshmodules(1)). Each built-in widget has two names: its normal
12165 canonical name, and the same name preceded by a `.'. The `.' name is
12166 special: it can't be rebound to a different widget. This makes the
12167 widget available even when its usual name has been redefined.
12168
12169 User-defined widgets are defined using `zle -N', and implemented as
12170 shell functions. When the widget is executed, the corresponding shell
12171 function is executed, and can perform editing (or other) actions. It
12172 is recommended that user-defined widgets should not have names starting
12173 with `.'.
12174
12176 User-defined widgets, being implemented as shell functions, can execute
12177 any normal shell command. They can also run other widgets (whether
12178 built-in or user-defined) using the zle builtin command. The standard
12179 input of the function is redirected from /dev/null to prevent external
12180 commands from unintentionally blocking ZLE by reading from the termi‐
12181 nal, but read -k or read -q can be used to read characters. Finally,
12182 they can examine and edit the ZLE buffer being edited by reading and
12183 setting the special parameters described below.
12184
12185 These special parameters are always available in widget functions, but
12186 are not in any way special outside ZLE. If they have some normal value
12187 outside ZLE, that value is temporarily inaccessible, but will return
12188 when the widget function exits. These special parameters in fact have
12189 local scope, like parameters created in a function using local.
12190
12191 Inside completion widgets and traps called while ZLE is active, these
12192 parameters are available read-only.
12193
12194 Note that the parameters appear as local to any ZLE widget in which
12195 they appear. Hence if it is desired to override them this needs to be
12196 done within a nested function:
12197
12198 widget-function() {
12199 # $WIDGET here refers to the special variable
12200 # that is local inside widget-function
12201 () {
12202 # This anonymous nested function allows WIDGET
12203 # to be used as a local variable. The -h
12204 # removes the special status of the variable.
12205 local -h WIDGET
12206 }
12207 }
12208
12209 BUFFER (scalar)
12210 The entire contents of the edit buffer. If it is written to,
12211 the cursor remains at the same offset, unless that would put it
12212 outside the buffer.
12213
12214 BUFFERLINES (integer)
12215 The number of screen lines needed for the edit buffer currently
12216 displayed on screen (i.e. without any changes to the preceding
12217 parameters done after the last redisplay); read-only.
12218
12219 CONTEXT (scalar)
12220 The context in which zle was called to read a line; read-only.
12221 One of the values:
12222
12223 start The start of a command line (at prompt PS1).
12224
12225 cont A continuation to a command line (at prompt PS2).
12226
12227 select In a select loop (at prompt PS3).
12228
12229 vared Editing a variable in vared.
12230
12231 CURSOR (integer)
12232 The offset of the cursor, within the edit buffer. This is in
12233 the range 0 to $#BUFFER, and is by definition equal to
12234 $#LBUFFER. Attempts to move the cursor outside the buffer will
12235 result in the cursor being moved to the appropriate end of the
12236 buffer.
12237
12238 CUTBUFFER (scalar)
12239 The last item cut using one of the `kill-' commands; the string
12240 which the next yank would insert in the line. Later entries in
12241 the kill ring are in the array killring. Note that the command
12242 `zle copy-region-as-kill string' can be used to set the text of
12243 the cut buffer from a shell function and cycle the kill ring in
12244 the same way as interactively killing text.
12245
12246 HISTNO (integer)
12247 The current history number. Setting this has the same effect as
12248 moving up or down in the history to the corresponding history
12249 line. An attempt to set it is ignored if the line is not stored
12250 in the history. Note this is not the same as the parameter
12251 HISTCMD, which always gives the number of the history line being
12252 added to the main shell's history. HISTNO refers to the line
12253 being retrieved within zle.
12254
12255 ISEARCHMATCH_ACTIVE (integer)
12256 ISEARCHMATCH_START (integer)
12257 ISEARCHMATCH_END (integer)
12258 ISEARCHMATCH_ACTIVE indicates whether a part of the BUFFER is
12259 currently matched by an incremental search pattern. ISEARCH‐
12260 MATCH_START and ISEARCHMATCH_END give the location of the
12261 matched part and are in the same units as CURSOR. They are only
12262 valid for reading when ISEARCHMATCH_ACTIVE is non-zero.
12263
12264 All parameters are read-only.
12265
12266 KEYMAP (scalar)
12267 The name of the currently selected keymap; read-only.
12268
12269 KEYS (scalar)
12270 The keys typed to invoke this widget, as a literal string;
12271 read-only.
12272
12273 KEYS_QUEUED_COUNT (integer)
12274 The number of bytes pushed back to the input queue and therefore
12275 available for reading immediately before any I/O is done;
12276 read-only. See also PENDING; the two values are distinct.
12277
12278 killring (array)
12279 The array of previously killed items, with the most recently
12280 killed first. This gives the items that would be retrieved by a
12281 yank-pop in the same order. Note, however, that the most re‐
12282 cently killed item is in $CUTBUFFER; $killring shows the array
12283 of previous entries.
12284
12285 The default size for the kill ring is eight, however the length
12286 may be changed by normal array operations. Any empty string in
12287 the kill ring is ignored by the yank-pop command, hence the size
12288 of the array effectively sets the maximum length of the kill
12289 ring, while the number of non-zero strings gives the current
12290 length, both as seen by the user at the command line.
12291
12292 LASTABORTEDSEARCH (scalar)
12293 The last search string used by an interactive search that was
12294 aborted by the user (status 3 returned by the search widget).
12295
12296 LASTSEARCH (scalar)
12297 The last search string used by an interactive search; read-only.
12298 This is set even if the search failed (status 0, 1 or 2 returned
12299 by the search widget), but not if it was aborted by the user.
12300
12301 LASTWIDGET (scalar)
12302 The name of the last widget that was executed; read-only.
12303
12304 LBUFFER (scalar)
12305 The part of the buffer that lies to the left of the cursor posi‐
12306 tion. If it is assigned to, only that part of the buffer is re‐
12307 placed, and the cursor remains between the new $LBUFFER and the
12308 old $RBUFFER.
12309
12310 MARK (integer)
12311 Like CURSOR, but for the mark. With vi-mode operators that wait
12312 for a movement command to select a region of text, setting MARK
12313 allows the selection to extend in both directions from the ini‐
12314 tial cursor position.
12315
12316 NUMERIC (integer)
12317 The numeric argument. If no numeric argument was given, this pa‐
12318 rameter is unset. When this is set inside a widget function,
12319 builtin widgets called with the zle builtin command will use the
12320 value assigned. If it is unset inside a widget function, builtin
12321 widgets called behave as if no numeric argument was given.
12322
12323 PENDING (integer)
12324 The number of bytes pending for input, i.e. the number of bytes
12325 which have already been typed and can immediately be read. On
12326 systems where the shell is not able to get this information,
12327 this parameter will always have a value of zero. Read-only.
12328 See also KEYS_QUEUED_COUNT; the two values are distinct.
12329
12330 PREBUFFER (scalar)
12331 In a multi-line input at the secondary prompt, this read-only
12332 parameter contains the contents of the lines before the one the
12333 cursor is currently in.
12334
12335 PREDISPLAY (scalar)
12336 Text to be displayed before the start of the editable text buf‐
12337 fer. This does not have to be a complete line; to display a
12338 complete line, a newline must be appended explicitly. The text
12339 is reset on each new invocation (but not recursive invocation)
12340 of zle.
12341
12342 POSTDISPLAY (scalar)
12343 Text to be displayed after the end of the editable text buffer.
12344 This does not have to be a complete line; to display a complete
12345 line, a newline must be prepended explicitly. The text is reset
12346 on each new invocation (but not recursive invocation) of zle.
12347
12348 RBUFFER (scalar)
12349 The part of the buffer that lies to the right of the cursor po‐
12350 sition. If it is assigned to, only that part of the buffer is
12351 replaced, and the cursor remains between the old $LBUFFER and
12352 the new $RBUFFER.
12353
12354 REGION_ACTIVE (integer)
12355 Indicates if the region is currently active. It can be assigned
12356 0 or 1 to deactivate and activate the region respectively. A
12357 value of 2 activates the region in line-wise mode with the high‐
12358 lighted text extending for whole lines only; see Character High‐
12359 lighting below.
12360
12361 region_highlight (array)
12362 Each element of this array may be set to a string that describes
12363 highlighting for an arbitrary region of the command line that
12364 will take effect the next time the command line is redisplayed.
12365 Highlighting of the non-editable parts of the command line in
12366 PREDISPLAY and POSTDISPLAY are possible, but note that the P
12367 flag is needed for character indexing to include PREDISPLAY.
12368
12369 Each string consists of the following whitespace-separated
12370 parts:
12371
12372 • Optionally, a `P' to signify that the start and end off‐
12373 set that follow include any string set by the PREDISPLAY
12374 special parameter; this is needed if the predisplay
12375 string itself is to be highlighted. Whitespace between
12376 the `P' and the start offset is optional.
12377
12378 • A start offset in the same units as CURSOR.
12379
12380 • An end offset in the same units as CURSOR.
12381
12382 • A highlight specification in the same format as used for
12383 contexts in the parameter zle_highlight, see the section
12384 `Character Highlighting' below; for example, standout or
12385 fg=red,bold.
12386
12387 • Optionally, a string of the form `memo=token'. The token
12388 consists of everything between the `=' and the next
12389 whitespace, comma, NUL, or the end of the string. The
12390 token is preserved verbatim but not parsed in any way.
12391
12392 Plugins may use this to identify array elements they have
12393 added: for example, a plugin might set token to its (the
12394 plugin's) name and then use `region_highlight=( ${re‐
12395 gion_highlight:#*memo=token} )' in order to remove array
12396 elements it have added.
12397
12398 (This example uses the `${name:#pattern}' array-grepping
12399 syntax described in the section `Parameter Expansion' in
12400 zshexpn(1).)
12401
12402 For example,
12403
12404 region_highlight=("P0 20 bold memo=foobar")
12405
12406 specifies that the first twenty characters of the text including
12407 any predisplay string should be highlighted in bold.
12408
12409 Note that the effect of region_highlight is not saved and disap‐
12410 pears as soon as the line is accepted.
12411
12412 Note that zsh 5.8 and older do not support the `memo=token'
12413 field and may misparse the third (highlight specification) field
12414 when a memo is given.
12415
12416
12417 The final highlighting on the command line depends on both re‐
12418 gion_highlight and zle_highlight; see the section CHARACTER
12419 HIGHLIGHTING below for details.
12420
12421 registers (associative array)
12422 The contents of each of the vi register buffers. These are typi‐
12423 cally set using vi-set-buffer followed by a delete, change or
12424 yank command.
12425
12426 SUFFIX_ACTIVE (integer)
12427 SUFFIX_START (integer)
12428 SUFFIX_END (integer)
12429 SUFFIX_ACTIVE indicates whether an auto-removable completion
12430 suffix is currently active. SUFFIX_START and SUFFIX_END give the
12431 location of the suffix and are in the same units as CURSOR. They
12432 are only valid for reading when SUFFIX_ACTIVE is non-zero.
12433
12434 All parameters are read-only.
12435
12436 UNDO_CHANGE_NO (integer)
12437 A number representing the state of the undo history. The only
12438 use of this is passing as an argument to the undo widget in or‐
12439 der to undo back to the recorded point. Read-only.
12440
12441 UNDO_LIMIT_NO (integer)
12442 A number corresponding to an existing change in the undo his‐
12443 tory; compare UNDO_CHANGE_NO. If this is set to a value greater
12444 than zero, the undo command will not allow the line to be undone
12445 beyond the given change number. It is still possible to use
12446 `zle undo change' in a widget to undo beyond that point; in that
12447 case, it will not be possible to undo at all until UNDO_LIMIT_NO
12448 is reduced. Set to 0 to disable the limit.
12449
12450 A typical use of this variable in a widget function is as fol‐
12451 lows (note the additional function scope is required):
12452
12453 () {
12454 local UNDO_LIMIT_NO=$UNDO_CHANGE_NO
12455 # Perform some form of recursive edit.
12456 }
12457
12458 WIDGET (scalar)
12459 The name of the widget currently being executed; read-only.
12460
12461 WIDGETFUNC (scalar)
12462 The name of the shell function that implements a widget defined
12463 with either zle -N or zle -C. In the former case, this is the
12464 second argument to the zle -N command that defined the widget,
12465 or the first argument if there was no second argument. In the
12466 latter case this is the third argument to the zle -C command
12467 that defined the widget. Read-only.
12468
12469 WIDGETSTYLE (scalar)
12470 Describes the implementation behind the completion widget cur‐
12471 rently being executed; the second argument that followed zle -C
12472 when the widget was defined. This is the name of a builtin com‐
12473 pletion widget. For widgets defined with zle -N this is set to
12474 the empty string. Read-only.
12475
12476 YANK_ACTIVE (integer)
12477 YANK_START (integer)
12478 YANK_END (integer)
12479 YANK_ACTIVE indicates whether text has just been yanked (pasted)
12480 into the buffer. YANK_START and YANK_END give the location of
12481 the pasted text and are in the same units as CURSOR. They are
12482 only valid for reading when YANK_ACTIVE is non-zero. They can
12483 also be assigned by widgets that insert text in a yank-like
12484 fashion, for example wrappers of bracketed-paste. See also zle
12485 -f.
12486
12487 YANK_ACTIVE is read-only.
12488
12489 ZLE_RECURSIVE (integer)
12490 Usually zero, but incremented inside any instance of recur‐
12491 sive-edit. Hence indicates the current recursion level.
12492
12493 ZLE_RECURSIVE is read-only.
12494
12495 ZLE_STATE (scalar)
12496 Contains a set of space-separated words that describe the cur‐
12497 rent zle state.
12498
12499 Currently, the states shown are the insert mode as set by the
12500 overwrite-mode or vi-replace widgets and whether history com‐
12501 mands will visit imported entries as controlled by the set-lo‐
12502 cal-history widget. The string contains `insert' if characters
12503 to be inserted on the command line move existing characters to
12504 the right or `overwrite' if characters to be inserted overwrite
12505 existing characters. It contains `localhistory' if only local
12506 history commands will be visited or `globalhistory' if imported
12507 history commands will also be visited.
12508
12509 The substrings are sorted in alphabetical order so that if you
12510 want to test for two specific substrings in a future-proof way,
12511 you can do match by doing:
12512
12513 if [[ $ZLE_STATE == *globalhistory*insert* ]]; then ...; fi
12514
12515 Special Widgets
12516 There are a few user-defined widgets which are special to the shell.
12517 If they do not exist, no special action is taken. The environment pro‐
12518 vided is identical to that for any other editing widget.
12519
12520 zle-isearch-exit
12521 Executed at the end of incremental search at the point where the
12522 isearch prompt is removed from the display. See zle-isearch-up‐
12523 date for an example.
12524
12525 zle-isearch-update
12526 Executed within incremental search when the display is about to
12527 be redrawn. Additional output below the incremental search
12528 prompt can be generated by using `zle -M' within the widget.
12529 For example,
12530
12531 zle-isearch-update() { zle -M "Line $HISTNO"; }
12532 zle -N zle-isearch-update
12533
12534 Note the line output by `zle -M' is not deleted on exit from in‐
12535 cremental search. This can be done from a zle-isearch-exit wid‐
12536 get:
12537
12538 zle-isearch-exit() { zle -M ""; }
12539 zle -N zle-isearch-exit
12540
12541 zle-line-pre-redraw
12542 Executed whenever the input line is about to be redrawn, provid‐
12543 ing an opportunity to update the region_highlight array.
12544
12545 zle-line-init
12546 Executed every time the line editor is started to read a new
12547 line of input. The following example puts the line editor into
12548 vi command mode when it starts up.
12549
12550 zle-line-init() { zle -K vicmd; }
12551 zle -N zle-line-init
12552
12553 (The command inside the function sets the keymap directly; it is
12554 equivalent to zle vi-cmd-mode.)
12555
12556 zle-line-finish
12557 This is similar to zle-line-init but is executed every time the
12558 line editor has finished reading a line of input.
12559
12560 zle-history-line-set
12561 Executed when the history line changes.
12562
12563 zle-keymap-select
12564 Executed every time the keymap changes, i.e. the special parame‐
12565 ter KEYMAP is set to a different value, while the line editor is
12566 active. Initialising the keymap when the line editor starts
12567 does not cause the widget to be called.
12568
12569 The value $KEYMAP within the function reflects the new keymap.
12570 The old keymap is passed as the sole argument.
12571
12572 This can be used for detecting switches between the vi command
12573 (vicmd) and insert (usually main) keymaps.
12574
12576 The following is a list of all the standard widgets, and their default
12577 bindings in emacs mode, vi command mode and vi insert mode (the
12578 `emacs', `vicmd' and `viins' keymaps, respectively).
12579
12580 Note that cursor keys are bound to movement keys in all three keymaps;
12581 the shell assumes that the cursor keys send the key sequences reported
12582 by the terminal-handling library (termcap or terminfo). The key se‐
12583 quences shown in the list are those based on the VT100, common on many
12584 modern terminals, but in fact these are not necessarily bound. In the
12585 case of the viins keymap, the initial escape character of the sequences
12586 serves also to return to the vicmd keymap: whether this happens is de‐
12587 termined by the KEYTIMEOUT parameter, see zshparam(1).
12588
12589 Movement
12590 vi-backward-blank-word (unbound) (B) (unbound)
12591 Move backward one word, where a word is defined as a series of
12592 non-blank characters.
12593
12594 vi-backward-blank-word-end (unbound) (gE) (unbound)
12595 Move to the end of the previous word, where a word is defined as
12596 a series of non-blank characters.
12597
12598 backward-char (^B ESC-[D) (unbound) (unbound)
12599 Move backward one character.
12600
12601 vi-backward-char (unbound) (^H h ^?) (ESC-[D)
12602 Move backward one character, without changing lines.
12603
12604 backward-word (ESC-B ESC-b) (unbound) (unbound)
12605 Move to the beginning of the previous word.
12606
12607 emacs-backward-word
12608 Move to the beginning of the previous word.
12609
12610 vi-backward-word (unbound) (b) (unbound)
12611 Move to the beginning of the previous word, vi-style.
12612
12613 vi-backward-word-end (unbound) (ge) (unbound)
12614 Move to the end of the previous word, vi-style.
12615
12616 beginning-of-line (^A) (unbound) (unbound)
12617 Move to the beginning of the line. If already at the beginning
12618 of the line, move to the beginning of the previous line, if any.
12619
12620 vi-beginning-of-line
12621 Move to the beginning of the line, without changing lines.
12622
12623 down-line (unbound) (unbound) (unbound)
12624 Move down a line in the buffer.
12625
12626 end-of-line (^E) (unbound) (unbound)
12627 Move to the end of the line. If already at the end of the line,
12628 move to the end of the next line, if any.
12629
12630 vi-end-of-line (unbound) ($) (unbound)
12631 Move to the end of the line. If an argument is given to this
12632 command, the cursor will be moved to the end of the line (argu‐
12633 ment - 1) lines down.
12634
12635 vi-forward-blank-word (unbound) (W) (unbound)
12636 Move forward one word, where a word is defined as a series of
12637 non-blank characters.
12638
12639 vi-forward-blank-word-end (unbound) (E) (unbound)
12640 Move to the end of the current word, or, if at the end of the
12641 current word, to the end of the next word, where a word is de‐
12642 fined as a series of non-blank characters.
12643
12644 forward-char (^F ESC-[C) (unbound) (unbound)
12645 Move forward one character.
12646
12647 vi-forward-char (unbound) (space l) (ESC-[C)
12648 Move forward one character.
12649
12650 vi-find-next-char (^X^F) (f) (unbound)
12651 Read a character from the keyboard, and move to the next occur‐
12652 rence of it in the line.
12653
12654 vi-find-next-char-skip (unbound) (t) (unbound)
12655 Read a character from the keyboard, and move to the position
12656 just before the next occurrence of it in the line.
12657
12658 vi-find-prev-char (unbound) (F) (unbound)
12659 Read a character from the keyboard, and move to the previous oc‐
12660 currence of it in the line.
12661
12662 vi-find-prev-char-skip (unbound) (T) (unbound)
12663 Read a character from the keyboard, and move to the position
12664 just after the previous occurrence of it in the line.
12665
12666 vi-first-non-blank (unbound) (^) (unbound)
12667 Move to the first non-blank character in the line.
12668
12669 vi-forward-word (unbound) (w) (unbound)
12670 Move forward one word, vi-style.
12671
12672 forward-word (ESC-F ESC-f) (unbound) (unbound)
12673 Move to the beginning of the next word. The editor's idea of a
12674 word is specified with the WORDCHARS parameter.
12675
12676 emacs-forward-word
12677 Move to the end of the next word.
12678
12679 vi-forward-word-end (unbound) (e) (unbound)
12680 Move to the end of the next word.
12681
12682 vi-goto-column (ESC-|) (|) (unbound)
12683 Move to the column specified by the numeric argument.
12684
12685 vi-goto-mark (unbound) (`) (unbound)
12686 Move to the specified mark.
12687
12688 vi-goto-mark-line (unbound) (') (unbound)
12689 Move to beginning of the line containing the specified mark.
12690
12691 vi-repeat-find (unbound) (;) (unbound)
12692 Repeat the last vi-find command.
12693
12694 vi-rev-repeat-find (unbound) (,) (unbound)
12695 Repeat the last vi-find command in the opposite direction.
12696
12697 up-line (unbound) (unbound) (unbound)
12698 Move up a line in the buffer.
12699
12700 History Control
12701 beginning-of-buffer-or-history (ESC-<) (gg) (unbound)
12702 Move to the beginning of the buffer, or if already there, move
12703 to the first event in the history list.
12704
12705 beginning-of-line-hist
12706 Move to the beginning of the line. If already at the beginning
12707 of the buffer, move to the previous history line.
12708
12709 beginning-of-history
12710 Move to the first event in the history list.
12711
12712 down-line-or-history (^N ESC-[B) (j) (ESC-[B)
12713 Move down a line in the buffer, or if already at the bottom
12714 line, move to the next event in the history list.
12715
12716 vi-down-line-or-history (unbound) (+) (unbound)
12717 Move down a line in the buffer, or if already at the bottom
12718 line, move to the next event in the history list. Then move to
12719 the first non-blank character on the line.
12720
12721 down-line-or-search
12722 Move down a line in the buffer, or if already at the bottom
12723 line, search forward in the history for a line beginning with
12724 the first word in the buffer.
12725
12726 If called from a function by the zle command with arguments, the
12727 first argument is taken as the string for which to search,
12728 rather than the first word in the buffer.
12729
12730 down-history (unbound) (^N) (unbound)
12731 Move to the next event in the history list.
12732
12733 history-beginning-search-backward
12734 Search backward in the history for a line beginning with the
12735 current line up to the cursor. This leaves the cursor in its
12736 original position.
12737
12738 end-of-buffer-or-history (ESC->) (unbound) (unbound)
12739 Move to the end of the buffer, or if already there, move to the
12740 last event in the history list.
12741
12742 end-of-line-hist
12743 Move to the end of the line. If already at the end of the buf‐
12744 fer, move to the next history line.
12745
12746 end-of-history
12747 Move to the last event in the history list.
12748
12749 vi-fetch-history (unbound) (G) (unbound)
12750 Fetch the history line specified by the numeric argument. This
12751 defaults to the current history line (i.e. the one that isn't
12752 history yet).
12753
12754 history-incremental-search-backward (^R ^Xr) (unbound) (unbound)
12755 Search backward incrementally for a specified string. The
12756 search is case-insensitive if the search string does not have
12757 uppercase letters and no numeric argument was given. The string
12758 may begin with `^' to anchor the search to the beginning of the
12759 line. When called from a user-defined function returns the fol‐
12760 lowing statuses: 0, if the search succeeded; 1, if the search
12761 failed; 2, if the search term was a bad pattern; 3, if the
12762 search was aborted by the send-break command.
12763
12764 A restricted set of editing functions is available in the
12765 mini-buffer. Keys are looked up in the special isearch keymap,
12766 and if not found there in the main keymap (note that by default
12767 the isearch keymap is empty). An interrupt signal, as defined
12768 by the stty setting, will stop the search and go back to the
12769 original line. An undefined key will have the same effect.
12770 Note that the following always perform the same task within in‐
12771 cremental searches and cannot be replaced by user defined wid‐
12772 gets, nor can the set of functions be extended. The supported
12773 functions are:
12774
12775 accept-and-hold
12776 accept-and-infer-next-history
12777 accept-line
12778 accept-line-and-down-history
12779 Perform the usual function after exiting incremental
12780 search. The command line displayed is executed.
12781
12782 backward-delete-char
12783 vi-backward-delete-char
12784 Back up one place in the search history. If the search
12785 has been repeated this does not immediately erase a char‐
12786 acter in the minibuffer.
12787
12788 accept-search
12789 Exit incremental search, retaining the command line but
12790 performing no further action. Note that this function is
12791 not bound by default and has no effect outside incremen‐
12792 tal search.
12793
12794 backward-delete-word
12795 backward-kill-word
12796 vi-backward-kill-word
12797 Back up one character in the minibuffer; if multiple
12798 searches have been performed since the character was in‐
12799 serted the search history is rewound to the point just
12800 before the character was entered. Hence this has the ef‐
12801 fect of repeating backward-delete-char.
12802
12803 clear-screen
12804 Clear the screen, remaining in incremental search mode.
12805
12806 history-incremental-search-backward
12807 Find the next occurrence of the contents of the mini-buf‐
12808 fer. If the mini-buffer is empty, the most recent previ‐
12809 ously used search string is reinstated.
12810
12811 history-incremental-search-forward
12812 Invert the sense of the search.
12813
12814 magic-space
12815 Inserts a non-magical space.
12816
12817 quoted-insert
12818 vi-quoted-insert
12819 Quote the character to insert into the minibuffer.
12820
12821 redisplay
12822 Redisplay the command line, remaining in incremental
12823 search mode.
12824
12825 vi-cmd-mode
12826 Select the `vicmd' keymap; the `main' keymap (insert
12827 mode) will be selected initially.
12828
12829 In addition, the modifications that were made while in vi
12830 insert mode are merged to form a single undo event.
12831
12832 vi-repeat-search
12833 vi-rev-repeat-search
12834 Repeat the search. The direction of the search is indi‐
12835 cated in the mini-buffer.
12836
12837 Any character that is not bound to one of the above functions,
12838 or self-insert or self-insert-unmeta, will cause the mode to be
12839 exited. The character is then looked up and executed in the
12840 keymap in effect at that point.
12841
12842 When called from a widget function by the zle command, the in‐
12843 cremental search commands can take a string argument. This will
12844 be treated as a string of keys, as for arguments to the bindkey
12845 command, and used as initial input for the command. Any charac‐
12846 ters in the string which are unused by the incremental search
12847 will be silently ignored. For example,
12848
12849 zle history-incremental-search-backward forceps
12850
12851 will search backwards for forceps, leaving the minibuffer con‐
12852 taining the string `forceps'.
12853
12854 history-incremental-search-forward (^S ^Xs) (unbound) (unbound)
12855 Search forward incrementally for a specified string. The search
12856 is case-insensitive if the search string does not have uppercase
12857 letters and no numeric argument was given. The string may begin
12858 with `^' to anchor the search to the beginning of the line. The
12859 functions available in the mini-buffer are the same as for his‐
12860 tory-incremental-search-backward.
12861
12862 history-incremental-pattern-search-backward
12863 history-incremental-pattern-search-forward
12864 These widgets behave similarly to the corresponding widgets with
12865 no -pattern, but the search string typed by the user is treated
12866 as a pattern, respecting the current settings of the various op‐
12867 tions affecting pattern matching. See FILENAME GENERATION in
12868 zshexpn(1) for a description of patterns. If no numeric argu‐
12869 ment was given lowercase letters in the search string may match
12870 uppercase letters in the history. The string may begin with `^'
12871 to anchor the search to the beginning of the line.
12872
12873 The prompt changes to indicate an invalid pattern; this may sim‐
12874 ply indicate the pattern is not yet complete.
12875
12876 Note that only non-overlapping matches are reported, so an ex‐
12877 pression with wildcards may return fewer matches on a line than
12878 are visible by inspection.
12879
12880 history-search-backward (ESC-P ESC-p) (unbound) (unbound)
12881 Search backward in the history for a line beginning with the
12882 first word in the buffer.
12883
12884 If called from a function by the zle command with arguments, the
12885 first argument is taken as the string for which to search,
12886 rather than the first word in the buffer.
12887
12888 vi-history-search-backward (unbound) (/) (unbound)
12889 Search backward in the history for a specified string. The
12890 string may begin with `^' to anchor the search to the beginning
12891 of the line.
12892
12893 A restricted set of editing functions is available in the
12894 mini-buffer. An interrupt signal, as defined by the stty set‐
12895 ting, will stop the search. The functions available in the
12896 mini-buffer are: accept-line, backward-delete-char, vi-back‐
12897 ward-delete-char, backward-kill-word, vi-backward-kill-word,
12898 clear-screen, redisplay, quoted-insert and vi-quoted-insert.
12899
12900 vi-cmd-mode is treated the same as accept-line, and magic-space
12901 is treated as a space. Any other character that is not bound to
12902 self-insert or self-insert-unmeta will beep and be ignored. If
12903 the function is called from vi command mode, the bindings of the
12904 current insert mode will be used.
12905
12906 If called from a function by the zle command with arguments, the
12907 first argument is taken as the string for which to search,
12908 rather than the first word in the buffer.
12909
12910 history-search-forward (ESC-N ESC-n) (unbound) (unbound)
12911 Search forward in the history for a line beginning with the
12912 first word in the buffer.
12913
12914 If called from a function by the zle command with arguments, the
12915 first argument is taken as the string for which to search,
12916 rather than the first word in the buffer.
12917
12918 vi-history-search-forward (unbound) (?) (unbound)
12919 Search forward in the history for a specified string. The
12920 string may begin with `^' to anchor the search to the beginning
12921 of the line. The functions available in the mini-buffer are the
12922 same as for vi-history-search-backward. Argument handling is
12923 also the same as for that command.
12924
12925 infer-next-history (^X^N) (unbound) (unbound)
12926 Search in the history list for a line matching the current one
12927 and fetch the event following it.
12928
12929 insert-last-word (ESC-_ ESC-.) (unbound) (unbound)
12930 Insert the last word from the previous history event at the cur‐
12931 sor position. If a positive numeric argument is given, insert
12932 that word from the end of the previous history event. If the
12933 argument is zero or negative insert that word from the left
12934 (zero inserts the previous command word). Repeating this com‐
12935 mand replaces the word just inserted with the last word from the
12936 history event prior to the one just used; numeric arguments can
12937 be used in the same way to pick a word from that event.
12938
12939 When called from a shell function invoked from a user-defined
12940 widget, the command can take one to three arguments. The first
12941 argument specifies a history offset which applies to successive
12942 calls to this widget: if it is -1, the default behaviour is
12943 used, while if it is 1, successive calls will move forwards
12944 through the history. The value 0 can be used to indicate that
12945 the history line examined by the previous execution of the com‐
12946 mand will be reexamined. Note that negative numbers should be
12947 preceded by a `--' argument to avoid confusing them with op‐
12948 tions.
12949
12950 If two arguments are given, the second specifies the word on the
12951 command line in normal array index notation (as a more natural
12952 alternative to the numeric argument). Hence 1 is the first
12953 word, and -1 (the default) is the last word.
12954
12955 If a third argument is given, its value is ignored, but it is
12956 used to signify that the history offset is relative to the cur‐
12957 rent history line, rather than the one remembered after the pre‐
12958 vious invocations of insert-last-word.
12959
12960 For example, the default behaviour of the command corresponds to
12961
12962 zle insert-last-word -- -1 -1
12963
12964 while the command
12965
12966 zle insert-last-word -- -1 1 -
12967
12968 always copies the first word of the line in the history immedi‐
12969 ately before the line being edited. This has the side effect
12970 that later invocations of the widget will be relative to that
12971 line.
12972
12973 vi-repeat-search (unbound) (n) (unbound)
12974 Repeat the last vi history search.
12975
12976 vi-rev-repeat-search (unbound) (N) (unbound)
12977 Repeat the last vi history search, but in reverse.
12978
12979 up-line-or-history (^P ESC-[A) (k) (ESC-[A)
12980 Move up a line in the buffer, or if already at the top line,
12981 move to the previous event in the history list.
12982
12983 vi-up-line-or-history (unbound) (-) (unbound)
12984 Move up a line in the buffer, or if already at the top line,
12985 move to the previous event in the history list. Then move to
12986 the first non-blank character on the line.
12987
12988 up-line-or-search
12989 Move up a line in the buffer, or if already at the top line,
12990 search backward in the history for a line beginning with the
12991 first word in the buffer.
12992
12993 If called from a function by the zle command with arguments, the
12994 first argument is taken as the string for which to search,
12995 rather than the first word in the buffer.
12996
12997 up-history (unbound) (^P) (unbound)
12998 Move to the previous event in the history list.
12999
13000 history-beginning-search-forward
13001 Search forward in the history for a line beginning with the cur‐
13002 rent line up to the cursor. This leaves the cursor in its orig‐
13003 inal position.
13004
13005 set-local-history
13006 By default, history movement commands visit the imported lines
13007 as well as the local lines. This widget lets you toggle this on
13008 and off, or set it with the numeric argument. Zero for both lo‐
13009 cal and imported lines and nonzero for only local lines.
13010
13011 Modifying Text
13012 vi-add-eol (unbound) (A) (unbound)
13013 Move to the end of the line and enter insert mode.
13014
13015 vi-add-next (unbound) (a) (unbound)
13016 Enter insert mode after the current cursor position, without
13017 changing lines.
13018
13019 backward-delete-char (^H ^?) (unbound) (unbound)
13020 Delete the character behind the cursor.
13021
13022 vi-backward-delete-char (unbound) (X) (^H)
13023 Delete the character behind the cursor, without changing lines.
13024 If in insert mode, this won't delete past the point where insert
13025 mode was last entered.
13026
13027 backward-delete-word
13028 Delete the word behind the cursor.
13029
13030 backward-kill-line
13031 Kill from the beginning of the line to the cursor position.
13032
13033 backward-kill-word (^W ESC-^H ESC-^?) (unbound) (unbound)
13034 Kill the word behind the cursor.
13035
13036 vi-backward-kill-word (unbound) (unbound) (^W)
13037 Kill the word behind the cursor, without going past the point
13038 where insert mode was last entered.
13039
13040 capitalize-word (ESC-C ESC-c) (unbound) (unbound)
13041 Capitalize the current word and move past it.
13042
13043 vi-change (unbound) (c) (unbound)
13044 Read a movement command from the keyboard, and kill from the
13045 cursor position to the endpoint of the movement. Then enter in‐
13046 sert mode. If the command is vi-change, change the current
13047 line.
13048
13049 For compatibility with vi, if the command is vi-forward-word or
13050 vi-forward-blank-word, the whitespace after the word is not in‐
13051 cluded. If you prefer the more consistent behaviour with the
13052 whitespace included use the following key binding:
13053
13054 bindkey -a -s cw dwi
13055
13056 vi-change-eol (unbound) (C) (unbound)
13057 Kill to the end of the line and enter insert mode.
13058
13059 vi-change-whole-line (unbound) (S) (unbound)
13060 Kill the current line and enter insert mode.
13061
13062 copy-region-as-kill (ESC-W ESC-w) (unbound) (unbound)
13063 Copy the area from the cursor to the mark to the kill buffer.
13064
13065 If called from a ZLE widget function in the form `zle copy-re‐
13066 gion-as-kill string' then string will be taken as the text to
13067 copy to the kill buffer. The cursor, the mark and the text on
13068 the command line are not used in this case.
13069
13070 copy-prev-word (ESC-^_) (unbound) (unbound)
13071 Duplicate the word to the left of the cursor.
13072
13073 copy-prev-shell-word
13074 Like copy-prev-word, but the word is found by using shell pars‐
13075 ing, whereas copy-prev-word looks for blanks. This makes a dif‐
13076 ference when the word is quoted and contains spaces.
13077
13078 vi-delete (unbound) (d) (unbound)
13079 Read a movement command from the keyboard, and kill from the
13080 cursor position to the endpoint of the movement. If the command
13081 is vi-delete, kill the current line.
13082
13083 delete-char
13084 Delete the character under the cursor.
13085
13086 vi-delete-char (unbound) (x) (unbound)
13087 Delete the character under the cursor, without going past the
13088 end of the line.
13089
13090 delete-word
13091 Delete the current word.
13092
13093 down-case-word (ESC-L ESC-l) (unbound) (unbound)
13094 Convert the current word to all lowercase and move past it.
13095
13096 vi-down-case (unbound) (gu) (unbound)
13097 Read a movement command from the keyboard, and convert all char‐
13098 acters from the cursor position to the endpoint of the movement
13099 to lowercase. If the movement command is vi-down-case, swap the
13100 case of all characters on the current line.
13101
13102 kill-word (ESC-D ESC-d) (unbound) (unbound)
13103 Kill the current word.
13104
13105 gosmacs-transpose-chars
13106 Exchange the two characters behind the cursor.
13107
13108 vi-indent (unbound) (>) (unbound)
13109 Indent a number of lines.
13110
13111 vi-insert (unbound) (i) (unbound)
13112 Enter insert mode.
13113
13114 vi-insert-bol (unbound) (I) (unbound)
13115 Move to the first non-blank character on the line and enter in‐
13116 sert mode.
13117
13118 vi-join (^X^J) (J) (unbound)
13119 Join the current line with the next one.
13120
13121 kill-line (^K) (unbound) (unbound)
13122 Kill from the cursor to the end of the line. If already on the
13123 end of the line, kill the newline character.
13124
13125 vi-kill-line (unbound) (unbound) (^U)
13126 Kill from the cursor back to wherever insert mode was last en‐
13127 tered.
13128
13129 vi-kill-eol (unbound) (D) (unbound)
13130 Kill from the cursor to the end of the line.
13131
13132 kill-region
13133 Kill from the cursor to the mark.
13134
13135 kill-buffer (^X^K) (unbound) (unbound)
13136 Kill the entire buffer.
13137
13138 kill-whole-line (^U) (unbound) (unbound)
13139 Kill the current line.
13140
13141 vi-match-bracket (^X^B) (%) (unbound)
13142 Move to the bracket character (one of {}, () or []) that matches
13143 the one under the cursor. If the cursor is not on a bracket
13144 character, move forward without going past the end of the line
13145 to find one, and then go to the matching bracket.
13146
13147 vi-open-line-above (unbound) (O) (unbound)
13148 Open a line above the cursor and enter insert mode.
13149
13150 vi-open-line-below (unbound) (o) (unbound)
13151 Open a line below the cursor and enter insert mode.
13152
13153 vi-oper-swap-case (unbound) (g~) (unbound)
13154 Read a movement command from the keyboard, and swap the case of
13155 all characters from the cursor position to the endpoint of the
13156 movement. If the movement command is vi-oper-swap-case, swap
13157 the case of all characters on the current line.
13158
13159 overwrite-mode (^X^O) (unbound) (unbound)
13160 Toggle between overwrite mode and insert mode.
13161
13162 vi-put-before (unbound) (P) (unbound)
13163 Insert the contents of the kill buffer before the cursor. If
13164 the kill buffer contains a sequence of lines (as opposed to
13165 characters), paste it above the current line.
13166
13167 vi-put-after (unbound) (p) (unbound)
13168 Insert the contents of the kill buffer after the cursor. If the
13169 kill buffer contains a sequence of lines (as opposed to charac‐
13170 ters), paste it below the current line.
13171
13172 put-replace-selection (unbound) (unbound) (unbound)
13173 Replace the contents of the current region or selection with the
13174 contents of the kill buffer. If the kill buffer contains a se‐
13175 quence of lines (as opposed to characters), the current line
13176 will be split by the pasted lines.
13177
13178 quoted-insert (^V) (unbound) (unbound)
13179 Insert the next character typed into the buffer literally. An
13180 interrupt character will not be inserted.
13181
13182 vi-quoted-insert (unbound) (unbound) (^Q ^V)
13183 Display a `^' at the cursor position, and insert the next char‐
13184 acter typed into the buffer literally. An interrupt character
13185 will not be inserted.
13186
13187 quote-line (ESC-') (unbound) (unbound)
13188 Quote the current line; that is, put a `'' character at the be‐
13189 ginning and the end, and convert all `'' characters to `'\'''.
13190
13191 quote-region (ESC-") (unbound) (unbound)
13192 Quote the region from the cursor to the mark.
13193
13194 vi-replace (unbound) (R) (unbound)
13195 Enter overwrite mode.
13196
13197 vi-repeat-change (unbound) (.) (unbound)
13198 Repeat the last vi mode text modification. If a count was used
13199 with the modification, it is remembered. If a count is given to
13200 this command, it overrides the remembered count, and is remem‐
13201 bered for future uses of this command. The cut buffer specifi‐
13202 cation is similarly remembered.
13203
13204 vi-replace-chars (unbound) (r) (unbound)
13205 Replace the character under the cursor with a character read
13206 from the keyboard.
13207
13208 self-insert (printable characters) (unbound) (printable characters and
13209 some control characters)
13210 Insert a character into the buffer at the cursor position.
13211
13212 self-insert-unmeta (ESC-^I ESC-^J ESC-^M) (unbound) (unbound)
13213 Insert a character into the buffer after stripping the meta bit
13214 and converting ^M to ^J.
13215
13216 vi-substitute (unbound) (s) (unbound)
13217 Substitute the next character(s).
13218
13219 vi-swap-case (unbound) (~) (unbound)
13220 Swap the case of the character under the cursor and move past
13221 it.
13222
13223 transpose-chars (^T) (unbound) (unbound)
13224 Exchange the two characters to the left of the cursor if at end
13225 of line, else exchange the character under the cursor with the
13226 character to the left.
13227
13228 transpose-words (ESC-T ESC-t) (unbound) (unbound)
13229 Exchange the current word with the one before it.
13230
13231 With a positive numeric argument N, the word around the cursor,
13232 or following it if the cursor is between words, is transposed
13233 with the preceding N words. The cursor is put at the end of the
13234 resulting group of words.
13235
13236 With a negative numeric argument -N, the effect is the same as
13237 using a positive argument N except that the original cursor po‐
13238 sition is retained, regardless of how the words are rearranged.
13239
13240 vi-unindent (unbound) (<) (unbound)
13241 Unindent a number of lines.
13242
13243 vi-up-case (unbound) (gU) (unbound)
13244 Read a movement command from the keyboard, and convert all char‐
13245 acters from the cursor position to the endpoint of the movement
13246 to lowercase. If the movement command is vi-up-case, swap the
13247 case of all characters on the current line.
13248
13249 up-case-word (ESC-U ESC-u) (unbound) (unbound)
13250 Convert the current word to all caps and move past it.
13251
13252 yank (^Y) (unbound) (unbound)
13253 Insert the contents of the kill buffer at the cursor position.
13254
13255 yank-pop (ESC-y) (unbound) (unbound)
13256 Remove the text just yanked, rotate the kill-ring (the history
13257 of previously killed text) and yank the new top. Only works
13258 following yank, vi-put-before, vi-put-after or yank-pop.
13259
13260 vi-yank (unbound) (y) (unbound)
13261 Read a movement command from the keyboard, and copy the region
13262 from the cursor position to the endpoint of the movement into
13263 the kill buffer. If the command is vi-yank, copy the current
13264 line.
13265
13266 vi-yank-whole-line (unbound) (Y) (unbound)
13267 Copy the current line into the kill buffer.
13268
13269 vi-yank-eol
13270 Copy the region from the cursor position to the end of the line
13271 into the kill buffer. Arguably, this is what Y should do in vi,
13272 but it isn't what it actually does.
13273
13274 Arguments
13275 digit-argument (ESC-0..ESC-9) (1-9) (unbound)
13276 Start a new numeric argument, or add to the current one. See
13277 also vi-digit-or-beginning-of-line. This only works if bound to
13278 a key sequence ending in a decimal digit.
13279
13280 Inside a widget function, a call to this function treats the
13281 last key of the key sequence which called the widget as the
13282 digit.
13283
13284 neg-argument (ESC--) (unbound) (unbound)
13285 Changes the sign of the following argument.
13286
13287 universal-argument
13288 Multiply the argument of the next command by 4. Alternatively,
13289 if this command is followed by an integer (positive or nega‐
13290 tive), use that as the argument for the next command. Thus dig‐
13291 its cannot be repeated using this command. For example, if this
13292 command occurs twice, followed immediately by forward-char, move
13293 forward sixteen spaces; if instead it is followed by -2, then
13294 forward-char, move backward two spaces.
13295
13296 Inside a widget function, if passed an argument, i.e. `zle uni‐
13297 versal-argument num', the numeric argument will be set to num;
13298 this is equivalent to `NUMERIC=num'.
13299
13300 argument-base
13301 Use the existing numeric argument as a numeric base, which must
13302 be in the range 2 to 36 inclusive. Subsequent use of digit-ar‐
13303 gument and universal-argument will input a new numeric argument
13304 in the given base. The usual hexadecimal convention is used:
13305 the letter a or A corresponds to 10, and so on. Arguments in
13306 bases requiring digits from 10 upwards are more conveniently in‐
13307 put with universal-argument, since ESC-a etc. are not usually
13308 bound to digit-argument.
13309
13310 The function can be used with a command argument inside a
13311 user-defined widget. The following code sets the base to 16 and
13312 lets the user input a hexadecimal argument until a key out of
13313 the digit range is typed:
13314
13315 zle argument-base 16
13316 zle universal-argument
13317
13318 Completion
13319 accept-and-menu-complete
13320 In a menu completion, insert the current completion into the
13321 buffer, and advance to the next possible completion.
13322
13323 complete-word
13324 Attempt completion on the current word.
13325
13326 delete-char-or-list (^D) (unbound) (unbound)
13327 Delete the character under the cursor. If the cursor is at the
13328 end of the line, list possible completions for the current word.
13329
13330 expand-cmd-path
13331 Expand the current command to its full pathname.
13332
13333 expand-or-complete (TAB) (unbound) (TAB)
13334 Attempt shell expansion on the current word. If that fails, at‐
13335 tempt completion.
13336
13337 expand-or-complete-prefix
13338 Attempt shell expansion on the current word up to cursor.
13339
13340 expand-history (ESC-space ESC-!) (unbound) (unbound)
13341 Perform history expansion on the edit buffer.
13342
13343 expand-word (^X*) (unbound) (unbound)
13344 Attempt shell expansion on the current word.
13345
13346 list-choices (ESC-^D) (^D =) (^D)
13347 List possible completions for the current word.
13348
13349 list-expand (^Xg ^XG) (^G) (^G)
13350 List the expansion of the current word.
13351
13352 magic-space
13353 Perform history expansion and insert a space into the buffer.
13354 This is intended to be bound to space.
13355
13356 menu-complete
13357 Like complete-word, except that menu completion is used. See
13358 the MENU_COMPLETE option.
13359
13360 menu-expand-or-complete
13361 Like expand-or-complete, except that menu completion is used.
13362
13363 reverse-menu-complete
13364 Perform menu completion, like menu-complete, except that if a
13365 menu completion is already in progress, move to the previous
13366 completion rather than the next.
13367
13368 end-of-list
13369 When a previous completion displayed a list below the prompt,
13370 this widget can be used to move the prompt below the list.
13371
13372 Miscellaneous
13373 accept-and-hold (ESC-A ESC-a) (unbound) (unbound)
13374 Push the contents of the buffer on the buffer stack and execute
13375 it.
13376
13377 accept-and-infer-next-history
13378 Execute the contents of the buffer. Then search the history
13379 list for a line matching the current one and push the event fol‐
13380 lowing onto the buffer stack.
13381
13382 accept-line (^J ^M) (^J ^M) (^J ^M)
13383 Finish editing the buffer. Normally this causes the buffer to
13384 be executed as a shell command.
13385
13386 accept-line-and-down-history (^O) (unbound) (unbound)
13387 Execute the current line, and push the next history event on the
13388 buffer stack.
13389
13390 auto-suffix-remove
13391 If the previous action added a suffix (space, slash, etc.) to
13392 the word on the command line, remove it. Otherwise do nothing.
13393 Removing the suffix ends any active menu completion or menu se‐
13394 lection.
13395
13396 This widget is intended to be called from user-defined widgets
13397 to enforce a desired suffix-removal behavior.
13398
13399 auto-suffix-retain
13400 If the previous action added a suffix (space, slash, etc.) to
13401 the word on the command line, force it to be preserved. Other‐
13402 wise do nothing. Retaining the suffix ends any active menu com‐
13403 pletion or menu selection.
13404
13405 This widget is intended to be called from user-defined widgets
13406 to enforce a desired suffix-preservation behavior.
13407
13408 beep Beep, unless the BEEP option is unset.
13409
13410 bracketed-paste (^[[200~) (^[[200~) (^[[200~)
13411 This widget is invoked when text is pasted to the terminal emu‐
13412 lator. It is not intended to be bound to actual keys but instead
13413 to the special sequence generated by the terminal emulator when
13414 text is pasted.
13415
13416 When invoked interactively, the pasted text is inserted to the
13417 buffer and placed in the cutbuffer. If a numeric argument is
13418 given, shell quoting will be applied to the pasted text before
13419 it is inserted.
13420
13421 When a named buffer is specified with vi-set-buffer ("x), the
13422 pasted text is stored in that named buffer but not inserted.
13423
13424 When called from a widget function as `bracketed-paste name`,
13425 the pasted text is assigned to the variable name and no other
13426 processing is done.
13427
13428 See also the zle_bracketed_paste parameter.
13429
13430 vi-cmd-mode (^X^V) (unbound) (^[)
13431 Enter command mode; that is, select the `vicmd' keymap. Yes,
13432 this is bound by default in emacs mode.
13433
13434 vi-caps-lock-panic
13435 Hang until any lowercase key is pressed. This is for vi users
13436 without the mental capacity to keep track of their caps lock key
13437 (like the author).
13438
13439 clear-screen (^L ESC-^L) (^L) (^L)
13440 Clear the screen and redraw the prompt.
13441
13442 deactivate-region
13443 Make the current region inactive. This disables vim-style visual
13444 selection mode if it is active.
13445
13446 describe-key-briefly
13447 Reads a key sequence, then prints the function bound to that se‐
13448 quence.
13449
13450 exchange-point-and-mark (^X^X) (unbound) (unbound)
13451 Exchange the cursor position (point) with the position of the
13452 mark. Unless a negative numeric argument is given, the region
13453 between point and mark is activated so that it can be high‐
13454 lighted. If a zero numeric argument is given, the region is ac‐
13455 tivated but point and mark are not swapped.
13456
13457 execute-named-cmd (ESC-x) (:) (unbound)
13458 Read the name of an editor command and execute it. Aliasing
13459 this widget with `zle -A' or replacing it with `zle -N' has no
13460 effect when interpreting key bindings, but `zle exe‐
13461 cute-named-cmd' will invoke such an alias or replacement.
13462
13463 A restricted set of editing functions is available in the
13464 mini-buffer. Keys are looked up in the special command keymap,
13465 and if not found there in the main keymap. An interrupt signal,
13466 as defined by the stty setting, will abort the function. Note
13467 that the following always perform the same task within the exe‐
13468 cuted-named-cmd environment and cannot be replaced by user de‐
13469 fined widgets, nor can the set of functions be extended. The
13470 allowed functions are: backward-delete-char, vi-back‐
13471 ward-delete-char, clear-screen, redisplay, quoted-insert,
13472 vi-quoted-insert, backward-kill-word, vi-backward-kill-word,
13473 kill-whole-line, vi-kill-line, backward-kill-line, list-choices,
13474 delete-char-or-list, complete-word, accept-line, expand-or-com‐
13475 plete and expand-or-complete-prefix.
13476
13477 kill-region kills the last word, and vi-cmd-mode is treated the
13478 same as accept-line. The space and tab characters, if not bound
13479 to one of these functions, will complete the name and then list
13480 the possibilities if the AUTO_LIST option is set. Any other
13481 character that is not bound to self-insert or self-insert-unmeta
13482 will beep and be ignored. The bindings of the current insert
13483 mode will be used.
13484
13485 Currently this command may not be redefined or called by name.
13486
13487 execute-last-named-cmd (ESC-z) (unbound) (unbound)
13488 Redo the last function executed with execute-named-cmd.
13489
13490 Like execute-named-cmd, this command may not be redefined, but
13491 it may be called by name.
13492
13493 get-line (ESC-G ESC-g) (unbound) (unbound)
13494 Pop the top line off the buffer stack and insert it at the cur‐
13495 sor position.
13496
13497 pound-insert (unbound) (#) (unbound)
13498 If there is no # character at the beginning of the buffer, add
13499 one to the beginning of each line. If there is one, remove a #
13500 from each line that has one. In either case, accept the current
13501 line. The INTERACTIVE_COMMENTS option must be set for this to
13502 have any usefulness.
13503
13504 vi-pound-insert
13505 If there is no # character at the beginning of the current line,
13506 add one. If there is one, remove it. The INTERACTIVE_COMMENTS
13507 option must be set for this to have any usefulness.
13508
13509 push-input
13510 Push the entire current multiline construct onto the buffer
13511 stack and return to the top-level (PS1) prompt. If the current
13512 parser construct is only a single line, this is exactly like
13513 push-line. Next time the editor starts up or is popped with
13514 get-line, the construct will be popped off the top of the buffer
13515 stack and loaded into the editing buffer.
13516
13517 push-line (^Q ESC-Q ESC-q) (unbound) (unbound)
13518 Push the current buffer onto the buffer stack and clear the buf‐
13519 fer. Next time the editor starts up, the buffer will be popped
13520 off the top of the buffer stack and loaded into the editing buf‐
13521 fer.
13522
13523 push-line-or-edit
13524 At the top-level (PS1) prompt, equivalent to push-line. At a
13525 secondary (PS2) prompt, move the entire current multiline con‐
13526 struct into the editor buffer. The latter is equivalent to
13527 push-input followed by get-line.
13528
13529 read-command
13530 Only useful from a user-defined widget. A keystroke is read
13531 just as in normal operation, but instead of the command being
13532 executed the name of the command that would be executed is
13533 stored in the shell parameter REPLY. This can be used as the
13534 argument of a future zle command. If the key sequence is not
13535 bound, status 1 is returned; typically, however, REPLY is set to
13536 undefined-key to indicate a useless key sequence.
13537
13538 recursive-edit
13539 Only useful from a user-defined widget. At this point in the
13540 function, the editor regains control until one of the standard
13541 widgets which would normally cause zle to exit (typically an ac‐
13542 cept-line caused by hitting the return key) is executed. In‐
13543 stead, control returns to the user-defined widget. The status
13544 returned is non-zero if the return was caused by an error, but
13545 the function still continues executing and hence may tidy up.
13546 This makes it safe for the user-defined widget to alter the com‐
13547 mand line or key bindings temporarily.
13548
13549 The following widget, caps-lock, serves as an example.
13550
13551 self-insert-ucase() {
13552 LBUFFER+=${(U)KEYS[-1]}
13553 }
13554
13555 integer stat
13556
13557 zle -N self-insert self-insert-ucase
13558 zle -A caps-lock save-caps-lock
13559 zle -A accept-line caps-lock
13560
13561 zle recursive-edit
13562 stat=$?
13563
13564 zle -A .self-insert self-insert
13565 zle -A save-caps-lock caps-lock
13566 zle -D save-caps-lock
13567
13568 (( stat )) && zle send-break
13569
13570 return $stat
13571
13572 This causes typed letters to be inserted capitalised until ei‐
13573 ther accept-line (i.e. typically the return key) is typed or the
13574 caps-lock widget is invoked again; the later is handled by sav‐
13575 ing the old definition of caps-lock as save-caps-lock and then
13576 rebinding it to invoke accept-line. Note that an error from the
13577 recursive edit is detected as a non-zero return status and prop‐
13578 agated by using the send-break widget.
13579
13580 redisplay (unbound) (^R) (^R)
13581 Redisplays the edit buffer.
13582
13583 reset-prompt (unbound) (unbound) (unbound)
13584 Force the prompts on both the left and right of the screen to be
13585 re-expanded, then redisplay the edit buffer. This reflects
13586 changes both to the prompt variables themselves and changes in
13587 the expansion of the values (for example, changes in time or di‐
13588 rectory, or changes to the value of variables referred to by the
13589 prompt).
13590
13591 Otherwise, the prompt is only expanded each time zle starts, and
13592 when the display has been interrupted by output from another
13593 part of the shell (such as a job notification) which causes the
13594 command line to be reprinted.
13595
13596 reset-prompt doesn't alter the special parameter LASTWIDGET.
13597
13598 send-break (^G ESC-^G) (unbound) (unbound)
13599 Abort the current editor function, e.g. execute-named-command,
13600 or the editor itself, e.g. if you are in vared. Otherwise abort
13601 the parsing of the current line; in this case the aborted line
13602 is available in the shell variable ZLE_LINE_ABORTED. If the ed‐
13603 itor is aborted from within vared, the variable
13604 ZLE_VARED_ABORTED is set.
13605
13606 run-help (ESC-H ESC-h) (unbound) (unbound)
13607 Push the buffer onto the buffer stack, and execute the command
13608 `run-help cmd', where cmd is the current command. run-help is
13609 normally aliased to man.
13610
13611 vi-set-buffer (unbound) (") (unbound)
13612 Specify a buffer to be used in the following command. There are
13613 37 buffers that can be specified: the 26 `named' buffers "a to
13614 "z, the `yank' buffer "0, the nine `queued' buffers "1 to "9 and
13615 the `black hole' buffer "_. The named buffers can also be spec‐
13616 ified as "A to "Z.
13617
13618 When a buffer is specified for a cut, change or yank command,
13619 the text concerned replaces the previous contents of the speci‐
13620 fied buffer. If a named buffer is specified using a capital, the
13621 newly cut text is appended to the buffer instead of overwriting
13622 it. When using the "_ buffer, nothing happens. This can be use‐
13623 ful for deleting text without affecting any buffers.
13624
13625 If no buffer is specified for a cut or change command, "1 is
13626 used, and the contents of "1 to "8 are each shifted along one
13627 buffer; the contents of "9 is lost. If no buffer is specified
13628 for a yank command, "0 is used. Finally, a paste command without
13629 a specified buffer will paste the text from the most recent com‐
13630 mand regardless of any buffer that might have been used with
13631 that command.
13632
13633 When called from a widget function by the zle command, the buf‐
13634 fer can optionally be specified with an argument. For example,
13635
13636 zle vi-set-buffer A
13637
13638 vi-set-mark (unbound) (m) (unbound)
13639 Set the specified mark at the cursor position.
13640
13641 set-mark-command (^@) (unbound) (unbound)
13642 Set the mark at the cursor position. If called with a negative
13643 numeric argument, do not set the mark but deactivate the region
13644 so that it is no longer highlighted (it is still usable for
13645 other purposes). Otherwise the region is marked as active.
13646
13647 spell-word (ESC-$ ESC-S ESC-s) (unbound) (unbound)
13648 Attempt spelling correction on the current word.
13649
13650 split-undo
13651 Breaks the undo sequence at the current change. This is useful
13652 in vi mode as changes made in insert mode are coalesced on en‐
13653 tering command mode. Similarly, undo will normally revert as
13654 one all the changes made by a user-defined widget.
13655
13656 undefined-key
13657 This command is executed when a key sequence that is not bound
13658 to any command is typed. By default it beeps.
13659
13660 undo (^_ ^Xu ^X^U) (u) (unbound)
13661 Incrementally undo the last text modification. When called from
13662 a user-defined widget, takes an optional argument indicating a
13663 previous state of the undo history as returned by the
13664 UNDO_CHANGE_NO variable; modifications are undone until that
13665 state is reached, subject to any limit imposed by the
13666 UNDO_LIMIT_NO variable.
13667
13668 Note that when invoked from vi command mode, the full prior
13669 change made in insert mode is reverted, the changes having been
13670 merged when command mode was selected.
13671
13672 redo (unbound) (^R) (unbound)
13673 Incrementally redo undone text modifications.
13674
13675 vi-undo-change (unbound) (unbound) (unbound)
13676 Undo the last text modification. If repeated, redo the modifi‐
13677 cation.
13678
13679 visual-mode (unbound) (v) (unbound)
13680 Toggle vim-style visual selection mode. If line-wise visual mode
13681 is currently enabled then it is changed to being character-wise.
13682 If used following an operator, it forces the subsequent movement
13683 command to be treated as a character-wise movement.
13684
13685 visual-line-mode (unbound) (V) (unbound)
13686 Toggle vim-style line-wise visual selection mode. If charac‐
13687 ter-wise visual mode is currently enabled then it is changed to
13688 being line-wise. If used following an operator, it forces the
13689 subsequent movement command to be treated as a line-wise move‐
13690 ment.
13691
13692 what-cursor-position (^X=) (ga) (unbound)
13693 Print the character under the cursor, its code as an octal, dec‐
13694 imal and hexadecimal number, the current cursor position within
13695 the buffer and the column of the cursor in the current line.
13696
13697 where-is
13698 Read the name of an editor command and print the listing of key
13699 sequences that invoke the specified command. A restricted set
13700 of editing functions is available in the mini-buffer. Keys are
13701 looked up in the special command keymap, and if not found there
13702 in the main keymap.
13703
13704 which-command (ESC-?) (unbound) (unbound)
13705 Push the buffer onto the buffer stack, and execute the command
13706 `which-command cmd'. where cmd is the current command.
13707 which-command is normally aliased to whence.
13708
13709 vi-digit-or-beginning-of-line (unbound) (0) (unbound)
13710 If the last command executed was a digit as part of an argument,
13711 continue the argument. Otherwise, execute vi-beginning-of-line.
13712
13713 Text Objects
13714 Text objects are commands that can be used to select a block of text
13715 according to some criteria. They are a feature of the vim text editor
13716 and so are primarily intended for use with vi operators or from visual
13717 selection mode. However, they can also be used from vi-insert or emacs
13718 mode. Key bindings listed below apply to the viopp and visual keymaps.
13719
13720 select-a-blank-word (aW)
13721 Select a word including adjacent blanks, where a word is defined
13722 as a series of non-blank characters. With a numeric argument,
13723 multiple words will be selected.
13724
13725 select-a-shell-word (aa)
13726 Select the current command argument applying the normal rules
13727 for quoting.
13728
13729 select-a-word (aw)
13730 Select a word including adjacent blanks, using the normal
13731 vi-style word definition. With a numeric argument, multiple
13732 words will be selected.
13733
13734 select-in-blank-word (iW)
13735 Select a word, where a word is defined as a series of non-blank
13736 characters. With a numeric argument, multiple words will be se‐
13737 lected.
13738
13739 select-in-shell-word (ia)
13740 Select the current command argument applying the normal rules
13741 for quoting. If the argument begins and ends with matching quote
13742 characters, these are not included in the selection.
13743
13744 select-in-word (iw)
13745 Select a word, using the normal vi-style word definition. With a
13746 numeric argument, multiple words will be selected.
13747
13749 The line editor has the ability to highlight characters or regions of
13750 the line that have a particular significance. This is controlled by
13751 the array parameter zle_highlight, if it has been set by the user.
13752
13753 If the parameter contains the single entry none all highlighting is
13754 turned off. Note the parameter is still expected to be an array.
13755
13756 Otherwise each entry of the array should consist of a word indicating a
13757 context for highlighting, then a colon, then a comma-separated list of
13758 the types of highlighting to apply in that context.
13759
13760 The contexts available for highlighting are the following:
13761
13762 default
13763 Any text within the command line not affected by any other high‐
13764 lighting. Text outside the editable area of the command line is
13765 not affected.
13766
13767 isearch
13768 When one of the incremental history search widgets is active,
13769 the area of the command line matched by the search string or
13770 pattern.
13771
13772 region The currently selected text. In emacs terminology, this is re‐
13773 ferred to as the region and is bounded by the cursor (point) and
13774 the mark. The region is only highlighted if it is active, which
13775 is the case after the mark is modified with set-mark-command or
13776 exchange-point-and-mark. Note that whether or not the region is
13777 active has no effect on its use within emacs style widgets, it
13778 simply determines whether it is highlighted. In vi mode, the re‐
13779 gion corresponds to selected text in visual mode.
13780
13781 special
13782 Individual characters that have no direct printable representa‐
13783 tion but are shown in a special manner by the line editor.
13784 These characters are described below.
13785
13786 suffix This context is used in completion for characters that are
13787 marked as suffixes that will be removed if the completion ends
13788 at that point, the most obvious example being a slash (/) after
13789 a directory name. Note that suffix removal is configurable; the
13790 circumstances under which the suffix will be removed may differ
13791 for different completions.
13792
13793 paste Following a command to paste text, the characters that were in‐
13794 serted.
13795
13796 When region_highlight is set, the contexts that describe a region --
13797 isearch, region, suffix, and paste -- are applied first, then re‐
13798 gion_highlight is applied, then the remaining zle_highlight contexts
13799 are applied. If a particular character is affected by multiple speci‐
13800 fications, the last specification wins.
13801
13802 zle_highlight may contain additional fields for controlling how termi‐
13803 nal sequences to change colours are output. Each of the following is
13804 followed by a colon and a string in the same form as for key bindings.
13805 This will not be necessary for the vast majority of terminals as the
13806 defaults shown in parentheses are widely used.
13807
13808 fg_start_code (\e[3)
13809 The start of the escape sequence for the foreground colour.
13810 This is followed by one to three ASCII digits representing the
13811 colour. Only used for palette colors, i.e. not 24-bit colors
13812 specified via a color triplet.
13813
13814 fg_default_code (9)
13815 The number to use instead of the colour to reset the default
13816 foreground colour.
13817
13818 fg_end_code (m)
13819 The end of the escape sequence for the foreground colour.
13820
13821 bg_start_code (\e[4)
13822 The start of the escape sequence for the background colour. See
13823 fg_start_code above.
13824
13825 bg_default_code (9)
13826 The number to use instead of the colour to reset the default
13827 background colour.
13828
13829 bg_end_code (m)
13830 The end of the escape sequence for the background colour.
13831
13832 The available types of highlighting are the following. Note that not
13833 all types of highlighting are available on all terminals:
13834
13835 none No highlighting is applied to the given context. It is not use‐
13836 ful for this to appear with other types of highlighting; it is
13837 used to override a default.
13838
13839 fg=colour
13840 The foreground colour should be set to colour, a decimal inte‐
13841 ger, the name of one of the eight most widely-supported colours
13842 or as a `#' followed by an RGB triplet in hexadecimal format.
13843
13844 Not all terminals support this and, of those that do, not all
13845 provide facilities to test the support, hence the user should
13846 decide based on the terminal type. Most terminals support the
13847 colours black, red, green, yellow, blue, magenta, cyan and
13848 white, which can be set by name. In addition. default may be
13849 used to set the terminal's default foreground colour. Abbrevia‐
13850 tions are allowed; b or bl selects black. Some terminals may
13851 generate additional colours if the bold attribute is also
13852 present.
13853
13854 On recent terminals and on systems with an up-to-date terminal
13855 database the number of colours supported may be tested by the
13856 command `echotc Co'; if this succeeds, it indicates a limit on
13857 the number of colours which will be enforced by the line editor.
13858 The number of colours is in any case limited to 256 (i.e. the
13859 range 0 to 255).
13860
13861 Some modern terminal emulators have support for 24-bit true
13862 colour (16 million colours). In this case, the hex triplet for‐
13863 mat can be used. This consists of a `#' followed by either a
13864 three or six digit hexadecimal number describing the red, green
13865 and blue components of the colour. Hex triplets can also be used
13866 with 88 and 256 colour terminals via the zsh/nearcolor module
13867 (see zshmodules(1)).
13868
13869 Colour is also known as color.
13870
13871 bg=colour
13872 The background colour should be set to colour. This works simi‐
13873 larly to the foreground colour, except the background is not
13874 usually affected by the bold attribute.
13875
13876 bold The characters in the given context are shown in a bold font.
13877 Not all terminals distinguish bold fonts.
13878
13879 standout
13880 The characters in the given context are shown in the terminal's
13881 standout mode. The actual effect is specific to the terminal;
13882 on many terminals it is inverse video. On some such terminals,
13883 where the cursor does not blink it appears with standout mode
13884 negated, making it less than clear where the cursor actually is.
13885 On such terminals one of the other effects may be preferable for
13886 highlighting the region and matched search string.
13887
13888 underline
13889 The characters in the given context are shown underlined. Some
13890 terminals show the foreground in a different colour instead; in
13891 this case whitespace will not be highlighted.
13892
13893 The characters described above as `special' are as follows. The for‐
13894 matting described here is used irrespective of whether the characters
13895 are highlighted:
13896
13897 ASCII control characters
13898 Control characters in the ASCII range are shown as `^' followed
13899 by the base character.
13900
13901 Unprintable multibyte characters
13902 This item applies to control characters not in the ASCII range,
13903 plus other characters as follows. If the MULTIBYTE option is in
13904 effect, multibyte characters not in the ASCII character set that
13905 are reported as having zero width are treated as combining char‐
13906 acters when the option COMBINING_CHARS is on. If the option is
13907 off, or if a character appears where a combining character is
13908 not valid, the character is treated as unprintable.
13909
13910 Unprintable multibyte characters are shown as a hexadecimal num‐
13911 ber between angle brackets. The number is the code point of the
13912 character in the wide character set; this may or may not be Uni‐
13913 code, depending on the operating system.
13914
13915 Invalid multibyte characters
13916 If the MULTIBYTE option is in effect, any sequence of one or
13917 more bytes that does not form a valid character in the current
13918 character set is treated as a series of bytes each shown as a
13919 special character. This case can be distinguished from other
13920 unprintable characters as the bytes are represented as two hexa‐
13921 decimal digits between angle brackets, as distinct from the four
13922 or eight digits that are used for unprintable characters that
13923 are nonetheless valid in the current character set.
13924
13925 Not all systems support this: for it to work, the system's rep‐
13926 resentation of wide characters must be code values from the Uni‐
13927 versal Character Set, as defined by IS0 10646 (also known as
13928 Unicode).
13929
13930 Wrapped double-width characters
13931 When a double-width character appears in the final column of a
13932 line, it is instead shown on the next line. The empty space left
13933 in the original position is highlighted as a special character.
13934
13935 If zle_highlight is not set or no value applies to a particular con‐
13936 text, the defaults applied are equivalent to
13937
13938 zle_highlight=(region:standout special:standout
13939 suffix:bold isearch:underline paste:standout)
13940
13941 i.e. both the region and special characters are shown in standout mode.
13942
13943 Within widgets, arbitrary regions may be highlighted by setting the
13944 special array parameter region_highlight; see above.
13945
13946ZSHCOMPWID(1) General Commands Manual ZSHCOMPWID(1)
13947
13948
13949
13951 zshcompwid - zsh completion widgets
13952
13954 The shell's programmable completion mechanism can be manipulated in two
13955 ways; here the low-level features supporting the newer, function-based
13956 mechanism are defined. A complete set of shell functions based on
13957 these features is described in zshcompsys(1), and users with no inter‐
13958 est in adding to that system (or, potentially, writing their own -- see
13959 dictionary entry for `hubris') should skip the current section. The
13960 older system based on the compctl builtin command is described in zsh‐
13961 compctl(1).
13962
13963 Completion widgets are defined by the -C option to the zle builtin com‐
13964 mand provided by the zsh/zle module (see zshzle(1)). For example,
13965
13966 zle -C complete expand-or-complete completer
13967
13968 defines a widget named `complete'. The second argument is the name of
13969 any of the builtin widgets that handle completions: complete-word, ex‐
13970 pand-or-complete, expand-or-complete-prefix, menu-complete, menu-ex‐
13971 pand-or-complete, reverse-menu-complete, list-choices, or
13972 delete-char-or-list. Note that this will still work even if the widget
13973 in question has been re-bound.
13974
13975 When this newly defined widget is bound to a key using the bindkey
13976 builtin command defined in the zsh/zle module (see zshzle(1)), typing
13977 that key will call the shell function `completer'. This function is re‐
13978 sponsible for generating completion matches using the builtins de‐
13979 scribed below. As with other ZLE widgets, the function is called with
13980 its standard input closed.
13981
13982 Once the function returns, the completion code takes over control again
13983 and treats the matches in the same manner as the specified builtin wid‐
13984 get, in this case expand-or-complete.
13985
13987 The parameters ZLE_REMOVE_SUFFIX_CHARS and ZLE_SPACE_SUFFIX_CHARS are
13988 used by the completion mechanism, but are not special. See Parameters
13989 Used By The Shell in zshparam(1).
13990
13991 Inside completion widgets, and any functions called from them, some pa‐
13992 rameters have special meaning; outside these functions they are not
13993 special to the shell in any way. These parameters are used to pass in‐
13994 formation between the completion code and the completion widget. Some
13995 of the builtin commands and the condition codes use or change the cur‐
13996 rent values of these parameters. Any existing values will be hidden
13997 during execution of completion widgets; except for compstate, the pa‐
13998 rameters are reset on each function exit (including nested function
13999 calls from within the completion widget) to the values they had when
14000 the function was entered.
14001
14002 CURRENT
14003 This is the number of the current word, i.e. the word the cursor
14004 is currently on in the words array. Note that this value is
14005 only correct if the ksharrays option is not set.
14006
14007 IPREFIX
14008 Initially this will be set to the empty string. This parameter
14009 functions like PREFIX; it contains a string which precedes the
14010 one in PREFIX and is not considered part of the list of matches.
14011 Typically, a string is transferred from the beginning of PREFIX
14012 to the end of IPREFIX, for example:
14013
14014 IPREFIX=${PREFIX%%\=*}=
14015 PREFIX=${PREFIX#*=}
14016
14017 causes the part of the prefix up to and including the first
14018 equal sign not to be treated as part of a matched string. This
14019 can be done automatically by the compset builtin, see below.
14020
14021 ISUFFIX
14022 As IPREFIX, but for a suffix that should not be considered part
14023 of the matches; note that the ISUFFIX string follows the SUFFIX
14024 string.
14025
14026 PREFIX Initially this will be set to the part of the current word from
14027 the beginning of the word up to the position of the cursor; it
14028 may be altered to give a common prefix for all matches.
14029
14030 QIPREFIX
14031 This parameter is read-only and contains the quoted string up to
14032 the word being completed. E.g. when completing `"foo', this pa‐
14033 rameter contains the double quote. If the -q option of compset
14034 is used (see below), and the original string was `"foo bar' with
14035 the cursor on the `bar', this parameter contains `"foo '.
14036
14037 QISUFFIX
14038 Like QIPREFIX, but containing the suffix.
14039
14040 SUFFIX Initially this will be set to the part of the current word from
14041 the cursor position to the end; it may be altered to give a com‐
14042 mon suffix for all matches. It is most useful when the option
14043 COMPLETE_IN_WORD is set, as otherwise the whole word on the com‐
14044 mand line is treated as a prefix.
14045
14046 compstate
14047 This is an associative array with various keys and values that
14048 the completion code uses to exchange information with the com‐
14049 pletion widget. The keys are:
14050
14051 all_quotes
14052 The -q option of the compset builtin command (see below)
14053 allows a quoted string to be broken into separate words;
14054 if the cursor is on one of those words, that word will be
14055 completed, possibly invoking `compset -q' recursively.
14056 With this key it is possible to test the types of quoted
14057 strings which are currently broken into parts in this
14058 fashion. Its value contains one character for each quot‐
14059 ing level. The characters are a single quote or a double
14060 quote for strings quoted with these characters, a dollars
14061 sign for strings quoted with $'...' and a backslash for
14062 strings not starting with a quote character. The first
14063 character in the value always corresponds to the inner‐
14064 most quoting level.
14065
14066 context
14067 This will be set by the completion code to the overall
14068 context in which completion is attempted. Possible values
14069 are:
14070
14071 array_value
14072 when completing inside the value of an array pa‐
14073 rameter assignment; in this case the words array
14074 contains the words inside the parentheses.
14075
14076 brace_parameter
14077 when completing the name of a parameter in a pa‐
14078 rameter expansion beginning with ${. This context
14079 will also be set when completing parameter flags
14080 following ${(; the full command line argument is
14081 presented and the handler must test the value to
14082 be completed to ascertain that this is the case.
14083
14084 assign_parameter
14085 when completing the name of a parameter in a pa‐
14086 rameter assignment.
14087
14088 command
14089 when completing for a normal command (either in
14090 command position or for an argument of the com‐
14091 mand).
14092
14093 condition
14094 when completing inside a `[[...]]' conditional ex‐
14095 pression; in this case the words array contains
14096 only the words inside the conditional expression.
14097
14098 math when completing in a mathematical environment such
14099 as a `((...))' construct.
14100
14101 parameter
14102 when completing the name of a parameter in a pa‐
14103 rameter expansion beginning with $ but not ${.
14104
14105 redirect
14106 when completing after a redirection operator.
14107
14108 subscript
14109 when completing inside a parameter subscript.
14110
14111 value when completing the value of a parameter assign‐
14112 ment.
14113
14114 exact Controls the behaviour when the REC_EXACT option is set.
14115 It will be set to accept if an exact match would be ac‐
14116 cepted, and will be unset otherwise.
14117
14118 If it was set when at least one match equal to the string
14119 on the line was generated, the match is accepted.
14120
14121 exact_string
14122 The string of an exact match if one was found, otherwise
14123 unset.
14124
14125 ignored
14126 The number of completions that were ignored because they
14127 matched one of the patterns given with the -F option to
14128 the compadd builtin command.
14129
14130 insert This controls the manner in which a match is inserted
14131 into the command line. On entry to the widget function,
14132 if it is unset the command line is not to be changed; if
14133 set to unambiguous, any prefix common to all matches is
14134 to be inserted; if set to automenu-unambiguous, the com‐
14135 mon prefix is to be inserted and the next invocation of
14136 the completion code may start menu completion (due to the
14137 AUTO_MENU option being set); if set to menu or automenu
14138 menu completion will be started for the matches currently
14139 generated (in the latter case this will happen because
14140 the AUTO_MENU is set). The value may also contain the
14141 string `tab' when the completion code would normally not
14142 really do completion, but only insert the TAB character.
14143
14144 On exit it may be set to any of the values above (where
14145 setting it to the empty string is the same as unsetting
14146 it), or to a number, in which case the match whose number
14147 is given will be inserted into the command line. Nega‐
14148 tive numbers count backward from the last match (with
14149 `-1' selecting the last match) and out-of-range values
14150 are wrapped around, so that a value of zero selects the
14151 last match and a value one more than the maximum selects
14152 the first. Unless the value of this key ends in a space,
14153 the match is inserted as in a menu completion, i.e. with‐
14154 out automatically appending a space.
14155
14156 Both menu and automenu may also specify the number of the
14157 match to insert, given after a colon. For example,
14158 `menu:2' says to start menu completion, beginning with
14159 the second match.
14160
14161 Note that a value containing the substring `tab' makes
14162 the matches generated be ignored and only the TAB be in‐
14163 serted.
14164
14165 Finally, it may also be set to all, which makes all
14166 matches generated be inserted into the line.
14167
14168 insert_positions
14169 When the completion system inserts an unambiguous string
14170 into the line, there may be multiple places where charac‐
14171 ters are missing or where the character inserted differs
14172 from at least one match. The value of this key contains
14173 a colon separated list of all these positions, as indexes
14174 into the command line.
14175
14176 last_prompt
14177 If this is set to a non-empty string for every match
14178 added, the completion code will move the cursor back to
14179 the previous prompt after the list of completions has
14180 been displayed. Initially this is set or unset according
14181 to the ALWAYS_LAST_PROMPT option.
14182
14183 list This controls whether or how the list of matches will be
14184 displayed. If it is unset or empty they will never be
14185 listed; if its value begins with list, they will always
14186 be listed; if it begins with autolist or ambiguous, they
14187 will be listed when the AUTO_LIST or LIST_AMBIGUOUS op‐
14188 tions respectively would normally cause them to be.
14189
14190 If the substring force appears in the value, this makes
14191 the list be shown even if there is only one match. Nor‐
14192 mally, the list would be shown only if there are at least
14193 two matches.
14194
14195 The value contains the substring packed if the
14196 LIST_PACKED option is set. If this substring is given for
14197 all matches added to a group, this group will show the
14198 LIST_PACKED behavior. The same is done for the
14199 LIST_ROWS_FIRST option with the substring rows.
14200
14201 Finally, if the value contains the string explanations,
14202 only the explanation strings, if any, will be listed and
14203 if it contains messages, only the messages (added with
14204 the -x option of compadd) will be listed. If it contains
14205 both explanations and messages both kinds of explanation
14206 strings will be listed. It will be set appropriately on
14207 entry to a completion widget and may be changed there.
14208
14209 list_lines
14210 This gives the number of lines that are needed to display
14211 the full list of completions. Note that to calculate the
14212 total number of lines to display you need to add the num‐
14213 ber of lines needed for the command line to this value,
14214 this is available as the value of the BUFFERLINES special
14215 parameter.
14216
14217 list_max
14218 Initially this is set to the value of the LISTMAX parame‐
14219 ter. It may be set to any other value; when the widget
14220 exits this value will be used in the same way as the
14221 value of LISTMAX.
14222
14223 nmatches
14224 The number of matches added by the completion code so
14225 far.
14226
14227 old_insert
14228 On entry to the widget this will be set to the number of
14229 the match of an old list of completions that is currently
14230 inserted into the command line. If no match has been in‐
14231 serted, this is unset.
14232
14233 As with old_list, the value of this key will only be used
14234 if it is the string keep. If it was set to this value by
14235 the widget and there was an old match inserted into the
14236 command line, this match will be kept and if the value of
14237 the insert key specifies that another match should be in‐
14238 serted, this will be inserted after the old one.
14239
14240 old_list
14241 This is set to yes if there is still a valid list of com‐
14242 pletions from a previous completion at the time the wid‐
14243 get is invoked. This will usually be the case if and
14244 only if the previous editing operation was a completion
14245 widget or one of the builtin completion functions. If
14246 there is a valid list and it is also currently shown on
14247 the screen, the value of this key is shown.
14248
14249 After the widget has exited the value of this key is only
14250 used if it was set to keep. In this case the completion
14251 code will continue to use this old list. If the widget
14252 generated new matches, they will not be used.
14253
14254 parameter
14255 The name of the parameter when completing in a subscript
14256 or in the value of a parameter assignment.
14257
14258 pattern_insert
14259 Normally this is set to menu, which specifies that menu
14260 completion will be used whenever a set of matches was
14261 generated using pattern_match (see below). If it is set
14262 to any other non-empty string by the user and menu com‐
14263 pletion is not selected by other option settings, the
14264 code will instead insert any common prefix for the gener‐
14265 ated matches as with normal completion.
14266
14267 pattern_match
14268 Locally controls the behaviour given by the GLOB_COMPLETE
14269 option. Initially it is set to `*' if and only if the
14270 option is set. The completion widget may set it to this
14271 value, to an empty string (which has the same effect as
14272 unsetting it), or to any other non-empty string. If it
14273 is non-empty, unquoted metacharacters on the command line
14274 will be treated as patterns; if it is `*', then addition‐
14275 ally a wildcard `*' is assumed at the cursor position; if
14276 it is empty or unset, metacharacters will be treated lit‐
14277 erally.
14278
14279 Note that the match specifications given to the compadd
14280 builtin command are not used if this is set to a
14281 non-empty string.
14282
14283 quote When completing inside quotes, this contains the quota‐
14284 tion character (i.e. either a single quote, a double
14285 quote, or a backtick). Otherwise it is unset.
14286
14287 quoting
14288 When completing inside single quotes, this is set to the
14289 string single; inside double quotes, the string double;
14290 inside backticks, the string backtick. Otherwise it is
14291 unset.
14292
14293 redirect
14294 The redirection operator when completing in a redirection
14295 position, i.e. one of <, >, etc.
14296
14297 restore
14298 This is set to auto before a function is entered, which
14299 forces the special parameters mentioned above (words,
14300 CURRENT, PREFIX, IPREFIX, SUFFIX, and ISUFFIX) to be re‐
14301 stored to their previous values when the function exits.
14302 If a function unsets it or sets it to any other string,
14303 they will not be restored.
14304
14305 to_end Specifies the occasions on which the cursor is moved to
14306 the end of a string when a match is inserted. On entry
14307 to a widget function, it may be single if this will hap‐
14308 pen when a single unambiguous match was inserted or match
14309 if it will happen any time a match is inserted (for exam‐
14310 ple, by menu completion; this is likely to be the effect
14311 of the ALWAYS_TO_END option).
14312
14313 On exit, it may be set to single as above. It may also
14314 be set to always, or to the empty string or unset; in
14315 those cases the cursor will be moved to the end of the
14316 string always or never respectively. Any other string is
14317 treated as match.
14318
14319 unambiguous
14320 This key is read-only and will always be set to the com‐
14321 mon (unambiguous) prefix the completion code has gener‐
14322 ated for all matches added so far.
14323
14324 unambiguous_cursor
14325 This gives the position the cursor would be placed at if
14326 the common prefix in the unambiguous key were inserted,
14327 relative to the value of that key. The cursor would be
14328 placed before the character whose index is given by this
14329 key.
14330
14331 unambiguous_positions
14332 This contains all positions where characters in the unam‐
14333 biguous string are missing or where the character in‐
14334 serted differs from at least one of the matches. The po‐
14335 sitions are given as indexes into the string given by the
14336 value of the unambiguous key.
14337
14338 vared If completion is called while editing a line using the
14339 vared builtin, the value of this key is set to the name
14340 of the parameter given as an argument to vared. This key
14341 is only set while a vared command is active.
14342
14343 words This array contains the words present on the command line cur‐
14344 rently being edited.
14345
14347 compadd [ -akqQfenUl12C ] [ -F array ]
14348 [-P prefix ] [ -S suffix ]
14349 [-p hidden-prefix ] [ -s hidden-suffix ]
14350 [-i ignored-prefix ] [ -I ignored-suffix ]
14351 [-W file-prefix ] [ -d array ]
14352 [-J group-name ] [ -X explanation ] [ -x message ]
14353 [-V group-name ] [ -o [ order ] ]
14354 [-r remove-chars ] [ -R remove-func ]
14355 [-D array ] [ -O array ] [ -A array ]
14356 [-E number ]
14357 [-M match-spec ] [ -- ] [ completions ... ]
14358
14359 This builtin command can be used to add matches directly and
14360 control all the information the completion code stores with each
14361 possible completion. The return status is zero if at least one
14362 match was added and non-zero if no matches were added.
14363
14364 The completion code breaks each match into seven fields in the
14365 order:
14366
14367 <ipre><apre><hpre><body><hsuf><asuf><isuf>
14368
14369 The first field is an ignored prefix taken from the command
14370 line, the contents of the IPREFIX parameter plus the string
14371 given with the -i option. With the -U option, only the string
14372 from the -i option is used. The field <apre> is an optional pre‐
14373 fix string given with the -P option. The <hpre> field is a
14374 string that is considered part of the match but that should not
14375 be shown when listing completions, given with the -p option; for
14376 example, functions that do filename generation might specify a
14377 common path prefix this way. <body> is the part of the match
14378 that should appear in the list of matches shown to the user.
14379 The suffixes <hsuf>, <asuf> and <isuf> correspond to the pre‐
14380 fixes <hpre>, <apre> and <ipre> and are given by the options -s,
14381 -S and -I, respectively.
14382
14383 The supported flags are:
14384
14385 -P prefix
14386 This gives a string to be inserted before each match.
14387 The string given is not considered as part of the match
14388 and any shell metacharacters in it will not be quoted
14389 when the string is inserted.
14390
14391 -S suffix
14392 Like -P, but gives a string to be inserted after each
14393 match.
14394
14395 -p hidden-prefix
14396 This gives a string that should be inserted before each
14397 match but that should not appear in the list of matches.
14398 Unless the -U option is given, this string must be
14399 matched as part of the string on the command line.
14400
14401 -s hidden-suffix
14402 Like `-p', but gives a string to insert after each match.
14403
14404 -i ignored-prefix
14405 This gives a string to insert just before any string
14406 given with the `-P' option. Without `-P' the string is
14407 inserted before the string given with `-p' or directly
14408 before each match.
14409
14410 -I ignored-suffix
14411 Like -i, but gives an ignored suffix.
14412
14413 -a With this flag the completions are taken as names of ar‐
14414 rays and the actual completions are their values. If
14415 only some elements of the arrays are needed, the comple‐
14416 tions may also contain subscripts, as in `foo[2,-1]'.
14417
14418 -k With this flag the completions are taken as names of as‐
14419 sociative arrays and the actual completions are their
14420 keys. As for -a, the words may also contain subscripts,
14421 as in `foo[(R)*bar*]'.
14422
14423 -d array
14424 This adds per-completion display strings. The array
14425 should contain one element per completion given. The com‐
14426 pletion code will then display the first element instead
14427 of the first completion, and so on. The array may be
14428 given as the name of an array parameter or directly as a
14429 space-separated list of words in parentheses.
14430
14431 If there are fewer display strings than completions, the
14432 leftover completions will be displayed unchanged and if
14433 there are more display strings than completions, the
14434 leftover display strings will be silently ignored.
14435
14436 -l This option only has an effect if used together with the
14437 -d option. If it is given, the display strings are listed
14438 one per line, not arrayed in columns.
14439
14440 -o [ order ]
14441 This controls the order in which matches are sorted. or‐
14442 der is a comma-separated list comprising the following
14443 possible values. These values can be abbreviated to
14444 their initial two or three characters. Note that the or‐
14445 der forms part of the group name space so matches with
14446 different orderings will not be in the same group.
14447
14448 match If given, the order of the output is determined by
14449 the match strings; otherwise it is determined by
14450 the display strings (i.e. the strings given by the
14451 -d option). This is the default if `-o' is speci‐
14452 fied but the order argument is omitted.
14453
14454 nosort This specifies that the completions are pre-sorted
14455 and their order should be preserved. This value
14456 only makes sense alone and cannot be combined with
14457 any others.
14458
14459 numeric
14460 If the matches include numbers, sort them numeri‐
14461 cally rather than lexicographically.
14462
14463 reverse
14464 Arrange the matches backwards by reversing the
14465 sort ordering.
14466
14467 -J group-name
14468 Gives the name of the group that the matches should be
14469 stored in.
14470
14471 -V group-name
14472 Like -J but naming an unsorted group. This option is
14473 identical to the combination of -J and -o nosort.
14474
14475 -1 If given together with the -V option, makes only consecu‐
14476 tive duplicates in the group be removed. If combined with
14477 the -J option, this has no visible effect. Note that
14478 groups with and without this flag are in different name
14479 spaces.
14480
14481 -2 If given together with the -J or -V option, makes all du‐
14482 plicates be kept. Again, groups with and without this
14483 flag are in different name spaces.
14484
14485 -X explanation
14486 The explanation string will be printed with the list of
14487 matches, above the group currently selected.
14488
14489 Within the explanation, the following sequences may be
14490 used to specify output attributes as described in the
14491 section EXPANSION OF PROMPT SEQUENCES in zshmisc(1):
14492 `%B', `%S', `%U', `%F', `%K' and their lower case coun‐
14493 terparts, as well as `%{...%}'. `%F', `%K' and `%{...%}'
14494 take arguments in the same form as prompt expansion.
14495 (Note that the sequence `%G' is not available; an argu‐
14496 ment to `%{' should be used instead.) The sequence `%%'
14497 produces a literal `%'.
14498
14499 These sequences are most often employed by users when
14500 customising the format style (see zshcompsys(1)), but
14501 they must also be taken into account when writing comple‐
14502 tion functions, as passing descriptions with unescaped
14503 `%' characters to utility functions such as _arguments
14504 and _message may produce unexpected results. If arbitrary
14505 text is to be passed in a description, it can be escaped
14506 using e.g. ${my_str//\%/%%}.
14507
14508 -x message
14509 Like -X, but the message will be printed even if there
14510 are no matches in the group.
14511
14512 -q The suffix given with -S will be automatically removed if
14513 the next character typed is a blank or does not insert
14514 anything, or if the suffix consists of only one character
14515 and the next character typed is the same character.
14516
14517 -r remove-chars
14518 This is a more versatile form of the -q option. The suf‐
14519 fix given with -S or the slash automatically added after
14520 completing directories will be automatically removed if
14521 the next character typed inserts one of the characters
14522 given in the remove-chars. This string is parsed as a
14523 characters class and understands the backslash sequences
14524 used by the print command. For example, `-r "a-z\t"' re‐
14525 moves the suffix if the next character typed inserts a
14526 lower case character or a TAB, and `-r "^0-9"' removes
14527 the suffix if the next character typed inserts anything
14528 but a digit. One extra backslash sequence is understood
14529 in this string: `\-' stands for all characters that in‐
14530 sert nothing. Thus `-S "=" -q' is the same as `-S "=" -r
14531 "= \t\n\-"'.
14532
14533 This option may also be used without the -S option; then
14534 any automatically added space will be removed when one of
14535 the characters in the list is typed.
14536
14537 -R remove-func
14538 This is another form of the -r option. When a match has
14539 been accepted and a suffix has been inserted, the func‐
14540 tion remove-func will be called after the next character
14541 typed. It is passed the length of the suffix as an argu‐
14542 ment and can use the special parameters available in or‐
14543 dinary (non-completion) zle widgets (see zshzle(1)) to
14544 analyse and modify the command line.
14545
14546 -f If this flag is given, all of the matches built from the
14547 completions are marked as being the names of files. They
14548 are not required to be actual filenames, but if they are,
14549 and the option LIST_TYPES is set, the characters describ‐
14550 ing the types of the files in the completion lists will
14551 be shown. This also forces a slash to be added when the
14552 name of a directory is completed.
14553
14554 -e This flag can be used to tell the completion code that
14555 the matches added are parameter names for a parameter ex‐
14556 pansion. This will make the AUTO_PARAM_SLASH and
14557 AUTO_PARAM_KEYS options be used for the matches.
14558
14559 -W file-prefix
14560 This string is a pathname that will be prepended to each
14561 match together with any prefix specified by the -p option
14562 to form a complete filename for testing. Hence it is
14563 only useful if combined with the -f flag, as the tests
14564 will not otherwise be performed.
14565
14566 -F array
14567 Specifies an array containing patterns. completions that
14568 match one of these patterns are ignored, that is, not
14569 considered to be matches.
14570
14571 The array may be the name of an array parameter or a list
14572 of literal patterns enclosed in parentheses and quoted,
14573 as in `-F "(*?.o *?.h)"'. If the name of an array is
14574 given, the elements of the array are taken as the pat‐
14575 terns.
14576
14577 -Q This flag instructs the completion code not to quote any
14578 metacharacters in the matches when inserting them into
14579 the command line.
14580
14581 -M match-spec
14582 This gives local match specifications as described below
14583 in the section `Completion Matching Control'. This option
14584 may be given more than once. In this case all
14585 match-specs given are concatenated with spaces between
14586 them to form the specification string to use. Note that
14587 they will only be used if the -U option is not given.
14588
14589 -n Specifies that matching completions are to be added to
14590 the set of matches, but are not to be listed to the user.
14591
14592 -U If this flag is given, all completions are added to the
14593 set of matches and no matching will be done by the com‐
14594 pletion code. Normally this is used in functions that do
14595 the matching themselves.
14596
14597 -O array
14598 If this option is given, the completions are not added to
14599 the set of matches. Instead, matching is done as usual
14600 and all of the completions that match will be stored in
14601 the array parameter whose name is given as array.
14602
14603 -A array
14604 As the -O option, except that instead of those of the
14605 completions which match being stored in array, the
14606 strings generated internally by the completion code are
14607 stored. For example, with a match specification of `-M
14608 "L:|no="', a current word of `nof' and completions of
14609 `foo', this option stores the string `nofoo' in the ar‐
14610 ray, whereas the -O option stores the `foo' originally
14611 given.
14612
14613 -D array
14614 As with -O, the completions are not added to the set of
14615 matches. Instead, whenever the nth completion does not
14616 match, the nth element of the array is removed. Elements
14617 for which the corresponding completion matches are re‐
14618 tained. This option can be used more than once to remove
14619 elements from multiple arrays.
14620
14621 -C This option adds a special match which expands to all
14622 other matches when inserted into the line, even those
14623 that are added after this option is used. Together with
14624 the -d option it is possible to specify a string that
14625 should be displayed in the list for this special match.
14626 If no string is given, it will be shown as a string con‐
14627 taining the strings that would be inserted for the other
14628 matches, truncated to the width of the screen.
14629
14630 -E number
14631 This option adds number empty matches after matching com‐
14632 pletions have been added. An empty match takes up space
14633 in completion listings but will never be inserted in the
14634 line and can't be selected with menu completion or menu
14635 selection. This makes empty matches only useful to for‐
14636 mat completion lists and to make explanatory string be
14637 shown in completion lists (since empty matches can be
14638 given display strings with the -d option). And because
14639 all but one empty string would otherwise be removed, this
14640 option implies the -V and -2 options (even if an explicit
14641 -J option is given). This can be important to note as it
14642 affects the name space into which matches are added.
14643
14644 -
14645 -- This flag ends the list of flags and options. All argu‐
14646 ments after it will be taken as the completions even if
14647 they begin with hyphens.
14648
14649 Except for the -M flag, if any of these flags is given more than
14650 once, the first one (and its argument) will be used.
14651
14652 compset -p number
14653 compset -P [ number ] pattern
14654 compset -s number
14655 compset -S [ number ] pattern
14656 compset -n begin [ end ]
14657 compset -N beg-pat [ end-pat ]
14658 compset -q
14659 This command simplifies modification of the special parameters,
14660 while its return status allows tests on them to be carried out.
14661
14662 The options are:
14663
14664 -p number
14665 If the value of the PREFIX parameter is at least number
14666 characters long, the first number characters are removed
14667 from it and appended to the contents of the IPREFIX pa‐
14668 rameter.
14669
14670 -P [ number ] pattern
14671 If the value of the PREFIX parameter begins with anything
14672 that matches the pattern, the matched portion is removed
14673 from PREFIX and appended to IPREFIX.
14674
14675 Without the optional number, the longest match is taken,
14676 but if number is given, anything up to the numberth match
14677 is moved. If the number is negative, the numberth long‐
14678 est match is moved. For example, if PREFIX contains the
14679 string `a=b=c', then compset -P '*\=' will move the
14680 string `a=b=' into the IPREFIX parameter, but compset -P
14681 1 '*\=' will move only the string `a='.
14682
14683 -s number
14684 As -p, but transfer the last number characters from the
14685 value of SUFFIX to the front of the value of ISUFFIX.
14686
14687 -S [ number ] pattern
14688 As -P, but match the last portion of SUFFIX and transfer
14689 the matched portion to the front of the value of ISUFFIX.
14690
14691 -n begin [ end ]
14692 If the current word position as specified by the parame‐
14693 ter CURRENT is greater than or equal to begin, anything
14694 up to the beginth word is removed from the words array
14695 and the value of the parameter CURRENT is decremented by
14696 begin.
14697
14698 If the optional end is given, the modification is done
14699 only if the current word position is also less than or
14700 equal to end. In this case, the words from position end
14701 onwards are also removed from the words array.
14702
14703 Both begin and end may be negative to count backwards
14704 from the last element of the words array.
14705
14706 -N beg-pat [ end-pat ]
14707 If one of the elements of the words array before the one
14708 at the index given by the value of the parameter CURRENT
14709 matches the pattern beg-pat, all elements up to and in‐
14710 cluding the matching one are removed from the words array
14711 and the value of CURRENT is changed to point to the same
14712 word in the changed array.
14713
14714 If the optional pattern end-pat is also given, and there
14715 is an element in the words array matching this pattern,
14716 the parameters are modified only if the index of this
14717 word is higher than the one given by the CURRENT parame‐
14718 ter (so that the matching word has to be after the cur‐
14719 sor). In this case, the words starting with the one
14720 matching end-pat are also removed from the words array.
14721 If words contains no word matching end-pat, the testing
14722 and modification is performed as if it were not given.
14723
14724 -q The word currently being completed is split on spaces
14725 into separate words, respecting the usual shell quoting
14726 conventions. The resulting words are stored in the words
14727 array, and CURRENT, PREFIX, SUFFIX, QIPREFIX, and QISUF‐
14728 FIX are modified to reflect the word part that is com‐
14729 pleted.
14730
14731 In all the above cases the return status is zero if the test
14732 succeeded and the parameters were modified and non-zero other‐
14733 wise. This allows one to use this builtin in tests such as:
14734
14735 if compset -P '*\='; then ...
14736
14737 This forces anything up to and including the last equal sign to
14738 be ignored by the completion code.
14739
14740 compcall [ -TD ]
14741 This allows the use of completions defined with the compctl
14742 builtin from within completion widgets. The list of matches
14743 will be generated as if one of the non-widget completion func‐
14744 tions (complete-word, etc.) had been called, except that only
14745 compctls given for specific commands are used. To force the code
14746 to try completions defined with the -T option of compctl and/or
14747 the default completion (whether defined by compctl -D or the
14748 builtin default) in the appropriate places, the -T and/or -D
14749 flags can be passed to compcall.
14750
14751 The return status can be used to test if a matching compctl def‐
14752 inition was found. It is non-zero if a compctl was found and
14753 zero otherwise.
14754
14755 Note that this builtin is defined by the zsh/compctl module.
14756
14758 The following additional condition codes for use within the [[ ... ]]
14759 construct are available in completion widgets. These work on the spe‐
14760 cial parameters. All of these tests can also be performed by the
14761 compset builtin, but in the case of the condition codes the contents of
14762 the special parameters are not modified.
14763
14764 -prefix [ number ] pattern
14765 true if the test for the -P option of compset would succeed.
14766
14767 -suffix [ number ] pattern
14768 true if the test for the -S option of compset would succeed.
14769
14770 -after beg-pat
14771 true if the test of the -N option with only the beg-pat given
14772 would succeed.
14773
14774 -between beg-pat end-pat
14775 true if the test for the -N option with both patterns would suc‐
14776 ceed.
14777
14779 When the user invokes completion, the current word on the command line
14780 (that is, the word the cursor is currently on) is used to generate a
14781 match pattern. Only those completions that match the pattern are of‐
14782 fered to the user as matches.
14783
14784 The default match pattern is generated from the current word by either
14785
14786 • appending a `*' (matching any number of characters in a comple‐
14787 tion) or,
14788
14789 • if the shell option COMPLETE_IN_WORD is set, inserting a `*' at
14790 the cursor position.
14791
14792 This narrow pattern can be broadened selectively by passing a match
14793 specification to the compadd builtin command through its -M option (see
14794 `Completion Builtin Commands' above). A match specification consists
14795 of one or more matchers separated by whitespace. Matchers in a match
14796 specification are applied one at a time, from left to right. Once all
14797 matchers have been applied, completions are compared to the final match
14798 pattern and non-matching ones are discarded.
14799
14800 • Note that the -M option is ignored if the current word contains
14801 a glob pattern and the shell option GLOB_COMPLETE is set or if
14802 the pattern_match key of the special associative array compstate
14803 is set to a non-empty value (see `Completion Special Parameters'
14804 above).
14805
14806 • Users of the completion system (see zshcompsys(1)) should gen‐
14807 erally not use the -M option directly, but rather use the
14808 matcher-list and matcher styles (see the subsection Standard
14809 Styles in the documentation for COMPLETION SYSTEM CONFIGURATION
14810 in zshcompsys(1)).
14811
14812 Each matcher consists of
14813
14814 • a case-sensitive letter
14815
14816 • a `:',
14817
14818 • one or more patterns separated by pipes (`|'),
14819
14820 • an equals sign (`='), and
14821
14822 • another pattern.
14823
14824 The patterns before the `=' are used to match substrings of the current
14825 word. For each matched substring, the corresponding part of the match
14826 pattern is broadened with the pattern after the `=', by means of a log‐
14827 ical OR.
14828
14829 Each pattern in a matcher cosists of either
14830
14831 • the empty string or
14832
14833 • a sequence of
14834
14835 • literal characters (which may be quoted with a `\'),
14836
14837 • question marks (`?'),
14838
14839 • bracket expressions (`[...]'; see the subsection Glob Op‐
14840 erators in the documentation for GLOB OPERATORS in zsh‐
14841 expn(1)), and/or
14842
14843 • brace expressions (see below).
14844
14845
14846 Other shell patterns are not allowed.
14847
14848 A brace expression, like a bracket expression, consists of a list of
14849
14850 • literal characters,
14851
14852 • ranges (`0-9'), and/or
14853
14854 • character classes (`[:name:]').
14855
14856 However, they differ from each other as follows:
14857
14858 • A brace expression is delimited by a pair of braces (`{...}').
14859
14860 • Brace expressions do not support negations. That is, an initial
14861 `!' or `^' has no special meaning and will be interpreted as a
14862 literal character.
14863
14864 • When a character in the current word matches the nth pattern in
14865 a brace expression, the corresponding part of the match pattern
14866 is broadened only with the nth pattern of the brace expression
14867 on the other side of the `=', if there is one; if there is no
14868 brace expression on the other side, then this pattern is the
14869 empty string. However, if either brace expression has more ele‐
14870 ments than the other, then the excess entries are simply ig‐
14871 nored. When comparing indexes, each literal character or char‐
14872 acter class counts as one element, but each range is instead ex‐
14873 panded to the full list of literal characters it represents.
14874 Additionally, if on both sides of the `=', the nth pattern is
14875 `[:upper:]' or `[:lower:]', then these are expanded as ranges,
14876 too.
14877
14878 Note that, although the matching system does not yet handle multibyte
14879 characters, this is likely to be a future extension. Hence, using
14880 `[:upper:]' and `[:lower:]' is recommended over `A-Z' and `a-z'.
14881
14882 Below are the different forms of matchers supported. Each uppercase
14883 form behaves exactly like its lowercase counterpart, but adds an addi‐
14884 tional step after the match pattern has filtered out non-matching com‐
14885 pletions: Each of a match's substrings that was matched by a subpat‐
14886 tern from an uppercase matcher is replaced with the corresponding sub‐
14887 string of the current word. However, patterns from lowercase matchers
14888 have higher weight: If a substring of the current word was matched by
14889 patterns from both a lowercase and an uppercase matcher, then the low‐
14890 ercase matcher's pattern wins and the corresponding part of the match
14891 is not modified.
14892
14893 Unless indicated otherwise, each example listed assumes COM‐
14894 PLETE_IN_WORD to be unset (as it is by default).
14895
14896 m:word-pat=match-pat
14897 M:word-pat=match-pat
14898
14899 For each substring of the current word that matches word-pat,
14900 broaden the corresponding part of the match pattern to addition‐
14901 ally match match-pat.
14902
14903 Examples:
14904
14905 m:{[:lower:]}={[:upper:]} lets any lower case character
14906 in the current word be completed to itself or its upper‐
14907 case counterpart. So, the completions `foo', `FOO' and
14908 `Foo' will are be considered matches for the word `fo'.
14909
14910 M:_= inserts every underscore from the current word into
14911 each match, in the same relative position, determined by
14912 matching the substrings around it. So, given a comple‐
14913 tion `foo', the word `f_o' will be completed to the match
14914 `f_oo', even though the latter was not present as a com‐
14915 pletion.
14916
14917 b:word-pat=match-pat
14918 B:word-pat=match-pat
14919 e:word-pat=match-pat
14920 E:word-pat=match-pat
14921
14922 For each consecutive substring at the b:eginning or e:nd of the
14923 current word that matches word-pat, broaden the corresponding
14924 part of the match pattern to additionally match match-pat.
14925
14926 Examples:
14927
14928 `b:-=+' lets any number of minuses at the start of the
14929 current word be completed to a minus or a plus.
14930
14931 `B:0=' adds all zeroes at the beginning of the current
14932 word to the beginning of each match.
14933
14934 l:|word-pat=match-pat
14935 L:|word-pat=match-pat
14936 R:word-pat|=match-pat
14937 r:word-pat|=match-pat
14938
14939 If there is a substring at the l:eft or r:ight edge of the cur‐
14940 rent word that matches word-pat, then broaden the corresponding
14941 part of the match pattern to additionally match match-pat.
14942
14943 For each l:, L:, r: and R: matcher (including the ones below),
14944 the pattern match-pat may also be a `*'. This matches any num‐
14945 ber of characters in a completion.
14946
14947 Examples:
14948
14949 `r:|=*' appends a `*' to the match pattern, even when
14950 COMPLETE_IN_WORD is set and the cursor is not at the end
14951 of the current word.
14952
14953 If the current word starts with a minus, then `L:|-='
14954 will prepend it to each match.
14955
14956 l:anchor|word-pat=match-pat
14957 L:anchor|word-pat=match-pat
14958 r:word-pat|anchor=match-pat
14959 R:word-pat|anchor=match-pat
14960
14961 For each substring of the current word that matches word-pat and
14962 has on its l:eft or r:ight another substring matching anchor,
14963 broaden the corresponding part of the match pattern to addition‐
14964 ally match match-pat.
14965
14966 Note that these matchers (and the ones below) modify only what
14967 is matched by word-pat; they do not change the matching behavior
14968 of what is matched by anchor (or coanchor; see the matchers be‐
14969 low). Thus, unless its corresponding part of the match pattern
14970 has been modified, the anchor in the current word has to match
14971 literally in each completion, just like any other substring of
14972 the current word.
14973
14974 If a matcher includes at least one anchor (which includes the
14975 matchers with two anchors, below), then match-pat may also be
14976 `*' or `**'. `*' can match any part of a completion that does
14977 not contain any substrings matching anchor, whereas a `**' can
14978 match any part of a completion, period. (Note that this is dif‐
14979 ferent from the behavior of `*' in the anchorless forms of `l:'
14980 and `r:' and and also different from `*' and `**' in glob ex‐
14981 pressions.)
14982
14983 Examples:
14984
14985 `r:|.=*' makes the completion `comp.sources.unix' a match
14986 for the word `..u' -- but not for the word `.u'.
14987
14988 Given a completion `--foo', the matcher `L:--|no-=' will
14989 complete the word `--no-' to the match `--no-foo'.
14990
14991 l:anchor||coanchor=match-pat
14992 L:anchor||coanchor=match-pat
14993 r:coanchor||anchor=match-pat
14994 R:coanchor||anchor=match-pat
14995
14996 For any two consecutive substrings of the current word that
14997 match anchor and coanchor, in the order given, insert the pat‐
14998 tern match-pat between their corresponding parts in the match
14999 pattern.
15000
15001 Note that, unlike anchor, the pattern coanchor does not change
15002 what `*' can match.
15003
15004 Examples:
15005
15006 `r:?||[[:upper:]]=*' will complete the current word `fB'
15007 to `fooBar', but it will not complete it to `fooHooBar'
15008 (because `*' here cannot match anything that includes a
15009 match for `[[:upper:]]), nor will it complete `B' to
15010 `fooBar' (because there is no character in the current
15011 word to match coanchor).
15012
15013 Given the current word `pass.n' and a completion
15014 `pass.byname', the matcher `L:.||[[:alpha:]]=by' will
15015 produce the match `pass.name'.
15016
15017 x:
15018
15019 Ignore this matcher and all matchers to its right.
15020
15021 This matcher is used to mark the end of a match specification.
15022 In a single standalone list of matchers, this has no use, but
15023 where match specifications are concatenated, as is often the
15024 case when using the completion system (see zshcompsys(1)), it
15025 can allow one match specification to override another.
15026
15028 The first step is to define the widget:
15029
15030 zle -C complete complete-word complete-files
15031
15032 Then the widget can be bound to a key using the bindkey builtin com‐
15033 mand:
15034
15035 bindkey '^X\t' complete
15036
15037 After that the shell function complete-files will be invoked after typ‐
15038 ing control-X and TAB. The function should then generate the matches,
15039 e.g.:
15040
15041 complete-files () { compadd - * }
15042
15043 This function will complete files in the current directory matching the
15044 current word.
15045
15046
15047
15048ZSHCOMPSYS(1) General Commands Manual ZSHCOMPSYS(1)
15049
15050
15051
15053 zshcompsys - zsh completion system
15054
15056 This describes the shell code for the `new' completion system, referred
15057 to as compsys. It is written in shell functions based on the features
15058 described in zshcompwid(1).
15059
15060 The features are contextual, sensitive to the point at which completion
15061 is started. Many completions are already provided. For this reason, a
15062 user can perform a great many tasks without knowing any details beyond
15063 how to initialize the system, which is described below in INITIALIZA‐
15064 TION.
15065
15066 The context that decides what completion is to be performed may be
15067 • an argument or option position: these describe the position on
15068 the command line at which completion is requested. For example
15069 `first argument to rmdir, the word being completed names a di‐
15070 rectory';
15071
15072
15073 • a special context, denoting an element in the shell's syntax.
15074 For example `a word in command position' or `an array sub‐
15075 script'.
15076
15077
15078 A full context specification contains other elements, as we shall de‐
15079 scribe.
15080
15081 Besides commands names and contexts, the system employs two more con‐
15082 cepts, styles and tags. These provide ways for the user to configure
15083 the system's behaviour.
15084
15085 Tags play a dual role. They serve as a classification system for the
15086 matches, typically indicating a class of object that the user may need
15087 to distinguish. For example, when completing arguments of the ls com‐
15088 mand the user may prefer to try files before directories, so both of
15089 these are tags. They also appear as the rightmost element in a context
15090 specification.
15091
15092 Styles modify various operations of the completion system, such as out‐
15093 put formatting, but also what kinds of completers are used (and in what
15094 order), or which tags are examined. Styles may accept arguments and
15095 are manipulated using the zstyle command described in zshmodules(1).
15096
15097 In summary, tags describe what the completion objects are, and style
15098 how they are to be completed. At various points of execution, the com‐
15099 pletion system checks what styles and/or tags are defined for the cur‐
15100 rent context, and uses that to modify its behavior. The full descrip‐
15101 tion of context handling, which determines how tags and other elements
15102 of the context influence the behaviour of styles, is described below in
15103 COMPLETION SYSTEM CONFIGURATION.
15104
15105 When a completion is requested, a dispatcher function is called; see
15106 the description of _main_complete in the list of control functions be‐
15107 low. This dispatcher decides which function should be called to produce
15108 the completions, and calls it. The result is passed to one or more com‐
15109 pleters, functions that implement individual completion strategies:
15110 simple completion, error correction, completion with error correction,
15111 menu selection, etc.
15112
15113 More generally, the shell functions contained in the completion system
15114 are of two types:
15115 • those beginning `comp' are to be called directly; there are only
15116 a few of these;
15117
15118
15119 • those beginning `_' are called by the completion code. The
15120 shell functions of this set, which implement completion behav‐
15121 iour and may be bound to keystrokes, are referred to as `wid‐
15122 gets'. These proliferate as new completions are required.
15123
15124
15126 If the system was installed completely, it should be enough to call the
15127 shell function compinit from your initialization file; see the next
15128 section. However, the function compinstall can be run by a user to
15129 configure various aspects of the completion system.
15130
15131 Usually, compinstall will insert code into .zshrc, although if that is
15132 not writable it will save it in another file and tell you that file's
15133 location. Note that it is up to you to make sure that the lines added
15134 to .zshrc are actually run; you may, for example, need to move them to
15135 an earlier place in the file if .zshrc usually returns early. So long
15136 as you keep them all together (including the comment lines at the start
15137 and finish), you can rerun compinstall and it will correctly locate and
15138 modify these lines. Note, however, that any code you add to this sec‐
15139 tion by hand is likely to be lost if you rerun compinstall, although
15140 lines using the command `zstyle' should be gracefully handled.
15141
15142 The new code will take effect next time you start the shell, or run
15143 .zshrc by hand; there is also an option to make them take effect imme‐
15144 diately. However, if compinstall has removed definitions, you will
15145 need to restart the shell to see the changes.
15146
15147 To run compinstall you will need to make sure it is in a directory men‐
15148 tioned in your fpath parameter, which should already be the case if zsh
15149 was properly configured as long as your startup files do not remove the
15150 appropriate directories from fpath. Then it must be autoloaded (`au‐
15151 toload -U compinstall' is recommended). You can abort the installation
15152 any time you are being prompted for information, and your .zshrc will
15153 not be altered at all; changes only take place right at the end, where
15154 you are specifically asked for confirmation.
15155
15156 Use of compinit
15157 This section describes the use of compinit to initialize completion for
15158 the current session when called directly; if you have run compinstall
15159 it will be called automatically from your .zshrc.
15160
15161 To initialize the system, the function compinit should be in a direc‐
15162 tory mentioned in the fpath parameter, and should be autoloaded (`au‐
15163 toload -U compinit' is recommended), and then run simply as `compinit'.
15164 This will define a few utility functions, arrange for all the necessary
15165 shell functions to be autoloaded, and will then re-define all widgets
15166 that do completion to use the new system. If you use the menu-select
15167 widget, which is part of the zsh/complist module, you should make sure
15168 that that module is loaded before the call to compinit so that that
15169 widget is also re-defined. If completion styles (see below) are set up
15170 to perform expansion as well as completion by default, and the TAB key
15171 is bound to expand-or-complete, compinit will rebind it to com‐
15172 plete-word; this is necessary to use the correct form of expansion.
15173
15174 Should you need to use the original completion commands, you can still
15175 bind keys to the old widgets by putting a `.' in front of the widget
15176 name, e.g. `.expand-or-complete'.
15177
15178 To speed up the running of compinit, it can be made to produce a dumped
15179 configuration that will be read in on future invocations; this is the
15180 default, but can be turned off by calling compinit with the option -D.
15181 The dumped file is .zcompdump in the same directory as the startup
15182 files (i.e. $ZDOTDIR or $HOME); alternatively, an explicit file name
15183 can be given by `compinit -d dumpfile'. The next invocation of
15184 compinit will read the dumped file instead of performing a full ini‐
15185 tialization.
15186
15187 If the number of completion files changes, compinit will recognise this
15188 and produce a new dump file. However, if the name of a function or the
15189 arguments in the first line of a #compdef function (as described below)
15190 change, it is easiest to delete the dump file by hand so that compinit
15191 will re-create it the next time it is run. The check performed to see
15192 if there are new functions can be omitted by giving the option -C. In
15193 this case the dump file will only be created if there isn't one al‐
15194 ready.
15195
15196 The dumping is actually done by another function, compdump, but you
15197 will only need to run this yourself if you change the configuration
15198 (e.g. using compdef) and then want to dump the new one. The name of
15199 the old dumped file will be remembered for this purpose.
15200
15201 If the parameter _compdir is set, compinit uses it as a directory where
15202 completion functions can be found; this is only necessary if they are
15203 not already in the function search path.
15204
15205 For security reasons compinit also checks if the completion system
15206 would use files not owned by root or by the current user, or files in
15207 directories that are world- or group-writable or that are not owned by
15208 root or by the current user. If such files or directories are found,
15209 compinit will ask if the completion system should really be used. To
15210 avoid these tests and make all files found be used without asking, use
15211 the option -u, and to make compinit silently ignore all insecure files
15212 and directories use the option -i. This security check is skipped en‐
15213 tirely when the -C option is given, provided the dumpfile exists.
15214
15215 The security check can be retried at any time by running the function
15216 compaudit. This is the same check used by compinit, but when it is ex‐
15217 ecuted directly any changes to fpath are made local to the function so
15218 they do not persist. The directories to be checked may be passed as
15219 arguments; if none are given, compaudit uses fpath and _compdir to find
15220 completion system directories, adding missing ones to fpath as neces‐
15221 sary. To force a check of exactly the directories currently named in
15222 fpath, set _compdir to an empty string before calling compaudit or
15223 compinit.
15224
15225 The function bashcompinit provides compatibility with bash's program‐
15226 mable completion system. When run it will define the functions, comp‐
15227 gen and complete which correspond to the bash builtins with the same
15228 names. It will then be possible to use completion specifications and
15229 functions written for bash.
15230
15231 Autoloaded files
15232 The convention for autoloaded functions used in completion is that they
15233 start with an underscore; as already mentioned, the fpath/FPATH parame‐
15234 ter must contain the directory in which they are stored. If zsh was
15235 properly installed on your system, then fpath/FPATH automatically con‐
15236 tains the required directories for the standard functions.
15237
15238 For incomplete installations, if compinit does not find enough files
15239 beginning with an underscore (fewer than twenty) in the search path, it
15240 will try to find more by adding the directory _compdir to the search
15241 path. If that directory has a subdirectory named Base, all subdirecto‐
15242 ries will be added to the path. Furthermore, if the subdirectory Base
15243 has a subdirectory named Core, compinit will add all subdirectories of
15244 the subdirectories to the path: this allows the functions to be in the
15245 same format as in the zsh source distribution.
15246
15247 When compinit is run, it searches all such files accessible via
15248 fpath/FPATH and reads the first line of each of them. This line should
15249 contain one of the tags described below. Files whose first line does
15250 not start with one of these tags are not considered to be part of the
15251 completion system and will not be treated specially.
15252
15253 The tags are:
15254
15255 #compdef name ... [ -{p|P} pattern ... [ -N name ... ] ]
15256 The file will be made autoloadable and the function defined in
15257 it will be called when completing names, each of which is either
15258 the name of a command whose arguments are to be completed or one
15259 of a number of special contexts in the form -context- described
15260 below.
15261
15262 Each name may also be of the form `cmd=service'. When complet‐
15263 ing the command cmd, the function typically behaves as if the
15264 command (or special context) service was being completed in‐
15265 stead. This provides a way of altering the behaviour of func‐
15266 tions that can perform many different completions. It is imple‐
15267 mented by setting the parameter $service when calling the func‐
15268 tion; the function may choose to interpret this how it wishes,
15269 and simpler functions will probably ignore it.
15270
15271 If the #compdef line contains one of the options -p or -P, the
15272 words following are taken to be patterns. The function will be
15273 called when completion is attempted for a command or context
15274 that matches one of the patterns. The options -p and -P are
15275 used to specify patterns to be tried before or after other com‐
15276 pletions respectively. Hence -P may be used to specify default
15277 actions.
15278
15279 The option -N is used after a list following -p or -P; it speci‐
15280 fies that remaining words no longer define patterns. It is pos‐
15281 sible to toggle between the three options as many times as nec‐
15282 essary.
15283
15284 #compdef -k style key-sequence ...
15285 This option creates a widget behaving like the builtin widget
15286 style and binds it to the given key-sequences, if any. The
15287 style must be one of the builtin widgets that perform comple‐
15288 tion, namely complete-word, delete-char-or-list, expand-or-com‐
15289 plete, expand-or-complete-prefix, list-choices, menu-complete,
15290 menu-expand-or-complete, or reverse-menu-complete. If the
15291 zsh/complist module is loaded (see zshmodules(1)) the widget
15292 menu-select is also available.
15293
15294 When one of the key-sequences is typed, the function in the file
15295 will be invoked to generate the matches. Note that a key will
15296 not be re-bound if it already was (that is, was bound to some‐
15297 thing other than undefined-key). The widget created has the
15298 same name as the file and can be bound to any other keys using
15299 bindkey as usual.
15300
15301 #compdef -K widget-name style key-sequence [ name style seq ... ]
15302 This is similar to -k except that only one key-sequence argument
15303 may be given for each widget-name style pair. However, the en‐
15304 tire set of three arguments may be repeated with a different set
15305 of arguments. Note in particular that the widget-name must be
15306 distinct in each set. If it does not begin with `_' this will
15307 be added. The widget-name should not clash with the name of any
15308 existing widget: names based on the name of the function are
15309 most useful. For example,
15310
15311 #compdef -K _foo_complete complete-word "^X^C" \
15312 _foo_list list-choices "^X^D"
15313
15314 (all on one line) defines a widget _foo_complete for completion,
15315 bound to `^X^C', and a widget _foo_list for listing, bound to
15316 `^X^D'.
15317
15318 #autoload [ options ]
15319 Functions with the #autoload tag are marked for autoloading but
15320 are not otherwise treated specially. Typically they are to be
15321 called from within one of the completion functions. Any options
15322 supplied will be passed to the autoload builtin; a typical use
15323 is +X to force the function to be loaded immediately. Note that
15324 the -U and -z flags are always added implicitly.
15325
15326 The # is part of the tag name and no white space is allowed after it.
15327 The #compdef tags use the compdef function described below; the main
15328 difference is that the name of the function is supplied implicitly.
15329
15330 The special contexts for which completion functions can be defined are:
15331
15332 -array-value-
15333 The right hand side of an array-assignment (`name=(...)')
15334
15335 -assign-parameter-
15336 The name of a parameter in an assignment, i.e. on the left hand
15337 side of an `='
15338
15339 -brace-parameter-
15340 The name of a parameter expansion within braces (`${...}')
15341
15342 -command-
15343 A word in command position
15344
15345 -condition-
15346 A word inside a condition (`[[...]]')
15347
15348 -default-
15349 Any word for which no other completion is defined
15350
15351 -equal-
15352 A word beginning with an equals sign
15353
15354 -first-
15355 This is tried before any other completion function. The func‐
15356 tion called may set the _compskip parameter to one of various
15357 values: all: no further completion is attempted; a string con‐
15358 taining the substring patterns: no pattern completion functions
15359 will be called; a string containing default: the function for
15360 the `-default-' context will not be called, but functions de‐
15361 fined for commands will be.
15362
15363 -math- Inside mathematical contexts, such as `((...))'
15364
15365 -parameter-
15366 The name of a parameter expansion (`$...')
15367
15368 -redirect-
15369 The word after a redirection operator.
15370
15371 -subscript-
15372 The contents of a parameter subscript.
15373
15374 -tilde-
15375 After an initial tilde (`~'), but before the first slash in the
15376 word.
15377
15378 -value-
15379 On the right hand side of an assignment.
15380
15381 Default implementations are supplied for each of these contexts. In
15382 most cases the context -context- is implemented by a corresponding
15383 function _context, for example the context `-tilde-' and the function
15384 `_tilde').
15385
15386 The contexts -redirect- and -value- allow extra context-specific infor‐
15387 mation. (Internally, this is handled by the functions for each context
15388 calling the function _dispatch.) The extra information is added sepa‐
15389 rated by commas.
15390
15391 For the -redirect- context, the extra information is in the form `-re‐
15392 direct-,op,command', where op is the redirection operator and command
15393 is the name of the command on the line. If there is no command on the
15394 line yet, the command field will be empty.
15395
15396 For the -value- context, the form is `-value-,name,command', where name
15397 is the name of the parameter on the left hand side of the assignment.
15398 In the case of elements of an associative array, for example `as‐
15399 soc=(key <TAB>', name is expanded to `name-key'. In certain special
15400 contexts, such as completing after `make CFLAGS=', the command part
15401 gives the name of the command, here make; otherwise it is empty.
15402
15403 It is not necessary to define fully specific completions as the func‐
15404 tions provided will try to generate completions by progressively re‐
15405 placing the elements with `-default-'. For example, when completing
15406 after `foo=<TAB>', _value will try the names `-value-,foo,' (note the
15407 empty command part), `-value-,foo,-default-' and`-value-,-default-,-de‐
15408 fault-', in that order, until it finds a function to handle the con‐
15409 text.
15410
15411 As an example:
15412
15413 compdef '_files -g "*.log"' '-redirect-,2>,-default-'
15414
15415 completes files matching `*.log' after `2> <TAB>' for any command with
15416 no more specific handler defined.
15417
15418 Also:
15419
15420 compdef _foo -value-,-default-,-default-
15421
15422 specifies that _foo provides completions for the values of parameters
15423 for which no special function has been defined. This is usually han‐
15424 dled by the function _value itself.
15425
15426 The same lookup rules are used when looking up styles (as described be‐
15427 low); for example
15428
15429 zstyle ':completion:*:*:-redirect-,2>,*:*' file-patterns '*.log'
15430
15431 is another way to make completion after `2> <TAB>' complete files
15432 matching `*.log'.
15433
15434 Functions
15435 The following function is defined by compinit and may be called di‐
15436 rectly.
15437
15438 compdef [ -ane ] function name ... [ -{p|P} pattern ... [ -N name ...]]
15439 compdef -d name ...
15440 compdef -k [ -an ] function style key-sequence [ key-sequence ... ]
15441 compdef -K [ -an ] function name style key-seq [ name style seq ... ]
15442 The first form defines the function to call for completion in
15443 the given contexts as described for the #compdef tag above.
15444
15445 Alternatively, all the arguments may have the form `cmd=ser‐
15446 vice'. Here service should already have been defined by
15447 `cmd1=service' lines in #compdef files, as described above. The
15448 argument for cmd will be completed in the same way as service.
15449
15450 The function argument may alternatively be a string containing
15451 almost any shell code. If the string contains an equal sign,
15452 the above will take precedence. The option -e may be used to
15453 specify the first argument is to be evaluated as shell code even
15454 if it contains an equal sign. The string will be executed using
15455 the eval builtin command to generate completions. This provides
15456 a way of avoiding having to define a new completion function.
15457 For example, to complete files ending in `.h' as arguments to
15458 the command foo:
15459
15460 compdef '_files -g "*.h"' foo
15461
15462 The option -n prevents any completions already defined for the
15463 command or context from being overwritten.
15464
15465 The option -d deletes any completion defined for the command or
15466 contexts listed.
15467
15468 The names may also contain -p, -P and -N options as described
15469 for the #compdef tag. The effect on the argument list is iden‐
15470 tical, switching between definitions of patterns tried ini‐
15471 tially, patterns tried finally, and normal commands and con‐
15472 texts.
15473
15474 The parameter $_compskip may be set by any function defined for
15475 a pattern context. If it is set to a value containing the sub‐
15476 string `patterns' none of the pattern-functions will be called;
15477 if it is set to a value containing the substring `all', no other
15478 function will be called. Setting $_compskip in this manner is
15479 of particular utility when using the -p option, as otherwise the
15480 dispatcher will move on to additional functions (likely the de‐
15481 fault one) after calling the pattern-context one, which can man‐
15482 gle the display of completion possibilities if not handled prop‐
15483 erly.
15484
15485 The form with -k defines a widget with the same name as the
15486 function that will be called for each of the key-sequences; this
15487 is like the #compdef -k tag. The function should generate the
15488 completions needed and will otherwise behave like the builtin
15489 widget whose name is given as the style argument. The widgets
15490 usable for this are: complete-word, delete-char-or-list, ex‐
15491 pand-or-complete, expand-or-complete-prefix, list-choices,
15492 menu-complete, menu-expand-or-complete, and reverse-menu-com‐
15493 plete, as well as menu-select if the zsh/complist module is
15494 loaded. The option -n prevents the key being bound if it is al‐
15495 ready to bound to something other than undefined-key.
15496
15497 The form with -K is similar and defines multiple widgets based
15498 on the same function, each of which requires the set of three
15499 arguments name, style and key-sequence, where the latter two are
15500 as for -k and the first must be a unique widget name beginning
15501 with an underscore.
15502
15503 Wherever applicable, the -a option makes the function autoload‐
15504 able, equivalent to autoload -U function.
15505
15506 The function compdef can be used to associate existing completion func‐
15507 tions with new commands. For example,
15508
15509 compdef _pids foo
15510
15511 uses the function _pids to complete process IDs for the command foo.
15512
15513 Note also the _gnu_generic function described below, which can be used
15514 to complete options for commands that understand the `--help' option.
15515
15517 This section gives a short overview of how the completion system works,
15518 and then more detail on how users can configure how and when matches
15519 are generated.
15520
15521 Overview
15522 When completion is attempted somewhere on the command line the comple‐
15523 tion system begins building the context. The context represents every‐
15524 thing that the shell knows about the meaning of the command line and
15525 the significance of the cursor position. This takes account of a num‐
15526 ber of things including the command word (such as `grep' or `zsh') and
15527 options to which the current word may be an argument (such as the `-o'
15528 option to zsh which takes a shell option as an argument).
15529
15530 The context starts out very generic ("we are beginning a completion")
15531 and becomes more specific as more is learned ("the current word is in a
15532 position that is usually a command name" or "the current word might be
15533 a variable name" and so on). Therefore the context will vary during
15534 the same call to the completion system.
15535
15536 This context information is condensed into a string consisting of mul‐
15537 tiple fields separated by colons, referred to simply as `the context'
15538 in the remainder of the documentation. Note that a user of the comple‐
15539 tion system rarely needs to compose a context string, unless for exam‐
15540 ple a new function is being written to perform completion for a new
15541 command. What a user may need to do is compose a style pattern, which
15542 is matched against a context when needed to look up context-sensitive
15543 options that configure the completion system.
15544
15545 The next few paragraphs explain how a context is composed within the
15546 completion function suite. Following that is discussion of how styles
15547 are defined. Styles determine such things as how the matches are gen‐
15548 erated, similarly to shell options but with much more control. They
15549 are defined with the zstyle builtin command (see zshmodules(1)).
15550
15551 The context string always consists of a fixed set of fields, separated
15552 by colons and with a leading colon before the first. Fields which are
15553 not yet known are left empty, but the surrounding colons appear anyway.
15554 The fields are always in the order :completion:function:completer:com‐
15555 mand:argument:tag. These have the following meaning:
15556
15557 • The literal string completion, saying that this style is used by
15558 the completion system. This distinguishes the context from
15559 those used by, for example, zle widgets and ZFTP functions.
15560
15561
15562 • The function, if completion is called from a named widget rather
15563 than through the normal completion system. Typically this is
15564 blank, but it is set by special widgets such as predict-on and
15565 the various functions in the Widget directory of the distribu‐
15566 tion to the name of that function, often in an abbreviated form.
15567
15568
15569 • The completer currently active, the name of the function without
15570 the leading underscore and with other underscores converted to
15571 hyphens. A `completer' is in overall control of how completion
15572 is to be performed; `complete' is the simplest, but other com‐
15573 pleters exist to perform related tasks such as correction, or to
15574 modify the behaviour of a later completer. See the section
15575 `Control Functions' below for more information.
15576
15577
15578 • The command or a special -context-, just at it appears following
15579 the #compdef tag or the compdef function. Completion functions
15580 for commands that have sub-commands usually modify this field to
15581 contain the name of the command followed by a minus sign and the
15582 sub-command. For example, the completion function for the cvs
15583 command sets this field to cvs-add when completing arguments to
15584 the add subcommand.
15585
15586
15587 • The argument; this indicates which command line or option argu‐
15588 ment we are completing. For command arguments this generally
15589 takes the form argument-n, where n is the number of the argu‐
15590 ment, and for arguments to options the form option-opt-n where n
15591 is the number of the argument to option opt. However, this is
15592 only the case if the command line is parsed with standard
15593 UNIX-style options and arguments, so many completions do not set
15594 this.
15595
15596
15597 • The tag. As described previously, tags are used to discriminate
15598 between the types of matches a completion function can generate
15599 in a certain context. Any completion function may use any tag
15600 name it likes, but a list of the more common ones is given be‐
15601 low.
15602
15603
15604 The context is gradually put together as the functions are executed,
15605 starting with the main entry point, which adds :completion: and the
15606 function element if necessary. The completer then adds the completer
15607 element. The contextual completion adds the command and argument op‐
15608 tions. Finally, the tag is added when the types of completion are
15609 known. For example, the context name
15610
15611 :completion::complete:dvips:option-o-1:files
15612
15613 says that normal completion was attempted as the first argument to the
15614 option -o of the command dvips:
15615
15616 dvips -o ...
15617
15618 and the completion function will generate filenames.
15619
15620 Usually completion will be tried for all possible tags in an order
15621 given by the completion function. However, this can be altered by us‐
15622 ing the tag-order style. Completion is then restricted to the list of
15623 given tags in the given order.
15624
15625 The _complete_help bindable command shows all the contexts and tags
15626 available for completion at a particular point. This provides an easy
15627 way of finding information for tag-order and other styles. It is de‐
15628 scribed in the section `Bindable Commands' below.
15629
15630 When looking up styles the completion system uses full context names,
15631 including the tag. Looking up the value of a style therefore consists
15632 of two things: the context, which is matched to the most specific (best
15633 fitting) pattern, and the name of the style itself, which must be
15634 matched exactly. The following examples demonstrate that patterns may
15635 be loosely defined for styles that apply broadly, or as tightly defined
15636 as desired for styles that apply in narrower circumstances.
15637
15638 For example, many completion functions can generate matches in a simple
15639 and a verbose form and use the verbose style to decide which form
15640 should be used. To make all such functions use the verbose form, put
15641
15642 zstyle ':completion:*' verbose yes
15643
15644 in a startup file (probably .zshrc). This gives the verbose style the
15645 value yes in every context inside the completion system, unless that
15646 context has a more specific definition. It is best to avoid giving the
15647 pattern as `*' in case the style has some meaning outside the comple‐
15648 tion system.
15649
15650 Many such general purpose styles can be configured simply by using the
15651 compinstall function.
15652
15653 A more specific example of the use of the verbose style is by the com‐
15654 pletion for the kill builtin. If the style is set, the builtin lists
15655 full job texts and process command lines; otherwise it shows the bare
15656 job numbers and PIDs. To turn the style off for this use only:
15657
15658 zstyle ':completion:*:*:kill:*:*' verbose no
15659
15660 For even more control, the style can use one of the tags `jobs' or
15661 `processes'. To turn off verbose display only for jobs:
15662
15663 zstyle ':completion:*:*:kill:*:jobs' verbose no
15664
15665 The -e option to zstyle even allows completion function code to appear
15666 as the argument to a style; this requires some understanding of the in‐
15667 ternals of completion functions (see see zshcompwid(1))). For example,
15668
15669 zstyle -e ':completion:*' hosts 'reply=($myhosts)'
15670
15671 This forces the value of the hosts style to be read from the variable
15672 myhosts each time a host name is needed; this is useful if the value of
15673 myhosts can change dynamically. For another useful example, see the
15674 example in the description of the file-list style below. This form can
15675 be slow and should be avoided for commonly examined styles such as menu
15676 and list-rows-first.
15677
15678 Note that the order in which styles are defined does not matter; the
15679 style mechanism uses the most specific possible match for a particular
15680 style to determine the set of values. Strings are preferred over pat‐
15681 terns (for example, `:completion::complete:::foo' is more specific than
15682 `:completion::complete:::*'), and longer patterns are preferred over
15683 the pattern `*'. See zmodules(1) for details.
15684
15685 Context patterns that use something other than a wildcard (*) to match
15686 the middle parts of the context -- the completer, command, and argument
15687 in :completion:function:completer:command:argument:tag -- should in‐
15688 clude all six colons (:) explicitly. Without this, a pattern such as
15689 :completion:*:foo:* could match foo against a component other than the
15690 intended one (for example, against completer when a match against com‐
15691 mand was intended).
15692
15693 Style names like those of tags are arbitrary and depend on the comple‐
15694 tion function. However, the following two sections list some of the
15695 most common tags and styles.
15696
15697 Standard Tags
15698 Some of the following are only used when looking up particular styles
15699 and do not refer to a type of match.
15700
15701 accounts
15702 used to look up the users-hosts style
15703
15704 all-expansions
15705 used by the _expand completer when adding the single string con‐
15706 taining all possible expansions
15707
15708 all-files
15709 for the names of all files (as distinct from a particular sub‐
15710 set, see the globbed-files tag).
15711
15712 arguments
15713 for arguments to a command
15714
15715 arrays for names of array parameters
15716
15717 association-keys
15718 for keys of associative arrays; used when completing inside a
15719 subscript to a parameter of this type
15720
15721 bookmarks
15722 when completing bookmarks (e.g. for URLs and the zftp function
15723 suite)
15724
15725 builtins
15726 for names of builtin commands
15727
15728 characters
15729 for single characters in arguments of commands such as stty.
15730 Also used when completing character classes after an opening
15731 bracket
15732
15733 colormapids
15734 for X colormap ids
15735
15736 colors for color names
15737
15738 commands
15739 for names of external commands. Also used by complex commands
15740 such as cvs when completing names subcommands.
15741
15742 contexts
15743 for contexts in arguments to the zstyle builtin command
15744
15745 corrections
15746 used by the _approximate and _correct completers for possible
15747 corrections
15748
15749 cursors
15750 for cursor names used by X programs
15751
15752 default
15753 used in some contexts to provide a way of supplying a default
15754 when more specific tags are also valid. Note that this tag is
15755 used when only the function field of the context name is set
15756
15757 descriptions
15758 used when looking up the value of the format style to generate
15759 descriptions for types of matches
15760
15761 devices
15762 for names of device special files
15763
15764 directories
15765 for names of directories -- local-directories is used instead
15766 when completing arguments of cd and related builtin commands
15767 when the cdpath array is set
15768
15769 directory-stack
15770 for entries in the directory stack
15771
15772 displays
15773 for X display names
15774
15775 domains
15776 for network domains
15777
15778 email-plugin
15779 for email addresses from the `_email-plugin' backend of
15780 _email_addresses
15781
15782 expansions
15783 used by the _expand completer for individual words (as opposed
15784 to the complete set of expansions) resulting from the expansion
15785 of a word on the command line
15786
15787 extensions
15788 for X server extensions
15789
15790 file-descriptors
15791 for numbers of open file descriptors
15792
15793 files the generic file-matching tag used by functions completing file‐
15794 names
15795
15796 fonts for X font names
15797
15798 fstypes
15799 for file system types (e.g. for the mount command)
15800
15801 functions
15802 names of functions -- normally shell functions, although certain
15803 commands may understand other kinds of function
15804
15805 globbed-files
15806 for filenames when the name has been generated by pattern match‐
15807 ing
15808
15809 groups for names of user groups
15810
15811 history-words
15812 for words from the history
15813
15814 hosts for hostnames
15815
15816 indexes
15817 for array indexes
15818
15819 interfaces
15820 for network interfaces
15821
15822 jobs for jobs (as listed by the `jobs' builtin)
15823
15824 keymaps
15825 for names of zsh keymaps
15826
15827 keysyms
15828 for names of X keysyms
15829
15830 libraries
15831 for names of system libraries
15832
15833 limits for system limits
15834
15835 local-directories
15836 for names of directories that are subdirectories of the current
15837 working directory when completing arguments of cd and related
15838 builtin commands (compare path-directories) -- when the cdpath
15839 array is unset, directories is used instead
15840
15841 mailboxes
15842 for e-mail folders
15843
15844 manuals
15845 for names of manual pages
15846
15847 maps for map names (e.g. NIS maps)
15848
15849 messages
15850 used to look up the format style for messages
15851
15852 modifiers
15853 for names of X modifiers
15854
15855 modules
15856 for modules (e.g. zsh modules)
15857
15858 my-accounts
15859 used to look up the users-hosts style
15860
15861 named-directories
15862 for named directories (you wouldn't have guessed that, would
15863 you?)
15864
15865 names for all kinds of names
15866
15867 newsgroups
15868 for USENET groups
15869
15870 nicknames
15871 for nicknames of NIS maps
15872
15873 options
15874 for command options
15875
15876 original
15877 used by the _approximate, _correct and _expand completers when
15878 offering the original string as a match
15879
15880 other-accounts
15881 used to look up the users-hosts style
15882
15883 packages
15884 for packages (e.g. rpm or installed Debian packages)
15885
15886 parameters
15887 for names of parameters
15888
15889 path-directories
15890 for names of directories found by searching the cdpath array
15891 when completing arguments of cd and related builtin commands
15892 (compare local-directories)
15893
15894 paths used to look up the values of the expand, ambiguous and spe‐
15895 cial-dirs styles
15896
15897 pods for perl pods (documentation files)
15898
15899 ports for communication ports
15900
15901 prefixes
15902 for prefixes (like those of a URL)
15903
15904 printers
15905 for print queue names
15906
15907 processes
15908 for process identifiers
15909
15910 processes-names
15911 used to look up the command style when generating the names of
15912 processes for killall
15913
15914 sequences
15915 for sequences (e.g. mh sequences)
15916
15917 sessions
15918 for sessions in the zftp function suite
15919
15920 signals
15921 for signal names
15922
15923 strings
15924 for strings (e.g. the replacement strings for the cd builtin
15925 command)
15926
15927 styles for styles used by the zstyle builtin command
15928
15929 suffixes
15930 for filename extensions
15931
15932 tags for tags (e.g. rpm tags)
15933
15934 targets
15935 for makefile targets
15936
15937 time-zones
15938 for time zones (e.g. when setting the TZ parameter)
15939
15940 types for types of whatever (e.g. address types for the xhost command)
15941
15942 urls used to look up the urls and local styles when completing URLs
15943
15944 users for usernames
15945
15946 values for one of a set of values in certain lists
15947
15948 variant
15949 used by _pick_variant to look up the command to run when deter‐
15950 mining what program is installed for a particular command name.
15951
15952 visuals
15953 for X visuals
15954
15955 warnings
15956 used to look up the format style for warnings
15957
15958 widgets
15959 for zsh widget names
15960
15961 windows
15962 for IDs of X windows
15963
15964 zsh-options
15965 for shell options
15966
15967 Standard Styles
15968 Note that the values of several of these styles represent boolean val‐
15969 ues. Any of the strings `true', `on', `yes', and `1' can be used for
15970 the value `true' and any of the strings `false', `off', `no', and `0'
15971 for the value `false'. The behavior for any other value is undefined
15972 except where explicitly mentioned. The default value may be either
15973 `true' or `false' if the style is not set.
15974
15975 Some of these styles are tested first for every possible tag corre‐
15976 sponding to a type of match, and if no style was found, for the default
15977 tag. The most notable styles of this type are menu, list-colors and
15978 styles controlling completion listing such as list-packed and
15979 last-prompt. When tested for the default tag, only the function field
15980 of the context will be set so that a style using the default tag will
15981 normally be defined along the lines of:
15982
15983 zstyle ':completion:*:default' menu ...
15984
15985 accept-exact
15986 This is tested for the default tag in addition to the tags valid
15987 for the current context. If it is set to `true' and any of the
15988 trial matches is the same as the string on the command line,
15989 this match will immediately be accepted (even if it would other‐
15990 wise be considered ambiguous).
15991
15992 When completing pathnames (where the tag used is `paths') this
15993 style accepts any number of patterns as the value in addition to
15994 the boolean values. Pathnames matching one of these patterns
15995 will be accepted immediately even if the command line contains
15996 some more partially typed pathname components and these match no
15997 file under the directory accepted.
15998
15999 This style is also used by the _expand completer to decide if
16000 words beginning with a tilde or parameter expansion should be
16001 expanded. For example, if there are parameters foo and foobar,
16002 the string `$foo' will only be expanded if accept-exact is set
16003 to `true'; otherwise the completion system will be allowed to
16004 complete $foo to $foobar. If the style is set to `continue',
16005 _expand will add the expansion as a match and the completion
16006 system will also be allowed to continue.
16007
16008 accept-exact-dirs
16009 This is used by filename completion. Unlike accept-exact it is
16010 a boolean. By default, filename completion examines all compo‐
16011 nents of a path to see if there are completions of that compo‐
16012 nent, even if the component matches an existing directory. For
16013 example, when completion after /usr/bin/, the function examines
16014 possible completions to /usr.
16015
16016 When this style is `true', any prefix of a path that matches an
16017 existing directory is accepted without any attempt to complete
16018 it further. Hence, in the given example, the path /usr/bin/ is
16019 accepted immediately and completion tried in that directory.
16020
16021 This style is also useful when completing after directories that
16022 magically appear when referenced, such as ZFS .zfs directories
16023 or NetApp .snapshot directories. When the style is set the
16024 shell does not check for the existence of the directory within
16025 the parent directory.
16026
16027 If you wish to inhibit this behaviour entirely, set the
16028 path-completion style (see below) to `false'.
16029
16030 add-space
16031 This style is used by the _expand completer. If it is `true'
16032 (the default), a space will be inserted after all words result‐
16033 ing from the expansion, or a slash in the case of directory
16034 names. If the value is `file', the completer will only add a
16035 space to names of existing files. Either a boolean `true' or
16036 the value `file' may be combined with `subst', in which case the
16037 completer will not add a space to words generated from the ex‐
16038 pansion of a substitution of the form `$(...)' or `${...}'.
16039
16040 The _prefix completer uses this style as a simple boolean value
16041 to decide if a space should be inserted before the suffix.
16042
16043 ambiguous
16044 This applies when completing non-final components of filename
16045 paths, in other words those with a trailing slash. If it is
16046 set, the cursor is left after the first ambiguous component,
16047 even if menu completion is in use. The style is always tested
16048 with the paths tag.
16049
16050 assign-list
16051 When completing after an equals sign that is being treated as an
16052 assignment, the completion system normally completes only one
16053 filename. In some cases the value may be a list of filenames
16054 separated by colons, as with PATH and similar parameters. This
16055 style can be set to a list of patterns matching the names of
16056 such parameters.
16057
16058 The default is to complete lists when the word on the line al‐
16059 ready contains a colon.
16060
16061 auto-description
16062 If set, this style's value will be used as the description for
16063 options that are not described by the completion functions, but
16064 that have exactly one argument. The sequence `%d' in the value
16065 will be replaced by the description for this argument. Depend‐
16066 ing on personal preferences, it may be useful to set this style
16067 to something like `specify: %d'. Note that this may not work
16068 for some commands.
16069
16070 avoid-completer
16071 This is used by the _all_matches completer to decide if the
16072 string consisting of all matches should be added to the list
16073 currently being generated. Its value is a list of names of com‐
16074 pleters. If any of these is the name of the completer that gen‐
16075 erated the matches in this completion, the string will not be
16076 added.
16077
16078 The default value for this style is `_expand _old_list _correct
16079 _approximate', i.e. it contains the completers for which a
16080 string with all matches will almost never be wanted.
16081
16082 cache-path
16083 This style defines the path where any cache files containing
16084 dumped completion data are stored. It defaults to `$ZDOT‐
16085 DIR/.zcompcache', or `$HOME/.zcompcache' if $ZDOTDIR is not de‐
16086 fined. The completion cache will not be used unless the
16087 use-cache style is set.
16088
16089 cache-policy
16090 This style defines the function that will be used to determine
16091 whether a cache needs rebuilding. See the section on the
16092 _cache_invalid function below.
16093
16094 call-command
16095 This style is used in the function for commands such as make and
16096 ant where calling the command directly to generate matches suf‐
16097 fers problems such as being slow or, as in the case of make can
16098 potentially cause actions in the makefile to be executed. If it
16099 is set to `true' the command is called to generate matches. The
16100 default value of this style is `false'.
16101
16102 command
16103 In many places, completion functions need to call external com‐
16104 mands to generate the list of completions. This style can be
16105 used to override the command that is called in some such cases.
16106 The elements of the value are joined with spaces to form a com‐
16107 mand line to execute. The value can also start with a hyphen,
16108 in which case the usual command will be added to the end; this
16109 is most useful for putting `builtin' or `command' in front to
16110 make sure the appropriate version of a command is called, for
16111 example to avoid calling a shell function with the same name as
16112 an external command.
16113
16114 As an example, the completion function for process IDs uses this
16115 style with the processes tag to generate the IDs to complete and
16116 the list of processes to display (if the verbose style is
16117 `true'). The list produced by the command should look like the
16118 output of the ps command. The first line is not displayed, but
16119 is searched for the string `PID' (or `pid') to find the position
16120 of the process IDs in the following lines. If the line does not
16121 contain `PID', the first numbers in each of the other lines are
16122 taken as the process IDs to complete.
16123
16124 Note that the completion function generally has to call the
16125 specified command for each attempt to generate the completion
16126 list. Hence care should be taken to specify only commands that
16127 take a short time to run, and in particular to avoid any that
16128 may never terminate.
16129
16130 command-path
16131 This is a list of directories to search for commands to com‐
16132 plete. The default for this style is the value of the special
16133 parameter path.
16134
16135 commands
16136 This is used by the function completing sub-commands for the
16137 system initialisation scripts (residing in /etc/init.d or some‐
16138 where not too far away from that). Its values give the default
16139 commands to complete for those commands for which the completion
16140 function isn't able to find them out automatically. The default
16141 for this style are the two strings `start' and `stop'.
16142
16143 complete
16144 This is used by the _expand_alias function when invoked as a
16145 bindable command. If set to `true' and the word on the command
16146 line is not the name of an alias, matching alias names will be
16147 completed.
16148
16149 complete-options
16150 This is used by the completer for cd, chdir and pushd. For
16151 these commands a - is used to introduce a directory stack entry
16152 and completion of these is far more common than completing op‐
16153 tions. Hence unless the value of this style is `true' options
16154 will not be completed, even after an initial -. If it is
16155 `true', options will be completed after an initial - unless
16156 there is a preceding -- on the command line.
16157
16158 completer
16159 The strings given as the value of this style provide the names
16160 of the completer functions to use. The available completer func‐
16161 tions are described in the section `Control Functions' below.
16162
16163 Each string may be either the name of a completer function or a
16164 string of the form `function:name'. In the first case the com‐
16165 pleter field of the context will contain the name of the com‐
16166 pleter without the leading underscore and with all other under‐
16167 scores replaced by hyphens. In the second case the function is
16168 the name of the completer to call, but the context will contain
16169 the user-defined name in the completer field of the context. If
16170 the name starts with a hyphen, the string for the context will
16171 be build from the name of the completer function as in the first
16172 case with the name appended to it. For example:
16173
16174 zstyle ':completion:*' completer _complete _complete:-foo
16175
16176 Here, completion will call the _complete completer twice, once
16177 using `complete' and once using `complete-foo' in the completer
16178 field of the context. Normally, using the same completer more
16179 than once only makes sense when used with the `functions:name'
16180 form, because otherwise the context name will be the same in all
16181 calls to the completer; possible exceptions to this rule are the
16182 _ignored and _prefix completers.
16183
16184 The default value for this style is `_complete _ignored': only
16185 completion will be done, first using the ignored-patterns style
16186 and the $fignore array and then without ignoring matches.
16187
16188 condition
16189 This style is used by the _list completer function to decide if
16190 insertion of matches should be delayed unconditionally. The de‐
16191 fault is `true'.
16192
16193 delimiters
16194 This style is used when adding a delimiter for use with history
16195 modifiers or glob qualifiers that have delimited arguments. It
16196 is an array of preferred delimiters to add. Non-special charac‐
16197 ters are preferred as the completion system may otherwise become
16198 confused. The default list is :, +, /, -, %. The list may be
16199 empty to force a delimiter to be typed.
16200
16201 disabled
16202 If this is set to `true', the _expand_alias completer and bind‐
16203 able command will try to expand disabled aliases, too. The de‐
16204 fault is `false'.
16205
16206 domains
16207 A list of names of network domains for completion. If this is
16208 not set, domain names will be taken from the file /etc/re‐
16209 solv.conf.
16210
16211 environ
16212 The environ style is used when completing for `sudo'. It is set
16213 to an array of `VAR=value' assignments to be exported into the
16214 local environment before the completion for the target command
16215 is invoked.
16216 zstyle ':completion:*:sudo::' environ \
16217 PATH="/sbin:/usr/sbin:$PATH" HOME="/root"
16218
16219 expand This style is used when completing strings consisting of multi‐
16220 ple parts, such as path names.
16221
16222 If one of its values is the string `prefix', the partially typed
16223 word from the line will be expanded as far as possible even if
16224 trailing parts cannot be completed.
16225
16226 If one of its values is the string `suffix', matching names for
16227 components after the first ambiguous one will also be added.
16228 This means that the resulting string is the longest unambiguous
16229 string possible. However, menu completion can be used to cycle
16230 through all matches.
16231
16232 extra-verbose
16233 If set, the completion listing is more verbose at the cost of a
16234 probable decrease in completion speed. Completion performance
16235 will suffer if this style is set to `true'.
16236
16237 fake This style may be set for any completion context. It specifies
16238 additional strings that will always be completed in that con‐
16239 text. The form of each string is `value:description'; the colon
16240 and description may be omitted, but any literal colons in value
16241 must be quoted with a backslash. Any description provided is
16242 shown alongside the value in completion listings.
16243
16244 It is important to use a sufficiently restrictive context when
16245 specifying fake strings. Note that the styles fake-files and
16246 fake-parameters provide additional features when completing
16247 files or parameters.
16248
16249 fake-always
16250 This works identically to the fake style except that the ig‐
16251 nored-patterns style is not applied to it. This makes it possi‐
16252 ble to override a set of matches completely by setting the ig‐
16253 nored patterns to `*'.
16254
16255 The following shows a way of supplementing any tag with arbi‐
16256 trary data, but having it behave for display purposes like a
16257 separate tag. In this example we use the features of the
16258 tag-order style to divide the named-directories tag into two
16259 when performing completion with the standard completer complete
16260 for arguments of cd. The tag named-directories-normal behaves
16261 as normal, but the tag named-directories-mine contains a fixed
16262 set of directories. This has the effect of adding the match
16263 group `extra directories' with the given completions.
16264
16265 zstyle ':completion::complete:cd:*' tag-order \
16266 'named-directories:-mine:extra\ directories
16267 named-directories:-normal:named\ directories *'
16268 zstyle ':completion::complete:cd:*:named-directories-mine' \
16269 fake-always mydir1 mydir2
16270 zstyle ':completion::complete:cd:*:named-directories-mine' \
16271 ignored-patterns '*'
16272
16273 fake-files
16274 This style is used when completing files and looked up without a
16275 tag. Its values are of the form `dir:names...'. This will add
16276 the names (strings separated by spaces) as possible matches when
16277 completing in the directory dir, even if no such files really
16278 exist. The dir may be a pattern; pattern characters or colons
16279 in dir should be quoted with a backslash to be treated liter‐
16280 ally.
16281
16282 This can be useful on systems that support special file systems
16283 whose top-level pathnames can not be listed or generated with
16284 glob patterns (but see accept-exact-dirs for a more general way
16285 of dealing with this problem). It can also be used for directo‐
16286 ries for which one does not have read permission.
16287
16288 The pattern form can be used to add a certain `magic' entry to
16289 all directories on a particular file system.
16290
16291 fake-parameters
16292 This is used by the completion function for parameter names.
16293 Its values are names of parameters that might not yet be set but
16294 should be completed nonetheless. Each name may also be followed
16295 by a colon and a string specifying the type of the parameter
16296 (like `scalar', `array' or `integer'). If the type is given,
16297 the name will only be completed if parameters of that type are
16298 required in the particular context. Names for which no type is
16299 specified will always be completed.
16300
16301 file-list
16302 This style controls whether files completed using the standard
16303 builtin mechanism are to be listed with a long list similar to
16304 ls -l. Note that this feature uses the shell module zsh/stat
16305 for file information; this loads the builtin stat which will re‐
16306 place any external stat executable. To avoid this the following
16307 code can be included in an initialization file:
16308
16309 zmodload -i zsh/stat
16310 disable stat
16311
16312 The style may either be set to a `true' value (or `all'), or one
16313 of the values `insert' or `list', indicating that files are to
16314 be listed in long format in all circumstances, or when attempt‐
16315 ing to insert a file name, or when listing file names without
16316 attempting to insert one.
16317
16318 More generally, the value may be an array of any of the above
16319 values, optionally followed by =num. If num is present it gives
16320 the maximum number of matches for which long listing style will
16321 be used. For example,
16322
16323 zstyle ':completion:*' file-list list=20 insert=10
16324
16325 specifies that long format will be used when listing up to 20
16326 files or inserting a file with up to 10 matches (assuming a
16327 listing is to be shown at all, for example on an ambiguous com‐
16328 pletion), else short format will be used.
16329
16330 zstyle -e ':completion:*' file-list \
16331 '(( ${+NUMERIC} )) && reply=(true)'
16332
16333 specifies that long format will be used any time a numeric argu‐
16334 ment is supplied, else short format.
16335
16336 file-patterns
16337 This is used by the standard function for completing filenames,
16338 _files. If the style is unset up to three tags are offered,
16339 `globbed-files',`directories' and `all-files', depending on the
16340 types of files expected by the caller of _files. The first two
16341 (`globbed-files' and `directories') are normally offered to‐
16342 gether to make it easier to complete files in sub-directories.
16343
16344 The file-patterns style provides alternatives to the default
16345 tags, which are not used. Its value consists of elements of the
16346 form `pattern:tag'; each string may contain any number of such
16347 specifications separated by spaces.
16348
16349 The pattern is a pattern that is to be used to generate file‐
16350 names. Any occurrence of the sequence `%p' is replaced by any
16351 pattern(s) passed by the function calling _files. Colons in the
16352 pattern must be preceded by a backslash to make them distin‐
16353 guishable from the colon before the tag. If more than one pat‐
16354 tern is needed, the patterns can be given inside braces, sepa‐
16355 rated by commas.
16356
16357 The tags of all strings in the value will be offered by _files
16358 and used when looking up other styles. Any tags in the same
16359 word will be offered at the same time and before later words.
16360 If no `:tag' is given the `files' tag will be used.
16361
16362 The tag may also be followed by an optional second colon and a
16363 description, which will be used for the `%d' in the value of the
16364 format style (if that is set) instead of the default description
16365 supplied by the completion function. The inclusion of a de‐
16366 scription also gives precedence to associated options such as
16367 for completion grouping so it can be used where files should be
16368 separated.
16369
16370 For example, to make the rm command first complete only names of
16371 object files and then the names of all files if there is no
16372 matching object file:
16373
16374 zstyle ':completion:*:*:rm:*:*' file-patterns \
16375 '*.o:object-files' '%p:all-files'
16376
16377 To alter the default behaviour of file completion -- offer files
16378 matching a pattern and directories on the first attempt, then
16379 all files -- to offer only matching files on the first attempt,
16380 then directories, and finally all files:
16381
16382 zstyle ':completion:*' file-patterns \
16383 '%p:globbed-files' '*(-/):directories' '*:all-files'
16384
16385 This works even where there is no special pattern: _files
16386 matches all files using the pattern `*' at the first step and
16387 stops when it sees this pattern. Note also it will never try a
16388 pattern more than once for a single completion attempt.
16389
16390 To separate directories into a separate group from the files but
16391 still complete them at the first attempt, a description needs to
16392 be given. Note that directories need to be explicitly excluded
16393 from the globbed-files because `*' will match directories. For
16394 grouping, it is also necessary to set the group-name style.
16395
16396 zstyle ':completion:*' file-patterns \
16397 '%p(^-/):globbed-files *(-/):directories:location'
16398
16399 During the execution of completion functions, the EXTENDED_GLOB
16400 option is in effect, so the characters `#', `~' and `^' have
16401 special meanings in the patterns.
16402
16403 file-sort
16404 The standard filename completion function uses this style with‐
16405 out a tag to determine in which order the names should be
16406 listed; menu completion will cycle through them in the same or‐
16407 der. The possible values are: `size' to sort by the size of the
16408 file; `links' to sort by the number of links to the file; `modi‐
16409 fication' (or `time' or `date') to sort by the last modification
16410 time; `access' to sort by the last access time; and `inode' (or
16411 `change') to sort by the last inode change time. If the style
16412 is set to any other value, or is unset, files will be sorted al‐
16413 phabetically by name. If the value contains the string `re‐
16414 verse', sorting is done in the opposite order. If the value
16415 contains the string `follow', timestamps are associated with the
16416 targets of symbolic links; the default is to use the timestamps
16417 of the links themselves.
16418
16419 file-split-chars
16420 A set of characters that will cause all file completions for the
16421 given context to be split at the point where any of the charac‐
16422 ters occurs. A typical use is to set the style to :; then ev‐
16423 erything up to and including the last : in the string so far is
16424 ignored when completing files. As this is quite heavy-handed,
16425 it is usually preferable to update completion functions for con‐
16426 texts where this behaviour is useful.
16427
16428 filter The ldap plugin of email address completion (see _email_ad‐
16429 dresses) uses this style to specify the attributes to match
16430 against when filtering entries. So for example, if the style is
16431 set to `sn', matching is done against surnames. Standard LDAP
16432 filtering is used so normal completion matching is bypassed. If
16433 this style is not set, the LDAP plugin is skipped. You may also
16434 need to set the command style to specify how to connect to your
16435 LDAP server.
16436
16437 force-list
16438 This forces a list of completions to be shown at any point where
16439 listing is done, even in cases where the list would usually be
16440 suppressed. For example, normally the list is only shown if
16441 there are at least two different matches. By setting this style
16442 to `always', the list will always be shown, even if there is
16443 only a single match that will immediately be accepted. The
16444 style may also be set to a number. In this case the list will
16445 be shown if there are at least that many matches, even if they
16446 would all insert the same string.
16447
16448 This style is tested for the default tag as well as for each tag
16449 valid for the current completion. Hence the listing can be
16450 forced only for certain types of match.
16451
16452 format If this is set for the descriptions tag, its value is used as a
16453 string to display above matches in completion lists. The se‐
16454 quence `%d' in this string will be replaced with a short de‐
16455 scription of what these matches are. This string may also con‐
16456 tain the output attribute sequences understood by compadd -X
16457 (see zshcompwid(1)).
16458
16459 The style is tested with each tag valid for the current comple‐
16460 tion before it is tested for the descriptions tag. Hence dif‐
16461 ferent format strings can be defined for different types of
16462 match.
16463
16464 Note also that some completer functions define additional
16465 `%'-sequences. These are described for the completer functions
16466 that make use of them.
16467
16468 Some completion functions display messages that may be cus‐
16469 tomised by setting this style for the messages tag. Here, the
16470 `%d' is replaced with a message given by the completion func‐
16471 tion.
16472
16473 Finally, the format string is looked up with the warnings tag,
16474 for use when no matches could be generated at all. In this case
16475 the `%d' is replaced with the descriptions for the matches that
16476 were expected separated by spaces. The sequence `%D' is re‐
16477 placed with the same descriptions separated by newlines.
16478
16479 It is possible to use printf-style field width specifiers with
16480 `%d' and similar escape sequences. This is handled by the zfor‐
16481 mat builtin command from the zsh/zutil module, see zshmod‐
16482 ules(1).
16483
16484 gain-privileges
16485 If set to true, this style enables the use of commands like sudo
16486 or doas to gain extra privileges when retrieving information for
16487 completion. This is only done when a command such as sudo ap‐
16488 pears on the command-line. To force the use of, e.g. sudo or to
16489 override any prefix that might be added due to gain-privileges,
16490 the command style can be used with a value that begins with a
16491 hyphen.
16492
16493 glob This is used by the _expand completer. If it is set to `true'
16494 (the default), globbing will be attempted on the words resulting
16495 from a previous substitution (see the substitute style) or else
16496 the original string from the line.
16497
16498 global If this is set to `true' (the default), the _expand_alias com‐
16499 pleter and bindable command will try to expand global aliases.
16500
16501 group-name
16502 The completion system can group different types of matches,
16503 which appear in separate lists. This style can be used to give
16504 the names of groups for particular tags. For example, in com‐
16505 mand position the completion system generates names of builtin
16506 and external commands, names of aliases, shell functions and pa‐
16507 rameters and reserved words as possible completions. To have
16508 the external commands and shell functions listed separately:
16509
16510 zstyle ':completion:*:*:-command-:*:commands' \
16511 group-name commands
16512 zstyle ':completion:*:*:-command-:*:functions' \
16513 group-name functions
16514
16515 As a consequence, any match with the same tag will be displayed
16516 in the same group.
16517
16518 If the name given is the empty string the name of the tag for
16519 the matches will be used as the name of the group. So, to have
16520 all different types of matches displayed separately, one can
16521 just set:
16522
16523 zstyle ':completion:*' group-name ''
16524
16525 All matches for which no group name is defined will be put in a
16526 group named -default-.
16527
16528 To display the group name in the output, see the format style
16529 (q.v.) under the descriptions tag.
16530
16531 group-order
16532 This style is additional to the group-name style to specify the
16533 order for display of the groups defined by that style (compare
16534 tag-order, which determines which completions appear at all).
16535 The groups named are shown in the given order; any other groups
16536 are shown in the order defined by the completion function.
16537
16538 For example, to have names of builtin commands, shell functions
16539 and external commands appear in that order when completing in
16540 command position:
16541
16542 zstyle ':completion:*:*:-command-:*:*' group-order \
16543 builtins functions commands
16544
16545 groups A list of names of UNIX groups. If this is not set, group names
16546 are taken from the YP database or the file `/etc/group'.
16547
16548 hidden If this is set to `true', matches for the given context will not
16549 be listed, although any description for the matches set with the
16550 format style will be shown. If it is set to `all', not even the
16551 description will be displayed.
16552
16553 Note that the matches will still be completed; they are just not
16554 shown in the list. To avoid having matches considered as possi‐
16555 ble completions at all, the tag-order style can be modified as
16556 described below.
16557
16558 hosts A list of names of hosts that should be completed. If this is
16559 not set, hostnames are taken from the file `/etc/hosts'.
16560
16561 hosts-ports
16562 This style is used by commands that need or accept hostnames and
16563 network ports. The strings in the value should be of the form
16564 `host:port'. Valid ports are determined by the presence of
16565 hostnames; multiple ports for the same host may appear.
16566
16567 ignore-line
16568 This is tested for each tag valid for the current completion.
16569 If it is set to `true', none of the words that are already on
16570 the line will be considered as possible completions. If it is
16571 set to `current', the word the cursor is on will not be consid‐
16572 ered as a possible completion. The value `current-shown' is
16573 similar but only applies if the list of completions is currently
16574 shown on the screen. Finally, if the style is set to `other',
16575 all words on the line except for the current one will be ex‐
16576 cluded from the possible completions.
16577
16578 The values `current' and `current-shown' are a bit like the op‐
16579 posite of the accept-exact style: only strings with missing
16580 characters will be completed.
16581
16582 Note that you almost certainly don't want to set this to `true'
16583 or `other' for a general context such as `:completion:*'. This
16584 is because it would disallow completion of, for example, options
16585 multiple times even if the command in question accepts the op‐
16586 tion more than once.
16587
16588 ignore-parents
16589 The style is tested without a tag by the function completing
16590 pathnames in order to determine whether to ignore the names of
16591 directories already mentioned in the current word, or the name
16592 of the current working directory. The value must include one or
16593 both of the following strings:
16594
16595 parent The name of any directory whose path is already contained
16596 in the word on the line is ignored. For example, when
16597 completing after foo/../, the directory foo will not be
16598 considered a valid completion.
16599
16600 pwd The name of the current working directory will not be
16601 completed; hence, for example, completion after ../ will
16602 not use the name of the current directory.
16603
16604 In addition, the value may include one or both of:
16605
16606 .. Ignore the specified directories only when the word on
16607 the line contains the substring `../'.
16608
16609 directory
16610 Ignore the specified directories only when names of di‐
16611 rectories are completed, not when completing names of
16612 files.
16613
16614 Excluded values act in a similar fashion to values of the ig‐
16615 nored-patterns style, so they can be restored to consideration
16616 by the _ignored completer.
16617
16618 ignored-patterns
16619 A list of patterns; any trial completion matching one of the
16620 patterns will be excluded from consideration. The _ignored com‐
16621 pleter can appear in the list of completers to restore the ig‐
16622 nored matches. This is a more configurable version of the shell
16623 parameter $fignore.
16624
16625 Note that the EXTENDED_GLOB option is set during the execution
16626 of completion functions, so the characters `#', `~' and `^' have
16627 special meanings in the patterns.
16628
16629 insert This style is used by the _all_matches completer to decide
16630 whether to insert the list of all matches unconditionally in‐
16631 stead of adding the list as another match.
16632
16633 insert-ids
16634 When completing process IDs, for example as arguments to the
16635 kill and wait builtins the name of a command may be converted to
16636 the appropriate process ID. A problem arises when the process
16637 name typed is not unique. By default (or if this style is set
16638 explicitly to `menu') the name will be converted immediately to
16639 a set of possible IDs, and menu completion will be started to
16640 cycle through them.
16641
16642 If the value of the style is `single', the shell will wait until
16643 the user has typed enough to make the command unique before con‐
16644 verting the name to an ID; attempts at completion will be unsuc‐
16645 cessful until that point. If the value is any other string,
16646 menu completion will be started when the string typed by the
16647 user is longer than the common prefix to the corresponding IDs.
16648
16649 insert-sections
16650 This style is used with tags of the form `manuals.X' when com‐
16651 pleting names of manual pages. If set and the X in the tag name
16652 matches the section number of the page being completed, the sec‐
16653 tion number is inserted along with the page name. For example,
16654 given
16655
16656 zstyle ':completion:*:manuals.*' insert-sections true
16657
16658 man ssh_<TAB> may be completed to man 5 ssh_config.
16659
16660 The value may also be set to one of `prepend', or `suffix'.
16661 `prepend' behaves the same as `true' as in the above example,
16662 while `suffix' would complete man ssh_<TAB> as man ssh_config.5.
16663
16664 This is especially useful in conjunction with separate-sections,
16665 as it ensures that the page requested of man corresponds to the
16666 one displayed in the completion listing when there are multiple
16667 pages with the same name (e.g., printf(1) and printf(3)).
16668
16669 The default for this style is `false'.
16670
16671 insert-tab
16672 If this is set to `true', the completion system will insert a
16673 TAB character (assuming that was used to start completion) in‐
16674 stead of performing completion when there is no non-blank char‐
16675 acter to the left of the cursor. If it is set to `false', com‐
16676 pletion will be done even there.
16677
16678 The value may also contain the substrings `pending' or `pend‐
16679 ing=val'. In this case, the typed character will be inserted
16680 instead of starting completion when there is unprocessed input
16681 pending. If a val is given, completion will not be done if
16682 there are at least that many characters of unprocessed input.
16683 This is often useful when pasting characters into a terminal.
16684 Note however, that it relies on the $PENDING special parameter
16685 from the zsh/zle module being set properly which is not guaran‐
16686 teed on all platforms.
16687
16688 The default value of this style is `true' except for completion
16689 within vared builtin command where it is `false'.
16690
16691 insert-unambiguous
16692 This is used by the _match and _approximate completers. These
16693 completers are often used with menu completion since the word
16694 typed may bear little resemblance to the final completion. How‐
16695 ever, if this style is `true', the completer will start menu
16696 completion only if it could find no unambiguous initial string
16697 at least as long as the original string typed by the user.
16698
16699 In the case of the _approximate completer, the completer field
16700 in the context will already have been set to one of correct-num
16701 or approximate-num, where num is the number of errors that were
16702 accepted.
16703
16704 In the case of the _match completer, the style may also be set
16705 to the string `pattern'. Then the pattern on the line is left
16706 unchanged if it does not match unambiguously.
16707
16708 keep-prefix
16709 This style is used by the _expand completer. If it is `true',
16710 the completer will try to keep a prefix containing a tilde or
16711 parameter expansion. Hence, for example, the string `~/f*'
16712 would be expanded to `~/foo' instead of `/home/user/foo'. If
16713 the style is set to `changed' (the default), the prefix will
16714 only be left unchanged if there were other changes between the
16715 expanded words and the original word from the command line. Any
16716 other value forces the prefix to be expanded unconditionally.
16717
16718 The behaviour of _expand when this style is `true' is to cause
16719 _expand to give up when a single expansion with the restored
16720 prefix is the same as the original; hence any remaining com‐
16721 pleters may be called.
16722
16723 known-hosts-files
16724 This style should contain a list of files to search for host
16725 names and (if the use-ip style is set) IP addresses in a format
16726 compatible with ssh known_hosts files. If it is not set, the
16727 files /etc/ssh/ssh_known_hosts and ~/.ssh/known_hosts are used.
16728
16729 last-prompt
16730 This is a more flexible form of the ALWAYS_LAST_PROMPT option.
16731 If it is `true', the completion system will try to return the
16732 cursor to the previous command line after displaying a comple‐
16733 tion list. It is tested for all tags valid for the current com‐
16734 pletion, then the default tag. The cursor will be moved back to
16735 the previous line if this style is `true' for all types of
16736 match. Note that unlike the ALWAYS_LAST_PROMPT option this is
16737 independent of the numeric argument.
16738
16739 list This style is used by the _history_complete_word bindable com‐
16740 mand. If it is set to `true' it has no effect. If it is set to
16741 `false' matches will not be listed. This overrides the setting
16742 of the options controlling listing behaviour, in particular
16743 AUTO_LIST. The context always starts with `:completion:his‐
16744 tory-words'.
16745
16746 list-colors
16747 If the zsh/complist module is loaded, this style can be used to
16748 set color specifications. This mechanism replaces the use of
16749 the ZLS_COLORS and ZLS_COLOURS parameters described in the sec‐
16750 tion `The zsh/complist Module' in zshmodules(1), but the syntax
16751 is the same.
16752
16753 If this style is set for the default tag, the strings in the
16754 value are taken as specifications that are to be used every‐
16755 where. If it is set for other tags, the specifications are used
16756 only for matches of the type described by the tag. For this to
16757 work best, the group-name style must be set to an empty string.
16758
16759 In addition to setting styles for specific tags, it is also pos‐
16760 sible to use group names specified explicitly by the group-name
16761 tag together with the `(group)' syntax allowed by the ZLS_COLORS
16762 and ZLS_COLOURS parameters and simply using the default tag.
16763
16764 It is possible to use any color specifications already set up
16765 for the GNU version of the ls command:
16766
16767 zstyle ':completion:*:default' list-colors \
16768 ${(s.:.)LS_COLORS}
16769
16770 The default colors are the same as for the GNU ls command and
16771 can be obtained by setting the style to an empty string (i.e.
16772 '').
16773
16774 list-dirs-first
16775 This is used by file completion and corresponds to a particular
16776 setting of the file-patterns style. If set, the default direc‐
16777 tories to be completed are listed separately from and before
16778 completion for other files.
16779
16780 list-grouped
16781 If this style is `true' (the default), the completion system
16782 will try to make certain completion listings more compact by
16783 grouping matches. For example, options for commands that have
16784 the same description (shown when the verbose style is set to
16785 `true') will appear as a single entry. However, menu selection
16786 can be used to cycle through all the matches.
16787
16788 list-packed
16789 This is tested for each tag valid in the current context as well
16790 as the default tag. If it is set to `true', the corresponding
16791 matches appear in listings as if the LIST_PACKED option were
16792 set. If it is set to `false', they are listed normally.
16793
16794 list-prompt
16795 If this style is set for the default tag, completion lists that
16796 don't fit on the screen can be scrolled (see the description of
16797 the zsh/complist module in zshmodules(1)). The value, if not
16798 the empty string, will be displayed after every screenful and
16799 the shell will prompt for a key press; if the style is set to
16800 the empty string, a default prompt will be used.
16801
16802 The value may contain the escape sequences: `%l' or `%L', which
16803 will be replaced by the number of the last line displayed and
16804 the total number of lines; `%m' or `%M', the number of the last
16805 match shown and the total number of matches; and `%p' and `%P',
16806 `Top' when at the beginning of the list, `Bottom' when at the
16807 end and the position shown as a percentage of the total length
16808 otherwise. In each case the form with the uppercase letter will
16809 be replaced by a string of fixed width, padded to the right
16810 with spaces, while the lowercase form will be replaced by a
16811 variable width string. As in other prompt strings, the escape
16812 sequences `%S', `%s', `%B', `%b', `%U', `%u' for entering and
16813 leaving the display modes standout, bold and underline, and
16814 `%F', `%f', `%K', `%k' for changing the foreground background
16815 colour, are also available, as is the form `%{...%}' for enclos‐
16816 ing escape sequences which display with zero (or, with a numeric
16817 argument, some other) width.
16818
16819 After deleting this prompt the variable LISTPROMPT should be un‐
16820 set for the removal to take effect.
16821
16822 list-rows-first
16823 This style is tested in the same way as the list-packed style
16824 and determines whether matches are to be listed in a rows-first
16825 fashion as if the LIST_ROWS_FIRST option were set.
16826
16827 list-separator
16828 The value of this style is used in completion listing to sepa‐
16829 rate the string to complete from a description when possible
16830 (e.g. when completing options). It defaults to `--' (two hy‐
16831 phens).
16832
16833 list-suffixes
16834 This style is used by the function that completes filenames. If
16835 it is `true', and completion is attempted on a string containing
16836 multiple partially typed pathname components, all ambiguous com‐
16837 ponents will be shown. Otherwise, completion stops at the first
16838 ambiguous component.
16839
16840 local This is for use with functions that complete URLs for which the
16841 corresponding files are available directly from the file system.
16842 Its value should consist of three strings: a hostname, the path
16843 to the default web pages for the server, and the directory name
16844 used by a user placing web pages within their home area.
16845
16846 For example:
16847
16848 zstyle ':completion:*' local toast \
16849 /var/http/public/toast public_html
16850
16851 Completion after `http://toast/stuff/' will look for files in
16852 the directory /var/http/public/toast/stuff, while completion
16853 after `http://toast/~yousir/' will look for files in the direc‐
16854 tory ~yousir/public_html.
16855
16856 mail-directory
16857 If set, zsh will assume that mailbox files can be found in the
16858 directory specified. It defaults to `~/Mail'.
16859
16860 match-original
16861 This is used by the _match completer. If it is set to only,
16862 _match will try to generate matches without inserting a `*' at
16863 the cursor position. If set to any other non-empty value, it
16864 will first try to generate matches without inserting the `*' and
16865 if that yields no matches, it will try again with the `*' in‐
16866 serted. If it is unset or set to the empty string, matching
16867 will only be performed with the `*' inserted.
16868
16869 matcher
16870 This style is tested separately for each tag valid in the cur‐
16871 rent context. Its value is placed before any match specifica‐
16872 tions given by the matcher-list style so can override them via
16873 the use of an x: specification. The value should be in the form
16874 described in the section `Completion Matching Control' in zsh‐
16875 compwid(1). For examples of this, see the description of the
16876 tag-order style.
16877
16878 For notes comparing the use of this and the matcher-list style,
16879 see under the description of the tag-order style.
16880
16881 matcher-list
16882 This style can be set to a list of match specifications that are
16883 to be applied everywhere. Match specifications are described in
16884 the section `Completion Matching Control' in zshcompwid(1). The
16885 completion system will try them one after another for each com‐
16886 pleter selected. For example, to try first simple completion
16887 and, if that generates no matches, case-insensitive completion:
16888
16889 zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}'
16890
16891 By default each specification replaces the previous one; how‐
16892 ever, if a specification is prefixed with +, it is added to the
16893 existing list. Hence it is possible to create increasingly gen‐
16894 eral specifications without repetition:
16895
16896 zstyle ':completion:*' matcher-list \
16897 '' '+m:{a-z}={A-Z}' '+m:{A-Z}={a-z}'
16898
16899 It is possible to create match specifications valid for particu‐
16900 lar completers by using the third field of the context. This
16901 applies only to completers that override the global
16902 matcher-list, which as of this writing includes only _prefix and
16903 _ignored. For example, to use the completers _complete and
16904 _prefix but allow case-insensitive completion only with _com‐
16905 plete:
16906
16907 zstyle ':completion:*' completer _complete _prefix
16908 zstyle ':completion:*:complete:*:*:*' matcher-list \
16909 '' 'm:{a-zA-Z}={A-Za-z}'
16910
16911 User-defined names, as explained for the completer style, are
16912 available. This makes it possible to try the same completer
16913 more than once with different match specifications each time.
16914 For example, to try normal completion without a match specifica‐
16915 tion, then normal completion with case-insensitive matching,
16916 then correction, and finally partial-word completion:
16917
16918 zstyle ':completion:*' completer \
16919 _complete _correct _complete:foo
16920 zstyle ':completion:*:complete:*:*:*' matcher-list \
16921 '' 'm:{a-zA-Z}={A-Za-z}'
16922 zstyle ':completion:*:foo:*:*:*' matcher-list \
16923 'm:{a-zA-Z}={A-Za-z} r:|[-_./]=* r:|=*'
16924
16925 If the style is unset in any context no match specification is
16926 applied. Note also that some completers such as _correct and
16927 _approximate do not use the match specifications at all, though
16928 these completers will only ever be called once even if the
16929 matcher-list contains more than one element.
16930
16931 Where multiple specifications are useful, note that the entire
16932 completion is done for each element of matcher-list, which can
16933 quickly reduce the shell's performance. As a rough rule of
16934 thumb, one to three strings will give acceptable performance.
16935 On the other hand, putting multiple space-separated values into
16936 the same string does not have an appreciable impact on perfor‐
16937 mance.
16938
16939 If there is no current matcher or it is empty, and the option
16940 NO_CASE_GLOB is in effect, the matching for files is performed
16941 case-insensitively in any case. However, any matcher must ex‐
16942 plicitly specify case-insensitive matching if that is required.
16943
16944 For notes comparing the use of this and the matcher style, see
16945 under the description of the tag-order style.
16946
16947 max-errors
16948 This is used by the _approximate and _correct completer func‐
16949 tions to determine the maximum number of errors to allow. The
16950 completer will try to generate completions by first allowing one
16951 error, then two errors, and so on, until either a match or
16952 matches were found or the maximum number of errors given by this
16953 style has been reached.
16954
16955 If the value for this style contains the string `numeric', the
16956 completer function will take any numeric argument as the maximum
16957 number of errors allowed. For example, with
16958
16959 zstyle ':completion:*:approximate:::' max-errors 2 numeric
16960
16961 two errors are allowed if no numeric argument is given, but with
16962 a numeric argument of six (as in `ESC-6 TAB'), up to six errors
16963 are accepted. Hence with a value of `0 numeric', no correcting
16964 completion will be attempted unless a numeric argument is given.
16965
16966 If the value contains the string `not-numeric', the completer
16967 will not try to generate corrected completions when given a nu‐
16968 meric argument, so in this case the number given should be
16969 greater than zero. For example, `2 not-numeric' specifies that
16970 correcting completion with two errors will usually be performed,
16971 but if a numeric argument is given, correcting completion will
16972 not be performed.
16973
16974 The default value for this style is `2 numeric'.
16975
16976 max-matches-width
16977 This style is used to determine the trade off between the width
16978 of the display used for matches and the width used for their de‐
16979 scriptions when the verbose style is in effect. The value gives
16980 the number of display columns to reserve for the matches. The
16981 default is half the width of the screen.
16982
16983 This has the most impact when several matches have the same de‐
16984 scription and so will be grouped together. Increasing the style
16985 will allow more matches to be grouped together; decreasing it
16986 will allow more of the description to be visible.
16987
16988 menu If this is `true' in the context of any of the tags defined for
16989 the current completion menu completion will be used. The value
16990 for a specific tag will take precedence over that for the `de‐
16991 fault' tag.
16992
16993 If none of the values found in this way is `true' but at least
16994 one is set to `auto', the shell behaves as if the AUTO_MENU op‐
16995 tion is set.
16996
16997 If one of the values is explicitly set to `false', menu comple‐
16998 tion will be explicitly turned off, overriding the MENU_COMPLETE
16999 option and other settings.
17000
17001 In the form `yes=num', where `yes' may be any of the `true' val‐
17002 ues (`yes', `true', `on' and `1'), menu completion will be
17003 turned on if there are at least num matches. In the form
17004 `yes=long', menu completion will be turned on if the list does
17005 not fit on the screen. This does not activate menu completion
17006 if the widget normally only lists completions, but menu comple‐
17007 tion can be activated in that case with the value
17008 `yes=long-list' (Typically, the value `select=long-list' de‐
17009 scribed later is more useful as it provides control over
17010 scrolling.)
17011
17012 Similarly, with any of the `false' values (as in `no=10'), menu
17013 completion will not be used if there are num or more matches.
17014
17015 The value of this widget also controls menu selection, as imple‐
17016 mented by the zsh/complist module. The following values may ap‐
17017 pear either alongside or instead of the values above.
17018
17019 If the value contains the string `select', menu selection will
17020 be started unconditionally.
17021
17022 In the form `select=num', menu selection will only be started if
17023 there are at least num matches. If the values for more than one
17024 tag provide a number, the smallest number is taken.
17025
17026 Menu selection can be turned off explicitly by defining a value
17027 containing the string`no-select'.
17028
17029 It is also possible to start menu selection only if the list of
17030 matches does not fit on the screen by using the value `se‐
17031 lect=long'. To start menu selection even if the current widget
17032 only performs listing, use the value `select=long-list'.
17033
17034 To turn on menu completion or menu selection when there are a
17035 certain number of matches or the list of matches does not fit on
17036 the screen, both of `yes=' and `select=' may be given twice,
17037 once with a number and once with `long' or `long-list'.
17038
17039 Finally, it is possible to activate two special modes of menu
17040 selection. The word `interactive' in the value causes interac‐
17041 tive mode to be entered immediately when menu selection is
17042 started; see the description of the zsh/complist module in zsh‐
17043 modules(1) for a description of interactive mode. Including the
17044 string `search' does the same for incremental search mode. To
17045 select backward incremental search, include the string
17046 `search-backward'.
17047
17048 muttrc If set, gives the location of the mutt configuration file. It
17049 defaults to `~/.muttrc'.
17050
17051 numbers
17052 This is used with the jobs tag. If it is `true', the shell will
17053 complete job numbers instead of the shortest unambiguous prefix
17054 of the job command text. If the value is a number, job numbers
17055 will only be used if that many words from the job descriptions
17056 are required to resolve ambiguities. For example, if the value
17057 is `1', strings will only be used if all jobs differ in the
17058 first word on their command lines.
17059
17060 old-list
17061 This is used by the _oldlist completer. If it is set to `al‐
17062 ways', then standard widgets which perform listing will retain
17063 the current list of matches, however they were generated; this
17064 can be turned off explicitly with the value `never', giving the
17065 behaviour without the _oldlist completer. If the style is un‐
17066 set, or any other value, then the existing list of completions
17067 is displayed if it is not already; otherwise, the standard com‐
17068 pletion list is generated; this is the default behaviour of
17069 _oldlist. However, if there is an old list and this style con‐
17070 tains the name of the completer function that generated the
17071 list, then the old list will be used even if it was generated by
17072 a widget which does not do listing.
17073
17074 For example, suppose you type ^Xc to use the _correct_word wid‐
17075 get, which generates a list of corrections for the word under
17076 the cursor. Usually, typing ^D would generate a standard list
17077 of completions for the word on the command line, and show that.
17078 With _oldlist, it will instead show the list of corrections al‐
17079 ready generated.
17080
17081 As another example consider the _match completer: with the in‐
17082 sert-unambiguous style set to `true' it inserts only a common
17083 prefix string, if there is any. However, this may remove parts
17084 of the original pattern, so that further completion could pro‐
17085 duce more matches than on the first attempt. By using the
17086 _oldlist completer and setting this style to _match, the list of
17087 matches generated on the first attempt will be used again.
17088
17089 old-matches
17090 This is used by the _all_matches completer to decide if an old
17091 list of matches should be used if one exists. This is selected
17092 by one of the `true' values or by the string `only'. If the
17093 value is `only', _all_matches will only use an old list and
17094 won't have any effect on the list of matches currently being
17095 generated.
17096
17097 If this style is set it is generally unwise to call the
17098 _all_matches completer unconditionally. One possible use is for
17099 either this style or the completer style to be defined with the
17100 -e option to zstyle to make the style conditional.
17101
17102 old-menu
17103 This is used by the _oldlist completer. It controls how menu
17104 completion behaves when a completion has already been inserted
17105 and the user types a standard completion key such as TAB. The
17106 default behaviour of _oldlist is that menu completion always
17107 continues with the existing list of completions. If this style
17108 is set to `false', however, a new completion is started if the
17109 old list was generated by a different completion command; this
17110 is the behaviour without the _oldlist completer.
17111
17112 For example, suppose you type ^Xc to generate a list of correc‐
17113 tions, and menu completion is started in one of the usual ways.
17114 Usually, or with this style set to `false', typing TAB at this
17115 point would start trying to complete the line as it now appears.
17116 With _oldlist, it instead continues to cycle through the list of
17117 corrections.
17118
17119 original
17120 This is used by the _approximate and _correct completers to de‐
17121 cide if the original string should be added as a possible com‐
17122 pletion. Normally, this is done only if there are at least two
17123 possible corrections, but if this style is set to `true', it is
17124 always added. Note that the style will be examined with the
17125 completer field in the context name set to correct-num or ap‐
17126 proximate-num, where num is the number of errors that were ac‐
17127 cepted.
17128
17129 packageset
17130 This style is used when completing arguments of the Debian
17131 `dpkg' program. It contains an override for the default package
17132 set for a given context. For example,
17133
17134 zstyle ':completion:*:complete:dpkg:option--status-1:*' \
17135 packageset avail
17136
17137 causes available packages, rather than only installed packages,
17138 to be completed for `dpkg --status'.
17139
17140 path The function that completes color names uses this style with the
17141 colors tag. The value should be the pathname of a file contain‐
17142 ing color names in the format of an X11 rgb.txt file. If the
17143 style is not set but this file is found in one of various stan‐
17144 dard locations it will be used as the default.
17145
17146 path-completion
17147 This is used by filename completion. By default, filename com‐
17148 pletion examines all components of a path to see if there are
17149 completions of that component. For example, /u/b/z can be com‐
17150 pleted to /usr/bin/zsh. Explicitly setting this style to
17151 `false' inhibits this behaviour for path components up to the /
17152 before the cursor; this overrides the setting of accept-ex‐
17153 act-dirs.
17154
17155 Even with the style set to `false', it is still possible to com‐
17156 plete multiple paths by setting the option COMPLETE_IN_WORD and
17157 moving the cursor back to the first component in the path to be
17158 completed. For example, /u/b/z can be completed to /usr/bin/zsh
17159 if the cursor is after the /u.
17160
17161 pine-directory
17162 If set, specifies the directory containing PINE mailbox files.
17163 There is no default, since recursively searching this directory
17164 is inconvenient for anyone who doesn't use PINE.
17165
17166 ports A list of Internet service names (network ports) to complete.
17167 If this is not set, service names are taken from the file
17168 `/etc/services'.
17169
17170 prefix-hidden
17171 This is used for certain completions which share a common pre‐
17172 fix, for example command options beginning with dashes. If it
17173 is `true', the prefix will not be shown in the list of matches.
17174
17175 The default value for this style is `false'.
17176
17177 prefix-needed
17178 This style is also relevant for matches with a common prefix.
17179 If it is set to `true' this common prefix must be typed by the
17180 user to generate the matches.
17181
17182 The style is applicable to the options, signals, jobs, func‐
17183 tions, and parameters completion tags.
17184
17185 For command options, this means that the initial `-', `+', or
17186 `--' must be typed explicitly before option names will be com‐
17187 pleted.
17188
17189 For signals, an initial `-' is required before signal names will
17190 be completed.
17191
17192 For jobs, an initial `%' is required before job names will be
17193 completed.
17194
17195 For function and parameter names, an initial `_' or `.' is re‐
17196 quired before function or parameter names starting with those
17197 characters will be completed.
17198
17199 The default value for this style is `false' for function and pa‐
17200 rameter completions, and `true' otherwise.
17201
17202 preserve-prefix
17203 This style is used when completing path names. Its value should
17204 be a pattern matching an initial prefix of the word to complete
17205 that should be left unchanged under all circumstances. For ex‐
17206 ample, on some Unices an initial `//' (double slash) has a spe‐
17207 cial meaning; setting this style to the string `//' will pre‐
17208 serve it. As another example, setting this style to `?:/' under
17209 Cygwin would allow completion after `a:/...' and so on.
17210
17211 range This is used by the _history completer and the _history_com‐
17212 plete_word bindable command to decide which words should be com‐
17213 pleted.
17214
17215 If it is a single number, only the last N words from the history
17216 will be completed.
17217
17218 If it is a range of the form `max:slice', the last slice words
17219 will be completed; then if that yields no matches, the slice
17220 words before those will be tried and so on. This process stops
17221 either when at least one match has been found, or max words have
17222 been tried.
17223
17224 The default is to complete all words from the history at once.
17225
17226 recursive-files
17227 If this style is set, its value is an array of patterns to be
17228 tested against `$PWD/': note the trailing slash, which allows
17229 directories in the pattern to be delimited unambiguously by in‐
17230 cluding slashes on both sides. If an ordinary file completion
17231 fails and the word on the command line does not yet have a di‐
17232 rectory part to its name, the style is retrieved using the same
17233 tag as for the completion just attempted, then the elements
17234 tested against $PWD/ in turn. If one matches, then the shell
17235 reattempts completion by prepending the word on the command line
17236 with each directory in the expansion of **/*(/) in turn. Typi‐
17237 cally the elements of the style will be set to restrict the num‐
17238 ber of directories beneath the current one to a manageable num‐
17239 ber, for example `*/.git/*'.
17240
17241 For example,
17242
17243 zstyle ':completion:*' recursive-files '*/zsh/*'
17244
17245 If the current directory is /home/pws/zsh/Src, then zle_tr<TAB>
17246 can be completed to Zle/zle_tricky.c.
17247
17248 regular
17249 This style is used by the _expand_alias completer and bindable
17250 command. If set to `true' (the default), regular aliases will
17251 be expanded but only in command position. If it is set to
17252 `false', regular aliases will never be expanded. If it is set
17253 to `always', regular aliases will be expanded even if not in
17254 command position.
17255
17256 rehash If this is set when completing external commands, the internal
17257 list (hash) of commands will be updated for each search by issu‐
17258 ing the rehash command. There is a speed penalty for this which
17259 is only likely to be noticeable when directories in the path
17260 have slow file access.
17261
17262 remote-access
17263 If set to `false', certain commands will be prevented from mak‐
17264 ing Internet connections to retrieve remote information. This
17265 includes the completion for the CVS command.
17266
17267 It is not always possible to know if connections are in fact to
17268 a remote site, so some may be prevented unnecessarily.
17269
17270 remove-all-dups
17271 The _history_complete_word bindable command and the _history
17272 completer use this to decide if all duplicate matches should be
17273 removed, rather than just consecutive duplicates.
17274
17275 select-prompt
17276 If this is set for the default tag, its value will be displayed
17277 during menu selection (see the menu style above) when the com‐
17278 pletion list does not fit on the screen as a whole. The same
17279 escapes as for the list-prompt style are understood, except that
17280 the numbers refer to the match or line the mark is on. A de‐
17281 fault prompt is used when the value is the empty string.
17282
17283 select-scroll
17284 This style is tested for the default tag and determines how a
17285 completion list is scrolled during a menu selection (see the
17286 menu style above) when the completion list does not fit on the
17287 screen as a whole. If the value is `0' (zero), the list is
17288 scrolled by half-screenfuls; if it is a positive integer, the
17289 list is scrolled by the given number of lines; if it is a nega‐
17290 tive number, the list is scrolled by a screenful minus the abso‐
17291 lute value of the given number of lines. The default is to
17292 scroll by single lines.
17293
17294 separate-sections
17295 This style is used with the manuals tag when completing names of
17296 manual pages. If it is `true', entries for different sections
17297 are added separately using tag names of the form `manuals.X',
17298 where X is the section number. When the group-name style is
17299 also in effect, pages from different sections will appear sepa‐
17300 rately. This style is also used similarly with the words style
17301 when completing words for the dict command. It allows words from
17302 different dictionary databases to be added separately. See also
17303 insert-sections.
17304
17305 The default for this style is `false'.
17306
17307 show-ambiguity
17308 If the zsh/complist module is loaded, this style can be used to
17309 highlight the first ambiguous character in completion lists. The
17310 value is either a color indication such as those supported by
17311 the list-colors style or, with a value of `true', a default of
17312 underlining is selected. The highlighting is only applied if the
17313 completion display strings correspond to the actual matches.
17314
17315 show-completer
17316 Tested whenever a new completer is tried. If it is `true', the
17317 completion system outputs a progress message in the listing area
17318 showing what completer is being tried. The message will be
17319 overwritten by any output when completions are found and is re‐
17320 moved after completion is finished.
17321
17322 single-ignored
17323 This is used by the _ignored completer when there is only one
17324 match. If its value is `show', the single match will be dis‐
17325 played but not inserted. If the value is `menu', then the sin‐
17326 gle match and the original string are both added as matches and
17327 menu completion is started, making it easy to select either of
17328 them.
17329
17330 sort This allows the standard ordering of matches to be overridden.
17331
17332 If its value is `true' or `false', sorting is enabled or dis‐
17333 abled. Additionally the values associated with the `-o' option
17334 to compadd can also be listed: match, nosort, numeric, reverse.
17335 If it is not set for the context, the standard behaviour of the
17336 calling widget is used.
17337
17338 The style is tested first against the full context including the
17339 tag, and if that fails to produce a value against the context
17340 without the tag.
17341
17342 In many cases where a calling widget explicitly selects a par‐
17343 ticular ordering in lieu of the default, a value of `true' is
17344 not honoured. An example of where this is not the case is for
17345 command history where the default of sorting matches chronologi‐
17346 cally may be overridden by setting the style to `true'.
17347
17348 In the _expand completer, if it is set to `true', the expansions
17349 generated will always be sorted. If it is set to `menu', then
17350 the expansions are only sorted when they are offered as single
17351 strings but not in the string containing all possible expan‐
17352 sions.
17353
17354 special-dirs
17355 Normally, the completion code will not produce the directory
17356 names `.' and `..' as possible completions. If this style is
17357 set to `true', it will add both `.' and `..' as possible comple‐
17358 tions; if it is set to `..', only `..' will be added.
17359
17360 The following example sets special-dirs to `..' when the current
17361 prefix is empty, is a single `.', or consists only of a path be‐
17362 ginning with `../'. Otherwise the value is `false'.
17363
17364 zstyle -e ':completion:*' special-dirs \
17365 '[[ $PREFIX = (../)#(|.|..) ]] && reply=(..)'
17366
17367 squeeze-slashes
17368 If set to `true', sequences of slashes in filename paths (for
17369 example in `foo//bar') will be treated as a single slash. This
17370 is the usual behaviour of UNIX paths. However, by default the
17371 file completion function behaves as if there were a `*' between
17372 the slashes.
17373
17374 stop If set to `true', the _history_complete_word bindable command
17375 will stop once when reaching the beginning or end of the his‐
17376 tory. Invoking _history_complete_word will then wrap around to
17377 the opposite end of the history. If this style is set to
17378 `false' (the default), _history_complete_word will loop immedi‐
17379 ately as in a menu completion.
17380
17381 strip-comments
17382 If set to `true', this style causes non-essential comment text
17383 to be removed from completion matches. Currently it is only
17384 used when completing e-mail addresses where it removes any dis‐
17385 play name from the addresses, cutting them down to plain
17386 user@host form.
17387
17388 subst-globs-only
17389 This is used by the _expand completer. If it is set to `true',
17390 the expansion will only be used if it resulted from globbing;
17391 hence, if expansions resulted from the use of the substitute
17392 style described below, but these were not further changed by
17393 globbing, the expansions will be rejected.
17394
17395 The default for this style is `false'.
17396
17397 substitute
17398 This boolean style controls whether the _expand completer will
17399 first try to expand all substitutions in the string (such as
17400 `$(...)' and `${...}').
17401
17402 The default is `true'.
17403
17404 suffix This is used by the _expand completer if the word starts with a
17405 tilde or contains a parameter expansion. If it is set to
17406 `true', the word will only be expanded if it doesn't have a suf‐
17407 fix, i.e. if it is something like `~foo' or `$foo' rather than
17408 `~foo/' or `$foo/bar', unless that suffix itself contains char‐
17409 acters eligible for expansion. The default for this style is
17410 `true'.
17411
17412 tag-order
17413 This provides a mechanism for sorting how the tags available in
17414 a particular context will be used.
17415
17416 The values for the style are sets of space-separated lists of
17417 tags. The tags in each value will be tried at the same time; if
17418 no match is found, the next value is used. (See the file-pat‐
17419 terns style for an exception to this behavior.)
17420
17421 For example:
17422
17423 zstyle ':completion:*:complete:-command-:*:*' tag-order \
17424 'commands functions'
17425
17426 specifies that completion in command position first offers ex‐
17427 ternal commands and shell functions. Remaining tags will be
17428 tried if no completions are found.
17429
17430 In addition to tag names, each string in the value may take one
17431 of the following forms:
17432
17433 - If any value consists of only a hyphen, then only the
17434 tags specified in the other values are generated. Nor‐
17435 mally all tags not explicitly selected are tried last if
17436 the specified tags fail to generate any matches. This
17437 means that a single value consisting only of a single hy‐
17438 phen turns off completion.
17439
17440 ! tags...
17441 A string starting with an exclamation mark specifies
17442 names of tags that are not to be used. The effect is the
17443 same as if all other possible tags for the context had
17444 been listed.
17445
17446 tag:label ...
17447 Here, tag is one of the standard tags and label is an ar‐
17448 bitrary name. Matches are generated as normal but the
17449 name label is used in contexts instead of tag. This is
17450 not useful in words starting with !.
17451
17452 If the label starts with a hyphen, the tag is prepended
17453 to the label to form the name used for lookup. This can
17454 be used to make the completion system try a certain tag
17455 more than once, supplying different style settings for
17456 each attempt; see below for an example.
17457
17458 tag:label:description
17459 As before, but description will replace the `%d' in the
17460 value of the format style instead of the default descrip‐
17461 tion supplied by the completion function. Spaces in the
17462 description must be quoted with a backslash. A `%d' ap‐
17463 pearing in description is replaced with the description
17464 given by the completion function.
17465
17466 In any of the forms above the tag may be a pattern or several
17467 patterns in the form `{pat1,pat2...}'. In this case all match‐
17468 ing tags will be used except for any given explicitly in the
17469 same string.
17470
17471 One use of these features is to try one tag more than once, set‐
17472 ting other styles differently on each attempt, but still to use
17473 all the other tags without having to repeat them all. For exam‐
17474 ple, to make completion of function names in command position
17475 ignore all the completion functions starting with an underscore
17476 the first time completion is tried:
17477
17478 zstyle ':completion:*:*:-command-:*:*' tag-order \
17479 'functions:-non-comp *' functions
17480 zstyle ':completion:*:functions-non-comp' \
17481 ignored-patterns '_*'
17482
17483 On the first attempt, all tags will be offered but the functions
17484 tag will be replaced by functions-non-comp. The ignored-pat‐
17485 terns style is set for this tag to exclude functions starting
17486 with an underscore. If there are no matches, the second value
17487 of the tag-order style is used which completes functions using
17488 the default tag, this time presumably including all function
17489 names.
17490
17491 The matches for one tag can be split into different groups. For
17492 example:
17493
17494 zstyle ':completion:*' tag-order \
17495 'options:-long:long\ options
17496 options:-short:short\ options
17497 options:-single-letter:single\ letter\ options'
17498 zstyle ':completion:*:options-long' \
17499 ignored-patterns '[-+](|-|[^-]*)'
17500 zstyle ':completion:*:options-short' \
17501 ignored-patterns '--*' '[-+]?'
17502 zstyle ':completion:*:options-single-letter' \
17503 ignored-patterns '???*'
17504
17505 With the group-names style set, options beginning with `--', op‐
17506 tions beginning with a single `-' or `+' but containing multiple
17507 characters, and single-letter options will be displayed in sepa‐
17508 rate groups with different descriptions.
17509
17510 Another use of patterns is to try multiple match specifications
17511 one after another. The matcher-list style offers something sim‐
17512 ilar, but it is tested very early in the completion system and
17513 hence can't be set for single commands nor for more specific
17514 contexts. Here is how to try normal completion without any
17515 match specification and, if that generates no matches, try again
17516 with case-insensitive matching, restricting the effect to argu‐
17517 ments of the command foo:
17518
17519 zstyle ':completion:*:*:foo:*:*' tag-order '*' '*:-case'
17520 zstyle ':completion:*-case' matcher 'm:{a-z}={A-Z}'
17521
17522 First, all the tags offered when completing after foo are tried
17523 using the normal tag name. If that generates no matches, the
17524 second value of tag-order is used, which tries all tags again
17525 except that this time each has -case appended to its name for
17526 lookup of styles. Hence this time the value for the matcher
17527 style from the second call to zstyle in the example is used to
17528 make completion case-insensitive.
17529
17530 It is possible to use the -e option of the zstyle builtin com‐
17531 mand to specify conditions for the use of particular tags. For
17532 example:
17533
17534 zstyle -e '*:-command-:*' tag-order '
17535 if [[ -n $PREFIX$SUFFIX ]]; then
17536 reply=( )
17537 else
17538 reply=( - )
17539 fi'
17540
17541 Completion in command position will be attempted only if the
17542 string typed so far is not empty. This is tested using the PRE‐
17543 FIX special parameter; see zshcompwid for a description of pa‐
17544 rameters which are special inside completion widgets. Setting
17545 reply to an empty array provides the default behaviour of trying
17546 all tags at once; setting it to an array containing only a hy‐
17547 phen disables the use of all tags and hence of all completions.
17548
17549 If no tag-order style has been defined for a context, the
17550 strings `(|*-)argument-* (|*-)option-* values' and `options'
17551 plus all tags offered by the completion function will be used to
17552 provide a sensible default behavior that causes arguments
17553 (whether normal command arguments or arguments of options) to be
17554 completed before option names for most commands.
17555
17556 urls This is used together with the urls tag by functions completing
17557 URLs.
17558
17559 If the value consists of more than one string, or if the only
17560 string does not name a file or directory, the strings are used
17561 as the URLs to complete.
17562
17563 If the value contains only one string which is the name of a
17564 normal file the URLs are taken from that file (where the URLs
17565 may be separated by white space or newlines).
17566
17567 Finally, if the only string in the value names a directory, the
17568 directory hierarchy rooted at this directory gives the comple‐
17569 tions. The top level directory should be the file access
17570 method, such as `http', `ftp', `bookmark' and so on. In many
17571 cases the next level of directories will be a filename. The di‐
17572 rectory hierarchy can descend as deep as necessary.
17573
17574 For example,
17575
17576 zstyle ':completion:*' urls ~/.urls
17577 mkdir -p ~/.urls/ftp/ftp.zsh.org/pub
17578
17579 allows completion of all the components of the URL
17580 ftp://ftp.zsh.org/pub after suitable commands such as `netscape'
17581 or `lynx'. Note, however, that access methods and files are
17582 completed separately, so if the hosts style is set hosts can be
17583 completed without reference to the urls style.
17584
17585 See the description in the function _urls itself for more infor‐
17586 mation (e.g. `more $^fpath/_urls(N)').
17587
17588 use-cache
17589 If this is set, the completion caching layer is activated for
17590 any completions which use it (via the _store_cache, _re‐
17591 trieve_cache, and _cache_invalid functions). The directory con‐
17592 taining the cache files can be changed with the cache-path
17593 style.
17594
17595 use-compctl
17596 If this style is set to a string not equal to false, 0, no, and
17597 off, the completion system may use any completion specifications
17598 defined with the compctl builtin command. If the style is un‐
17599 set, this is done only if the zsh/compctl module is loaded. The
17600 string may also contain the substring `first' to use completions
17601 defined with `compctl -T', and the substring `default' to use
17602 the completion defined with `compctl -D'.
17603
17604 Note that this is only intended to smooth the transition from
17605 compctl to the new completion system and may disappear in the
17606 future.
17607
17608 Note also that the definitions from compctl will only be used if
17609 there is no specific completion function for the command in
17610 question. For example, if there is a function _foo to complete
17611 arguments to the command foo, compctl will never be invoked for
17612 foo. However, the compctl version will be tried if foo only
17613 uses default completion.
17614
17615 use-ip By default, the function _hosts that completes host names strips
17616 IP addresses from entries read from host databases such as NIS
17617 and ssh files. If this style is `true', the corresponding IP
17618 addresses can be completed as well. This style is not use in
17619 any context where the hosts style is set; note also it must be
17620 set before the cache of host names is generated (typically the
17621 first completion attempt).
17622
17623 users This may be set to a list of usernames to be completed. If it
17624 is not set all usernames will be completed. Note that if it is
17625 set only that list of users will be completed; this is because
17626 on some systems querying all users can take a prohibitive amount
17627 of time.
17628
17629 users-hosts
17630 The values of this style should be of the form `user@host' or
17631 `user:host'. It is used for commands that need pairs of user-
17632 and hostnames. These commands will complete usernames from this
17633 style (only), and will restrict subsequent hostname completion
17634 to hosts paired with that user in one of the values of the
17635 style.
17636
17637 It is possible to group values for sets of commands which allow
17638 a remote login, such as rlogin and ssh, by using the my-accounts
17639 tag. Similarly, values for sets of commands which usually refer
17640 to the accounts of other people, such as talk and finger, can be
17641 grouped by using the other-accounts tag. More ambivalent com‐
17642 mands may use the accounts tag.
17643
17644 users-hosts-ports
17645 Like users-hosts but used for commands like telnet and contain‐
17646 ing strings of the form `user@host:port'.
17647
17648 verbose
17649 If set, as it is by default, the completion listing is more ver‐
17650 bose. In particular many commands show descriptions for options
17651 if this style is `true'.
17652
17653 word This is used by the _list completer, which prevents the inser‐
17654 tion of completions until a second completion attempt when the
17655 line has not changed. The normal way of finding out if the line
17656 has changed is to compare its entire contents between the two
17657 occasions. If this style is `true', the comparison is instead
17658 performed only on the current word. Hence if completion is per‐
17659 formed on another word with the same contents, completion will
17660 not be delayed.
17661
17663 The initialization script compinit redefines all the widgets which per‐
17664 form completion to call the supplied widget function _main_complete.
17665 This function acts as a wrapper calling the so-called `completer' func‐
17666 tions that generate matches. If _main_complete is called with argu‐
17667 ments, these are taken as the names of completer functions to be called
17668 in the order given. If no arguments are given, the set of functions to
17669 try is taken from the completer style. For example, to use normal com‐
17670 pletion and correction if that doesn't generate any matches:
17671
17672 zstyle ':completion:*' completer _complete _correct
17673
17674 after calling compinit. The default value for this style is `_complete
17675 _ignored', i.e. normally only ordinary completion is tried, first with
17676 the effect of the ignored-patterns style and then without it. The
17677 _main_complete function uses the return status of the completer func‐
17678 tions to decide if other completers should be called. If the return
17679 status is zero, no other completers are tried and the _main_complete
17680 function returns.
17681
17682 If the first argument to _main_complete is a single hyphen, the argu‐
17683 ments will not be taken as names of completers. Instead, the second
17684 argument gives a name to use in the completer field of the context and
17685 the other arguments give a command name and arguments to call to gener‐
17686 ate the matches.
17687
17688 The following completer functions are contained in the distribution,
17689 although users may write their own. Note that in contexts the leading
17690 underscore is stripped, for example basic completion is performed in
17691 the context `:completion::complete:...'.
17692
17693 _all_matches
17694 This completer can be used to add a string consisting of all
17695 other matches. As it influences later completers it must appear
17696 as the first completer in the list. The list of all matches is
17697 affected by the avoid-completer and old-matches styles described
17698 above.
17699
17700 It may be useful to use the _generic function described below to
17701 bind _all_matches to its own keystroke, for example:
17702
17703 zle -C all-matches complete-word _generic
17704 bindkey '^Xa' all-matches
17705 zstyle ':completion:all-matches:*' old-matches only
17706 zstyle ':completion:all-matches::::' completer _all_matches
17707
17708 Note that this does not generate completions by itself: first
17709 use any of the standard ways of generating a list of comple‐
17710 tions, then use ^Xa to show all matches. It is possible instead
17711 to add a standard completer to the list and request that the
17712 list of all matches should be directly inserted:
17713
17714 zstyle ':completion:all-matches::::' completer \
17715 _all_matches _complete
17716 zstyle ':completion:all-matches:*' insert true
17717
17718 In this case the old-matches style should not be set.
17719
17720 _approximate
17721 This is similar to the basic _complete completer but allows the
17722 completions to undergo corrections. The maximum number of er‐
17723 rors can be specified by the max-errors style; see the descrip‐
17724 tion of approximate matching in zshexpn(1) for how errors are
17725 counted. Normally this completer will only be tried after the
17726 normal _complete completer:
17727
17728 zstyle ':completion:*' completer _complete _approximate
17729
17730 This will give correcting completion if and only if normal com‐
17731 pletion yields no possible completions. When corrected comple‐
17732 tions are found, the completer will normally start menu comple‐
17733 tion allowing you to cycle through these strings.
17734
17735 This completer uses the tags corrections and original when gen‐
17736 erating the possible corrections and the original string. The
17737 format style for the former may contain the additional sequences
17738 `%e' and `%o' which will be replaced by the number of errors ac‐
17739 cepted to generate the corrections and the original string, re‐
17740 spectively.
17741
17742 The completer progressively increases the number of errors al‐
17743 lowed up to the limit by the max-errors style, hence if a com‐
17744 pletion is found with one error, no completions with two errors
17745 will be shown, and so on. It modifies the completer name in the
17746 context to indicate the number of errors being tried: on the
17747 first try the completer field contains `approximate-1', on the
17748 second try `approximate-2', and so on.
17749
17750 When _approximate is called from another function, the number of
17751 errors to accept may be passed with the -a option. The argument
17752 is in the same format as the max-errors style, all in one
17753 string.
17754
17755 Note that this completer (and the _correct completer mentioned
17756 below) can be quite expensive to call, especially when a large
17757 number of errors are allowed. One way to avoid this is to set
17758 up the completer style using the -e option to zstyle so that
17759 some completers are only used when completion is attempted a
17760 second time on the same string, e.g.:
17761
17762 zstyle -e ':completion:*' completer '
17763 if [[ $_last_try != "$HISTNO$BUFFER$CURSOR" ]]; then
17764 _last_try="$HISTNO$BUFFER$CURSOR"
17765 reply=(_complete _match _prefix)
17766 else
17767 reply=(_ignored _correct _approximate)
17768 fi'
17769
17770 This uses the HISTNO parameter and the BUFFER and CURSOR special
17771 parameters that are available inside zle and completion widgets
17772 to find out if the command line hasn't changed since the last
17773 time completion was tried. Only then are the _ignored, _correct
17774 and _approximate completers called.
17775
17776 _canonical_paths [ -A var ] [ -N ] [ -MJV12nfX ] tag descr [ paths ...
17777 ]
17778 This completion function completes all paths given to it, and
17779 also tries to offer completions which point to the same file as
17780 one of the paths given (relative path when an absolute path is
17781 given, and vice versa; when ..'s are present in the word to be
17782 completed; and some paths got from symlinks).
17783
17784 -A, if specified, takes the paths from the array variable speci‐
17785 fied. Paths can also be specified on the command line as shown
17786 above. -N, if specified, prevents canonicalizing the paths
17787 given before using them for completion, in case they are already
17788 so. The options -M, -J, -V, -1, -2, -n, -F, -X are passed to
17789 compadd.
17790
17791 See _description for a description of tag and descr.
17792
17793 _cmdambivalent
17794 Completes the remaining positional arguments as an external com‐
17795 mand. The external command and its arguments are completed as
17796 separate arguments (in a manner appropriate for completing
17797 /usr/bin/env) if there are two or more remaining positional ar‐
17798 guments on the command line, and as a quoted command string (in
17799 the manner of system(...)) otherwise. See also _cmdstring and
17800 _precommand.
17801
17802 This function takes no arguments.
17803
17804 _cmdstring
17805 Completes an external command as a single argument, as for sys‐
17806 tem(...).
17807
17808 _complete
17809 This completer generates all possible completions in a con‐
17810 text-sensitive manner, i.e. using the settings defined with the
17811 compdef function explained above and the current settings of all
17812 special parameters. This gives the normal completion behaviour.
17813
17814 To complete arguments of commands, _complete uses the utility
17815 function _normal, which is in turn responsible for finding the
17816 particular function; it is described below. Various contexts of
17817 the form -context- are handled specifically. These are all men‐
17818 tioned above as possible arguments to the #compdef tag.
17819
17820 Before trying to find a function for a specific context, _com‐
17821 plete checks if the parameter `compcontext' is set. Setting
17822 `compcontext' allows the usual completion dispatching to be
17823 overridden which is useful in places such as a function that
17824 uses vared for input. If it is set to an array, the elements are
17825 taken to be the possible matches which will be completed using
17826 the tag `values' and the description `value'. If it is set to an
17827 associative array, the keys are used as the possible completions
17828 and the values (if non-empty) are used as descriptions for the
17829 matches. If `compcontext' is set to a string containing colons,
17830 it should be of the form `tag:descr:action'. In this case the
17831 tag and descr give the tag and description to use and the action
17832 indicates what should be completed in one of the forms accepted
17833 by the _arguments utility function described below.
17834
17835 Finally, if `compcontext' is set to a string without colons, the
17836 value is taken as the name of the context to use and the func‐
17837 tion defined for that context will be called. For this purpose,
17838 there is a special context named -command-line- that completes
17839 whole command lines (commands and their arguments). This is not
17840 used by the completion system itself but is nonetheless handled
17841 when explicitly called.
17842
17843 _correct
17844 Generate corrections, but not completions, for the current word;
17845 this is similar to _approximate but will not allow any number of
17846 extra characters at the cursor as that completer does. The ef‐
17847 fect is similar to spell-checking. It is based on _approximate,
17848 but the completer field in the context name is correct.
17849
17850 For example, with:
17851
17852 zstyle ':completion:::::' completer \
17853 _complete _correct _approximate
17854 zstyle ':completion:*:correct:::' max-errors 2 not-numeric
17855 zstyle ':completion:*:approximate:::' max-errors 3 numeric
17856
17857 correction will accept up to two errors. If a numeric argument
17858 is given, correction will not be performed, but correcting com‐
17859 pletion will be, and will accept as many errors as given by the
17860 numeric argument. Without a numeric argument, first correction
17861 and then correcting completion will be tried, with the first one
17862 accepting two errors and the second one accepting three errors.
17863
17864 When _correct is called as a function, the number of errors to
17865 accept may be given following the -a option. The argument is in
17866 the same form a values to the accept style, all in one string.
17867
17868 This completer function is intended to be used without the _ap‐
17869 proximate completer or, as in the example, just before it. Us‐
17870 ing it after the _approximate completer is useless since _ap‐
17871 proximate will at least generate the corrected strings generated
17872 by the _correct completer -- and probably more.
17873
17874 _expand
17875 This completer function does not really perform completion, but
17876 instead checks if the word on the command line is eligible for
17877 expansion and, if it is, gives detailed control over how this
17878 expansion is done. For this to happen, the completion system
17879 needs to be invoked with complete-word, not expand-or-complete
17880 (the default binding for TAB), as otherwise the string will be
17881 expanded by the shell's internal mechanism before the completion
17882 system is started. Note also this completer should be called
17883 before the _complete completer function.
17884
17885 The tags used when generating expansions are all-expansions for
17886 the string containing all possible expansions, expansions when
17887 adding the possible expansions as single matches and original
17888 when adding the original string from the line. The order in
17889 which these strings are generated, if at all, can be controlled
17890 by the group-order and tag-order styles, as usual.
17891
17892 The format string for all-expansions and for expansions may con‐
17893 tain the sequence `%o' which will be replaced by the original
17894 string from the line.
17895
17896 The kind of expansion to be tried is controlled by the substi‐
17897 tute, glob and subst-globs-only styles.
17898
17899 It is also possible to call _expand as a function, in which case
17900 the different modes may be selected with options: -s for substi‐
17901 tute, -g for glob and -o for subst-globs-only.
17902
17903 _expand_alias
17904 If the word the cursor is on is an alias, it is expanded and no
17905 other completers are called. The types of aliases which are to
17906 be expanded can be controlled with the styles regular, global
17907 and disabled.
17908
17909 This function is also a bindable command, see the section `Bind‐
17910 able Commands' below.
17911
17912 _extensions
17913 If the cursor follows the string `*.', filename extensions are
17914 completed. The extensions are taken from files in current direc‐
17915 tory or a directory specified at the beginning of the current
17916 word. For exact matches, completion continues to allow other
17917 completers such as _expand to expand the pattern. The standard
17918 add-space and prefix-hidden styles are observed.
17919
17920 _external_pwds
17921 Completes current directories of other zsh processes belonging
17922 to the current user.
17923
17924 This is intended to be used via _generic, bound to a custom key
17925 combination. Note that pattern matching is enabled so matching
17926 is performed similar to how it works with the _match completer.
17927
17928 _history
17929 Complete words from the shell's command history. This com‐
17930 pleter can be controlled by the remove-all-dups, and sort styles
17931 as for the _history_complete_word bindable command, see the sec‐
17932 tion `Bindable Commands' below and the section `Completion Sys‐
17933 tem Configuration' above.
17934
17935 _ignored
17936 The ignored-patterns style can be set to a list of patterns
17937 which are compared against possible completions; matching ones
17938 are removed. With this completer those matches can be rein‐
17939 stated, as if no ignored-patterns style were set. The completer
17940 actually generates its own list of matches; which completers are
17941 invoked is determined in the same way as for the _prefix com‐
17942 pleter. The single-ignored style is also available as described
17943 above.
17944
17945 _list This completer allows the insertion of matches to be delayed un‐
17946 til completion is attempted a second time without the word on
17947 the line being changed. On the first attempt, only the list of
17948 matches will be shown. It is affected by the styles condition
17949 and word, see the section `Completion System Configuration'
17950 above.
17951
17952 _match This completer is intended to be used after the _complete com‐
17953 pleter. It behaves similarly but the string on the command line
17954 may be a pattern to match against trial completions. This gives
17955 the effect of the GLOB_COMPLETE option.
17956
17957 Normally completion will be performed by taking the pattern from
17958 the line, inserting a `*' at the cursor position and comparing
17959 the resulting pattern with the possible completions generated.
17960 This can be modified with the match-original style described
17961 above.
17962
17963 The generated matches will be offered in a menu completion un‐
17964 less the insert-unambiguous style is set to `true'; see the de‐
17965 scription above for other options for this style.
17966
17967 Note that matcher specifications defined globally or used by the
17968 completion functions (the styles matcher-list and matcher) will
17969 not be used.
17970
17971 _menu This completer was written as simple example function to show
17972 how menu completion can be enabled in shell code. However, it
17973 has the notable effect of disabling menu selection which can be
17974 useful with _generic based widgets. It should be used as the
17975 first completer in the list. Note that this is independent of
17976 the setting of the MENU_COMPLETE option and does not work with
17977 the other menu completion widgets such as reverse-menu-complete,
17978 or accept-and-menu-complete.
17979
17980 _oldlist
17981 This completer controls how the standard completion widgets be‐
17982 have when there is an existing list of completions which may
17983 have been generated by a special completion (i.e. a sepa‐
17984 rately-bound completion command). It allows the ordinary com‐
17985 pletion keys to continue to use the list of completions thus
17986 generated, instead of producing a new list of ordinary contex‐
17987 tual completions. It should appear in the list of completers
17988 before any of the widgets which generate matches. It uses two
17989 styles: old-list and old-menu, see the section `Completion Sys‐
17990 tem Configuration' above.
17991
17992 _precommand
17993 Complete an external command in word-separated arguments, as for
17994 exec and /usr/bin/env.
17995
17996 _prefix
17997 This completer can be used to try completion with the suffix
17998 (everything after the cursor) ignored. In other words, the suf‐
17999 fix will not be considered to be part of the word to complete.
18000 The effect is similar to the expand-or-complete-prefix command.
18001
18002 The completer style is used to decide which other completers are
18003 to be called to generate matches. If this style is unset, the
18004 list of completers set for the current context is used -- ex‐
18005 cept, of course, the _prefix completer itself. Furthermore, if
18006 this completer appears more than once in the list of completers
18007 only those completers not already tried by the last invocation
18008 of _prefix will be called.
18009
18010 For example, consider this global completer style:
18011
18012 zstyle ':completion:*' completer \
18013 _complete _prefix _correct _prefix:foo
18014
18015 Here, the _prefix completer tries normal completion but ignoring
18016 the suffix. If that doesn't generate any matches, and neither
18017 does the call to the _correct completer after it, _prefix will
18018 be called a second time and, now only trying correction with the
18019 suffix ignored. On the second invocation the completer part of
18020 the context appears as `foo'.
18021
18022 To use _prefix as the last resort and try only normal completion
18023 when it is invoked:
18024
18025 zstyle ':completion:*' completer _complete ... _prefix
18026 zstyle ':completion::prefix:*' completer _complete
18027
18028 The add-space style is also respected. If it is set to `true'
18029 then _prefix will insert a space between the matches generated
18030 (if any) and the suffix.
18031
18032 Note that this completer is only useful if the COMPLETE_IN_WORD
18033 option is set; otherwise, the cursor will be moved to the end of
18034 the current word before the completion code is called and hence
18035 there will be no suffix.
18036
18037 _user_expand
18038 This completer behaves similarly to the _expand completer but
18039 instead performs expansions defined by users. The styles
18040 add-space and sort styles specific to the _expand completer are
18041 usable with _user_expand in addition to other styles handled
18042 more generally by the completion system. The tag all-expansions
18043 is also available.
18044
18045 The expansion depends on the array style user-expand being de‐
18046 fined for the current context; remember that the context for
18047 completers is less specific than that for contextual completion
18048 as the full context has not yet been determined. Elements of
18049 the array may have one of the following forms:
18050
18051 $hash
18052
18053 hash is the name of an associative array. Note this is
18054 not a full parameter expression, merely a $, suitably
18055 quoted to prevent immediate expansion, followed by the
18056 name of an associative array. If the trial expansion
18057 word matches a key in hash, the resulting expansion is
18058 the corresponding value.
18059 _func
18060
18061 _func is the name of a shell function whose name must be‐
18062 gin with _ but is not otherwise special to the completion
18063 system. The function is called with the trial word as an
18064 argument. If the word is to be expanded, the function
18065 should set the array reply to a list of expansions. Op‐
18066 tionally, it can set REPLY to a word that will be used as
18067 a description for the set of expansions. The return sta‐
18068 tus of the function is irrelevant.
18070 In addition to the context-dependent completions provided, which are
18071 expected to work in an intuitively obvious way, there are a few widgets
18072 implementing special behaviour which can be bound separately to keys.
18073 The following is a list of these and their default bindings.
18074
18075 _bash_completions
18076 This function is used by two widgets, _bash_complete-word and
18077 _bash_list-choices. It exists to provide compatibility with
18078 completion bindings in bash. The last character of the binding
18079 determines what is completed: `!', command names; `$', environ‐
18080 ment variables; `@', host names; `/', file names; `~' user
18081 names. In bash, the binding preceded by `\e' gives completion,
18082 and preceded by `^X' lists options. As some of these bindings
18083 clash with standard zsh bindings, only `\e~' and `^X~' are bound
18084 by default. To add the rest, the following should be added to
18085 .zshrc after compinit has been run:
18086
18087 for key in '!' '$' '@' '/' '~'; do
18088 bindkey "\e$key" _bash_complete-word
18089 bindkey "^X$key" _bash_list-choices
18090 done
18091
18092 This includes the bindings for `~' in case they were already
18093 bound to something else; the completion code does not override
18094 user bindings.
18095
18096 _correct_filename (^XC)
18097 Correct the filename path at the cursor position. Allows up to
18098 six errors in the name. Can also be called with an argument to
18099 correct a filename path, independently of zle; the correction is
18100 printed on standard output.
18101
18102 _correct_word (^Xc)
18103 Performs correction of the current argument using the usual con‐
18104 textual completions as possible choices. This stores the string
18105 `correct-word' in the function field of the context name and
18106 then calls the _correct completer.
18107
18108 _expand_alias (^Xa)
18109 This function can be used as a completer and as a bindable com‐
18110 mand. It expands the word the cursor is on if it is an alias.
18111 The types of alias expanded can be controlled with the styles
18112 regular, global and disabled.
18113
18114 When used as a bindable command there is one additional feature
18115 that can be selected by setting the complete style to `true'.
18116 In this case, if the word is not the name of an alias, _ex‐
18117 pand_alias tries to complete the word to a full alias name with‐
18118 out expanding it. It leaves the cursor directly after the com‐
18119 pleted word so that invoking _expand_alias once more will expand
18120 the now-complete alias name.
18121
18122 _expand_word (^Xe)
18123 Performs expansion on the current word: equivalent to the stan‐
18124 dard expand-word command, but using the _expand completer. Be‐
18125 fore calling it, the function field of the context is set to
18126 `expand-word'.
18127
18128 _generic
18129 This function is not defined as a widget and not bound by de‐
18130 fault. However, it can be used to define a widget and will then
18131 store the name of the widget in the function field of the con‐
18132 text and call the completion system. This allows custom comple‐
18133 tion widgets with their own set of style settings to be defined
18134 easily. For example, to define a widget that performs normal
18135 completion and starts menu selection:
18136
18137 zle -C foo complete-word _generic
18138 bindkey '...' foo
18139 zstyle ':completion:foo:*' menu yes select=1
18140
18141 Note in particular that the completer style may be set for the
18142 context in order to change the set of functions used to generate
18143 possible matches. If _generic is called with arguments, those
18144 are passed through to _main_complete as the list of completers
18145 in place of those defined by the completer style.
18146
18147 _history_complete_word (\e/)
18148 Complete words from the shell's command history. This uses the
18149 list, remove-all-dups, sort, and stop styles.
18150
18151 _most_recent_file (^Xm)
18152 Complete the name of the most recently modified file matching
18153 the pattern on the command line (which may be blank). If given
18154 a numeric argument N, complete the Nth most recently modified
18155 file. Note the completion, if any, is always unique.
18156
18157 _next_tags (^Xn)
18158 This command alters the set of matches used to that for the next
18159 tag, or set of tags, either as given by the tag-order style or
18160 as set by default; these matches would otherwise not be avail‐
18161 able. Successive invocations of the command cycle through all
18162 possible sets of tags.
18163
18164 _read_comp (^X^R)
18165 Prompt the user for a string, and use that to perform completion
18166 on the current word. There are two possibilities for the
18167 string. First, it can be a set of words beginning `_', for ex‐
18168 ample `_files -/', in which case the function with any arguments
18169 will be called to generate the completions. Unambiguous parts
18170 of the function name will be completed automatically (normal
18171 completion is not available at this point) until a space is
18172 typed.
18173
18174 Second, any other string will be passed as a set of arguments to
18175 compadd and should hence be an expression specifying what should
18176 be completed.
18177
18178 A very restricted set of editing commands is available when
18179 reading the string: `DEL' and `^H' delete the last character;
18180 `^U' deletes the line, and `^C' and `^G' abort the function,
18181 while `RET' accepts the completion. Note the string is used
18182 verbatim as a command line, so arguments must be quoted in ac‐
18183 cordance with standard shell rules.
18184
18185 Once a string has been read, the next call to _read_comp will
18186 use the existing string instead of reading a new one. To force
18187 a new string to be read, call _read_comp with a numeric argu‐
18188 ment.
18189
18190 _complete_debug (^X?)
18191 This widget performs ordinary completion, but captures in a tem‐
18192 porary file a trace of the shell commands executed by the com‐
18193 pletion system. Each completion attempt gets its own file. A
18194 command to view each of these files is pushed onto the editor
18195 buffer stack.
18196
18197 _complete_help (^Xh)
18198 This widget displays information about the context names, the
18199 tags, and the completion functions used when completing at the
18200 current cursor position. If given a numeric argument other than
18201 1 (as in `ESC-2 ^Xh'), then the styles used and the contexts for
18202 which they are used will be shown, too.
18203
18204 Note that the information about styles may be incomplete; it de‐
18205 pends on the information available from the completion functions
18206 called, which in turn is determined by the user's own styles and
18207 other settings.
18208
18209 _complete_help_generic
18210 Unlike other commands listed here, this must be created as a
18211 normal ZLE widget rather than a completion widget (i.e. with zle
18212 -N). It is used for generating help with a widget bound to the
18213 _generic widget that is described above.
18214
18215 If this widget is created using the name of the function, as it
18216 is by default, then when executed it will read a key sequence.
18217 This is expected to be bound to a call to a completion function
18218 that uses the _generic widget. That widget will be executed,
18219 and information provided in the same format that the _com‐
18220 plete_help widget displays for contextual completion.
18221
18222 If the widget's name contains debug, for example if it is cre‐
18223 ated as `zle -N _complete_debug_generic _complete_help_generic',
18224 it will read and execute the keystring for a generic widget as
18225 before, but then generate debugging information as done by _com‐
18226 plete_debug for contextual completion.
18227
18228 If the widget's name contains noread, it will not read a
18229 keystring but instead arrange that the next use of a generic
18230 widget run in the same shell will have the effect as described
18231 above.
18232
18233 The widget works by setting the shell parameter
18234 ZSH_TRACE_GENERIC_WIDGET which is read by _generic. Unsetting
18235 the parameter cancels any pending effect of the noread form.
18236
18237 For example, after executing the following:
18238
18239 zle -N _complete_debug_generic _complete_help_generic
18240 bindkey '^x:' _complete_debug_generic
18241
18242 typing `C-x :' followed by the key sequence for a generic widget
18243 will cause trace output for that widget to be saved to a file.
18244
18245 _complete_tag (^Xt)
18246 This widget completes symbol tags created by the etags or ctags
18247 programmes (note there is no connection with the completion sys‐
18248 tem's tags) stored in a file TAGS, in the format used by etags,
18249 or tags, in the format created by ctags. It will look back up
18250 the path hierarchy for the first occurrence of either file; if
18251 both exist, the file TAGS is preferred. You can specify the
18252 full path to a TAGS or tags file by setting the parameter $TAGS‐
18253 FILE or $tagsfile respectively. The corresponding completion
18254 tags used are etags and vtags, after emacs and vi respectively.
18255
18257 Descriptions follow for utility functions that may be useful when writ‐
18258 ing completion functions. If functions are installed in subdirecto‐
18259 ries, most of these reside in the Base subdirectory. Like the example
18260 functions for commands in the distribution, the utility functions gen‐
18261 erating matches all follow the convention of returning status zero if
18262 they generated completions and non-zero if no matching completions
18263 could be added.
18264
18265 _absolute_command_paths
18266 This function completes external commands as absolute paths (un‐
18267 like _command_names -e which completes their basenames). It
18268 takes no arguments.
18269
18270 _all_labels [ -x ] [ -12VJ ] tag name descr [ command arg ... ]
18271 This is a convenient interface to the _next_label function be‐
18272 low, implementing the loop shown in the _next_label example.
18273 The command and its arguments are called to generate the
18274 matches. The options stored in the parameter name will automat‐
18275 ically be inserted into the args passed to the command. Nor‐
18276 mally, they are put directly after the command, but if one of
18277 the args is a single hyphen, they are inserted directly before
18278 that. If the hyphen is the last argument, it will be removed
18279 from the argument list before the command is called. This al‐
18280 lows _all_labels to be used in almost all cases where the
18281 matches can be generated by a single call to the compadd builtin
18282 command or by a call to one of the utility functions.
18283
18284 For example:
18285
18286 local expl
18287 ...
18288 if _requested foo; then
18289 ...
18290 _all_labels foo expl '...' compadd ... - $matches
18291 fi
18292
18293 Will complete the strings from the matches parameter, using com‐
18294 padd with additional options which will take precedence over
18295 those generated by _all_labels.
18296
18297 _alternative [ -O name ] [ -C name ] spec ...
18298 This function is useful in simple cases where multiple tags are
18299 available. Essentially it implements a loop like the one de‐
18300 scribed for the _tags function below.
18301
18302 The tags to use and the action to perform if a tag is requested
18303 are described using the specs which are of the form: `tag:de‐
18304 scr:action'. The tags are offered using _tags and if the tag is
18305 requested, the action is executed with the given description de‐
18306 scr. The actions are those accepted by the _arguments function
18307 (described below), with the following exceptions:
18308 • The `->state' and `=...' forms are not supported.
18309
18310
18311 • The `((a\:bar b\:baz))' form does not need the colon to
18312 be escaped, since the specs have no colon-separated
18313 fields after the action.
18314
18315
18316 For example, the action may be a simple function call:
18317
18318 _alternative \
18319 'users:user:_users' \
18320 'hosts:host:_hosts'
18321
18322 offers usernames and hostnames as possible matches, generated by
18323 the _users and _hosts functions respectively.
18324
18325 Like _arguments, this function uses _all_labels to execute the
18326 actions, which will loop over all sets of tags. Special han‐
18327 dling is only required if there is an additional valid tag, for
18328 example inside a function called from _alternative.
18329
18330 The option `-O name' is used in the same way as by the _argu‐
18331 ments function. In other words, the elements of the name array
18332 will be passed to compadd when executing an action.
18333
18334 Like _tags this function supports the -C option to give a dif‐
18335 ferent name for the argument context field.
18336
18337
18338 _arguments [ -nswWCRS ] [ -A pat ] [ -O name ] [ -M matchspec ]
18339 [ : ] spec ...
18340 _arguments [ opt ... ] -- [ -l ] [ -i pats ] [ -s pair ]
18341 [ helpspec ...]
18342 This function can be used to give a complete specification for
18343 completion for a command whose arguments follow standard UNIX
18344 option and argument conventions.
18345
18346 Options Overview
18347
18348 Options to _arguments itself must be in separate words, i.e. -s
18349 -w, not -sw. The options are followed by specs that describe
18350 options and arguments of the analyzed command. To avoid ambigu‐
18351 ity, all options to _arguments itself may be separated from the
18352 spec forms by a single colon.
18353
18354 The `--' form is used to intuit spec forms from the help output
18355 of the command being analyzed, and is described in detail below.
18356 The opts for the `--' form are otherwise the same options as the
18357 first form. Note that `-s' following `--' has a distinct mean‐
18358 ing from `-s' preceding `--', and both may appear.
18359
18360 The option switches -s, -S, -A, -w, and -W affect how _arguments
18361 parses the analyzed command line's options. These switches are
18362 useful for commands with standard argument parsing.
18363
18364 The options of _arguments have the following meanings:
18365
18366 -n With this option, _arguments sets the parameter NORMARG
18367 to the position of the first normal argument in the
18368 $words array, i.e. the position after the end of the op‐
18369 tions. If that argument has not been reached, NORMARG is
18370 set to -1. The caller should declare `integer NORMARG'
18371 if the -n option is passed; otherwise the parameter is
18372 not used.
18373
18374 -s Enable option stacking for single-letter options, whereby
18375 multiple single-letter options may be combined into a
18376 single word. For example, the two options `-x' and `-y'
18377 may be combined into a single word `-xy'. By default,
18378 every word corresponds to a single option name (`-xy' is
18379 a single option named `xy').
18380
18381 Options beginning with a single hyphen or plus sign are
18382 eligible for stacking; words beginning with two hyphens
18383 are not.
18384
18385 Note that -s after -- has a different meaning, which is
18386 documented in the segment entitled `Deriving spec forms
18387 from the help output'.
18388
18389 -w In combination with -s, allow option stacking even if one
18390 or more of the options take arguments. For example, if
18391 -x takes an argument, with no -s, `-xy' is considered as
18392 a single (unhandled) option; with -s, -xy is an option
18393 with the argument `y'; with both -s and -w, -xy is the
18394 option -x and the option -y with arguments to -x (and to
18395 -y, if it takes arguments) still to come in subsequent
18396 words.
18397
18398 -W This option takes -w a stage further: it is possible to
18399 complete single-letter options even after an argument
18400 that occurs in the same word. However, it depends on the
18401 action performed whether options will really be completed
18402 at this point. For more control, use a utility function
18403 like _guard as part of the action.
18404
18405 -C Modify the curcontext parameter for an action of the form
18406 `->state'. This is discussed in detail below.
18407
18408 -R Return status 300 instead of zero when a $state is to be
18409 handled, in the `->string' syntax.
18410
18411 -S Do not complete options after a `--' appearing on the
18412 line, and ignore the `--'. For example, with -S, in the
18413 line
18414
18415 foobar -x -- -y
18416
18417 the `-x' is considered an option, the `-y' is considered
18418 an argument, and the `--' is considered to be neither.
18419
18420 -A pat Do not complete options after the first non-option argu‐
18421 ment on the line. pat is a pattern matching all strings
18422 which are not to be taken as arguments. For example, to
18423 make _arguments stop completing options after the first
18424 normal argument, but ignoring all strings starting with a
18425 hyphen even if they are not described by one of the opt‐
18426 specs, the form is `-A "-*"'.
18427
18428 -O name
18429 Pass the elements of the array name as arguments to func‐
18430 tions called to execute actions. This is discussed in
18431 detail below.
18432
18433 -M matchspec
18434 Use the match specification matchspec for completing op‐
18435 tion names and values. The default matchspec allows par‐
18436 tial word completion after `_' and `-', such as complet‐
18437 ing `-f-b' to `-foo-bar'. The default matchspec is:
18438 r:|[_-]=* r:|=*
18439
18440 -0 When populating values of the `opt_args' associative ar‐
18441 ray, don't backslash-escape colons and backslashes and
18442 use NUL rather than colon for joining multiple values.
18443 This option is described in more detail below, under the
18444 heading specs: actions.
18445
18446 specs: overview
18447
18448 Each of the following forms is a spec describing individual sets
18449 of options or arguments on the command line being analyzed.
18450
18451 n:message:action
18452 n::message:action
18453 This describes the n'th normal argument. The message
18454 will be printed above the matches generated and the ac‐
18455 tion indicates what can be completed in this position
18456 (see below). If there are two colons before the message
18457 the argument is optional. If the message contains only
18458 white space, nothing will be printed above the matches
18459 unless the action adds an explanation string itself.
18460
18461 :message:action
18462 ::message:action
18463 Similar, but describes the next argument, whatever number
18464 that happens to be. If all arguments are specified in
18465 this form in the correct order the numbers are unneces‐
18466 sary.
18467
18468 *:message:action
18469 *::message:action
18470 *:::message:action
18471 This describes how arguments (usually non-option argu‐
18472 ments, those not beginning with - or +) are to be com‐
18473 pleted when neither of the first two forms was provided.
18474 Any number of arguments can be completed in this fashion.
18475
18476 With two colons before the message, the words special ar‐
18477 ray and the CURRENT special parameter are modified to re‐
18478 fer only to the normal arguments when the action is exe‐
18479 cuted or evaluated. With three colons before the message
18480 they are modified to refer only to the normal arguments
18481 covered by this description.
18482
18483 optspec
18484 optspec:...
18485 This describes an option. The colon indicates handling
18486 for one or more arguments to the option; if it is not
18487 present, the option is assumed to take no arguments.
18488
18489 The following forms are available for the initial opt‐
18490 spec, whether or not the option has arguments.
18491
18492 *optspec
18493 Here optspec is one of the remaining forms below.
18494 This indicates the following optspec may be re‐
18495 peated. Otherwise if the corresponding option is
18496 already present on the command line to the left of
18497 the cursor it will not be offered again.
18498
18499 -optname
18500 +optname
18501 In the simplest form the optspec is just the op‐
18502 tion name beginning with a minus or a plus sign,
18503 such as `-foo'. The first argument for the option
18504 (if any) must follow as a separate word directly
18505 after the option.
18506
18507 Either of `-+optname' and `+-optname' can be used
18508 to specify that -optname and +optname are both
18509 valid.
18510
18511 In all the remaining forms, the leading `-' may be
18512 replaced by or paired with `+' in this way.
18513
18514 -optname-
18515 The first argument of the option must come di‐
18516 rectly after the option name in the same word.
18517 For example, `-foo-:...' specifies that the com‐
18518 pleted option and argument will look like
18519 `-fooarg'.
18520
18521 -optname+
18522 The first argument may appear immediately after
18523 optname in the same word, or may appear as a sepa‐
18524 rate word after the option. For example,
18525 `-foo+:...' specifies that the completed option
18526 and argument will look like either `-fooarg' or
18527 `-foo arg'.
18528
18529 -optname=
18530 The argument may appear as the next word, or in
18531 same word as the option name provided that it is
18532 separated from it by an equals sign, for example
18533 `-foo=arg' or `-foo arg'.
18534
18535 -optname=-
18536 The argument to the option must appear after an
18537 equals sign in the same word, and may not be given
18538 in the next argument.
18539
18540 optspec[explanation]
18541 An explanation string may be appended to any of
18542 the preceding forms of optspec by enclosing it in
18543 brackets, as in `-q[query operation]'.
18544
18545 The verbose style is used to decide whether the
18546 explanation strings are displayed with the option
18547 in a completion listing.
18548
18549 If no bracketed explanation string is given but
18550 the auto-description style is set and only one ar‐
18551 gument is described for this optspec, the value of
18552 the style is displayed, with any appearance of the
18553 sequence `%d' in it replaced by the message of the
18554 first optarg that follows the optspec; see below.
18555
18556 It is possible for options with a literal `+' or `=' to
18557 appear, but that character must be quoted, for example
18558 `-\+'.
18559
18560 Each optarg following an optspec must take one of the
18561 following forms:
18562
18563 :message:action
18564 ::message:action
18565 An argument to the option; message and action are
18566 treated as for ordinary arguments. In the first
18567 form, the argument is mandatory, and in the second
18568 form it is optional.
18569
18570 This group may be repeated for options which take
18571 multiple arguments. In other words, :message1:ac‐
18572 tion1:message2:action2 specifies that the option
18573 takes two arguments.
18574
18575 :*pattern:message:action
18576 :*pattern::message:action
18577 :*pattern:::message:action
18578 This describes multiple arguments. Only the last
18579 optarg for an option taking multiple arguments may
18580 be given in this form. If the pattern is empty
18581 (i.e. :*:), all the remaining words on the line
18582 are to be completed as described by the action;
18583 otherwise, all the words up to and including a
18584 word matching the pattern are to be completed us‐
18585 ing the action.
18586
18587 Multiple colons are treated as for the `*:...'
18588 forms for ordinary arguments: when the message is
18589 preceded by two colons, the words special array
18590 and the CURRENT special parameter are modified
18591 during the execution or evaluation of the action
18592 to refer only to the words after the option. When
18593 preceded by three colons, they are modified to re‐
18594 fer only to the words covered by this description.
18595
18596 Any literal colon in an optname, message, or action must be pre‐
18597 ceded by a backslash, `\:'.
18598
18599 Each of the forms above may be preceded by a list in parentheses
18600 of option names and argument numbers. If the given option is on
18601 the command line, the options and arguments indicated in paren‐
18602 theses will not be offered. For example, `(-two -three
18603 1)-one:...' completes the option `-one'; if this appears on the
18604 command line, the options -two and -three and the first ordinary
18605 argument will not be completed after it. `(-foo):...' specifies
18606 an ordinary argument completion; -foo will not be completed if
18607 that argument is already present.
18608
18609 Other items may appear in the list of excluded options to indi‐
18610 cate various other items that should not be applied when the
18611 current specification is matched: a single star (*) for the rest
18612 arguments (i.e. a specification of the form `*:...'); a colon
18613 (:) for all normal (non-option-) arguments; and a hyphen (-) for
18614 all options. For example, if `(*)' appears before an option and
18615 the option appears on the command line, the list of remaining
18616 arguments (those shown in the above table beginning with `*:')
18617 will not be completed.
18618
18619 To aid in reuse of specifications, it is possible to precede any
18620 of the forms above with `!'; then the form will no longer be
18621 completed, although if the option or argument appears on the
18622 command line they will be skipped as normal. The main use for
18623 this is when the arguments are given by an array, and _arguments
18624 is called repeatedly for more specific contexts: on the first
18625 call `_arguments $global_options' is used, and on subsequent
18626 calls `_arguments !$^global_options'.
18627
18628 specs: actions
18629
18630
18631 In each of the forms above the action determines how completions
18632 should be generated. Except for the `->string' form below, the
18633 action will be executed by calling the _all_labels function to
18634 process all tag labels. No special handling of tags is needed
18635 unless a function call introduces a new one.
18636
18637 The functions called to execute actions will be called with the
18638 elements of the array named by the `-O name' option as argu‐
18639 ments. This can be used, for example, to pass the same set of
18640 options for the compadd builtin to all actions.
18641
18642 The forms for action are as follows.
18643
18644 (single unquoted space)
18645 This is useful where an argument is required but it is
18646 not possible or desirable to generate matches for it.
18647 The message will be displayed but no completions listed.
18648 Note that even in this case the colon at the end of the
18649 message is needed; it may only be omitted when neither a
18650 message nor an action is given.
18651
18652 (item1 item2 ...)
18653 One of a list of possible matches, for example:
18654
18655 :foo:(foo bar baz)
18656
18657 ((item1\:desc1 ...))
18658 Similar to the above, but with descriptions for each pos‐
18659 sible match. Note the backslash before the colon. For
18660 example,
18661
18662 :foo:((a\:bar b\:baz))
18663
18664 The matches will be listed together with their descrip‐
18665 tions if the description style is set with the values tag
18666 in the context.
18667
18668 ->string
18669 In this form, _arguments processes the arguments and op‐
18670 tions and then returns control to the calling function
18671 with parameters set to indicate the state of processing;
18672 the calling function then makes its own arrangements for
18673 generating completions. For example, functions that im‐
18674 plement a state machine can use this type of action.
18675
18676 Where _arguments encounters action in the `->string' for‐
18677 mat, it will strip all leading and trailing whitespace
18678 from string and set the array state to the set of all
18679 strings for which an action is to be performed. The ele‐
18680 ments of the array state_descr are assigned the corre‐
18681 sponding message field from each optarg containing such
18682 an action.
18683
18684 By default and in common with all other well behaved com‐
18685 pletion functions, _arguments returns status zero if it
18686 was able to add matches and non-zero otherwise. However,
18687 if the -R option is given, _arguments will instead return
18688 a status of 300 to indicate that $state is to be handled.
18689
18690 In addition to $state and $state_descr, _arguments also
18691 sets the global parameters `context', `line' and
18692 `opt_args' as described below, and does not reset any
18693 changes made to the special parameters such as PREFIX and
18694 words. This gives the calling function the choice of re‐
18695 setting these parameters or propagating changes in them.
18696
18697 A function calling _arguments with at least one action
18698 containing a `->string' must therefore declare appropri‐
18699 ate local parameters:
18700
18701 local context state state_descr line
18702 typeset -A opt_args
18703
18704 to prevent _arguments from altering the global environ‐
18705 ment.
18706
18707 {eval-string}
18708 A string in braces is evaluated as shell code to generate
18709 matches. If the eval-string itself does not begin with
18710 an opening parenthesis or brace it is split into separate
18711 words before execution.
18712
18713 = action
18714 If the action starts with `= ' (an equals sign followed
18715 by a space), _arguments will insert the contents of the
18716 argument field of the current context as the new first
18717 element in the words special array and increment the
18718 value of the CURRENT special parameter. This has the ef‐
18719 fect of inserting a dummy word onto the completion com‐
18720 mand line while not changing the point at which comple‐
18721 tion is taking place.
18722
18723 This is most useful with one of the specifiers that re‐
18724 strict the words on the command line on which the action
18725 is to operate (the two- and three-colon forms above).
18726 One particular use is when an action itself causes _argu‐
18727 ments on a restricted range; it is necessary to use this
18728 trick to insert an appropriate command name into the
18729 range for the second call to _arguments to be able to
18730 parse the line.
18731
18732 word...
18733 word...
18734 This covers all forms other than those above. If the ac‐
18735 tion starts with a space, the remaining list of words
18736 will be invoked unchanged.
18737
18738 Otherwise it will be invoked with some extra strings
18739 placed after the first word; these are to be passed down
18740 as options to the compadd builtin. They ensure that the
18741 state specified by _arguments, in particular the descrip‐
18742 tions of options and arguments, is correctly passed to
18743 the completion command. These additional arguments are
18744 taken from the array parameter `expl'; this will be set
18745 up before executing the action and hence may be referred
18746 to inside it, typically in an expansion of the form
18747 `$expl[@]' which preserves empty elements of the array.
18748
18749 During the performance of the action the array `line' will be
18750 set to the normal arguments from the command line, i.e. the
18751 words from the command line after the command name excluding all
18752 options and their arguments. Options are stored in the associa‐
18753 tive array `opt_args' with option names as keys and their argu‐
18754 ments as the values. By default, all colons and backslashes in
18755 the value are escaped with backslashes, and if an option has
18756 multiple arguments (for example, when using an optspec of the
18757 form `*optspec'), they are joined with (unescaped) colons. How‐
18758 ever, if the -0 option was passed, no backslash escaping is per‐
18759 formed, and multiple values are joined with NUL bytes. For ex‐
18760 ample, after `zsh -o foo:foo -o bar:bar -o <TAB>', the contents
18761 of `opt_args' would be
18762
18763 typeset -A opt_args=( [-o]='foo\:foo:bar\:bar:' )
18764
18765 by default, and
18766
18767 typeset -A opt_args=( [-o]=$'foo:foo\x00bar:bar\x00' )
18768
18769 if _arguments had been called with the -0 option.
18770
18771 The parameter `context' is set when returning to the calling
18772 function to perform an action of the form `->string'. It is set
18773 to an array of elements corresponding to the elements of $state.
18774 Each element is a suitable name for the argument field of the
18775 context: either a string of the form `option-opt-n' for the n'th
18776 argument of the option -opt, or a string of the form `argu‐
18777 ment-n' for the n'th argument. For `rest' arguments, that is
18778 those in the list at the end not handled by position, n is the
18779 string `rest'. For example, when completing the argument of the
18780 -o option, the name is `option-o-1', while for the second normal
18781 (non-option-) argument it is `argument-2'.
18782
18783 Furthermore, during the evaluation of the action the context
18784 name in the curcontext parameter is altered to append the same
18785 string that is stored in the context parameter.
18786
18787 The option -C tells _arguments to modify the curcontext parame‐
18788 ter for an action of the form `->state'. This is the standard
18789 parameter used to keep track of the current context. Here it
18790 (and not the context array) should be made local to the calling
18791 function to avoid passing back the modified value and should be
18792 initialised to the current value at the start of the function:
18793
18794 local curcontext="$curcontext"
18795
18796 This is useful where it is not possible for multiple states to
18797 be valid together.
18798
18799 Grouping Options
18800
18801 Options can be grouped to simplify exclusion lists. A group is
18802 introduced with `+' followed by a name for the group in the sub‐
18803 sequent word. Whole groups can then be referenced in an exclu‐
18804 sion list or a group name can be used to disambiguate between
18805 two forms of the same option. For example:
18806
18807 _arguments \
18808 '(group2--x)-a' \
18809 + group1 \
18810 -m \
18811 '(group2)-n' \
18812 + group2 \
18813 -x -y
18814
18815 If the name of a group is specified in the form `(name)' then
18816 only one value from that group will ever be completed; more for‐
18817 mally, all specifications are mutually exclusive to all other
18818 specifications in that group. This is useful for defining op‐
18819 tions that are aliases for each other. For example:
18820
18821 _arguments \
18822 -a -b \
18823 + '(operation)' \
18824 {-c,--compress}'[compress]' \
18825 {-d,--decompress}'[decompress]' \
18826 {-l,--list}'[list]'
18827
18828 If an option in a group appears on the command line, it is
18829 stored in the associative array `opt_args' with 'group-option'
18830 as a key. In the example above, a key `operation--c' is used if
18831 the option `-c' is present on the command line.
18832
18833 Specifying Multiple Sets of Arguments
18834
18835 It is possible to specify multiple sets of options and arguments
18836 with the sets separated by single hyphens. This differs from
18837 groups in that sets are considered to be mutually exclusive of
18838 each other.
18839
18840 Specifications before the first set and from any group are com‐
18841 mon to all sets. For example:
18842
18843 _arguments \
18844 -a \
18845 - set1 \
18846 -c \
18847 - set2 \
18848 -d \
18849 ':arg:(x2 y2)'
18850
18851 This defines two sets. When the command line contains the op‐
18852 tion `-c', the `-d' option and the argument will not be consid‐
18853 ered possible completions. When it contains `-d' or an argu‐
18854 ment, the option `-c' will not be considered. However, after
18855 `-a' both sets will still be considered valid.
18856
18857 As for groups, the name of a set may appear in exclusion lists,
18858 either alone or preceding a normal option or argument specifica‐
18859 tion.
18860
18861 The completion code has to parse the command line separately for
18862 each set. This can be slow so sets should only be used when nec‐
18863 essary. A useful alternative is often an option specification
18864 with rest-arguments (as in `-foo:*:...'); here the option -foo
18865 swallows up all remaining arguments as described by the optarg
18866 definitions.
18867
18868 Deriving spec forms from the help output
18869
18870 The option `--' allows _arguments to work out the names of long
18871 options that support the `--help' option which is standard in
18872 many GNU commands. The command word is called with the argument
18873 `--help' and the output examined for option names. Clearly, it
18874 can be dangerous to pass this to commands which may not support
18875 this option as the behaviour of the command is unspecified.
18876
18877 In addition to options, `_arguments --' will try to deduce the
18878 types of arguments available for options when the form
18879 `--opt=val' is valid. It is also possible to provide hints by
18880 examining the help text of the command and adding helpspec of
18881 the form `pattern:message:action'; note that other _arguments
18882 spec forms are not used. The pattern is matched against the
18883 help text for an option, and if it matches the message and ac‐
18884 tion are used as for other argument specifiers. The special
18885 case of `*:' means both message and action are empty, which has
18886 the effect of causing options having no description in the help
18887 output to be ordered in listings ahead of options that have a
18888 description.
18889
18890 For example:
18891
18892 _arguments -- '*\*:toggle:(yes no)' \
18893 '*=FILE*:file:_files' \
18894 '*=DIR*:directory:_files -/' \
18895 '*=PATH*:directory:_files -/'
18896
18897 Here, `yes' and `no' will be completed as the argument of op‐
18898 tions whose description ends in a star; file names will be com‐
18899 pleted for options that contain the substring `=FILE' in the de‐
18900 scription; and directories will be completed for options whose
18901 description contains `=DIR' or `=PATH'. The last three are in
18902 fact the default and so need not be given explicitly, although
18903 it is possible to override the use of these patterns. A typical
18904 help text which uses this feature is:
18905
18906 -C, --directory=DIR change to directory DIR
18907
18908 so that the above specifications will cause directories to be
18909 completed after `--directory', though not after `-C'.
18910
18911 Note also that _arguments tries to find out automatically if the
18912 argument for an option is optional. This can be specified ex‐
18913 plicitly by doubling the colon before the message.
18914
18915 If the pattern ends in `(-)', this will be removed from the pat‐
18916 tern and the action will be used only directly after the `=',
18917 not in the next word. This is the behaviour of a normal speci‐
18918 fication defined with the form `=-'.
18919
18920 By default, the command (with the option `--help') is run after
18921 resetting all the locale categories (except for LC_CTYPE) to
18922 `C'. If the localized help output is known to work, the option
18923 `-l' can be specified after the `_arguments --' so that the com‐
18924 mand is run in the current locale.
18925
18926 The `_arguments --' can be followed by the option `-i patterns'
18927 to give patterns for options which are not to be completed. The
18928 patterns can be given as the name of an array parameter or as a
18929 literal list in parentheses. For example,
18930
18931 _arguments -- -i \
18932 "(--(en|dis)able-FEATURE*)"
18933
18934 will cause completion to ignore the options `--enable-FEATURE'
18935 and `--disable-FEATURE' (this example is useful with GNU config‐
18936 ure).
18937
18938 The `_arguments --' form can also be followed by the option `-s
18939 pair' to describe option aliases. The pair consists of a list
18940 of alternating patterns and corresponding replacements, enclosed
18941 in parens and quoted so that it forms a single argument word in
18942 the _arguments call.
18943
18944 For example, some configure-script help output describes options
18945 only as `--enable-foo', but the script also accepts the negated
18946 form `--disable-foo'. To allow completion of the second form:
18947
18948 _arguments -- -s "((#s)--enable- --disable-)"
18949
18950 Miscellaneous notes
18951
18952 Finally, note that _arguments generally expects to be the pri‐
18953 mary function handling any completion for which it is used. It
18954 may have side effects which change the treatment of any matches
18955 added by other functions called after it. To combine _arguments
18956 with other functions, those functions should be called either
18957 before _arguments, as an action within a spec, or in handlers
18958 for `->state' actions.
18959
18960 Here is a more general example of the use of _arguments:
18961
18962 _arguments '-l+:left border:' \
18963 '-format:paper size:(letter A4)' \
18964 '*-copy:output file:_files::resolution:(300 600)' \
18965 ':postscript file:_files -g \*.\(ps\|eps\)' \
18966 '*:page number:'
18967
18968 This describes three options: `-l', `-format', and `-copy'. The
18969 first takes one argument described as `left border' for which no
18970 completion will be offered because of the empty action. Its ar‐
18971 gument may come directly after the `-l' or it may be given as
18972 the next word on the line.
18973
18974 The `-format' option takes one argument in the next word, de‐
18975 scribed as `paper size' for which only the strings `letter' and
18976 `A4' will be completed.
18977
18978 The `-copy' option may appear more than once on the command line
18979 and takes two arguments. The first is mandatory and will be
18980 completed as a filename. The second is optional (because of the
18981 second colon before the description `resolution') and will be
18982 completed from the strings `300' and `600'.
18983
18984 The last two descriptions say what should be completed as argu‐
18985 ments. The first describes the first argument as a `postscript
18986 file' and makes files ending in `ps' or `eps' be completed. The
18987 last description gives all other arguments the description `page
18988 number' but does not offer completions.
18989
18990 _cache_invalid cache_identifier
18991 This function returns status zero if the completions cache cor‐
18992 responding to the given cache identifier needs rebuilding. It
18993 determines this by looking up the cache-policy style for the
18994 current context. This should provide a function name which is
18995 run with the full path to the relevant cache file as the only
18996 argument.
18997
18998 Example:
18999
19000 _example_caching_policy () {
19001 # rebuild if cache is more than a week old
19002 local -a oldp
19003 oldp=( "$1"(Nm+7) )
19004 (( $#oldp ))
19005 }
19006
19007 _call_function return name [ arg ... ]
19008 If a function name exists, it is called with the arguments args.
19009 The return argument gives the name of a parameter in which the
19010 return status from the function name should be stored; if return
19011 is empty or a single hyphen it is ignored.
19012
19013 The return status of _call_function itself is zero if the func‐
19014 tion name exists and was called and non-zero otherwise.
19015
19016 _call_program [ -l ] [ -p ] tag string ...
19017 This function provides a mechanism for the user to override the
19018 use of an external command. It looks up the command style with
19019 the supplied tag. If the style is set, its value is used as the
19020 command to execute. The strings from the call to _call_program,
19021 or from the style if set, are concatenated with spaces between
19022 them and the resulting string is evaluated. The return status
19023 is the return status of the command called.
19024
19025 By default, the command is run in an environment where all the
19026 locale categories (except for LC_CTYPE) are reset to `C' by
19027 calling the utility function _comp_locale (see below). If the
19028 option `-l' is given, the command is run with the current lo‐
19029 cale.
19030
19031 If the option `-p' is supplied it indicates that the command
19032 output is influenced by the permissions it is run with. If the
19033 gain-privileges style is set to true, _call_program will make
19034 use of commands such as sudo, if present on the command-line, to
19035 match the permissions to whatever the final command is likely to
19036 run under. When looking up the gain-privileges and command
19037 styles, the command component of the zstyle context will end
19038 with a slash (`/') followed by the command that would be used to
19039 gain privileges.
19040
19041 _combination [ -s pattern ] tag style spec ... field opts ...
19042 This function is used to complete combinations of values, for
19043 example pairs of hostnames and usernames. The style argument
19044 gives the style which defines the pairs; it is looked up in a
19045 context with the tag specified.
19046
19047 The style name consists of field names separated by hyphens, for
19048 example `users-hosts-ports'. For each field for a value is al‐
19049 ready known, a spec of the form `field=pattern' is given. For
19050 example, if the command line so far specifies a user `pws', the
19051 argument `users=pws' should appear.
19052
19053 The next argument with no equals sign is taken as the name of
19054 the field for which completions should be generated (presumably
19055 not one of the fields for which the value is known).
19056
19057 The matches generated will be taken from the value of the style.
19058 These should contain the possible values for the combinations in
19059 the appropriate order (users, hosts, ports in the example
19060 above). The values for the different fields are separated by
19061 colons. This can be altered with the option -s to _combination
19062 which specifies a pattern. Typically this is a character class,
19063 as for example `-s "[:@]"' in the case of the users-hosts style.
19064 Each `field=pattern' specification restricts the completions
19065 which apply to elements of the style with appropriately matching
19066 fields.
19067
19068 If no style with the given name is defined for the given tag, or
19069 if none of the strings in style's value match, but a function
19070 name of the required field preceded by an underscore is defined,
19071 that function will be called to generate the matches. For exam‐
19072 ple, if there is no `users-hosts-ports' or no matching hostname
19073 when a host is required, the function `_hosts' will automati‐
19074 cally be called.
19075
19076 If the same name is used for more than one field, in both the
19077 `field=pattern' and the argument that gives the name of the
19078 field to be completed, the number of the field (starting with
19079 one) may be given after the fieldname, separated from it by a
19080 colon.
19081
19082 All arguments after the required field name are passed to com‐
19083 padd when generating matches from the style value, or to the
19084 functions for the fields if they are called.
19085
19086 _command_names [ -e | - ]
19087 This function completes words that are valid at command posi‐
19088 tion: names of aliases, builtins, hashed commands, functions,
19089 and so on. With the -e flag, only hashed commands are com‐
19090 pleted. The - flag is ignored.
19091
19092 _comp_locale
19093 This function resets all the locale categories other than
19094 LC_CTYPE to `C' so that the output from external commands can be
19095 easily analyzed by the completion system. LC_CTYPE retains the
19096 current value (taking LC_ALL and LANG into account), ensuring
19097 that non-ASCII characters in file names are still handled prop‐
19098 erly.
19099
19100 This function should normally be run only in a subshell, because
19101 the new locale is exported to the environment. Typical usage
19102 would be `$(_comp_locale; command ...)'.
19103
19104 _completers [ -p ]
19105 This function completes names of completers.
19106
19107 -p Include the leading underscore (`_') in the matches.
19108
19109 _default
19110 This function corresponds to the -default- special context which
19111 is applied where no completion is defined. It is useful to call
19112 it under certain error conditions such as completion after an
19113 unrecognised subcommand. This applies the concept of graceful
19114 degradation to the completion system, allowing it to fallback on
19115 basic completion of commonly useful things like filenames.
19116
19117
19118 _describe [-12JVx] [ -oO | -t tag ] descr name1 [ name2 ] [ opt ... ]
19119 [ -- name1 [ name2 ] [ opt ... ] ... ]
19120 This function associates completions with descriptions. Multi‐
19121 ple groups separated by -- can be supplied, potentially with
19122 different completion options opts.
19123
19124 The descr is taken as a string to display above the matches if
19125 the format style for the descriptions tag is set. This is fol‐
19126 lowed by one or two names of arrays followed by options to pass
19127 to compadd. The array name1 contains the possible completions
19128 with their descriptions in the form `completion:description'.
19129 Any literal colons in completion must be quoted with a back‐
19130 slash. If a name2 is given, it should have the same number of
19131 elements as name1; in this case the corresponding elements are
19132 added as possible completions instead of the completion strings
19133 from name1. The completion list will retain the descriptions
19134 from name1. Finally, a set of completion options can appear.
19135
19136 If the option `-o' appears before the first argument, the
19137 matches added will be treated as names of command options (N.B.
19138 not shell options), typically following a `-', `--' or `+' on
19139 the command line. In this case _describe uses the prefix-hid‐
19140 den, prefix-needed and verbose styles to find out if the strings
19141 should be added as completions and if the descriptions should be
19142 shown. Without the `-o' option, only the verbose style is used
19143 to decide how descriptions are shown. If `-O' is used instead
19144 of `-o', command options are completed as above but _describe
19145 will not handle the prefix-needed style.
19146
19147 With the -t option a tag can be specified. The default is `val‐
19148 ues' or, if the -o option is given, `options'.
19149
19150 The options -1, -2, -J, -V, -x are passed to _next_label.
19151
19152 If selected by the list-grouped style, strings with the same de‐
19153 scription will appear together in the list.
19154
19155 _describe uses the _all_labels function to generate the matches,
19156 so it does not need to appear inside a loop over tag labels.
19157
19158 _description [ -x ] [ -12VJ ] tag name descr [ spec ... ]
19159 This function is not to be confused with the previous one; it is
19160 used as a helper function for creating options to compadd. It
19161 is buried inside many of the higher level completion functions
19162 and so often does not need to be called directly.
19163
19164 The styles listed below are tested in the current context using
19165 the given tag. The resulting options for compadd are put into
19166 the array named name (this is traditionally `expl', but this
19167 convention is not enforced). The description for the corre‐
19168 sponding set of matches is passed to the function in descr.
19169
19170 The styles tested are: format, hidden, matcher, ignore-line, ig‐
19171 nored-patterns, group-name and sort. The format style is first
19172 tested for the given tag and then for the descriptions tag if no
19173 value was found, while the remainder are only tested for the tag
19174 given as the first argument. The function also calls _setup
19175 which tests some more styles.
19176
19177 The string returned by the format style (if any) will be modi‐
19178 fied so that the sequence `%d' is replaced by the descr given as
19179 the third argument without any leading or trailing white space.
19180 If, after removing the white space, the descr is the empty
19181 string, the format style will not be used and the options put
19182 into the name array will not contain an explanation string to be
19183 displayed above the matches.
19184
19185 If _description is called with more than three arguments, the
19186 additional specs should be of the form `char:str'. These supply
19187 escape sequence replacements for the format style: every appear‐
19188 ance of `%char' will be replaced by string. If no additional
19189 specs are given but the description in descr conforms to a com‐
19190 mon form then further escape sequences are set for elements of
19191 that description. These elements correspond to a default value
19192 (`%o'), the units (`%m') range of acceptable values (`%r') and
19193 the remaining initial part of the description (`%h'). The form
19194 the description takes consists of specifying the units and range
19195 in parentheses and the default value in square brackets, for ex‐
19196 ample:
19197
19198 _description times expl 'timeout (seconds) (0-60) [20]'
19199
19200 It is possible to use zformat conditional expressions when
19201 styling these elements. So, for example, to add `default:' as a
19202 tag but only when there is a default value to show, the format
19203 style might include `%(o.default: %o.)'.
19204
19205 If the -x option is given, the description will be passed to
19206 compadd using the -x option instead of the default -X. This
19207 means that the description will be displayed even if there are
19208 no corresponding matches.
19209
19210 The options placed in the array name take account of the
19211 group-name style, so matches are placed in a separate group
19212 where necessary. The group normally has its elements sorted (by
19213 passing the option -J to compadd), but if an option starting
19214 with `-V', `-J', `-1', or `-2' is passed to _description, that
19215 option will be included in the array. Hence it is possible for
19216 the completion group to be unsorted by giving the option `-V',
19217 `-1V', or `-2V'.
19218
19219 In most cases, the function will be used like this:
19220
19221 local expl
19222 _description files expl file
19223 compadd "$expl[@]" - "$files[@]"
19224
19225 Note the use of the parameter expl, the hyphen, and the list of
19226 matches. Almost all calls to compadd within the completion sys‐
19227 tem use a similar format; this ensures that user-specified
19228 styles are correctly passed down to the builtins which implement
19229 the internals of completion.
19230
19231 _dir_list [ -s sep ] [ -S ]
19232 Complete a list of directory names separated by colons (the same
19233 format as $PATH).
19234
19235 -s sep Use sep as separator between items. sep defaults to a
19236 colon (`:').
19237
19238 -S Add sep instead of slash (`/') as an autoremoveable suf‐
19239 fix.
19240
19241 _dispatch context string ...
19242 This sets the current context to context and looks for comple‐
19243 tion functions to handle this context by hunting through the
19244 list of command names or special contexts (as described above
19245 for compdef) given as strings. The first completion function to
19246 be defined for one of the contexts in the list is used to gener‐
19247 ate matches. Typically, the last string is -default- to cause
19248 the function for default completion to be used as a fallback.
19249
19250 The function sets the parameter $service to the string being
19251 tried, and sets the context/command field (the fourth) of the
19252 $curcontext parameter to the context given as the first argu‐
19253 ment.
19254
19255 _email_addresses [ -c ] [ -n plugin ]
19256 Complete email addresses. Addresses are provided by plugins.
19257
19258 -c Complete bare localhost@domain.tld addresses, without a
19259 name part or a comment. Without this option, RFC822
19260 `Firstname Lastname <address>' strings are completed.
19261
19262 -n plugin
19263 Complete aliases from plugin.
19264
19265 The following plugins are available by default: _email-ldap (see
19266 the filter style), _email-local (completes user@hostname Unix
19267 addresses), _email-mail (completes aliases from ~/.mailrc),
19268 _email-mush, _email-mutt, and _email-pine.
19269
19270 Addresses from the _email-foo plugin are added under the tag
19271 `email-foo'.
19272
19273 Writing plugins
19274
19275 Plugins are written as separate functions with names starting
19276 with `_email-'. They are invoked with the -c option and compadd
19277 options. They should either do their own completion or set the
19278 $reply array to a list of `alias:address' elements and return
19279 300. New plugins will be picked up and run automatically.
19280
19281 _files The function _files is a wrapper around _path_files. It supports
19282 all of the same functionality, with some enhancements -- no‐
19283 tably, it respects the list-dirs-first style, and it allows
19284 users to override the behaviour of the -g and -/ options with
19285 the file-patterns style. _files should therefore be preferred
19286 over _path_files in most cases.
19287
19288 This function accepts the full set of options allowed by
19289 _path_files, described below.
19290
19291 _gnu_generic
19292 This function is a simple wrapper around the _arguments function
19293 described above. It can be used to determine automatically the
19294 long options understood by commands that produce a list when
19295 passed the option `--help'. It is intended to be used as a
19296 top-level completion function in its own right. For example, to
19297 enable option completion for the commands foo and bar, use
19298
19299 compdef _gnu_generic foo bar
19300
19301 after the call to compinit.
19302
19303 The completion system as supplied is conservative in its use of
19304 this function, since it is important to be sure the command un‐
19305 derstands the option `--help'.
19306
19307 _guard [ options ] pattern descr
19308 This function displays descr if pattern matches the string to be
19309 completed. It is intended to be used in the action for the
19310 specifications passed to _arguments and similar functions.
19311
19312 The return status is zero if the message was displayed and the
19313 word to complete is not empty, and non-zero otherwise.
19314
19315 The pattern may be preceded by any of the options understood by
19316 compadd that are passed down from _description, namely -M, -J,
19317 -V, -1, -2, -n, -F and -X. All of these options will be ig‐
19318 nored. This fits in conveniently with the argument-passing con‐
19319 ventions of actions for _arguments.
19320
19321 As an example, consider a command taking the options -n and
19322 -none, where -n must be followed by a numeric value in the same
19323 word. By using:
19324
19325 _arguments '-n-: :_guard "[0-9]#" "numeric value"' '-none'
19326
19327 _arguments can be made to both display the message `numeric
19328 value' and complete options after `-n<TAB>'. If the `-n' is al‐
19329 ready followed by one or more digits (the pattern passed to
19330 _guard) only the message will be displayed; if the `-n' is fol‐
19331 lowed by another character, only options are completed.
19332
19333 _message [ -r12 ] [ -VJ group ] descr
19334 _message -e [ tag ] descr
19335 The descr is used in the same way as the third argument to the
19336 _description function, except that the resulting string will al‐
19337 ways be shown whether or not matches were generated. This is
19338 useful for displaying a help message in places where no comple‐
19339 tions can be generated.
19340
19341 The format style is examined with the messages tag to find a
19342 message; the usual tag, descriptions, is used only if the style
19343 is not set with the former.
19344
19345 If the -r option is given, no style is used; the descr is taken
19346 literally as the string to display. This is most useful when
19347 the descr comes from a pre-processed argument list which already
19348 contains an expanded description. Note that this option does
19349 not disable the `%'-sequence parsing done by compadd.
19350
19351 The -12VJ options and the group are passed to compadd and hence
19352 determine the group the message string is added to.
19353
19354 The second -e form gives a description for completions with the
19355 tag tag to be shown even if there are no matches for that tag.
19356 This form is called by _arguments in the event that there is no
19357 action for an option specification. The tag can be omitted and
19358 if so the tag is taken from the parameter $curtag; this is main‐
19359 tained by the completion system and so is usually correct. Note
19360 that if there are no matches at the time this function is
19361 called, compstate[insert] is cleared, so additional matches gen‐
19362 erated later are not inserted on the command line.
19363
19364 _multi_parts [ -i ] sep array
19365 The argument sep is a separator character. The array may be ei‐
19366 ther the name of an array parameter or a literal array in the
19367 form `(foo bar)', a parenthesised list of words separated by
19368 whitespace. The possible completions are the strings from the
19369 array. However, each chunk delimited by sep will be completed
19370 separately. For example, the _tar function uses `_multi_parts /
19371 patharray' to complete partial file paths from the given array
19372 of complete file paths.
19373
19374 The -i option causes _multi_parts to insert a unique match even
19375 if that requires multiple separators to be inserted. This is
19376 not usually the expected behaviour with filenames, but certain
19377 other types of completion, for example those with a fixed set of
19378 possibilities, may be more suited to this form.
19379
19380 Like other utility functions, this function accepts the `-V',
19381 `-J', `-1', `-2', `-n', `-f', `-X', `-M', `-P', `-S', `-r',
19382 `-R', and `-q' options and passes them to the compadd builtin.
19383
19384 _next_label [ -x ] [ -12VJ ] tag name descr [ option ... ]
19385 This function is used to implement the loop over different tag
19386 labels for a particular tag as described above for the tag-order
19387 style. On each call it checks to see if there are any more tag
19388 labels; if there is it returns status zero, otherwise non-zero.
19389 As this function requires a current tag to be set, it must al‐
19390 ways follow a call to _tags or _requested.
19391
19392 The -x12VJ options and the first three arguments are passed to
19393 the _description function. Where appropriate the tag will be
19394 replaced by a tag label in this call. Any description given in
19395 the tag-order style is preferred to the descr passed to
19396 _next_label.
19397
19398 The options given after the descr are set in the parameter given
19399 by name, and hence are to be passed to compadd or whatever func‐
19400 tion is called to add the matches.
19401
19402 Here is a typical use of this function for the tag foo. The
19403 call to _requested determines if tag foo is required at all; the
19404 loop over _next_label handles any labels defined for the tag in
19405 the tag-order style.
19406
19407 local expl ret=1
19408 ...
19409 if _requested foo; then
19410 ...
19411 while _next_label foo expl '...'; do
19412 compadd "$expl[@]" ... && ret=0
19413 done
19414 ...
19415 fi
19416 return ret
19417
19418 _normal [ -P | -p precommand ]
19419 This is the standard function called to handle completion out‐
19420 side any special -context-. It is called both to complete the
19421 command word and also the arguments for a command. In the sec‐
19422 ond case, _normal looks for a special completion for that com‐
19423 mand, and if there is none it uses the completion for the -de‐
19424 fault- context.
19425
19426 A second use is to reexamine the command line specified by the
19427 $words array and the $CURRENT parameter after those have been
19428 modified. For example, the function _precommand, which com‐
19429 pletes after precommand specifiers such as nohup, removes the
19430 first word from the words array, decrements the CURRENT parame‐
19431 ter, then calls `_normal -p $service'. The effect is that `no‐
19432 hup cmd ...' is treated in the same way as `cmd ...'.
19433
19434 -P Reset the list of precommands. This option should be used
19435 if completing a command line which allows internal com‐
19436 mands (e.g. builtins and functions) regardless of prior
19437 precommands (e.g. `zsh -c').
19438
19439 -p precommand
19440 Append precommand to the list of precommands. This option
19441 should be used in nearly all cases in which -P is not ap‐
19442 plicable.
19443
19444 If the command name matches one of the patterns given by one of
19445 the options -p or -P to compdef, the corresponding completion
19446 function is called and then the parameter _compskip is checked.
19447 If it is set completion is terminated at that point even if no
19448 matches have been found. This is the same effect as in the
19449 -first- context.
19450
19451 _numbers [ option ... ] [ description ] [ suffix ... ]
19452 This can be used where a number is followed by a suffix to indi‐
19453 cate the units. The unit suffixes are completed and can also be
19454 included in the description used when completion is invoked for
19455 the preceding number.
19456
19457 In addition to common compadd options, _numbers accepts the fol‐
19458 lowing options:
19459
19460 -t tag Specify a tag to use instead of the default of numbers.
19461
19462 -u units
19463 Indicate the default units for the number, e.g. bytes.
19464
19465 -l min Specify the lowest possible value for the number.
19466
19467 -m max Specify the highest possible value for the number.
19468
19469 -d default
19470 Specify the default value.
19471
19472 -N Allow negative numbers. This is implied if the range in‐
19473 cludes a negative.
19474
19475 -f Allow decimal numbers.
19476
19477 Where a particular suffix represents the default units for a
19478 number, it should be prefixed with a colon. Additionally, suf‐
19479 fixes can be followed by a colon and a description. So for ex‐
19480 ample, the following allows the age of something to be speci‐
19481 fied, either in seconds or with an optional suffix with a longer
19482 unit of time:
19483
19484 _numbers -u seconds age :s:seconds m:minutes h:hours d:days
19485
19486 It is typically helpful for units to be presented in order of
19487 magnitude when completed. To facilitate this, the order in
19488 which they are given is preserved.
19489
19490 When the format style is looked up with the descriptions tag or
19491 the tag specified with -t, the list of suffixes is available as
19492 a `%x' escape sequence. This is in addition to the usual se‐
19493 quences documented under the format style. The form this list
19494 takes can also be configured. To this end, the format style is
19495 first looked up with the tag unit-suffixes. The retrieved format
19496 is applied to each suffix in turn and the results are then con‐
19497 catenated to form the completed list. For the unit-suffixes for‐
19498 mat, `%x' expands to the individual suffix and `%X' to its de‐
19499 scription. %d' indicates a default suffix and can be used in a
19500 condition. The index and reverse index are set in `%i' and `%r'
19501 respectively and are useful for text included only with the
19502 first and last suffixes in the list. So for example, the follow‐
19503 ing joins the suffixes together as a comma-separated list:
19504
19505 zstyle ':completion:*:unit-suffixes' format '%x%(r::,)'
19506
19507 _options
19508 This can be used to complete the names of shell options. It
19509 provides a matcher specification that ignores a leading `no',
19510 ignores underscores and allows upper-case letters to match their
19511 lower-case counterparts (for example, `glob', `noglob',
19512 `NO_GLOB' are all completed). Any arguments are propagated to
19513 the compadd builtin.
19514
19515 _options_set and _options_unset
19516 These functions complete only set or unset options, with the
19517 same matching specification used in the _options function.
19518
19519 Note that you need to uncomment a few lines in the _main_com‐
19520 plete function for these functions to work properly. The lines
19521 in question are used to store the option settings in effect be‐
19522 fore the completion widget locally sets the options it needs.
19523 Hence these functions are not generally used by the completion
19524 system.
19525
19526 _parameters
19527 This is used to complete the names of shell parameters.
19528
19529 The option `-g pattern' limits the completion to parameters
19530 whose type matches the pattern. The type of a parameter is that
19531 shown by `print ${(t)param}', hence judicious use of `*' in pat‐
19532 tern is probably necessary.
19533
19534 All other arguments are passed to the compadd builtin.
19535
19536 _path_files
19537 This function is used throughout the completion system to com‐
19538 plete filenames. It allows completion of partial paths. For
19539 example, the string `/u/i/s/sig' may be completed to `/usr/in‐
19540 clude/sys/signal.h'.
19541
19542 The options accepted by both _path_files and _files are:
19543
19544 -f Complete all filenames. This is the default.
19545
19546 -/ Specifies that only directories should be completed.
19547
19548 -g pattern
19549 Specifies that only files matching the pattern should be
19550 completed.
19551
19552 -W paths
19553 Specifies path prefixes that are to be prepended to the
19554 string from the command line to generate the filenames
19555 but that should not be inserted as completions nor shown
19556 in completion listings. Here, paths may be the name of
19557 an array parameter, a literal list of paths enclosed in
19558 parentheses or an absolute pathname.
19559
19560 -F ignored-files
19561 This behaves as for the corresponding option to the com‐
19562 padd builtin. It gives direct control over which file‐
19563 names should be ignored. If the option is not present,
19564 the ignored-patterns style is used.
19565
19566 Both _path_files and _files also accept the following options
19567 which are passed to compadd: `-J', `-V', `-1', `-2', `-n', `-X',
19568 `-M', `-P', `-S', `-q', `-r', and `-R'.
19569
19570 Finally, the _path_files function uses the styles expand, am‐
19571 biguous, special-dirs, list-suffixes and file-sort described
19572 above.
19573
19574
19575 _pick_variant [ -b builtin-label ] [ -c command ] [ -r name ]
19576 label=pattern ... label [ arg ... ]
19577 This function is used to resolve situations where a single com‐
19578 mand name requires more than one type of handling, either be‐
19579 cause it has more than one variant or because there is a name
19580 clash between two different commands.
19581
19582 The command to run is taken from the first element of the array
19583 words unless this is overridden by the option -c. This command
19584 is run and its output is compared with a series of patterns.
19585 Arguments to be passed to the command can be specified at the
19586 end after all the other arguments. The patterns to try in order
19587 are given by the arguments label=pattern; if the output of `com‐
19588 mand arg ...' contains pattern, then label is selected as the
19589 label for the command variant. If none of the patterns match,
19590 the final command label is selected and status 1 is returned.
19591
19592 If the `-b builtin-label' is given, the command is tested to see
19593 if it is provided as a shell builtin, possibly autoloaded; if
19594 so, the label builtin-label is selected as the label for the
19595 variant.
19596
19597 If the `-r name' is given, the label picked is stored in the pa‐
19598 rameter named name.
19599
19600 The results are also cached in the _cmd_variant associative ar‐
19601 ray indexed by the name of the command run.
19602
19603 _regex_arguments name spec ...
19604 This function generates a completion function name which matches
19605 the specifications specs, a set of regular expressions as de‐
19606 scribed below. After running _regex_arguments, the function
19607 name should be called as a normal completion function. The pat‐
19608 tern to be matched is given by the contents of the words array
19609 up to the current cursor position joined together with null
19610 characters; no quotation is applied.
19611
19612 The arguments are grouped as sets of alternatives separated by
19613 `|', which are tried one after the other until one matches.
19614 Each alternative consists of a one or more specifications which
19615 are tried left to right, with each pattern matched being
19616 stripped in turn from the command line being tested, until all
19617 of the group succeeds or until one fails; in the latter case,
19618 the next alternative is tried. This structure can be repeated
19619 to arbitrary depth by using parentheses; matching proceeds from
19620 inside to outside.
19621
19622 A special procedure is applied if no test succeeds but the re‐
19623 maining command line string contains no null character (implying
19624 the remaining word is the one for which completions are to be
19625 generated). The completion target is restricted to the remain‐
19626 ing word and any actions for the corresponding patterns are exe‐
19627 cuted. In this case, nothing is stripped from the command line
19628 string. The order of evaluation of the actions can be deter‐
19629 mined by the tag-order style; the various formats supported by
19630 _alternative can be used in action. The descr is used for set‐
19631 ting up the array parameter expl.
19632
19633 Specification arguments take one of following forms, in which
19634 metacharacters such as `(', `)', `#' and `|' should be quoted.
19635
19636 /pattern/ [%lookahead%] [-guard] [:tag:descr:action]
19637 This is a single primitive component. The function tests
19638 whether the combined pattern `(#b)((#B)pattern)look‐
19639 ahead*' matches the command line string. If so, `guard'
19640 is evaluated and its return status is examined to deter‐
19641 mine if the test has succeeded. The pattern string `[]'
19642 is guaranteed never to match. The lookahead is not
19643 stripped from the command line before the next pattern is
19644 examined.
19645
19646 The argument starting with : is used in the same manner
19647 as an argument to _alternative.
19648
19649 A component is used as follows: pattern is tested to see
19650 if the component already exists on the command line. If
19651 it does, any following specifications are examined to
19652 find something to complete. If a component is reached
19653 but no such pattern exists yet on the command line, the
19654 string containing the action is used to generate matches
19655 to insert at that point.
19656
19657 /pattern/+ [%lookahead%] [-guard] [:tag:descr:action]
19658 This is similar to `/pattern/ ...' but the left part of
19659 the command line string (i.e. the part already matched by
19660 previous patterns) is also considered part of the comple‐
19661 tion target.
19662
19663 /pattern/- [%lookahead%] [-guard] [:tag:descr:action]
19664 This is similar to `/pattern/ ...' but the actions of the
19665 current and previously matched patterns are ignored even
19666 if the following `pattern' matches the empty string.
19667
19668 ( spec )
19669 Parentheses may be used to groups specs; note each paren‐
19670 thesis is a single argument to _regex_arguments.
19671
19672 spec # This allows any number of repetitions of spec.
19673
19674 spec spec
19675 The two specs are to be matched one after the other as
19676 described above.
19677
19678 spec | spec
19679 Either of the two specs can be matched.
19680
19681 The function _regex_words can be used as a helper function to
19682 generate matches for a set of alternative words possibly with
19683 their own arguments as a command line argument.
19684
19685 Examples:
19686
19687 _regex_arguments _tst /$'[^\0]#\0'/ \
19688 /$'[^\0]#\0'/ :'compadd aaa'
19689
19690 This generates a function _tst that completes aaa as its only
19691 argument. The tag and description for the action have been
19692 omitted for brevity (this works but is not recommended in normal
19693 use). The first component matches the command word, which is
19694 arbitrary; the second matches any argument. As the argument is
19695 also arbitrary, any following component would not depend on aaa
19696 being present.
19697
19698 _regex_arguments _tst /$'[^\0]#\0'/ \
19699 /$'aaa\0'/ :'compadd aaa'
19700
19701 This is a more typical use; it is similar, but any following
19702 patterns would only match if aaa was present as the first argu‐
19703 ment.
19704
19705 _regex_arguments _tst /$'[^\0]#\0'/ \( \
19706 /$'aaa\0'/ :'compadd aaa' \
19707 /$'bbb\0'/ :'compadd bbb' \) \#
19708
19709 In this example, an indefinite number of command arguments may
19710 be completed. Odd arguments are completed as aaa and even argu‐
19711 ments as bbb. Completion fails unless the set of aaa and bbb
19712 arguments before the current one is matched correctly.
19713
19714 _regex_arguments _tst /$'[^\0]#\0'/ \
19715 \( /$'aaa\0'/ :'compadd aaa' \| \
19716 /$'bbb\0'/ :'compadd bbb' \) \#
19717
19718 This is similar, but either aaa or bbb may be completed for any
19719 argument. In this case _regex_words could be used to generate a
19720 suitable expression for the arguments.
19721
19722 _regex_words tag description spec ...
19723 This function can be used to generate arguments for the
19724 _regex_arguments command which may be inserted at any point
19725 where a set of rules is expected. The tag and description give
19726 a standard tag and description pertaining to the current con‐
19727 text. Each spec contains two or three arguments separated by a
19728 colon: note that there is no leading colon in this case.
19729
19730 Each spec gives one of a set of words that may be completed at
19731 this point, together with arguments. It is thus roughly equiva‐
19732 lent to the _arguments function when used in normal (non-regex)
19733 completion.
19734
19735 The part of the spec before the first colon is the word to be
19736 completed. This may contain a *; the entire word, before and
19737 after the * is completed, but only the text before the * is re‐
19738 quired for the context to be matched, so that further arguments
19739 may be completed after the abbreviated form.
19740
19741 The second part of spec is a description for the word being com‐
19742 pleted.
19743
19744 The optional third part of the spec describes how words follow‐
19745 ing the one being completed are themselves to be completed. It
19746 will be evaluated in order to avoid problems with quoting. This
19747 means that typically it contains a reference to an array con‐
19748 taining previously generated regex arguments.
19749
19750 The option -t term specifies a terminator for the word instead
19751 of the usual space. This is handled as an auto-removable suffix
19752 in the manner of the option -s sep to _values.
19753
19754 The result of the processing by _regex_words is placed in the
19755 array reply, which should be made local to the calling function.
19756 If the set of words and arguments may be matched repeatedly, a #
19757 should be appended to the generated array at that point.
19758
19759 For example:
19760
19761 local -a reply
19762 _regex_words mydb-commands 'mydb commands' \
19763 'add:add an entry to mydb:$mydb_add_cmds' \
19764 'show:show entries in mydb'
19765 _regex_arguments _mydb "$reply[@]"
19766 _mydb "$@"
19767
19768 This shows a completion function for a command mydb which takes
19769 two command arguments, add and show. show takes no arguments,
19770 while the arguments for add have already been prepared in an ar‐
19771 ray mydb_add_cmds, quite possibly by a previous call to
19772 _regex_words.
19773
19774 _requested [ -x ] [ -12VJ ] tag [ name descr [ command [ arg ... ] ]
19775 This function is called to decide whether a tag already regis‐
19776 tered by a call to _tags (see below) has been requested by the
19777 user and hence completion should be performed for it. It re‐
19778 turns status zero if the tag is requested and non-zero other‐
19779 wise. The function is typically used as part of a loop over
19780 different tags as follows:
19781
19782 _tags foo bar baz
19783 while _tags; do
19784 if _requested foo; then
19785 ... # perform completion for foo
19786 fi
19787 ... # test the tags bar and baz in the same way
19788 ... # exit loop if matches were generated
19789 done
19790
19791 Note that the test for whether matches were generated is not
19792 performed until the end of the _tags loop. This is so that the
19793 user can set the tag-order style to specify a set of tags to be
19794 completed at the same time.
19795
19796 If name and descr are given, _requested calls the _description
19797 function with these arguments together with the options passed
19798 to _requested.
19799
19800 If command is given, the _all_labels function will be called im‐
19801 mediately with the same arguments. In simple cases this makes
19802 it possible to perform the test for the tag and the matching in
19803 one go. For example:
19804
19805 local expl ret=1
19806 _tags foo bar baz
19807 while _tags; do
19808 _requested foo expl 'description' \
19809 compadd foobar foobaz && ret=0
19810 ...
19811 (( ret )) || break
19812 done
19813
19814 If the command is not compadd, it must nevertheless be prepared
19815 to handle the same options.
19816
19817 _retrieve_cache cache_identifier
19818 This function retrieves completion information from the file
19819 given by cache_identifier, stored in a directory specified by
19820 the cache-path style which defaults to ~/.zcompcache. The re‐
19821 turn status is zero if retrieval was successful. It will only
19822 attempt retrieval if the use-cache style is set, so you can call
19823 this function without worrying about whether the user wanted to
19824 use the caching layer.
19825
19826 See _store_cache below for more details.
19827
19828 _sep_parts
19829 This function is passed alternating arrays and separators as ar‐
19830 guments. The arrays specify completions for parts of strings to
19831 be separated by the separators. The arrays may be the names of
19832 array parameters or a quoted list of words in parentheses. For
19833 example, with the array `hosts=(ftp news)' the call `_sep_parts
19834 '(foo bar)' @ hosts' will complete the string `f' to `foo' and
19835 the string `b@n' to `bar@news'.
19836
19837 This function accepts the compadd options `-V', `-J', `-1',
19838 `-2', `-n', `-X', `-M', `-P', `-S', `-r', `-R', and `-q' and
19839 passes them on to the compadd builtin used to add the matches.
19840
19841 _sequence [ -s sep ] [ -n max ] [ -d ] function [ - ] ...
19842 This function is a wrapper to other functions for completing
19843 items in a separated list. The same function is used to complete
19844 each item in the list. The separator is specified with the -s
19845 option. If -s is omitted it will use `,'. Duplicate values are
19846 not matched unless -d is specified. If there is a fixed or maxi‐
19847 mum number of items in the list, this can be specified with the
19848 -n option.
19849
19850 Common compadd options are passed on to the function. It is pos‐
19851 sible to use compadd directly with _sequence, though _values may
19852 be more appropriate in this situation.
19853
19854 _setup tag [ group ]
19855 This function sets up the special parameters used by the comple‐
19856 tion system appropriately for the tag given as the first argu‐
19857 ment. It uses the styles list-colors, list-packed,
19858 list-rows-first, last-prompt, accept-exact, menu and force-list.
19859
19860 The optional group supplies the name of the group in which the
19861 matches will be placed. If it is not given, the tag is used as
19862 the group name.
19863
19864 This function is called automatically from _description and
19865 hence is not normally called explicitly.
19866
19867 _store_cache cache_identifier param ...
19868 This function, together with _retrieve_cache and _cache_invalid,
19869 implements a caching layer which can be used in any completion
19870 function. Data obtained by costly operations are stored in pa‐
19871 rameters; this function then dumps the values of those parame‐
19872 ters to a file. The data can then be retrieved quickly from
19873 that file via _retrieve_cache, even in different instances of
19874 the shell.
19875
19876 The cache_identifier specifies the file which the data should be
19877 dumped to. The file is stored in a directory specified by the
19878 cache-path style which defaults to ~/.zcompcache. The remaining
19879 params arguments are the parameters to dump to the file.
19880
19881 The return status is zero if storage was successful. The func‐
19882 tion will only attempt storage if the use-cache style is set, so
19883 you can call this function without worrying about whether the
19884 user wanted to use the caching layer.
19885
19886 The completion function may avoid calling _retrieve_cache when
19887 it already has the completion data available as parameters.
19888 However, in that case it should call _cache_invalid to check
19889 whether the data in the parameters and in the cache are still
19890 valid.
19891
19892 See the _perl_modules completion function for a simple example
19893 of the usage of the caching layer.
19894
19895 _tags [ [ -C name ] tag ... ]
19896 If called with arguments, these are taken to be the names of
19897 tags valid for completions in the current context. These tags
19898 are stored internally and sorted by using the tag-order style.
19899
19900 Next, _tags is called repeatedly without arguments from the same
19901 completion function. This successively selects the first, sec‐
19902 ond, etc. set of tags requested by the user. The return status
19903 is zero if at least one of the tags is requested and non-zero
19904 otherwise. To test if a particular tag is to be tried, the _re‐
19905 quested function should be called (see above).
19906
19907 If `-C name' is given, name is temporarily stored in the argu‐
19908 ment field (the fifth) of the context in the curcontext parame‐
19909 ter during the call to _tags; the field is restored on exit.
19910 This allows _tags to use a more specific context without having
19911 to change and reset the curcontext parameter (which has the same
19912 effect).
19913
19914 _tilde_files
19915 Like _files, but resolve leading tildes according to the rules
19916 of filename expansion, so the suggested completions don't start
19917 with a `~' even if the filename on the command-line does.
19918
19919 _values [ -O name ] [ -s sep ] [ -S sep ] [ -wC ] desc spec ...
19920 This is used to complete arbitrary keywords (values) and their
19921 arguments, or lists of such combinations.
19922
19923 If the first argument is the option `-O name', it will be used
19924 in the same way as by the _arguments function. In other words,
19925 the elements of the name array will be passed to compadd when
19926 executing an action.
19927
19928 If the first argument (or the first argument after `-O name') is
19929 `-s', the next argument is used as the character that separates
19930 multiple values. This character is automatically added after
19931 each value in an auto-removable fashion (see below); all values
19932 completed by `_values -s' appear in the same word on the command
19933 line, unlike completion using _arguments. If this option is not
19934 present, only a single value will be completed per word.
19935
19936 Normally, _values will only use the current word to determine
19937 which values are already present on the command line and hence
19938 are not to be completed again. If the -w option is given, other
19939 arguments are examined as well.
19940
19941 The first non-option argument, desc, is used as a string to
19942 print as a description before listing the values.
19943
19944 All other arguments describe the possible values and their argu‐
19945 ments in the same format used for the description of options by
19946 the _arguments function (see above). The only differences are
19947 that no minus or plus sign is required at the beginning, values
19948 can have only one argument, and the forms of action beginning
19949 with an equal sign are not supported.
19950
19951 The character separating a value from its argument can be set
19952 using the option -S (like -s, followed by the character to use
19953 as the separator in the next argument). By default the equals
19954 sign will be used as the separator between values and arguments.
19955
19956 Example:
19957
19958 _values -s , 'description' \
19959 '*foo[bar]' \
19960 '(two)*one[number]:first count:' \
19961 'two[another number]::second count:(1 2 3)'
19962
19963 This describes three possible values: `foo', `one', and `two'.
19964 The first is described as `bar', takes no argument and may ap‐
19965 pear more than once. The second is described as `number', may
19966 appear more than once, and takes one mandatory argument de‐
19967 scribed as `first count'; no action is specified, so it will not
19968 be completed. The `(two)' at the beginning says that if the
19969 value `one' is on the line, the value `two' will no longer be
19970 considered a possible completion. Finally, the last value
19971 (`two') is described as `another number' and takes an optional
19972 argument described as `second count' for which the completions
19973 (to appear after an `=') are `1', `2', and `3'. The _values
19974 function will complete lists of these values separated by com‐
19975 mas.
19976
19977 Like _arguments, this function temporarily adds another context
19978 name component to the arguments element (the fifth) of the cur‐
19979 rent context while executing the action. Here this name is just
19980 the name of the value for which the argument is completed.
19981
19982 The style verbose is used to decide if the descriptions for the
19983 values (but not those for the arguments) should be printed.
19984
19985 The associative array val_args is used to report values and
19986 their arguments; this works similarly to the opt_args associa‐
19987 tive array used by _arguments. Hence the function calling _val‐
19988 ues should declare the local parameters state, state_descr,
19989 line, context and val_args:
19990
19991 local context state state_descr line
19992 typeset -A val_args
19993
19994 when using an action of the form `->string'. With this function
19995 the context parameter will be set to the name of the value whose
19996 argument is to be completed. Note that for _values, the state
19997 and state_descr are scalars rather than arrays. Only a single
19998 matching state is returned.
19999
20000 Note also that _values normally adds the character used as the
20001 separator between values as an auto-removable suffix (similar to
20002 a `/' after a directory). However, this is not possible for a
20003 `->string' action as the matches for the argument are generated
20004 by the calling function. To get the usual behaviour, the call‐
20005 ing function can add the separator x as a suffix by passing the
20006 options `-qS x' either directly or indirectly to compadd.
20007
20008 The option -C is treated in the same way as it is by _arguments.
20009 In that case the parameter curcontext should be made local in‐
20010 stead of context (as described above).
20011
20012 _wanted [ -x ] [ -C name ] [ -12VJ ] tag name descr command [ arg ...]
20013 In many contexts, completion can only generate one particular
20014 set of matches, usually corresponding to a single tag. However,
20015 it is still necessary to decide whether the user requires
20016 matches of this type. This function is useful in such a case.
20017
20018 The arguments to _wanted are the same as those to _requested,
20019 i.e. arguments to be passed to _description. However, in this
20020 case the command is not optional; all the processing of tags,
20021 including the loop over both tags and tag labels and the genera‐
20022 tion of matches, is carried out automatically by _wanted.
20023
20024 Hence to offer only one tag and immediately add the correspond‐
20025 ing matches with the given description:
20026
20027 local expl
20028 _wanted tag expl 'description' \
20029 compadd -- match1 match2...
20030
20031 See also the use of _wanted in the example function in the sub‐
20032 section `Dynamic named directories' in zshexpn(1).
20033
20034 Note that, as for _requested, the command must be able to accept
20035 options to be passed down to compadd.
20036
20037 Like _tags this function supports the -C option to give a dif‐
20038 ferent name for the argument context field. The -x option has
20039 the same meaning as for _description.
20040
20041 _widgets [ -g pattern ]
20042 This function completes names of zle widgets (see the section
20043 `Widgets' in zshzle(1)). The pattern, if present, is matched
20044 against values of the $widgets special parameter, documented in
20045 the section `The zsh/zleparameter Module' in zshmodules(1).
20046
20048 There are some standard variables, initialised by the _main_complete
20049 function and then used from other functions.
20050
20051 The standard variables are:
20052
20053 _comp_caller_options
20054 The completion system uses setopt to set a number of options.
20055 This allows functions to be written without concern for compati‐
20056 bility with every possible combination of user options. However,
20057 sometimes completion needs to know what the user's option pref‐
20058 erences are. These are saved in the _comp_caller_options asso‐
20059 ciative array. Option names, spelled in lowercase without under‐
20060 scores, are mapped to one or other of the strings `on' and
20061 `off'.
20062
20063 _comp_priv_prefix
20064 Completion functions such as _sudo can set the _comp_priv_prefix
20065 array to a command prefix that may then be used by _call_program
20066 to match the privileges when calling programs to generate
20067 matches.
20068
20069 Two more features are offered by the _main_complete function. The ar‐
20070 rays compprefuncs and comppostfuncs may contain names of functions that
20071 are to be called immediately before or after completion has been tried.
20072 A function will only be called once unless it explicitly reinserts it‐
20073 self into the array.
20074
20076 In the source distribution, the files are contained in various subdi‐
20077 rectories of the Completion directory. They may have been installed in
20078 the same structure, or into one single function directory. The follow‐
20079 ing is a description of the files found in the original directory
20080 structure. If you wish to alter an installed file, you will need to
20081 copy it to some directory which appears earlier in your fpath than the
20082 standard directory where it appears.
20083
20084 Base The core functions and special completion widgets automatically
20085 bound to keys. You will certainly need most of these, though
20086 will probably not need to alter them. Many of these are docu‐
20087 mented above.
20088
20089 Zsh Functions for completing arguments of shell builtin commands and
20090 utility functions for this. Some of these are also used by
20091 functions from the Unix directory.
20092
20093 Unix Functions for completing arguments of external commands and
20094 suites of commands. They may need modifying for your system,
20095 although in many cases some attempt is made to decide which ver‐
20096 sion of a command is present. For example, completion for the
20097 mount command tries to determine the system it is running on,
20098 while completion for many other utilities try to decide whether
20099 the GNU version of the command is in use, and hence whether the
20100 --help option is supported.
20101
20102 X, AIX, BSD, ...
20103 Completion and utility function for commands available only on
20104 some systems. These are not arranged hierarchically, so, for
20105 example, both the Linux and Debian directories, as well as the X
20106 directory, may be useful on your system.
20107
20108
20109
20110ZSHCOMPCTL(1) General Commands Manual ZSHCOMPCTL(1)
20111
20112
20113
20115 zshcompctl - zsh programmable completion
20116
20118 This version of zsh has two ways of performing completion of words on
20119 the command line. New users of the shell may prefer to use the newer
20120 and more powerful system based on shell functions; this is described in
20121 zshcompsys(1), and the basic shell mechanisms which support it are de‐
20122 scribed in zshcompwid(1). This manual entry describes the older com‐
20123 pctl command.
20124
20125 compctl [ -CDT ] options [ command ... ]
20126 compctl [ -CDT ] options [ -x pattern options - ... -- ]
20127 [ + options [ -x ... -- ] ... [+] ] [ command ... ]
20128 compctl -M match-specs ...
20129 compctl -L [ -CDTM ] [ command ... ]
20130 compctl + command ...
20131
20132 Control the editor's completion behavior according to the supplied set
20133 of options. Various editing commands, notably expand-or-complete-word,
20134 usually bound to tab, will attempt to complete a word typed by the
20135 user, while others, notably delete-char-or-list, usually bound to ^D in
20136 EMACS editing mode, list the possibilities; compctl controls what those
20137 possibilities are. They may for example be filenames (the most common
20138 case, and hence the default), shell variables, or words from a
20139 user-specified list.
20140
20142 Completion of the arguments of a command may be different for each com‐
20143 mand or may use the default. The behavior when completing the command
20144 word itself may also be separately specified. These correspond to the
20145 following flags and arguments, all of which (except for -L) may be com‐
20146 bined with any combination of the options described subsequently in the
20147 section `Option Flags':
20148
20149 command ...
20150 controls completion for the named commands, which must be listed
20151 last on the command line. If completion is attempted for a com‐
20152 mand with a pathname containing slashes and no completion defi‐
20153 nition is found, the search is retried with the last pathname
20154 component. If the command starts with a =, completion is tried
20155 with the pathname of the command.
20156
20157 Any of the command strings may be patterns of the form normally
20158 used for filename generation. These should be quoted to protect
20159 them from immediate expansion; for example the command string
20160 'foo*' arranges for completion of the words of any command be‐
20161 ginning with foo. When completion is attempted, all pattern
20162 completions are tried in the reverse order of their definition
20163 until one matches. By default, completion then proceeds as nor‐
20164 mal, i.e. the shell will try to generate more matches for the
20165 specific command on the command line; this can be overridden by
20166 including -tn in the flags for the pattern completion.
20167
20168 Note that aliases are expanded before the command name is deter‐
20169 mined unless the COMPLETE_ALIASES option is set. Commands may
20170 not be combined with the -C, -D or -T flags.
20171
20172 -C controls completion when the command word itself is being com‐
20173 pleted. If no compctl -C command has been issued, the names of
20174 any executable command (whether in the path or specific to the
20175 shell, such as aliases or functions) are completed.
20176
20177 -D controls default completion behavior for the arguments of com‐
20178 mands not assigned any special behavior. If no compctl -D com‐
20179 mand has been issued, filenames are completed.
20180
20181 -T supplies completion flags to be used before any other processing
20182 is done, even before processing for compctls defined for spe‐
20183 cific commands. This is especially useful when combined with
20184 extended completion (the -x flag, see the section `Extended Com‐
20185 pletion' below). Using this flag you can define default behav‐
20186 ior which will apply to all commands without exception, or you
20187 can alter the standard behavior for all commands. For example,
20188 if your access to the user database is too slow and/or it con‐
20189 tains too many users (so that completion after `~' is too slow
20190 to be usable), you can use
20191
20192 compctl -T -x 's[~] C[0,[^/]#]' -k friends -S/ -tn
20193
20194 to complete the strings in the array friends after a `~'. The
20195 C[...] argument is necessary so that this form of ~-completion
20196 is not tried after the directory name is finished.
20197
20198 -L lists the existing completion behavior in a manner suitable for
20199 putting into a start-up script; the existing behavior is not
20200 changed. Any combination of the above forms, or the -M flag
20201 (which must follow the -L flag), may be specified, otherwise all
20202 defined completions are listed. Any other flags supplied are
20203 ignored.
20204
20205 no argument
20206 If no argument is given, compctl lists all defined completions
20207 in an abbreviated form; with a list of options, all completions
20208 with those flags set (not counting extended completion) are
20209 listed.
20210
20211 If the + flag is alone and followed immediately by the command list,
20212 the completion behavior for all the commands in the list is reset to
20213 the default. In other words, completion will subsequently use the op‐
20214 tions specified by the -D flag.
20215
20216 The form with -M as the first and only option defines global matching
20217 specifications (see zshcompwid). The match specifications given will be
20218 used for every completion attempt (only when using compctl, not with
20219 the new completion system) and are tried in the order in which they are
20220 defined until one generates at least one match. E.g.:
20221
20222 compctl -M '' 'm:{a-zA-Z}={A-Za-z}'
20223
20224 This will first try completion without any global match specifications
20225 (the empty string) and, if that generates no matches, will try case in‐
20226 sensitive completion.
20227
20229 [ -fcFBdeaRGovNAIOPZEnbjrzu/12 ]
20230 [ -k array ] [ -g globstring ] [ -s subststring ]
20231 [ -K function ]
20232 [ -Q ] [ -P prefix ] [ -S suffix ]
20233 [ -W file-prefix ] [ -H num pattern ]
20234 [ -q ] [ -X explanation ] [ -Y explanation ]
20235 [ -y func-or-var ] [ -l cmd ] [ -h cmd ] [ -U ]
20236 [ -t continue ] [ -J name ] [ -V name ]
20237 [ -M match-spec ]
20238
20239 The remaining options specify the type of command arguments to look for
20240 during completion. Any combination of these flags may be specified;
20241 the result is a sorted list of all the possibilities. The options are
20242 as follows.
20243
20244 Simple Flags
20245 These produce completion lists made up by the shell itself:
20246
20247 -f Filenames and file system paths.
20248
20249 -/ Just file system paths.
20250
20251 -c Command names, including aliases, shell functions, builtins and
20252 reserved words.
20253
20254 -F Function names.
20255
20256 -B Names of builtin commands.
20257
20258 -m Names of external commands.
20259
20260 -w Reserved words.
20261
20262 -a Alias names.
20263
20264 -R Names of regular (non-global) aliases.
20265
20266 -G Names of global aliases.
20267
20268 -d This can be combined with -F, -B, -w, -a, -R and -G to get names
20269 of disabled functions, builtins, reserved words or aliases.
20270
20271 -e This option (to show enabled commands) is in effect by default,
20272 but may be combined with -d; -de in combination with -F, -B, -w,
20273 -a, -R and -G will complete names of functions, builtins, re‐
20274 served words or aliases whether or not they are disabled.
20275
20276 -o Names of shell options (see zshoptions(1)).
20277
20278 -v Names of any variable defined in the shell.
20279
20280 -N Names of scalar (non-array) parameters.
20281
20282 -A Array names.
20283
20284 -I Names of integer variables.
20285
20286 -O Names of read-only variables.
20287
20288 -p Names of parameters used by the shell (including special parame‐
20289 ters).
20290
20291 -Z Names of shell special parameters.
20292
20293 -E Names of environment variables.
20294
20295 -n Named directories.
20296
20297 -b Key binding names.
20298
20299 -j Job names: the first word of the job leader's command line.
20300 This is useful with the kill builtin.
20301
20302 -r Names of running jobs.
20303
20304 -z Names of suspended jobs.
20305
20306 -u User names.
20307
20308 Flags with Arguments
20309 These have user supplied arguments to determine how the list of comple‐
20310 tions is to be made up:
20311
20312 -k array
20313 Names taken from the elements of $array (note that the `$' does
20314 not appear on the command line). Alternatively, the argument
20315 array itself may be a set of space- or comma-separated values in
20316 parentheses, in which any delimiter may be escaped with a back‐
20317 slash; in this case the argument should be quoted. For example,
20318
20319 compctl -k "(cputime filesize datasize stacksize
20320 coredumpsize resident descriptors)" limit
20321
20322 -g globstring
20323 The globstring is expanded using filename globbing; it should be
20324 quoted to protect it from immediate expansion. The resulting
20325 filenames are taken as the possible completions. Use `*(/)' in‐
20326 stead of `*/' for directories. The fignore special parameter is
20327 not applied to the resulting files. More than one pattern may
20328 be given separated by blanks. (Note that brace expansion is not
20329 part of globbing. Use the syntax `(either|or)' to match alter‐
20330 natives.)
20331
20332 -s subststring
20333 The subststring is split into words and these words are than ex‐
20334 panded using all shell expansion mechanisms (see zshexpn(1)).
20335 The resulting words are taken as possible completions. The fig‐
20336 nore special parameter is not applied to the resulting files.
20337 Note that -g is faster for filenames.
20338
20339 -K function
20340 Call the given function to get the completions. Unless the name
20341 starts with an underscore, the function is passed two arguments:
20342 the prefix and the suffix of the word on which completion is to
20343 be attempted, in other words those characters before the cursor
20344 position, and those from the cursor position onwards. The whole
20345 command line can be accessed with the -c and -l flags of the
20346 read builtin. The function should set the variable reply to an
20347 array containing the completions (one completion per element);
20348 note that reply should not be made local to the function. From
20349 such a function the command line can be accessed with the -c and
20350 -l flags to the read builtin. For example,
20351
20352 function whoson { reply=(`users`); }
20353 compctl -K whoson talk
20354
20355 completes only logged-on users after `talk'. Note that `whoson'
20356 must return an array, so `reply=`users`' would be incorrect.
20357
20358 -H num pattern
20359 The possible completions are taken from the last num history
20360 lines. Only words matching pattern are taken. If num is zero
20361 or negative the whole history is searched and if pattern is the
20362 empty string all words are taken (as with `*'). A typical use
20363 is
20364
20365 compctl -D -f + -H 0 ''
20366
20367 which forces completion to look back in the history list for a
20368 word if no filename matches.
20369
20370 Control Flags
20371 These do not directly specify types of name to be completed, but manip‐
20372 ulate the options that do:
20373
20374 -Q This instructs the shell not to quote any metacharacters in the
20375 possible completions. Normally the results of a completion are
20376 inserted into the command line with any metacharacters quoted so
20377 that they are interpreted as normal characters. This is appro‐
20378 priate for filenames and ordinary strings. However, for special
20379 effects, such as inserting a backquoted expression from a com‐
20380 pletion array (-k) so that the expression will not be evaluated
20381 until the complete line is executed, this option must be used.
20382
20383 -P prefix
20384 The prefix is inserted just before the completed string; any
20385 initial part already typed will be completed and the whole pre‐
20386 fix ignored for completion purposes. For example,
20387
20388 compctl -j -P "%" kill
20389
20390 inserts a `%' after the kill command and then completes job
20391 names.
20392
20393 -S suffix
20394 When a completion is found the suffix is inserted after the com‐
20395 pleted string. In the case of menu completion the suffix is in‐
20396 serted immediately, but it is still possible to cycle through
20397 the list of completions by repeatedly hitting the same key.
20398
20399 -W file-prefix
20400 With directory file-prefix: for command, file, directory and
20401 globbing completion (options -c, -f, -/, -g), the file prefix is
20402 implicitly added in front of the completion. For example,
20403
20404 compctl -/ -W ~/Mail maildirs
20405
20406 completes any subdirectories to any depth beneath the directory
20407 ~/Mail, although that prefix does not appear on the command
20408 line. The file-prefix may also be of the form accepted by the
20409 -k flag, i.e. the name of an array or a literal list in paren‐
20410 thesis. In this case all the directories in the list will be
20411 searched for possible completions.
20412
20413 -q If used with a suffix as specified by the -S option, this causes
20414 the suffix to be removed if the next character typed is a blank
20415 or does not insert anything or if the suffix consists of only
20416 one character and the next character typed is the same charac‐
20417 ter; this the same rule used for the AUTO_REMOVE_SLASH option.
20418 The option is most useful for list separators (comma, colon,
20419 etc.).
20420
20421 -l cmd This option restricts the range of command line words that are
20422 considered to be arguments. If combined with one of the ex‐
20423 tended completion patterns `p[...]', `r[...]', or `R[...]' (see
20424 the section `Extended Completion' below) the range is restricted
20425 to the range of arguments specified in the brackets. Completion
20426 is then performed as if these had been given as arguments to the
20427 cmd supplied with the option. If the cmd string is empty the
20428 first word in the range is instead taken as the command name,
20429 and command name completion performed on the first word in the
20430 range. For example,
20431
20432 compctl -x 'r[-exec,;]' -l '' -- find
20433
20434 completes arguments between `-exec' and the following `;' (or
20435 the end of the command line if there is no such string) as if
20436 they were a separate command line.
20437
20438 -h cmd Normally zsh completes quoted strings as a whole. With this op‐
20439 tion, completion can be done separately on different parts of
20440 such strings. It works like the -l option but makes the comple‐
20441 tion code work on the parts of the current word that are sepa‐
20442 rated by spaces. These parts are completed as if they were argu‐
20443 ments to the given cmd. If cmd is the empty string, the first
20444 part is completed as a command name, as with -l.
20445
20446 -U Use the whole list of possible completions, whether or not they
20447 actually match the word on the command line. The word typed so
20448 far will be deleted. This is most useful with a function (given
20449 by the -K option) which can examine the word components passed
20450 to it (or via the read builtin's -c and -l flags) and use its
20451 own criteria to decide what matches. If there is no completion,
20452 the original word is retained. Since the produced possible com‐
20453 pletions seldom have interesting common prefixes and suffixes,
20454 menu completion is started immediately if AUTO_MENU is set and
20455 this flag is used.
20456
20457 -y func-or-var
20458 The list provided by func-or-var is displayed instead of the
20459 list of completions whenever a listing is required; the actual
20460 completions to be inserted are not affected. It can be provided
20461 in two ways. Firstly, if func-or-var begins with a $ it defines
20462 a variable, or if it begins with a left parenthesis a literal
20463 array, which contains the list. A variable may have been set by
20464 a call to a function using the -K option. Otherwise it contains
20465 the name of a function which will be executed to create the
20466 list. The function will be passed as an argument list all
20467 matching completions, including prefixes and suffixes expanded
20468 in full, and should set the array reply to the result. In both
20469 cases, the display list will only be retrieved after a complete
20470 list of matches has been created.
20471
20472 Note that the returned list does not have to correspond, even in
20473 length, to the original set of matches, and may be passed as a
20474 scalar instead of an array. No special formatting of characters
20475 is performed on the output in this case; in particular, newlines
20476 are printed literally and if they appear output in columns is
20477 suppressed.
20478
20479 -X explanation
20480 Print explanation when trying completion on the current set of
20481 options. A `%n' in this string is replaced by the number of
20482 matches that were added for this explanation string. The expla‐
20483 nation only appears if completion was tried and there was no
20484 unique match, or when listing completions. Explanation strings
20485 will be listed together with the matches of the group specified
20486 together with the -X option (using the -J or -V option). If the
20487 same explanation string is given to multiple -X options, the
20488 string appears only once (for each group) and the number of
20489 matches shown for the `%n' is the total number of all matches
20490 for each of these uses. In any case, the explanation string will
20491 only be shown if there was at least one match added for the ex‐
20492 planation string.
20493
20494 The sequences %B, %b, %S, %s, %U, and %u specify output at‐
20495 tributes (bold, standout, and underline), %F, %f, %K, %k specify
20496 foreground and background colours, and %{...%} can be used to
20497 include literal escape sequences as in prompts.
20498
20499 -Y explanation
20500 Identical to -X, except that the explanation first undergoes ex‐
20501 pansion following the usual rules for strings in double quotes.
20502 The expansion will be carried out after any functions are called
20503 for the -K or -y options, allowing them to set variables.
20504
20505 -t continue
20506 The continue-string contains a character that specifies which
20507 set of completion flags should be used next. It is useful:
20508
20509 (i) With -T, or when trying a list of pattern completions, when
20510 compctl would usually continue with ordinary processing after
20511 finding matches; this can be suppressed with `-tn'.
20512
20513 (ii) With a list of alternatives separated by +, when compctl
20514 would normally stop when one of the alternatives generates
20515 matches. It can be forced to consider the next set of comple‐
20516 tions by adding `-t+' to the flags of the alternative before the
20517 `+'.
20518
20519 (iii) In an extended completion list (see below), when compctl
20520 would normally continue until a set of conditions succeeded,
20521 then use only the immediately following flags. With `-t-', com‐
20522 pctl will continue trying extended completions after the next
20523 `-'; with `-tx' it will attempt completion with the default
20524 flags, in other words those before the `-x'.
20525
20526 -J name
20527 This gives the name of the group the matches should be placed
20528 in. Groups are listed and sorted separately; likewise, menu com‐
20529 pletion will offer the matches in the groups in the order in
20530 which the groups were defined. If no group name is explicitly
20531 given, the matches are stored in a group named default. The
20532 first time a group name is encountered, a group with that name
20533 is created. After that all matches with the same group name are
20534 stored in that group.
20535
20536 This can be useful with non-exclusive alternative completions.
20537 For example, in
20538
20539 compctl -f -J files -t+ + -v -J variables foo
20540
20541 both files and variables are possible completions, as the -t+
20542 forces both sets of alternatives before and after the + to be
20543 considered at once. Because of the -J options, however, all
20544 files are listed before all variables.
20545
20546 -V name
20547 Like -J, but matches within the group will not be sorted in
20548 listings nor in menu completion. These unsorted groups are in a
20549 different name space from the sorted ones, so groups defined as
20550 -J files and -V files are distinct.
20551
20552 -1 If given together with the -V option, makes only consecutive du‐
20553 plicates in the group be removed. Note that groups with and
20554 without this flag are in different name spaces.
20555
20556 -2 If given together with the -J or -V option, makes all duplicates
20557 be kept. Again, groups with and without this flag are in differ‐
20558 ent name spaces.
20559
20560 -M match-spec
20561 This defines additional matching control specifications that
20562 should be used only when testing words for the list of flags
20563 this flag appears in. The format of the match-spec string is de‐
20564 scribed in zshcompwid.
20565
20567 compctl [ -CDT ] options + options [ + ... ] [ + ] command ...
20568
20569 The form with `+' specifies alternative options. Completion is tried
20570 with the options before the first `+'. If this produces no matches com‐
20571 pletion is tried with the flags after the `+' and so on. If there are
20572 no flags after the last `+' and a match has not been found up to that
20573 point, default completion is tried. If the list of flags contains a -t
20574 with a + character, the next list of flags is used even if the current
20575 list produced matches.
20576
20577 Additional options are available that restrict completion to some part
20578 of the command line; this is referred to as `extended completion'.
20579
20581 compctl [ -CDT ] options -x pattern options - ... --
20582 [ command ... ]
20583 compctl [ -CDT ] options [ -x pattern options - ... -- ]
20584 [ + options [ -x ... -- ] ... [+] ] [ command ... ]
20585
20586 The form with `-x' specifies extended completion for the commands
20587 given; as shown, it may be combined with alternative completion using
20588 `+'. Each pattern is examined in turn; when a match is found, the cor‐
20589 responding options, as described in the section `Option Flags' above,
20590 are used to generate possible completions. If no pattern matches, the
20591 options given before the -x are used.
20592
20593 Note that each pattern should be supplied as a single argument and
20594 should be quoted to prevent expansion of metacharacters by the shell.
20595
20596 A pattern is built of sub-patterns separated by commas; it matches if
20597 at least one of these sub-patterns matches (they are `or'ed). These
20598 sub-patterns are in turn composed of other sub-patterns separated by
20599 white spaces which match if all of the sub-patterns match (they are
20600 `and'ed). An element of the sub-patterns is of the form `c[...][...]',
20601 where the pairs of brackets may be repeated as often as necessary, and
20602 matches if any of the sets of brackets match (an `or'). The example
20603 below makes this clearer.
20604
20605 The elements may be any of the following:
20606
20607 s[string]...
20608 Matches if the current word on the command line starts with one
20609 of the strings given in brackets. The string is not removed and
20610 is not part of the completion.
20611
20612 S[string]...
20613 Like s[string] except that the string is part of the completion.
20614
20615 p[from,to]...
20616 Matches if the number of the current word is between one of the
20617 from and to pairs inclusive. The comma and to are optional; to
20618 defaults to the same value as from. The numbers may be nega‐
20619 tive: -n refers to the n'th last word on the line.
20620
20621 c[offset,string]...
20622 Matches if the string matches the word offset by offset from the
20623 current word position. Usually offset will be negative.
20624
20625 C[offset,pattern]...
20626 Like c but using pattern matching instead.
20627
20628 w[index,string]...
20629 Matches if the word in position index is equal to the corre‐
20630 sponding string. Note that the word count is made after any
20631 alias expansion.
20632
20633 W[index,pattern]...
20634 Like w but using pattern matching instead.
20635
20636 n[index,string]...
20637 Matches if the current word contains string. Anything up to and
20638 including the indexth occurrence of this string will not be con‐
20639 sidered part of the completion, but the rest will. index may be
20640 negative to count from the end: in most cases, index will be 1
20641 or -1. For example,
20642
20643 compctl -s '`users`' -x 'n[1,@]' -k hosts -- talk
20644
20645 will usually complete usernames, but if you insert an @ after
20646 the name, names from the array hosts (assumed to contain host‐
20647 names, though you must make the array yourself) will be com‐
20648 pleted. Other commands such as rcp can be handled similarly.
20649
20650 N[index,string]...
20651 Like n except that the string will be taken as a character
20652 class. Anything up to and including the indexth occurrence of
20653 any of the characters in string will not be considered part of
20654 the completion.
20655
20656 m[min,max]...
20657 Matches if the total number of words lies between min and max
20658 inclusive.
20659
20660 r[str1,str2]...
20661 Matches if the cursor is after a word with prefix str1. If
20662 there is also a word with prefix str2 on the command line after
20663 the one matched by str1 it matches only if the cursor is before
20664 this word. If the comma and str2 are omitted, it matches if the
20665 cursor is after a word with prefix str1.
20666
20667 R[str1,str2]...
20668 Like r but using pattern matching instead.
20669
20670 q[str]...
20671 Matches the word currently being completed is in single quotes
20672 and the str begins with the letter `s', or if completion is done
20673 in double quotes and str starts with the letter `d', or if com‐
20674 pletion is done in backticks and str starts with a `b'.
20675
20677 compctl -u -x 's[+] c[-1,-f],s[-f+]' \
20678 -g '~/Mail/*(:t)' - 's[-f],c[-1,-f]' -f -- mail
20679
20680 This is to be interpreted as follows:
20681
20682 If the current command is mail, then
20683
20684 if ((the current word begins with + and the previous word is -f)
20685 or (the current word begins with -f+)), then complete the
20686 non-directory part (the `:t' glob modifier) of files in the directory
20687 ~/Mail; else
20688
20689 if the current word begins with -f or the previous word was -f, then
20690 complete any file; else
20691
20692 complete user names.
20693
20694
20695
20696
20697ZSHMODULES(1) General Commands Manual ZSHMODULES(1)
20698
20699
20700
20702 zshmodules - zsh loadable modules
20703
20705 Some optional parts of zsh are in modules, separate from the core of
20706 the shell. Each of these modules may be linked in to the shell at
20707 build time, or can be dynamically linked while the shell is running if
20708 the installation supports this feature. Modules are linked at runtime
20709 with the zmodload command, see zshbuiltins(1).
20710
20711 The modules that are bundled with the zsh distribution are:
20712
20713 zsh/attr
20714 Builtins for manipulating extended attributes (xattr).
20715
20716 zsh/cap
20717 Builtins for manipulating POSIX.1e (POSIX.6) capability (privi‐
20718 lege) sets.
20719
20720 zsh/clone
20721 A builtin that can clone a running shell onto another terminal.
20722
20723 zsh/compctl
20724 The compctl builtin for controlling completion.
20725
20726 zsh/complete
20727 The basic completion code.
20728
20729 zsh/complist
20730 Completion listing extensions.
20731
20732 zsh/computil
20733 A module with utility builtins needed for the shell function
20734 based completion system.
20735
20736 zsh/curses
20737 curses windowing commands
20738
20739 zsh/datetime
20740 Some date/time commands and parameters.
20741
20742 zsh/db/gdbm
20743 Builtins for managing associative array parameters tied to GDBM
20744 databases.
20745
20746 zsh/deltochar
20747 A ZLE function duplicating EMACS' zap-to-char.
20748
20749 zsh/example
20750 An example of how to write a module.
20751
20752 zsh/files
20753 Some basic file manipulation commands as builtins.
20754
20755 zsh/langinfo
20756 Interface to locale information.
20757
20758 zsh/mapfile
20759 Access to external files via a special associative array.
20760
20761 zsh/mathfunc
20762 Standard scientific functions for use in mathematical evalua‐
20763 tions.
20764
20765 zsh/nearcolor
20766 Map colours to the nearest colour in the available palette.
20767
20768 zsh/newuser
20769 Arrange for files for new users to be installed.
20770
20771 zsh/parameter
20772 Access to internal hash tables via special associative arrays.
20773
20774 zsh/pcre
20775 Interface to the PCRE library.
20776
20777 zsh/param/private
20778 Builtins for managing private-scoped parameters in function con‐
20779 text.
20780
20781 zsh/regex
20782 Interface to the POSIX regex library.
20783
20784 zsh/sched
20785 A builtin that provides a timed execution facility within the
20786 shell.
20787
20788 zsh/net/socket
20789 Manipulation of Unix domain sockets
20790
20791 zsh/stat
20792 A builtin command interface to the stat system call.
20793
20794 zsh/system
20795 A builtin interface to various low-level system features.
20796
20797 zsh/net/tcp
20798 Manipulation of TCP sockets
20799
20800 zsh/termcap
20801 Interface to the termcap database.
20802
20803 zsh/terminfo
20804 Interface to the terminfo database.
20805
20806 zsh/watch
20807 Reporting of login and logout events.
20808
20809 zsh/zftp
20810 A builtin FTP client.
20811
20812 zsh/zle
20813 The Zsh Line Editor, including the bindkey and vared builtins.
20814
20815 zsh/zleparameter
20816 Access to internals of the Zsh Line Editor via parameters.
20817
20818 zsh/zprof
20819 A module allowing profiling for shell functions.
20820
20821 zsh/zpty
20822 A builtin for starting a command in a pseudo-terminal.
20823
20824 zsh/zselect
20825 Block and return when file descriptors are ready.
20826
20827 zsh/zutil
20828 Some utility builtins, e.g. the one for supporting configuration
20829 via styles.
20830
20832 The zsh/attr module is used for manipulating extended attributes. The
20833 -h option causes all commands to operate on symbolic links instead of
20834 their targets. The builtins in this module are:
20835
20836 zgetattr [ -h ] filename attribute [ parameter ]
20837 Get the extended attribute attribute from the specified file‐
20838 name. If the optional argument parameter is given, the attribute
20839 is set on that parameter instead of being printed to stdout.
20840
20841 zsetattr [ -h ] filename attribute value
20842 Set the extended attribute attribute on the specified filename
20843 to value.
20844
20845 zdelattr [ -h ] filename attribute
20846 Remove the extended attribute attribute from the specified file‐
20847 name.
20848
20849 zlistattr [ -h ] filename [ parameter ]
20850 List the extended attributes currently set on the specified
20851 filename. If the optional argument parameter is given, the list
20852 of attributes is set on that parameter instead of being printed
20853 to stdout.
20854
20855 zgetattr and zlistattr allocate memory dynamically. If the attribute
20856 or list of attributes grows between the allocation and the call to get
20857 them, they return 2. On all other errors, 1 is returned. This allows
20858 the calling function to check for this case and retry.
20859
20861 The zsh/cap module is used for manipulating POSIX.1e (POSIX.6) capabil‐
20862 ity sets. If the operating system does not support this interface, the
20863 builtins defined by this module will do nothing. The builtins in this
20864 module are:
20865
20866 cap [ capabilities ]
20867 Change the shell's process capability sets to the specified ca‐
20868 pabilities, otherwise display the shell's current capabilities.
20869
20870 getcap filename ...
20871 This is a built-in implementation of the POSIX standard utility.
20872 It displays the capability sets on each specified filename.
20873
20874 setcap capabilities filename ...
20875 This is a built-in implementation of the POSIX standard utility.
20876 It sets the capability sets on each specified filename to the
20877 specified capabilities.
20878
20880 The zsh/clone module makes available one builtin command:
20881
20882 clone tty
20883 Creates a forked instance of the current shell, attached to the
20884 specified tty. In the new shell, the PID, PPID and TTY special
20885 parameters are changed appropriately. $! is set to zero in the
20886 new shell, and to the new shell's PID in the original shell.
20887
20888 The return status of the builtin is zero in both shells if suc‐
20889 cessful, and non-zero on error.
20890
20891 The target of clone should be an unused terminal, such as an un‐
20892 used virtual console or a virtual terminal created by
20893
20894 xterm -e sh -c 'trap : INT QUIT TSTP; tty;
20895 while :; do sleep 100000000; done'
20896
20897 Some words of explanation are warranted about this long xterm
20898 command line: when doing clone on a pseudo-terminal, some other
20899 session ("session" meant as a unix session group, or SID) is al‐
20900 ready owning the terminal. Hence the cloned zsh cannot acquire
20901 the pseudo-terminal as a controlling tty. That means two things:
20902
20903 • the job control signals will go to the
20904 sh-started-by-xterm process group (that's why we disable
20905 INT QUIT and TSTP with trap; otherwise the while loop
20906 could get suspended or killed)
20907
20908 • the cloned shell will have job control disabled, and the
20909 job control keys (control-C, control-\ and control-Z)
20910 will not work.
20911
20912 This does not apply when cloning to an unused vc.
20913
20914 Cloning to a used (and unprepared) terminal will result in two
20915 processes reading simultaneously from the same terminal, with
20916 input bytes going randomly to either process.
20917
20918 clone is mostly useful as a shell built-in replacement for
20919 openvt.
20920
20922 The zsh/compctl module makes available two builtin commands. compctl,
20923 is the old, deprecated way to control completions for ZLE. See zshcom‐
20924 pctl(1). The other builtin command, compcall can be used in user-de‐
20925 fined completion widgets, see zshcompwid(1).
20926
20928 The zsh/complete module makes available several builtin commands which
20929 can be used in user-defined completion widgets, see zshcompwid(1).
20930
20932 The zsh/complist module offers three extensions to completion listings:
20933 the ability to highlight matches in such a list, the ability to scroll
20934 through long lists and a different style of menu completion.
20935
20936 Colored completion listings
20937 Whenever one of the parameters ZLS_COLORS or ZLS_COLOURS is set and the
20938 zsh/complist module is loaded or linked into the shell, completion
20939 lists will be colored. Note, however, that complist will not automati‐
20940 cally be loaded if it is not linked in: on systems with dynamic load‐
20941 ing, `zmodload zsh/complist' is required.
20942
20943 The parameters ZLS_COLORS and ZLS_COLOURS describe how matches are
20944 highlighted. To turn on highlighting an empty value suffices, in which
20945 case all the default values given below will be used. The format of
20946 the value of these parameters is the same as used by the GNU version of
20947 the ls command: a colon-separated list of specifications of the form
20948 `name=value'. The name may be one of the following strings, most of
20949 which specify file types for which the value will be used. The strings
20950 and their default values are:
20951
20952 no 0 for normal text (i.e. when displaying something other than a
20953 matched file)
20954
20955 fi 0 for regular files
20956
20957 di 32 for directories
20958
20959 ln 36 for symbolic links. If this has the special value target, sym‐
20960 bolic links are dereferenced and the target file used to deter‐
20961 mine the display format.
20962
20963 pi 31 for named pipes (FIFOs)
20964
20965 so 33 for sockets
20966
20967 bd 44;37
20968 for block devices
20969
20970 cd 44;37
20971 for character devices
20972
20973 or none
20974 for a symlink to nonexistent file (default is the value defined
20975 for ln)
20976
20977 mi none
20978 for a non-existent file (default is the value defined for fi);
20979 this code is currently not used
20980
20981 su 37;41
20982 for files with setuid bit set
20983
20984 sg 30;43
20985 for files with setgid bit set
20986
20987 tw 30;42
20988 for world writable directories with sticky bit set
20989
20990 ow 34;43
20991 for world writable directories without sticky bit set
20992
20993 sa none
20994 for files with an associated suffix alias; this is only tested
20995 after specific suffixes, as described below
20996
20997 st 37;44
20998 for directories with sticky bit set but not world writable
20999
21000 ex 35 for executable files
21001
21002 lc \e[ for the left code (see below)
21003
21004 rc m for the right code
21005
21006 tc 0 for the character indicating the file type printed after file‐
21007 names if the LIST_TYPES option is set
21008
21009 sp 0 for the spaces printed after matches to align the next column
21010
21011 ec none
21012 for the end code
21013
21014 Apart from these strings, the name may also be an asterisk (`*') fol‐
21015 lowed by any string. The value given for such a string will be used for
21016 all files whose name ends with the string. The name may also be an
21017 equals sign (`=') followed by a pattern; the EXTENDED_GLOB option will
21018 be turned on for evaluation of the pattern. The value given for this
21019 pattern will be used for all matches (not just filenames) whose display
21020 string are matched by the pattern. Definitions for the form with the
21021 leading equal sign take precedence over the values defined for file
21022 types, which in turn take precedence over the form with the leading as‐
21023 terisk (file extensions).
21024
21025 The leading-equals form also allows different parts of the displayed
21026 strings to be colored differently. For this, the pattern has to use
21027 the `(#b)' globbing flag and pairs of parentheses surrounding the parts
21028 of the strings that are to be colored differently. In this case the
21029 value may consist of more than one color code separated by equal signs.
21030 The first code will be used for all parts for which no explicit code is
21031 specified and the following codes will be used for the parts matched by
21032 the sub-patterns in parentheses. For example, the specification
21033 `=(#b)(?)*(?)=0=3=7' will be used for all matches which are at least
21034 two characters long and will use the code `3' for the first character,
21035 `7' for the last character and `0' for the rest.
21036
21037 All three forms of name may be preceded by a pattern in parentheses.
21038 If this is given, the value will be used only for matches in groups
21039 whose names are matched by the pattern given in the parentheses. For
21040 example, `(g*)m*=43' highlights all matches beginning with `m' in
21041 groups whose names begin with `g' using the color code `43'. In case
21042 of the `lc', `rc', and `ec' codes, the group pattern is ignored.
21043
21044 Note also that all patterns are tried in the order in which they appear
21045 in the parameter value until the first one matches which is then used.
21046 Patterns may be matched against completions, descriptions (possibly
21047 with spaces appended for padding), or lines consisting of a completion
21048 followed by a description. For consistent coloring it may be necessary
21049 to use more than one pattern or a pattern with backreferences.
21050
21051 When printing a match, the code prints the value of lc, the value for
21052 the file-type or the last matching specification with a `*', the value
21053 of rc, the string to display for the match itself, and then the value
21054 of ec if that is defined or the values of lc, no, and rc if ec is not
21055 defined.
21056
21057 The default values are ISO 6429 (ANSI) compliant and can be used on
21058 vt100 compatible terminals such as xterms. On monochrome terminals the
21059 default values will have no visible effect. The colors function from
21060 the contribution can be used to get associative arrays containing the
21061 codes for ANSI terminals (see the section `Other Functions' in zshcon‐
21062 trib(1)). For example, after loading colors, one could use
21063 `$color[red]' to get the code for foreground color red and
21064 `$color[bg-green]' for the code for background color green.
21065
21066 If the completion system invoked by compinit is used, these parameters
21067 should not be set directly because the system controls them itself.
21068 Instead, the list-colors style should be used (see the section `Comple‐
21069 tion System Configuration' in zshcompsys(1)).
21070
21071 Scrolling in completion listings
21072 To enable scrolling through a completion list, the LISTPROMPT parameter
21073 must be set. Its value will be used as the prompt; if it is the empty
21074 string, a default prompt will be used. The value may contain escapes
21075 of the form `%x'. It supports the escapes `%B', `%b', `%S', `%s',
21076 `%U', `%u', `%F', `%f', `%K', `%k' and `%{...%}' used also in shell
21077 prompts as well as three pairs of additional sequences: a `%l' or `%L'
21078 is replaced by the number of the last line shown and the total number
21079 of lines in the form `number/total'; a `%m' or `%M' is replaced with
21080 the number of the last match shown and the total number of matches; and
21081 `%p' or `%P' is replaced with `Top', `Bottom' or the position of the
21082 first line shown in percent of the total number of lines, respectively.
21083 In each of these cases the form with the uppercase letter will be re‐
21084 placed with a string of fixed width, padded to the right with spaces,
21085 while the lowercase form will not be padded.
21086
21087 If the parameter LISTPROMPT is set, the completion code will not ask if
21088 the list should be shown. Instead it immediately starts displaying the
21089 list, stopping after the first screenful, showing the prompt at the
21090 bottom, waiting for a keypress after temporarily switching to the
21091 listscroll keymap. Some of the zle functions have a special meaning
21092 while scrolling lists:
21093
21094 send-break
21095 stops listing discarding the key pressed
21096
21097 accept-line, down-history, down-line-or-history
21098 down-line-or-search, vi-down-line-or-history
21099 scrolls forward one line
21100
21101 complete-word, menu-complete, expand-or-complete
21102 expand-or-complete-prefix, menu-complete-or-expand
21103 scrolls forward one screenful
21104
21105 accept-search
21106 stop listing but take no other action
21107
21108 Every other character stops listing and immediately processes the key
21109 as usual. Any key that is not bound in the listscroll keymap or that
21110 is bound to undefined-key is looked up in the keymap currently se‐
21111 lected.
21112
21113 As for the ZLS_COLORS and ZLS_COLOURS parameters, LISTPROMPT should not
21114 be set directly when using the shell function based completion system.
21115 Instead, the list-prompt style should be used.
21116
21117 Menu selection
21118 The zsh/complist module also offers an alternative style of selecting
21119 matches from a list, called menu selection, which can be used if the
21120 shell is set up to return to the last prompt after showing a completion
21121 list (see the ALWAYS_LAST_PROMPT option in zshoptions(1)).
21122
21123 Menu selection can be invoked directly by the widget menu-select de‐
21124 fined by this module. This is a standard ZLE widget that can be bound
21125 to a key in the usual way as described in zshzle(1).
21126
21127 Alternatively, the parameter MENUSELECT can be set to an integer, which
21128 gives the minimum number of matches that must be present before menu
21129 selection is automatically turned on. This second method requires that
21130 menu completion be started, either directly from a widget such as
21131 menu-complete, or due to one of the options MENU_COMPLETE or AUTO_MENU
21132 being set. If MENUSELECT is set, but is 0, 1 or empty, menu selection
21133 will always be started during an ambiguous menu completion.
21134
21135 When using the completion system based on shell functions, the MENUSE‐
21136 LECT parameter should not be used (like the ZLS_COLORS and ZLS_COLOURS
21137 parameters described above). Instead, the menu style should be used
21138 with the select=... keyword.
21139
21140 After menu selection is started, the matches will be listed. If there
21141 are more matches than fit on the screen, only the first screenful is
21142 shown. The matches to insert into the command line can be selected
21143 from this list. In the list one match is highlighted using the value
21144 for ma from the ZLS_COLORS or ZLS_COLOURS parameter. The default value
21145 for this is `7' which forces the selected match to be highlighted using
21146 standout mode on a vt100-compatible terminal. If neither ZLS_COLORS
21147 nor ZLS_COLOURS is set, the same terminal control sequence as for the
21148 `%S' escape in prompts is used.
21149
21150 If there are more matches than fit on the screen and the parameter
21151 MENUPROMPT is set, its value will be shown below the matches. It sup‐
21152 ports the same escape sequences as LISTPROMPT, but the number of the
21153 match or line shown will be that of the one where the mark is placed.
21154 If its value is the empty string, a default prompt will be used.
21155
21156 The MENUSCROLL parameter can be used to specify how the list is
21157 scrolled. If the parameter is unset, this is done line by line, if it
21158 is set to `0' (zero), the list will scroll half the number of lines of
21159 the screen. If the value is positive, it gives the number of lines to
21160 scroll and if it is negative, the list will be scrolled the number of
21161 lines of the screen minus the (absolute) value.
21162
21163 As for the ZLS_COLORS, ZLS_COLOURS and LISTPROMPT parameters, neither
21164 MENUPROMPT nor MENUSCROLL should be set directly when using the shell
21165 function based completion system. Instead, the select-prompt and se‐
21166 lect-scroll styles should be used.
21167
21168 The completion code sometimes decides not to show all of the matches in
21169 the list. These hidden matches are either matches for which the com‐
21170 pletion function which added them explicitly requested that they not
21171 appear in the list (using the -n option of the compadd builtin command)
21172 or they are matches which duplicate a string already in the list (be‐
21173 cause they differ only in things like prefixes or suffixes that are not
21174 displayed). In the list used for menu selection, however, even these
21175 matches are shown so that it is possible to select them. To highlight
21176 such matches the hi and du capabilities in the ZLS_COLORS and
21177 ZLS_COLOURS parameters are supported for hidden matches of the first
21178 and second kind, respectively.
21179
21180 Selecting matches is done by moving the mark around using the zle move‐
21181 ment functions. When not all matches can be shown on the screen at the
21182 same time, the list will scroll up and down when crossing the top or
21183 bottom line. The following zle functions have special meaning during
21184 menu selection. Note that the following always perform the same task
21185 within the menu selection map and cannot be replaced by user defined
21186 widgets, nor can the set of functions be extended:
21187
21188 accept-line, accept-search
21189 accept the current match and leave menu selection (but do not
21190 cause the command line to be accepted)
21191
21192 send-break
21193 leaves menu selection and restores the previous contents of the
21194 command line
21195
21196 redisplay, clear-screen
21197 execute their normal function without leaving menu selection
21198
21199 accept-and-hold, accept-and-menu-complete
21200 accept the currently inserted match and continue selection al‐
21201 lowing to select the next match to insert into the line
21202
21203 accept-and-infer-next-history
21204 accepts the current match and then tries completion with menu
21205 selection again; in the case of files this allows one to select
21206 a directory and immediately attempt to complete files in it; if
21207 there are no matches, a message is shown and one can use undo to
21208 go back to completion on the previous level, every other key
21209 leaves menu selection (including the other zle functions which
21210 are otherwise special during menu selection)
21211
21212 undo removes matches inserted during the menu selection by one of the
21213 three functions before
21214
21215 down-history, down-line-or-history
21216 vi-down-line-or-history, down-line-or-search
21217 moves the mark one line down
21218
21219 up-history, up-line-or-history
21220 vi-up-line-or-history, up-line-or-search
21221 moves the mark one line up
21222
21223 forward-char, vi-forward-char
21224 moves the mark one column right
21225
21226 backward-char, vi-backward-char
21227 moves the mark one column left
21228
21229 forward-word, vi-forward-word
21230 vi-forward-word-end, emacs-forward-word
21231 moves the mark one screenful down
21232
21233 backward-word, vi-backward-word, emacs-backward-word
21234 moves the mark one screenful up
21235
21236 vi-forward-blank-word, vi-forward-blank-word-end
21237 moves the mark to the first line of the next group of matches
21238
21239 vi-backward-blank-word
21240 moves the mark to the last line of the previous group of matches
21241
21242 beginning-of-history
21243 moves the mark to the first line
21244
21245 end-of-history
21246 moves the mark to the last line
21247
21248 beginning-of-buffer-or-history, beginning-of-line
21249 beginning-of-line-hist, vi-beginning-of-line
21250 moves the mark to the leftmost column
21251
21252 end-of-buffer-or-history, end-of-line
21253 end-of-line-hist, vi-end-of-line
21254 moves the mark to the rightmost column
21255
21256 complete-word, menu-complete, expand-or-complete
21257 expand-or-complete-prefix, menu-expand-or-complete
21258 moves the mark to the next match
21259
21260 reverse-menu-complete
21261 moves the mark to the previous match
21262
21263 vi-insert
21264 this toggles between normal and interactive mode; in interactive
21265 mode the keys bound to self-insert and self-insert-unmeta insert
21266 into the command line as in normal editing mode but without
21267 leaving menu selection; after each character completion is tried
21268 again and the list changes to contain only the new matches; the
21269 completion widgets make the longest unambiguous string be in‐
21270 serted in the command line and undo and backward-delete-char go
21271 back to the previous set of matches
21272
21273 history-incremental-search-forward
21274 history-incremental-search-backward
21275 this starts incremental searches in the list of completions dis‐
21276 played; in this mode, accept-line only leaves incremental
21277 search, going back to the normal menu selection mode
21278
21279 All movement functions wrap around at the edges; any other zle function
21280 not listed leaves menu selection and executes that function. It is
21281 possible to make widgets in the above list do the same by using the
21282 form of the widget with a `.' in front. For example, the widget `.ac‐
21283 cept-line' has the effect of leaving menu selection and accepting the
21284 entire command line.
21285
21286 During this selection the widget uses the keymap menuselect. Any key
21287 that is not defined in this keymap or that is bound to undefined-key is
21288 looked up in the keymap currently selected. This is used to ensure
21289 that the most important keys used during selection (namely the cursor
21290 keys, return, and TAB) have sensible defaults. However, keys in the
21291 menuselect keymap can be modified directly using the bindkey builtin
21292 command (see zshmodules(1)). For example, to make the return key leave
21293 menu selection without accepting the match currently selected one could
21294 call
21295
21296 bindkey -M menuselect '^M' send-break
21297
21298 after loading the zsh/complist module.
21299
21301 The zsh/computil module adds several builtin commands that are used by
21302 some of the completion functions in the completion system based on
21303 shell functions (see zshcompsys(1) ). Except for compquote these
21304 builtin commands are very specialised and thus not very interesting
21305 when writing your own completion functions. In summary, these builtin
21306 commands are:
21307
21308 comparguments
21309 This is used by the _arguments function to do the argument and
21310 command line parsing. Like compdescribe it has an option -i to
21311 do the parsing and initialize some internal state and various
21312 options to access the state information to decide what should be
21313 completed.
21314
21315 compdescribe
21316 This is used by the _describe function to build the displays for
21317 the matches and to get the strings to add as matches with their
21318 options. On the first call one of the options -i or -I should
21319 be supplied as the first argument. In the first case, display
21320 strings without the descriptions will be generated, in the sec‐
21321 ond case, the string used to separate the matches from their de‐
21322 scriptions must be given as the second argument and the descrip‐
21323 tions (if any) will be shown. All other arguments are like the
21324 definition arguments to _describe itself.
21325
21326 Once compdescribe has been called with either the -i or the -I
21327 option, it can be repeatedly called with the -g option and the
21328 names of four parameters as its arguments. This will step
21329 through the different sets of matches and store the value of
21330 compstate[list] in the first scalar, the options for compadd in
21331 the second array, the matches in the third array, and the
21332 strings to be displayed in the completion listing in the fourth
21333 array. The arrays may then be directly given to compadd to reg‐
21334 ister the matches with the completion code.
21335
21336 compfiles
21337 Used by the _path_files function to optimize complex recursive
21338 filename generation (globbing). It does three things. With the
21339 -p and -P options it builds the glob patterns to use, including
21340 the paths already handled and trying to optimize the patterns
21341 with respect to the prefix and suffix from the line and the
21342 match specification currently used. The -i option does the di‐
21343 rectory tests for the ignore-parents style and the -r option
21344 tests if a component for some of the matches are equal to the
21345 string on the line and removes all other matches if that is
21346 true.
21347
21348 compgroups
21349 Used by the _tags function to implement the internals of the
21350 group-order style. This only takes its arguments as names of
21351 completion groups and creates the groups for it (all six types:
21352 sorted and unsorted, both without removing duplicates, with re‐
21353 moving all duplicates and with removing consecutive duplicates).
21354
21355 compquote [ -p ] names ...
21356 There may be reasons to write completion functions that have to
21357 add the matches using the -Q option to compadd and perform quot‐
21358 ing themselves. Instead of interpreting the first character of
21359 the all_quotes key of the compstate special association and us‐
21360 ing the q flag for parameter expansions, one can use this
21361 builtin command. The arguments are the names of scalar or array
21362 parameters and the values of these parameters are quoted as
21363 needed for the innermost quoting level. If the -p option is
21364 given, quoting is done as if there is some prefix before the
21365 values of the parameters, so that a leading equal sign will not
21366 be quoted.
21367
21368 The return status is non-zero in case of an error and zero oth‐
21369 erwise.
21370
21371 comptags
21372 comptry
21373 These implement the internals of the tags mechanism.
21374
21375 compvalues
21376 Like comparguments, but for the _values function.
21377
21379 The zsh/curses module makes available one builtin command and various
21380 parameters.
21381
21382 Builtin
21383 zcurses init
21384 zcurses end
21385 zcurses addwin targetwin nlines ncols begin_y begin_x [ parentwin ]
21386 zcurses delwin targetwin
21387 zcurses refresh [ targetwin ... ]
21388 zcurses touch targetwin ...
21389 zcurses move targetwin new_y new_x
21390 zcurses clear targetwin [ redraw | eol | bot ]
21391 zcurses position targetwin array
21392 zcurses char targetwin character
21393 zcurses string targetwin string
21394 zcurses border targetwin border
21395 zcurses attr targetwin [ [+|-]attribute | fg_col/bg_col ] [...]
21396 zcurses bg targetwin [ [+|-]attribute | fg_col/bg_col | @char ] [...]
21397 zcurses scroll targetwin [ on | off | [+|-]lines ]
21398 zcurses input targetwin [ param [ kparam [ mparam ] ] ]
21399 zcurses mouse [ delay num | [+|-]motion ]
21400 zcurses timeout targetwin intval
21401 zcurses querychar targetwin [ param ]
21402 zcurses resize height width [ endwin | nosave | endwin_nosave ]
21403 Manipulate curses windows. All uses of this command should be
21404 bracketed by `zcurses init' to initialise use of curses, and
21405 `zcurses end' to end it; omitting `zcurses end' can cause the
21406 terminal to be in an unwanted state.
21407
21408 The subcommand addwin creates a window with nlines lines and
21409 ncols columns. Its upper left corner will be placed at row be‐
21410 gin_y and column begin_x of the screen. targetwin is a string
21411 and refers to the name of a window that is not currently as‐
21412 signed. Note in particular the curses convention that vertical
21413 values appear before horizontal values.
21414
21415 If addwin is given an existing window as the final argument, the
21416 new window is created as a subwindow of parentwin. This differs
21417 from an ordinary new window in that the memory of the window
21418 contents is shared with the parent's memory. Subwindows must be
21419 deleted before their parent. Note that the coordinates of sub‐
21420 windows are relative to the screen, not the parent, as with
21421 other windows.
21422
21423 Use the subcommand delwin to delete a window created with ad‐
21424 dwin. Note that end does not implicitly delete windows, and
21425 that delwin does not erase the screen image of the window.
21426
21427 The window corresponding to the full visible screen is called
21428 stdscr; it always exists after `zcurses init' and cannot be
21429 delete with delwin.
21430
21431 The subcommand refresh will refresh window targetwin; this is
21432 necessary to make any pending changes (such as characters you
21433 have prepared for output with char) visible on the screen. re‐
21434 fresh without an argument causes the screen to be cleared and
21435 redrawn. If multiple windows are given, the screen is updated
21436 once at the end.
21437
21438 The subcommand touch marks the targetwins listed as changed.
21439 This is necessary before refreshing windows if a window that was
21440 in front of another window (which may be stdscr) is deleted.
21441
21442 The subcommand move moves the cursor position in targetwin to
21443 new coordinates new_y and new_x. Note that the subcommand
21444 string (but not the subcommand char) advances the cursor posi‐
21445 tion over the characters added.
21446
21447 The subcommand clear erases the contents of targetwin. One (and
21448 no more than one) of three options may be specified. With the
21449 option redraw, in addition the next refresh of targetwin will
21450 cause the screen to be cleared and repainted. With the option
21451 eol, targetwin is only cleared to the end of the current cursor
21452 line. With the option bot, targetwin is cleared to the end of
21453 the window, i.e everything to the right and below the cursor is
21454 cleared.
21455
21456 The subcommand position writes various positions associated with
21457 targetwin into the array named array. These are, in order:
21458 - The y and x coordinates of the cursor relative to the top
21459 left of targetwin
21460 - The y and x coordinates of the top left of targetwin on
21461 the screen
21462 - The size of targetwin in y and x dimensions.
21463
21464 Outputting characters and strings are achieved by char and
21465 string respectively.
21466
21467 To draw a border around window targetwin, use border. Note that
21468 the border is not subsequently handled specially: in other
21469 words, the border is simply a set of characters output at the
21470 edge of the window. Hence it can be overwritten, can scroll off
21471 the window, etc.
21472
21473 The subcommand attr will set targetwin's attributes or fore‐
21474 ground/background color pair for any successive character out‐
21475 put. Each attribute given on the line may be prepended by a +
21476 to set or a - to unset that attribute; + is assumed if absent.
21477 The attributes supported are blink, bold, dim, reverse, stand‐
21478 out, and underline.
21479
21480 Each fg_col/bg_col attribute (to be read as `fg_col on bg_col')
21481 sets the foreground and background color for character output.
21482 The color default is sometimes available (in particular if the
21483 library is ncurses), specifying the foreground or background
21484 color with which the terminal started. The color pair de‐
21485 fault/default is always available. To use more than the 8 named
21486 colors (red, green, etc.) construct the fg_col/bg_col pairs
21487 where fg_col and bg_col are decimal integers, e.g 128/200. The
21488 maximum color value is 254 if the terminal supports 256 colors.
21489
21490 bg overrides the color and other attributes of all characters in
21491 the window. Its usual use is to set the background initially,
21492 but it will overwrite the attributes of any characters at the
21493 time when it is called. In addition to the arguments allowed
21494 with attr, an argument @char specifies a character to be shown
21495 in otherwise blank areas of the window. Owing to limitations of
21496 curses this cannot be a multibyte character (use of ASCII char‐
21497 acters only is recommended). As the specified set of attributes
21498 override the existing background, turning attributes off in the
21499 arguments is not useful, though this does not cause an error.
21500
21501 The subcommand scroll can be used with on or off to enabled or
21502 disable scrolling of a window when the cursor would otherwise
21503 move below the window due to typing or output. It can also be
21504 used with a positive or negative integer to scroll the window up
21505 or down the given number of lines without changing the current
21506 cursor position (which therefore appears to move in the opposite
21507 direction relative to the window). In the second case, if
21508 scrolling is off it is temporarily turned on to allow the window
21509 to be scrolled.
21510
21511 The subcommand input reads a single character from the window
21512 without echoing it back. If param is supplied the character is
21513 assigned to the parameter param, else it is assigned to the pa‐
21514 rameter REPLY.
21515
21516 If both param and kparam are supplied, the key is read in `key‐
21517 pad' mode. In this mode special keys such as function keys and
21518 arrow keys return the name of the key in the parameter kparam.
21519 The key names are the macros defined in the curses.h or
21520 ncurses.h with the prefix `KEY_' removed; see also the descrip‐
21521 tion of the parameter zcurses_keycodes below. Other keys cause
21522 a value to be set in param as before. On a successful return
21523 only one of param or kparam contains a non-empty string; the
21524 other is set to an empty string.
21525
21526 If mparam is also supplied, input attempts to handle mouse in‐
21527 put. This is only available with the ncurses library; mouse
21528 handling can be detected by checking for the exit status of
21529 `zcurses mouse' with no arguments. If a mouse button is clicked
21530 (or double- or triple-clicked, or pressed or released with a
21531 configurable delay from being clicked) then kparam is set to the
21532 string MOUSE, and mparam is set to an array consisting of the
21533 following elements:
21534 - An identifier to discriminate different input devices;
21535 this is only rarely useful.
21536 - The x, y and z coordinates of the mouse click relative to
21537 the full screen, as three elements in that order (i.e.
21538 the y coordinate is, unusually, after the x coordinate).
21539 The z coordinate is only available for a few unusual in‐
21540 put devices and is otherwise set to zero.
21541 - Any events that occurred as separate items; usually there
21542 will be just one. An event consists of PRESSED, RE‐
21543 LEASED, CLICKED, DOUBLE_CLICKED or TRIPLE_CLICKED fol‐
21544 lowed immediately (in the same element) by the number of
21545 the button.
21546 - If the shift key was pressed, the string SHIFT.
21547 - If the control key was pressed, the string CTRL.
21548 - If the alt key was pressed, the string ALT.
21549
21550 Not all mouse events may be passed through to the terminal win‐
21551 dow; most terminal emulators handle some mouse events them‐
21552 selves. Note that the ncurses manual implies that using input
21553 both with and without mouse handling may cause the mouse cursor
21554 to appear and disappear.
21555
21556 The subcommand mouse can be used to configure the use of the
21557 mouse. There is no window argument; mouse options are global.
21558 `zcurses mouse' with no arguments returns status 0 if mouse han‐
21559 dling is possible, else status 1. Otherwise, the possible argu‐
21560 ments (which may be combined on the same command line) are as
21561 follows. delay num sets the maximum delay in milliseconds be‐
21562 tween press and release events to be considered as a click; the
21563 value 0 disables click resolution, and the default is one sixth
21564 of a second. motion proceeded by an optional `+' (the default)
21565 or - turns on or off reporting of mouse motion in addition to
21566 clicks, presses and releases, which are always reported. How‐
21567 ever, it appears reports for mouse motion are not currently im‐
21568 plemented.
21569
21570 The subcommand timeout specifies a timeout value for input from
21571 targetwin. If intval is negative, `zcurses input' waits indefi‐
21572 nitely for a character to be typed; this is the default. If
21573 intval is zero, `zcurses input' returns immediately; if there is
21574 typeahead it is returned, else no input is done and status 1 is
21575 returned. If intval is positive, `zcurses input' waits intval
21576 milliseconds for input and if there is none at the end of that
21577 period returns status 1.
21578
21579 The subcommand querychar queries the character at the current
21580 cursor position. The return values are stored in the array
21581 named param if supplied, else in the array reply. The first
21582 value is the character (which may be a multibyte character if
21583 the system supports them); the second is the color pair in the
21584 usual fg_col/bg_col notation, or 0 if color is not supported.
21585 Any attributes other than color that apply to the character, as
21586 set with the subcommand attr, appear as additional elements.
21587
21588 The subcommand resize resizes stdscr and all windows to given
21589 dimensions (windows that stick out from the new dimensions are
21590 resized down). The underlying curses extension (resize_term
21591 call) can be unavailable. To verify, zeroes can be used for
21592 height and width. If the result of the subcommand is 0, re‐
21593 size_term is available (2 otherwise). Tests show that resizing
21594 can be normally accomplished by calling zcurses end and zcurses
21595 refresh. The resize subcommand is provided for versatility. Mul‐
21596 tiple system configurations have been checked and zcurses end
21597 and zcurses refresh are still needed for correct terminal state
21598 after resize. To invoke them with resize, use endwin argument.
21599 Using nosave argument will cause new terminal state to not be
21600 saved internally by zcurses. This is also provided for versatil‐
21601 ity and should normally be not needed.
21602
21603 Parameters
21604 ZCURSES_COLORS
21605 Readonly integer. The maximum number of colors the terminal
21606 supports. This value is initialised by the curses library and
21607 is not available until the first time zcurses init is run.
21608
21609 ZCURSES_COLOR_PAIRS
21610 Readonly integer. The maximum number of color pairs
21611 fg_col/bg_col that may be defined in `zcurses attr' commands;
21612 note this limit applies to all color pairs that have been used
21613 whether or not they are currently active. This value is ini‐
21614 tialised by the curses library and is not available until the
21615 first time zcurses init is run.
21616
21617 zcurses_attrs
21618 Readonly array. The attributes supported by zsh/curses; avail‐
21619 able as soon as the module is loaded.
21620
21621 zcurses_colors
21622 Readonly array. The colors supported by zsh/curses; available
21623 as soon as the module is loaded.
21624
21625 zcurses_keycodes
21626 Readonly array. The values that may be returned in the second
21627 parameter supplied to `zcurses input' in the order in which they
21628 are defined internally by curses. Not all function keys are
21629 listed, only F0; curses reserves space for F0 up to F63.
21630
21631 zcurses_windows
21632 Readonly array. The current list of windows, i.e. all windows
21633 that have been created with `zcurses addwin' and not removed
21634 with `zcurses delwin'.
21635
21637 The zsh/datetime module makes available one builtin command:
21638
21639 strftime [ -s scalar | -n ] format [ epochtime [ nanoseconds ] ]
21640 strftime -r [ -q ] [ -s scalar | -n ] format timestring
21641 Output the date in the format specified. With no epochtime, the
21642 current system date/time is used; optionally, epochtime may be
21643 used to specify the number of seconds since the epoch, and
21644 nanoseconds may additionally be used to specify the number of
21645 nanoseconds past the second (otherwise that number is assumed to
21646 be 0). See strftime(3) for details. The zsh extensions de‐
21647 scribed in the section EXPANSION OF PROMPT SEQUENCES in zsh‐
21648 misc(1) are also available.
21649
21650 -n Suppress printing a newline after the formatted string.
21651
21652 -q Run quietly; suppress printing of all error messages de‐
21653 scribed below. Errors for invalid epochtime values are
21654 always printed.
21655
21656 -r With the option -r (reverse), use format to parse the in‐
21657 put string timestring and output the number of seconds
21658 since the epoch at which the time occurred. The parsing
21659 is implemented by the system function strptime; see strp‐
21660 time(3). This means that zsh format extensions are not
21661 available, but for reverse lookup they are not required.
21662
21663 In most implementations of strftime any timezone in the
21664 timestring is ignored and the local timezone declared by
21665 the TZ environment variable is used; other parameters are
21666 set to zero if not present.
21667
21668 If timestring does not match format the command returns
21669 status 1 and prints an error message. If timestring
21670 matches format but not all characters in timestring were
21671 used, the conversion succeeds but also prints an error
21672 message.
21673
21674 If either of the system functions strptime or mktime is
21675 not available, status 2 is returned and an error message
21676 is printed.
21677
21678 -s scalar
21679 Assign the date string (or epoch time in seconds if -r is
21680 given) to scalar instead of printing it.
21681
21682 Note that depending on the system's declared integral time type,
21683 strftime may produce incorrect results for epoch times greater
21684 than 2147483647 which corresponds to 2038-01-19 03:14:07 +0000.
21685
21686 The zsh/datetime module makes available several parameters; all are
21687 readonly:
21688
21689 EPOCHREALTIME
21690 A floating point value representing the number of seconds since
21691 the epoch. The notional accuracy is to nanoseconds if the
21692 clock_gettime call is available and to microseconds otherwise,
21693 but in practice the range of double precision floating point and
21694 shell scheduling latencies may be significant effects.
21695
21696 EPOCHSECONDS
21697 An integer value representing the number of seconds since the
21698 epoch.
21699
21700 epochtime
21701 An array value containing the number of seconds since the epoch
21702 in the first element and the remainder of the time since the
21703 epoch in nanoseconds in the second element. To ensure the two
21704 elements are consistent the array should be copied or otherwise
21705 referenced as a single substitution before the values are used.
21706 The following idiom may be used:
21707
21708 for secs nsecs in $epochtime; do
21709 ...
21710 done
21711
21713 The zsh/db/gdbm module is used to create "tied" associative arrays that
21714 interface to database files. If the GDBM interface is not available,
21715 the builtins defined by this module will report an error. This module
21716 is also intended as a prototype for creating additional database inter‐
21717 faces, so the ztie builtin may move to a more generic module in the fu‐
21718 ture.
21719
21720 The builtins in this module are:
21721
21722 ztie -d db/gdbm -f filename [ -r ] arrayname
21723 Open the GDBM database identified by filename and, if success‐
21724 ful, create the associative array arrayname linked to the file.
21725 To create a local tied array, the parameter must first be de‐
21726 clared, so commands similar to the following would be executed
21727 inside a function scope:
21728
21729 local -A sampledb
21730 ztie -d db/gdbm -f sample.gdbm sampledb
21731
21732 The -r option opens the database file for reading only, creating
21733 a parameter with the readonly attribute. Without this option,
21734 using `ztie' on a file for which the user does not have write
21735 permission is an error. If writable, the database is opened
21736 synchronously so fields changed in arrayname are immediately
21737 written to filename.
21738
21739 Changes to the file modes filename after it has been opened do
21740 not alter the state of arrayname, but `typeset -r arrayname'
21741 works as expected.
21742
21743 zuntie [ -u ] arrayname ...
21744 Close the GDBM database associated with each arrayname and then
21745 unset the parameter. The -u option forces an unset of parame‐
21746 ters made readonly with `ztie -r'.
21747
21748 This happens automatically if the parameter is explicitly unset
21749 or its local scope (function) ends. Note that a readonly param‐
21750 eter may not be explicitly unset, so the only way to unset a
21751 global parameter created with `ztie -r' is to use `zuntie -u'.
21752
21753 zgdbmpath parametername
21754 Put path to database file assigned to parametername into REPLY
21755 scalar.
21756
21757 zgdbm_tied
21758 Array holding names of all tied parameters.
21759
21760 The fields of an associative array tied to GDBM are neither cached nor
21761 otherwise stored in memory, they are read from or written to the data‐
21762 base on each reference. Thus, for example, the values in a readonly
21763 array may be changed by a second writer of the same database file.
21764
21766 The zsh/deltochar module makes available two ZLE functions:
21767
21768 delete-to-char
21769 Read a character from the keyboard, and delete from the cursor
21770 position up to and including the next (or, with repeat count n,
21771 the nth) instance of that character. Negative repeat counts
21772 mean delete backwards.
21773
21774 zap-to-char
21775 This behaves like delete-to-char, except that the final occur‐
21776 rence of the character itself is not deleted.
21777
21779 The zsh/example module makes available one builtin command:
21780
21781 example [ -flags ] [ args ... ]
21782 Displays the flags and arguments it is invoked with.
21783
21784 The purpose of the module is to serve as an example of how to write a
21785 module.
21786
21788 The zsh/files module makes available some common commands for file ma‐
21789 nipulation as builtins; these commands are probably not needed for many
21790 normal situations but can be useful in emergency recovery situations
21791 with constrained resources. The commands do not implement all features
21792 now required by relevant standards committees.
21793
21794 For all commands, a variant beginning zf_ is also available and loaded
21795 automatically. Using the features capability of zmodload will let you
21796 load only those names you want. Note that it's possible to load only
21797 the builtins with zsh-specific names using the following command:
21798
21799 zmodload -m -F zsh/files b:zf_\*
21800
21801 The commands loaded by default are:
21802
21803 chgrp [ -hRs ] group filename ...
21804 Changes group of files specified. This is equivalent to chown
21805 with a user-spec argument of `:group'.
21806
21807 chmod [ -Rs ] mode filename ...
21808 Changes mode of files specified.
21809
21810 The specified mode must be in octal.
21811
21812 The -R option causes chmod to recursively descend into directo‐
21813 ries, changing the mode of all files in the directory after
21814 changing the mode of the directory itself.
21815
21816 The -s option is a zsh extension to chmod functionality. It en‐
21817 ables paranoid behaviour, intended to avoid security problems
21818 involving a chmod being tricked into affecting files other than
21819 the ones intended. It will refuse to follow symbolic links, so
21820 that (for example) ``chmod 600 /tmp/foo/passwd'' can't acciden‐
21821 tally chmod /etc/passwd if /tmp/foo happens to be a link to
21822 /etc. It will also check where it is after leaving directories,
21823 so that a recursive chmod of a deep directory tree can't end up
21824 recursively chmoding /usr as a result of directories being moved
21825 up the tree.
21826
21827 chown [ -hRs ] user-spec filename ...
21828 Changes ownership and group of files specified.
21829
21830 The user-spec can be in four forms:
21831
21832 user change owner to user; do not change group
21833 user:: change owner to user; do not change group
21834 user: change owner to user; change group to user's primary
21835 group
21836 user:group
21837 change owner to user; change group to group
21838 :group do not change owner; change group to group
21839
21840 In each case, the `:' may instead be a `.'. The rule is that if
21841 there is a `:' then the separator is `:', otherwise if there is
21842 a `.' then the separator is `.', otherwise there is no separa‐
21843 tor.
21844
21845 Each of user and group may be either a username (or group name,
21846 as appropriate) or a decimal user ID (group ID). Interpretation
21847 as a name takes precedence, if there is an all-numeric username
21848 (or group name).
21849
21850 If the target is a symbolic link, the -h option causes chown to
21851 set the ownership of the link instead of its target.
21852
21853 The -R option causes chown to recursively descend into directo‐
21854 ries, changing the ownership of all files in the directory after
21855 changing the ownership of the directory itself.
21856
21857 The -s option is a zsh extension to chown functionality. It en‐
21858 ables paranoid behaviour, intended to avoid security problems
21859 involving a chown being tricked into affecting files other than
21860 the ones intended. It will refuse to follow symbolic links, so
21861 that (for example) ``chown luser /tmp/foo/passwd'' can't acci‐
21862 dentally chown /etc/passwd if /tmp/foo happens to be a link to
21863 /etc. It will also check where it is after leaving directories,
21864 so that a recursive chown of a deep directory tree can't end up
21865 recursively chowning /usr as a result of directories being moved
21866 up the tree.
21867
21868 ln [ -dfhins ] filename dest
21869 ln [ -dfhins ] filename ... dir
21870 Creates hard (or, with -s, symbolic) links. In the first form,
21871 the specified destination is created, as a link to the specified
21872 filename. In the second form, each of the filenames is taken in
21873 turn, and linked to a pathname in the specified directory that
21874 has the same last pathname component.
21875
21876 Normally, ln will not attempt to create hard links to directo‐
21877 ries. This check can be overridden using the -d option. Typi‐
21878 cally only the super-user can actually succeed in creating hard
21879 links to directories. This does not apply to symbolic links in
21880 any case.
21881
21882 By default, existing files cannot be replaced by links. The -i
21883 option causes the user to be queried about replacing existing
21884 files. The -f option causes existing files to be silently
21885 deleted, without querying. -f takes precedence.
21886
21887 The -h and -n options are identical and both exist for compati‐
21888 bility; either one indicates that if the target is a symlink
21889 then it should not be dereferenced. Typically this is used in
21890 combination with -sf so that if an existing link points to a di‐
21891 rectory then it will be removed, instead of followed. If this
21892 option is used with multiple filenames and the target is a sym‐
21893 bolic link pointing to a directory then the result is an error.
21894
21895 mkdir [ -p ] [ -m mode ] dir ...
21896 Creates directories. With the -p option, non-existing parent
21897 directories are first created if necessary, and there will be no
21898 complaint if the directory already exists. The -m option can be
21899 used to specify (in octal) a set of file permissions for the
21900 created directories, otherwise mode 777 modified by the current
21901 umask (see umask(2)) is used.
21902
21903 mv [ -fi ] filename dest
21904 mv [ -fi ] filename ... dir
21905 Moves files. In the first form, the specified filename is moved
21906 to the specified destination. In the second form, each of the
21907 filenames is taken in turn, and moved to a pathname in the spec‐
21908 ified directory that has the same last pathname component.
21909
21910 By default, the user will be queried before replacing any file
21911 that the user cannot write to, but writable files will be
21912 silently removed. The -i option causes the user to be queried
21913 about replacing any existing files. The -f option causes any
21914 existing files to be silently deleted, without querying. -f
21915 takes precedence.
21916
21917 Note that this mv will not move files across devices. Histori‐
21918 cal versions of mv, when actual renaming is impossible, fall
21919 back on copying and removing files; if this behaviour is de‐
21920 sired, use cp and rm manually. This may change in a future ver‐
21921 sion.
21922
21923 rm [ -dfiRrs ] filename ...
21924 Removes files and directories specified.
21925
21926 Normally, rm will not remove directories (except with the -R or
21927 -r options). The -d option causes rm to try removing directo‐
21928 ries with unlink (see unlink(2)), the same method used for
21929 files. Typically only the super-user can actually succeed in
21930 unlinking directories in this way. -d takes precedence over -R
21931 and -r.
21932
21933 By default, the user will be queried before removing any file
21934 that the user cannot write to, but writable files will be
21935 silently removed. The -i option causes the user to be queried
21936 about removing any files. The -f option causes files to be
21937 silently deleted, without querying, and suppresses all error in‐
21938 dications. -f takes precedence.
21939
21940 The -R and -r options cause rm to recursively descend into di‐
21941 rectories, deleting all files in the directory before removing
21942 the directory with the rmdir system call (see rmdir(2)).
21943
21944 The -s option is a zsh extension to rm functionality. It en‐
21945 ables paranoid behaviour, intended to avoid common security
21946 problems involving a root-run rm being tricked into removing
21947 files other than the ones intended. It will refuse to follow
21948 symbolic links, so that (for example) ``rm /tmp/foo/passwd''
21949 can't accidentally remove /etc/passwd if /tmp/foo happens to be
21950 a link to /etc. It will also check where it is after leaving
21951 directories, so that a recursive removal of a deep directory
21952 tree can't end up recursively removing /usr as a result of di‐
21953 rectories being moved up the tree.
21954
21955 rmdir dir ...
21956 Removes empty directories specified.
21957
21958 sync Calls the system call of the same name (see sync(2)), which
21959 flushes dirty buffers to disk. It might return before the I/O
21960 has actually been completed.
21961
21963 The zsh/langinfo module makes available one parameter:
21964
21965 langinfo
21966 An associative array that maps langinfo elements to their val‐
21967 ues.
21968
21969 Your implementation may support a number of the following keys:
21970
21971 CODESET, D_T_FMT, D_FMT, T_FMT, RADIXCHAR, THOUSEP, YESEXPR, NO‐
21972 EXPR, CRNCYSTR, ABDAY_{1..7}, DAY_{1..7}, ABMON_{1..12},
21973 MON_{1..12}, T_FMT_AMPM, AM_STR, PM_STR, ERA, ERA_D_FMT,
21974 ERA_D_T_FMT, ERA_T_FMT, ALT_DIGITS
21975
21977 The zsh/mapfile module provides one special associative array parameter
21978 of the same name.
21979
21980 mapfile
21981 This associative array takes as keys the names of files; the re‐
21982 sulting value is the content of the file. The value is treated
21983 identically to any other text coming from a parameter. The
21984 value may also be assigned to, in which case the file in ques‐
21985 tion is written (whether or not it originally existed); or an
21986 element may be unset, which will delete the file in question.
21987 For example, `vared 'mapfile[myfile]'' works as expected, edit‐
21988 ing the file `myfile'.
21989
21990 When the array is accessed as a whole, the keys are the names of
21991 files in the current directory, and the values are empty (to
21992 save a huge overhead in memory). Thus ${(k)mapfile} has the
21993 same effect as the glob operator *(D), since files beginning
21994 with a dot are not special. Care must be taken with expressions
21995 such as rm ${(k)mapfile}, which will delete every file in the
21996 current directory without the usual `rm *' test.
21997
21998 The parameter mapfile may be made read-only; in that case, files
21999 referenced may not be written or deleted.
22000
22001 A file may conveniently be read into an array as one line per
22002 element with the form `array=("${(f@)mapfile[filename]}")'. The
22003 double quotes and the `@' are necessary to prevent empty lines
22004 from being removed. Note that if the file ends with a newline,
22005 the shell will split on the final newline, generating an addi‐
22006 tional empty field; this can be suppressed by using `ar‐
22007 ray=("${(f@)${mapfile[filename]%$'\n'}}")'.
22008
22009 Limitations
22010 Although reading and writing of the file in question is efficiently
22011 handled, zsh's internal memory management may be arbitrarily baroque;
22012 however, mapfile is usually very much more efficient than anything in‐
22013 volving a loop. Note in particular that the whole contents of the file
22014 will always reside physically in memory when accessed (possibly multi‐
22015 ple times, due to standard parameter substitution operations). In par‐
22016 ticular, this means handling of sufficiently long files (greater than
22017 the machine's swap space, or than the range of the pointer type) will
22018 be incorrect.
22019
22020 No errors are printed or flagged for non-existent, unreadable, or un‐
22021 writable files, as the parameter mechanism is too low in the shell exe‐
22022 cution hierarchy to make this convenient.
22023
22024 It is unfortunate that the mechanism for loading modules does not yet
22025 allow the user to specify the name of the shell parameter to be given
22026 the special behaviour.
22027
22029 The zsh/mathfunc module provides standard mathematical functions for
22030 use when evaluating mathematical formulae. The syntax agrees with nor‐
22031 mal C and FORTRAN conventions, for example,
22032
22033 (( f = sin(0.3) ))
22034
22035 assigns the sine of 0.3 to the parameter f.
22036
22037 Most functions take floating point arguments and return a floating
22038 point value. However, any necessary conversions from or to integer
22039 type will be performed automatically by the shell. Apart from atan
22040 with a second argument and the abs, int and float functions, all func‐
22041 tions behave as noted in the manual page for the corresponding C func‐
22042 tion, except that any arguments out of range for the function in ques‐
22043 tion will be detected by the shell and an error reported.
22044
22045 The following functions take a single floating point argument: acos,
22046 acosh, asin, asinh, atan, atanh, cbrt, ceil, cos, cosh, erf, erfc, exp,
22047 expm1, fabs, floor, gamma, j0, j1, lgamma, log, log10, log1p, log2,
22048 logb, sin, sinh, sqrt, tan, tanh, y0, y1. The atan function can op‐
22049 tionally take a second argument, in which case it behaves like the C
22050 function atan2. The ilogb function takes a single floating point argu‐
22051 ment, but returns an integer.
22052
22053 The function signgam takes no arguments, and returns an integer, which
22054 is the C variable of the same name, as described in gamma(3). Note
22055 that it is therefore only useful immediately after a call to gamma or
22056 lgamma. Note also that `signgam()' and `signgam' are distinct expres‐
22057 sions.
22058
22059 The functions min, max, and sum are defined not in this module but in
22060 the zmathfunc autoloadable function, described in the section `Mathe‐
22061 matical Functions' in zshcontrib(1).
22062
22063 The following functions take two floating point arguments: copysign,
22064 fmod, hypot, nextafter.
22065
22066 The following take an integer first argument and a floating point sec‐
22067 ond argument: jn, yn.
22068
22069 The following take a floating point first argument and an integer sec‐
22070 ond argument: ldexp, scalb.
22071
22072 The function abs does not convert the type of its single argument; it
22073 returns the absolute value of either a floating point number or an in‐
22074 teger. The functions float and int convert their arguments into a
22075 floating point or integer value (by truncation) respectively.
22076
22077 Note that the C pow function is available in ordinary math evaluation
22078 as the `**' operator and is not provided here.
22079
22080 The function rand48 is available if your system's mathematical library
22081 has the function erand48(3). It returns a pseudo-random floating point
22082 number between 0 and 1. It takes a single string optional argument.
22083
22084 If the argument is not present, the random number seed is initialised
22085 by three calls to the rand(3) function --- this produces the same ran‐
22086 dom numbers as the next three values of $RANDOM.
22087
22088 If the argument is present, it gives the name of a scalar parameter
22089 where the current random number seed will be stored. On the first
22090 call, the value must contain at least twelve hexadecimal digits (the
22091 remainder of the string is ignored), or the seed will be initialised in
22092 the same manner as for a call to rand48 with no argument. Subsequent
22093 calls to rand48(param) will then maintain the seed in the parameter
22094 param as a string of twelve hexadecimal digits, with no base signifier.
22095 The random number sequences for different parameters are completely in‐
22096 dependent, and are also independent from that used by calls to rand48
22097 with no argument.
22098
22099 For example, consider
22100
22101 print $(( rand48(seed) ))
22102 print $(( rand48() ))
22103 print $(( rand48(seed) ))
22104
22105 Assuming $seed does not exist, it will be initialised by the first
22106 call. In the second call, the default seed is initialised; note, how‐
22107 ever, that because of the properties of rand() there is a correlation
22108 between the seeds used for the two initialisations, so for more secure
22109 uses, you should generate your own 12-byte seed. The third call re‐
22110 turns to the same sequence of random numbers used in the first call,
22111 unaffected by the intervening rand48().
22112
22114 The zsh/nearcolor module replaces colours specified as hex triplets
22115 with the nearest colour in the 88 or 256 colour palettes that are
22116 widely used by terminal emulators. By default, 24-bit true colour es‐
22117 cape codes are generated when colours are specified using hex triplets.
22118 These are not supported by all terminals. The purpose of this module
22119 is to make it easier to define colour preferences in a form that can
22120 work across a range of terminal emulators.
22121
22122 Aside from the default colour, the ANSI standard for terminal escape
22123 codes provides for eight colours. The bright attribute brings this to
22124 sixteen. These basic colours are commonly used in terminal applications
22125 due to being widely supported. Expanded 88 and 256 colour palettes are
22126 also common and, while the first sixteen colours vary somewhat between
22127 terminals and configurations, these add a generally consistent and pre‐
22128 dictable set of colours.
22129
22130 In order to use the zsh/nearcolor module, it only needs to be loaded.
22131 Thereafter, whenever a colour is specified using a hex triplet, it will
22132 be compared against each of the available colours and the closest will
22133 be selected. The first sixteen colours are never matched in this
22134 process due to being unpredictable.
22135
22136 It isn't possible to reliably detect support for true colour in the
22137 terminal emulator. It is therefore recommended to be selective in load‐
22138 ing the zsh/nearcolor module. For example, the following checks the
22139 COLORTERM environment variable:
22140
22141 [[ $COLORTERM = *(24bit|truecolor)* ]] || zmodload zsh/nearcolor
22142
22143 Note that some terminals accept the true color escape codes but map
22144 them internally to a more limited palette in a similar manner to the
22145 zsh/nearcolor module.
22146
22148 The zsh/newuser module is loaded at boot if it is available, the RCS
22149 option is set, and the PRIVILEGED option is not set (all three are true
22150 by default). This takes place immediately after commands in the global
22151 zshenv file (typically /etc/zshenv), if any, have been executed. If
22152 the module is not available it is silently ignored by the shell; the
22153 module may safely be removed from $MODULE_PATH by the administrator if
22154 it is not required.
22155
22156 On loading, the module tests if any of the start-up files .zshenv,
22157 .zprofile, .zshrc or .zlogin exist in the directory given by the envi‐
22158 ronment variable ZDOTDIR, or the user's home directory if that is not
22159 set. The test is not performed and the module halts processing if the
22160 shell was in an emulation mode (i.e. had been invoked as some other
22161 shell than zsh).
22162
22163 If none of the start-up files were found, the module then looks for the
22164 file newuser first in a sitewide directory, usually the parent direc‐
22165 tory of the site-functions directory, and if that is not found the mod‐
22166 ule searches in a version-specific directory, usually the parent of the
22167 functions directory containing version-specific functions. (These di‐
22168 rectories can be configured when zsh is built using the --en‐
22169 able-site-scriptdir=dir and --enable-scriptdir=dir flags to configure,
22170 respectively; the defaults are prefix/share/zsh and pre‐
22171 fix/share/zsh/$ZSH_VERSION where the default prefix is /usr/local.)
22172
22173 If the file newuser is found, it is then sourced in the same manner as
22174 a start-up file. The file is expected to contain code to install
22175 start-up files for the user, however any valid shell code will be exe‐
22176 cuted.
22177
22178 The zsh/newuser module is then unconditionally unloaded.
22179
22180 Note that it is possible to achieve exactly the same effect as the
22181 zsh/newuser module by adding code to /etc/zshenv. The module exists
22182 simply to allow the shell to make arrangements for new users without
22183 the need for intervention by package maintainers and system administra‐
22184 tors.
22185
22186 The script supplied with the module invokes the shell function
22187 zsh-newuser-install. This may be invoked directly by the user even if
22188 the zsh/newuser module is disabled. Note, however, that if the module
22189 is not installed the function will not be installed either. The func‐
22190 tion is documented in the section `User Configuration Functions' in
22191 zshcontrib(1).
22192
22194 The zsh/parameter module gives access to some of the internal hash ta‐
22195 bles used by the shell by defining some special parameters.
22196
22197 options
22198 The keys for this associative array are the names of the options
22199 that can be set and unset using the setopt and unsetopt
22200 builtins. The value of each key is either the string on if the
22201 option is currently set, or the string off if the option is un‐
22202 set. Setting a key to one of these strings is like setting or
22203 unsetting the option, respectively. Unsetting a key in this ar‐
22204 ray is like setting it to the value off.
22205
22206 commands
22207 This array gives access to the command hash table. The keys are
22208 the names of external commands, the values are the pathnames of
22209 the files that would be executed when the command would be in‐
22210 voked. Setting a key in this array defines a new entry in this
22211 table in the same way as with the hash builtin. Unsetting a key
22212 as in `unset "commands[foo]"' removes the entry for the given
22213 key from the command hash table.
22214
22215 functions
22216 This associative array maps names of enabled functions to their
22217 definitions. Setting a key in it is like defining a function
22218 with the name given by the key and the body given by the value.
22219 Unsetting a key removes the definition for the function named by
22220 the key.
22221
22222 dis_functions
22223 Like functions but for disabled functions.
22224
22225 functions_source
22226 This readonly associative array maps names of enabled functions
22227 to the name of the file containing the source of the function.
22228
22229 For an autoloaded function that has already been loaded, or
22230 marked for autoload with an absolute path, or that has had its
22231 path resolved with `functions -r', this is the file found for
22232 autoloading, resolved to an absolute path.
22233
22234 For a function defined within the body of a script or sourced
22235 file, this is the name of that file. In this case, this is the
22236 exact path originally used to that file, which may be a relative
22237 path.
22238
22239 For any other function, including any defined at an interactive
22240 prompt or an autoload function whose path has not yet been re‐
22241 solved, this is the empty string. However, the hash element is
22242 reported as defined just so long as the function is present:
22243 the keys to this hash are the same as those to $functions.
22244
22245 dis_functions_source
22246 Like functions_source but for disabled functions.
22247
22248 builtins
22249 This associative array gives information about the builtin com‐
22250 mands currently enabled. The keys are the names of the builtin
22251 commands and the values are either `undefined' for builtin com‐
22252 mands that will automatically be loaded from a module if invoked
22253 or `defined' for builtin commands that are already loaded.
22254
22255 dis_builtins
22256 Like builtins but for disabled builtin commands.
22257
22258 reswords
22259 This array contains the enabled reserved words.
22260
22261 dis_reswords
22262 Like reswords but for disabled reserved words.
22263
22264 patchars
22265 This array contains the enabled pattern characters.
22266
22267 dis_patchars
22268 Like patchars but for disabled pattern characters.
22269
22270 aliases
22271 This maps the names of the regular aliases currently enabled to
22272 their expansions.
22273
22274 dis_aliases
22275 Like aliases but for disabled regular aliases.
22276
22277 galiases
22278 Like aliases, but for global aliases.
22279
22280 dis_galiases
22281 Like galiases but for disabled global aliases.
22282
22283 saliases
22284 Like raliases, but for suffix aliases.
22285
22286 dis_saliases
22287 Like saliases but for disabled suffix aliases.
22288
22289 parameters
22290 The keys in this associative array are the names of the parame‐
22291 ters currently defined. The values are strings describing the
22292 type of the parameter, in the same format used by the t parame‐
22293 ter flag, see zshexpn(1) . Setting or unsetting keys in this
22294 array is not possible.
22295
22296 modules
22297 An associative array giving information about modules. The keys
22298 are the names of the modules loaded, registered to be au‐
22299 toloaded, or aliased. The value says which state the named mod‐
22300 ule is in and is one of the strings `loaded', `autoloaded', or
22301 `alias:name', where name is the name the module is aliased to.
22302
22303 Setting or unsetting keys in this array is not possible.
22304
22305 dirstack
22306 A normal array holding the elements of the directory stack. Note
22307 that the output of the dirs builtin command includes one more
22308 directory, the current working directory.
22309
22310 history
22311 This associative array maps history event numbers to the full
22312 history lines. Although it is presented as an associative ar‐
22313 ray, the array of all values (${history[@]}) is guaranteed to be
22314 returned in order from most recent to oldest history event, that
22315 is, by decreasing history event number.
22316
22317 historywords
22318 A special array containing the words stored in the history.
22319 These also appear in most to least recent order.
22320
22321 jobdirs
22322 This associative array maps job numbers to the directories from
22323 which the job was started (which may not be the current direc‐
22324 tory of the job).
22325
22326 The keys of the associative arrays are usually valid job num‐
22327 bers, and these are the values output with, for example,
22328 ${(k)jobdirs}. Non-numeric job references may be used when
22329 looking up a value; for example, ${jobdirs[%+]} refers to the
22330 current job.
22331
22332 See the jobs builtin for how job information is provided in a
22333 subshell.
22334
22335 jobtexts
22336 This associative array maps job numbers to the texts of the com‐
22337 mand lines that were used to start the jobs.
22338
22339 Handling of the keys of the associative array is as described
22340 for jobdirs above.
22341
22342 See the jobs builtin for how job information is provided in a
22343 subshell.
22344
22345 jobstates
22346 This associative array gives information about the states of the
22347 jobs currently known. The keys are the job numbers and the val‐
22348 ues are strings of the form `job-state:mark:pid=state...'. The
22349 job-state gives the state the whole job is currently in, one of
22350 `running', `suspended', or `done'. The mark is `+' for the cur‐
22351 rent job, `-' for the previous job and empty otherwise. This is
22352 followed by one `:pid=state' for every process in the job. The
22353 pids are, of course, the process IDs and the state describes the
22354 state of that process.
22355
22356 Handling of the keys of the associative array is as described
22357 for jobdirs above.
22358
22359 See the jobs builtin for how job information is provided in a
22360 subshell.
22361
22362 nameddirs
22363 This associative array maps the names of named directories to
22364 the pathnames they stand for.
22365
22366 userdirs
22367 This associative array maps user names to the pathnames of their
22368 home directories.
22369
22370 usergroups
22371 This associative array maps names of system groups of which the
22372 current user is a member to the corresponding group identifiers.
22373 The contents are the same as the groups output by the id com‐
22374 mand.
22375
22376 funcfiletrace
22377 This array contains the absolute line numbers and corresponding
22378 file names for the point where the current function, sourced
22379 file, or (if EVAL_LINENO is set) eval command was called. The
22380 array is of the same length as funcsourcetrace and functrace,
22381 but differs from funcsourcetrace in that the line and file are
22382 the point of call, not the point of definition, and differs from
22383 functrace in that all values are absolute line numbers in files,
22384 rather than relative to the start of a function, if any.
22385
22386 funcsourcetrace
22387 This array contains the file names and line numbers of the
22388 points where the functions, sourced files, and (if EVAL_LINENO
22389 is set) eval commands currently being executed were defined.
22390 The line number is the line where the `function name' or `name
22391 ()' started. In the case of an autoloaded function the line
22392 number is reported as zero. The format of each element is file‐
22393 name:lineno.
22394
22395 For functions autoloaded from a file in native zsh format, where
22396 only the body of the function occurs in the file, or for files
22397 that have been executed by the source or `.' builtins, the trace
22398 information is shown as filename:0, since the entire file is the
22399 definition. The source file name is resolved to an absolute
22400 path when the function is loaded or the path to it otherwise re‐
22401 solved.
22402
22403 Most users will be interested in the information in the func‐
22404 filetrace array instead.
22405
22406 funcstack
22407 This array contains the names of the functions, sourced files,
22408 and (if EVAL_LINENO is set) eval commands. currently being exe‐
22409 cuted. The first element is the name of the function using the
22410 parameter.
22411
22412 The standard shell array zsh_eval_context can be used to deter‐
22413 mine the type of shell construct being executed at each depth:
22414 note, however, that is in the opposite order, with the most re‐
22415 cent item last, and it is more detailed, for example including
22416 an entry for toplevel, the main shell code being executed either
22417 interactively or from a script, which is not present in $func‐
22418 stack.
22419
22420 functrace
22421 This array contains the names and line numbers of the callers
22422 corresponding to the functions currently being executed. The
22423 format of each element is name:lineno. Callers are also shown
22424 for sourced files; the caller is the point where the source or
22425 `.' command was executed.
22426
22428 The zsh/pcre module makes some commands available as builtins:
22429
22430 pcre_compile [ -aimxs ] PCRE
22431 Compiles a perl-compatible regular expression.
22432
22433 Option -a will force the pattern to be anchored. Option -i will
22434 compile a case-insensitive pattern. Option -m will compile a
22435 multi-line pattern; that is, ^ and $ will match newlines within
22436 the pattern. Option -x will compile an extended pattern,
22437 wherein whitespace and # comments are ignored. Option -s makes
22438 the dot metacharacter match all characters, including those that
22439 indicate newline.
22440
22441 pcre_study
22442 Studies the previously-compiled PCRE which may result in faster
22443 matching.
22444
22445 pcre_match [ -v var ] [ -a arr ] [ -n offset ] [ -b ] string
22446 Returns successfully if string matches the previously-compiled
22447 PCRE.
22448
22449 Upon successful match, if the expression captures substrings
22450 within parentheses, pcre_match will set the array match to those
22451 substrings, unless the -a option is given, in which case it will
22452 set the array arr. Similarly, the variable MATCH will be set to
22453 the entire matched portion of the string, unless the -v option
22454 is given, in which case the variable var will be set. No vari‐
22455 ables are altered if there is no successful match. A -n option
22456 starts searching for a match from the byte offset position in
22457 string. If the -b option is given, the variable ZPCRE_OP will
22458 be set to an offset pair string, representing the byte offset
22459 positions of the entire matched portion within the string. For
22460 example, a ZPCRE_OP set to "32 45" indicates that the matched
22461 portion began on byte offset 32 and ended on byte offset 44.
22462 Here, byte offset position 45 is the position directly after the
22463 matched portion. Keep in mind that the byte position isn't nec‐
22464 essarily the same as the character position when UTF-8 charac‐
22465 ters are involved. Consequently, the byte offset positions are
22466 only to be relied on in the context of using them for subsequent
22467 searches on string, using an offset position as an argument to
22468 the -n option. This is mostly used to implement the "find all
22469 non-overlapping matches" functionality.
22470
22471 A simple example of "find all non-overlapping matches":
22472
22473 string="The following zip codes: 78884 90210 99513"
22474 pcre_compile -m "\d{5}"
22475 accum=()
22476 pcre_match -b -- $string
22477 while [[ $? -eq 0 ]] do
22478 b=($=ZPCRE_OP)
22479 accum+=$MATCH
22480 pcre_match -b -n $b[2] -- $string
22481 done
22482 print -l $accum
22483
22484 The zsh/pcre module makes available the following test condition:
22485
22486 expr -pcre-match pcre
22487 Matches a string against a perl-compatible regular expression.
22488
22489 For example,
22490
22491 [[ "$text" -pcre-match ^d+$ ]] &&
22492 print text variable contains only "d's".
22493
22494 If the REMATCH_PCRE option is set, the =~ operator is equivalent
22495 to -pcre-match, and the NO_CASE_MATCH option may be used. Note
22496 that NO_CASE_MATCH never applies to the pcre_match builtin, in‐
22497 stead use the -i switch of pcre_compile.
22498
22500 The zsh/param/private module is used to create parameters whose scope
22501 is limited to the current function body, and not to other functions
22502 called by the current function.
22503
22504 This module provides a single autoloaded builtin:
22505
22506 private [ {+|-}AHUahlmrtux ] [ {+|-}EFLRZi [ n ] ] [ name[=value] ... ]
22507 The private builtin accepts all the same options and arguments
22508 as local (zshbuiltins(1)) except for the `-T' option. Tied pa‐
22509 rameters may not be made private.
22510
22511 The `-p' option is presently a no-op because the state of pri‐
22512 vate parameters cannot reliably be reloaded. This also applies
22513 to printing private parameters with `typeset -p'.
22514
22515 If used at the top level (outside a function scope), private
22516 creates a normal parameter in the same manner as declare or
22517 typeset. A warning about this is printed if WARN_CREATE_GLOBAL
22518 is set (zshoptions(1)). Used inside a function scope, private
22519 creates a local parameter similar to one declared with local,
22520 except having special properties noted below.
22521
22522 Special parameters which expose or manipulate internal shell
22523 state, such as ARGC, argv, COLUMNS, LINES, UID, EUID, IFS,
22524 PROMPT, RANDOM, SECONDS, etc., cannot be made private unless the
22525 `-h' option is used to hide the special meaning of the parame‐
22526 ter. This may change in the future.
22527
22528 As with other typeset equivalents, private is both a builtin and a re‐
22529 served word, so arrays may be assigned with parenthesized word list
22530 name=(value...) syntax. However, the reserved word `private' is not
22531 available until zsh/param/private is loaded, so care must be taken with
22532 order of execution and parsing for function definitions which use pri‐
22533 vate. To compensate for this, the module also adds the option `-P' to
22534 the `local' builtin to declare private parameters.
22535
22536 For example, this construction fails if zsh/param/private has not yet
22537 been loaded when `bad_declaration' is defined:
22538 bad_declaration() {
22539 zmodload zsh/param/private
22540 private array=( one two three )
22541 }
22542
22543 This construction works because local is already a keyword, and the
22544 module is loaded before the statement is executed:
22545 good_declaration() {
22546 zmodload zsh/param/private
22547 local -P array=( one two three )
22548 }
22549
22550 The following is usable in scripts but may have trouble with autoload:
22551 zmodload zsh/param/private
22552 iffy_declaration() {
22553 private array=( one two three )
22554 }
22555
22556 The private builtin may always be used with scalar assignments and for
22557 declarations without assignments.
22558
22559 Parameters declared with private have the following properties:
22560
22561 • Within the function body where it is declared, the parameter be‐
22562 haves as a local, except as noted above for tied or special pa‐
22563 rameters.
22564
22565 • The type of a parameter declared private cannot be changed in
22566 the scope where it was declared, even if the parameter is unset.
22567 Thus an array cannot be assigned to a private scalar, etc.
22568
22569 • Within any other function called by the declaring function, the
22570 private parameter does NOT hide other parameters of the same
22571 name, so for example a global parameter of the same name is vis‐
22572 ible and may be assigned or unset. This includes calls to
22573 anonymous functions, although that may also change in the fu‐
22574 ture. However, the private name may not be created outside the
22575 local scope when it was not previously declared.
22576
22577 • An exported private remains in the environment of inner scopes
22578 but appears unset for the current shell in those scopes. Gener‐
22579 ally, exporting private parameters should be avoided.
22580
22581 Note that this differs from the static scope defined by compiled lan‐
22582 guages derived from C, in that the a new call to the same function cre‐
22583 ates a new scope, i.e., the parameter is still associated with the call
22584 stack rather than with the function definition. It differs from ksh
22585 `typeset -S' because the syntax used to define the function has no
22586 bearing on whether the parameter scope is respected.
22587
22589 The zsh/regex module makes available the following test condition:
22590
22591 expr -regex-match regex
22592 Matches a string against a POSIX extended regular expression.
22593 On successful match, matched portion of the string will normally
22594 be placed in the MATCH variable. If there are any capturing
22595 parentheses within the regex, then the match array variable will
22596 contain those. If the match is not successful, then the vari‐
22597 ables will not be altered.
22598
22599 For example,
22600
22601 [[ alphabetical -regex-match ^a([^a]+)a([^a]+)a ]] &&
22602 print -l $MATCH X $match
22603
22604 If the option REMATCH_PCRE is not set, then the =~ operator will
22605 automatically load this module as needed and will invoke the
22606 -regex-match operator.
22607
22608 If BASH_REMATCH is set, then the array BASH_REMATCH will be set
22609 instead of MATCH and match.
22610
22611 Note that the zsh/regex module logic relies on the host system.
22612 The same expr and regex pair could produce different results on
22613 different platforms if a regex with non-standard syntax is
22614 given.
22615
22616 For example, no syntax for matching a word boundary is defined
22617 in the POSIX extended regular expression standard. GNU libc and
22618 BSD libc both provide such syntaxes as extensions (\b and
22619 [[:<:]]/[[:>:]] respectively), but neither of these syntaxes is
22620 supported by both of these implementations.
22621
22622 Refer to the regcomp(3) and re_format(7) manual pages on your
22623 system for locally-supported syntax.
22624
22626 The zsh/sched module makes available one builtin command and one param‐
22627 eter.
22628
22629 sched [-o] [+]hh:mm[:ss] command ...
22630 sched [-o] [+]seconds command ...
22631 sched [ -item ]
22632 Make an entry in the scheduled list of commands to execute. The
22633 time may be specified in either absolute or relative time, and
22634 either as hours, minutes and (optionally) seconds separated by a
22635 colon, or seconds alone. An absolute number of seconds indi‐
22636 cates the time since the epoch (1970/01/01 00:00); this is use‐
22637 ful in combination with the features in the zsh/datetime module,
22638 see the zsh/datetime module entry in zshmodules(1).
22639
22640 With no arguments, prints the list of scheduled commands. If
22641 the scheduled command has the -o flag set, this is shown at the
22642 start of the command.
22643
22644 With the argument `-item', removes the given item from the list.
22645 The numbering of the list is continuous and entries are in time
22646 order, so the numbering can change when entries are added or
22647 deleted.
22648
22649 Commands are executed either immediately before a prompt, or
22650 while the shell's line editor is waiting for input. In the lat‐
22651 ter case it is useful to be able to produce output that does not
22652 interfere with the line being edited. Providing the option -o
22653 causes the shell to clear the command line before the event and
22654 redraw it afterwards. This should be used with any scheduled
22655 event that produces visible output to the terminal; it is not
22656 needed, for example, with output that updates a terminal emula‐
22657 tor's title bar.
22658
22659 To effect changes to the editor buffer when an event executes,
22660 use the `zle' command with no arguments to test whether the edi‐
22661 tor is active, and if it is, then use `zle widget' to access the
22662 editor via the named widget.
22663
22664 The sched builtin is not made available by default when the
22665 shell starts in a mode emulating another shell. It can be made
22666 available with the command `zmodload -F zsh/sched b:sched'.
22667
22668 zsh_scheduled_events
22669 A readonly array corresponding to the events scheduled by the
22670 sched builtin. The indices of the array correspond to the num‐
22671 bers shown when sched is run with no arguments (provided that
22672 the KSH_ARRAYS option is not set). The value of the array con‐
22673 sists of the scheduled time in seconds since the epoch (see the
22674 section `The zsh/datetime Module' for facilities for using this
22675 number), followed by a colon, followed by any options (which may
22676 be empty but will be preceded by a `-' otherwise), followed by a
22677 colon, followed by the command to be executed.
22678
22679 The sched builtin should be used for manipulating the events.
22680 Note that this will have an immediate effect on the contents of
22681 the array, so that indices may become invalid.
22682
22684 The zsh/net/socket module makes available one builtin command:
22685
22686 zsocket [ -altv ] [ -d fd ] [ args ]
22687 zsocket is implemented as a builtin to allow full use of shell
22688 command line editing, file I/O, and job control mechanisms.
22689
22690 Outbound Connections
22691 zsocket [ -v ] [ -d fd ] filename
22692 Open a new Unix domain connection to filename. The shell param‐
22693 eter REPLY will be set to the file descriptor associated with
22694 that connection. Currently, only stream connections are sup‐
22695 ported.
22696
22697 If -d is specified, its argument will be taken as the target
22698 file descriptor for the connection.
22699
22700 In order to elicit more verbose output, use -v.
22701
22702 File descriptors can be closed with normal shell syntax when no
22703 longer needed, for example:
22704
22705 exec {REPLY}>&-
22706
22707 Inbound Connections
22708 zsocket -l [ -v ] [ -d fd ] filename
22709 zsocket -l will open a socket listening on filename. The shell
22710 parameter REPLY will be set to the file descriptor associated
22711 with that listener. The file descriptor remains open in sub‐
22712 shells and forked external executables.
22713
22714 If -d is specified, its argument will be taken as the target
22715 file descriptor for the connection.
22716
22717 In order to elicit more verbose output, use -v.
22718
22719 zsocket -a [ -tv ] [ -d targetfd ] listenfd
22720 zsocket -a will accept an incoming connection to the socket as‐
22721 sociated with listenfd. The shell parameter REPLY will be set
22722 to the file descriptor associated with the inbound connection.
22723 The file descriptor remains open in subshells and forked exter‐
22724 nal executables.
22725
22726 If -d is specified, its argument will be taken as the target
22727 file descriptor for the connection.
22728
22729 If -t is specified, zsocket will return if no incoming connec‐
22730 tion is pending. Otherwise it will wait for one.
22731
22732 In order to elicit more verbose output, use -v.
22733
22735 The zsh/stat module makes available one builtin command under two pos‐
22736 sible names:
22737
22738 zstat [ -gnNolLtTrs ] [ -f fd ] [ -H hash ] [ -A array ] [ -F fmt ]
22739 [ +element ] [ file ... ]
22740 stat ...
22741 The command acts as a front end to the stat system call (see
22742 stat(2)). The same command is provided with two names; as the
22743 name stat is often used by an external command it is recommended
22744 that only the zstat form of the command is used. This can be
22745 arranged by loading the module with the command `zmodload -F
22746 zsh/stat b:zstat'.
22747
22748 If the stat call fails, the appropriate system error message
22749 printed and status 1 is returned. The fields of struct stat
22750 give information about the files provided as arguments to the
22751 command. In addition to those available from the stat call, an
22752 extra element `link' is provided. These elements are:
22753
22754 device The number of the device on which the file resides.
22755
22756 inode The unique number of the file on this device (`inode'
22757 number).
22758
22759 mode The mode of the file; that is, the file's type and access
22760 permissions. With the -s option, this will be returned
22761 as a string corresponding to the first column in the dis‐
22762 play of the ls -l command.
22763
22764 nlink The number of hard links to the file.
22765
22766 uid The user ID of the owner of the file. With the -s op‐
22767 tion, this is displayed as a user name.
22768
22769 gid The group ID of the file. With the -s option, this is
22770 displayed as a group name.
22771
22772 rdev The raw device number. This is only useful for special
22773 devices.
22774
22775 size The size of the file in bytes.
22776
22777 atime
22778 mtime
22779 ctime The last access, modification and inode change times of
22780 the file, respectively, as the number of seconds since
22781 midnight GMT on 1st January, 1970. With the -s option,
22782 these are printed as strings for the local time zone; the
22783 format can be altered with the -F option, and with the -g
22784 option the times are in GMT.
22785
22786 blksize
22787 The number of bytes in one allocation block on the device
22788 on which the file resides.
22789
22790 block The number of disk blocks used by the file.
22791
22792 link If the file is a link and the -L option is in effect,
22793 this contains the name of the file linked to, otherwise
22794 it is empty. Note that if this element is selected
22795 (``zstat +link'') then the -L option is automatically
22796 used.
22797
22798 A particular element may be selected by including its name pre‐
22799 ceded by a `+' in the option list; only one element is allowed.
22800 The element may be shortened to any unique set of leading char‐
22801 acters. Otherwise, all elements will be shown for all files.
22802
22803 Options:
22804
22805 -A array
22806 Instead of displaying the results on standard output, as‐
22807 sign them to an array, one struct stat element per array
22808 element for each file in order. In this case neither the
22809 name of the element nor the name of the files appears in
22810 array unless the -t or -n options were given, respec‐
22811 tively. If -t is given, the element name appears as a
22812 prefix to the appropriate array element; if -n is given,
22813 the file name appears as a separate array element preced‐
22814 ing all the others. Other formatting options are re‐
22815 spected.
22816
22817 -H hash
22818 Similar to -A, but instead assign the values to hash.
22819 The keys are the elements listed above. If the -n option
22820 is provided then the name of the file is included in the
22821 hash with key name.
22822
22823 -f fd Use the file on file descriptor fd instead of named
22824 files; no list of file names is allowed in this case.
22825
22826 -F fmt Supplies a strftime (see strftime(3)) string for the for‐
22827 matting of the time elements. The format string supports
22828 all of the zsh extensions described in the section EXPAN‐
22829 SION OF PROMPT SEQUENCES in zshmisc(1). In particular,
22830 -F %s.%N can be used to show timestamps with nanosecond
22831 precision if supported by the system. The -s option is
22832 implied.
22833
22834 -g Show the time elements in the GMT time zone. The -s op‐
22835 tion is implied.
22836
22837 -l List the names of the type elements (to standard output
22838 or an array as appropriate) and return immediately; argu‐
22839 ments, and options other than -A, are ignored.
22840
22841 -L Perform an lstat (see lstat(2)) rather than a stat system
22842 call. In this case, if the file is a link, information
22843 about the link itself rather than the target file is re‐
22844 turned. This option is required to make the link element
22845 useful. It's important to note that this is the exact
22846 opposite from ls(1), etc.
22847
22848 -n Always show the names of files. Usually these are only
22849 shown when output is to standard output and there is more
22850 than one file in the list.
22851
22852 -N Never show the names of files.
22853
22854 -o If a raw file mode is printed, show it in octal, which is
22855 more useful for human consumption than the default of
22856 decimal. A leading zero will be printed in this case.
22857 Note that this does not affect whether a raw or formatted
22858 file mode is shown, which is controlled by the -r and -s
22859 options, nor whether a mode is shown at all.
22860
22861 -r Print raw data (the default format) alongside string data
22862 (the -s format); the string data appears in parentheses
22863 after the raw data.
22864
22865 -s Print mode, uid, gid and the three time elements as
22866 strings instead of numbers. In each case the format is
22867 like that of ls -l.
22868
22869 -t Always show the type names for the elements of struct
22870 stat. Usually these are only shown when output is to
22871 standard output and no individual element has been se‐
22872 lected.
22873
22874 -T Never show the type names of the struct stat elements.
22875
22877 The zsh/system module makes available various builtin commands and pa‐
22878 rameters.
22879
22880 Builtins
22881 syserror [ -e errvar ] [ -p prefix ] [ errno | errname ]
22882 This command prints out the error message associated with errno,
22883 a system error number, followed by a newline to standard error.
22884
22885 Instead of the error number, a name errname, for example ENOENT,
22886 may be used. The set of names is the same as the contents of
22887 the array errnos, see below.
22888
22889 If the string prefix is given, it is printed in front of the er‐
22890 ror message, with no intervening space.
22891
22892 If errvar is supplied, the entire message, without a newline, is
22893 assigned to the parameter names errvar and nothing is output.
22894
22895 A return status of 0 indicates the message was successfully
22896 printed (although it may not be useful if the error number was
22897 out of the system's range), a return status of 1 indicates an
22898 error in the parameters, and a return status of 2 indicates the
22899 error name was not recognised (no message is printed for this).
22900
22901
22902 sysopen [ -arw ] [ -m permissions ] [ -o options ]
22903 -u fd file
22904 This command opens a file. The -r, -w and -a flags indicate
22905 whether the file should be opened for reading, writing and ap‐
22906 pending, respectively. The -m option allows the initial permis‐
22907 sions to use when creating a file to be specified in octal form.
22908 The file descriptor is specified with -u. Either an explicit
22909 file descriptor in the range 0 to 9 can be specified or a vari‐
22910 able name can be given to which the file descriptor number will
22911 be assigned.
22912
22913 The -o option allows various system specific options to be spec‐
22914 ified as a comma-separated list. The following is a list of pos‐
22915 sible options. Note that, depending on the system, some may not
22916 be available.
22917 cloexec
22918 mark file to be closed when other programs are executed
22919 (else the file descriptor remains open in subshells and
22920 forked external executables)
22921
22922 create
22923 creat create file if it does not exist
22924
22925 excl create file, error if it already exists
22926
22927 noatime
22928 suppress updating of the file atime
22929
22930 nofollow
22931 fail if file is a symbolic link
22932
22933 nonblock
22934 the file is opened in nonblocking mode
22935
22936 sync request that writes wait until data has been physically
22937 written
22938
22939 truncate
22940 trunc truncate file to size 0
22941
22942 To close the file, use one of the following:
22943
22944 exec {fd}<&-
22945 exec {fd}>&-
22946
22947
22948 sysread [ -c countvar ] [ -i infd ] [ -o outfd ]
22949 [ -s bufsize ] [ -t timeout ] [ param ]
22950 Perform a single system read from file descriptor infd, or zero
22951 if that is not given. The result of the read is stored in param
22952 or REPLY if that is not given. If countvar is given, the number
22953 of bytes read is assigned to the parameter named by countvar.
22954
22955 The maximum number of bytes read is bufsize or 8192 if that is
22956 not given, however the command returns as soon as any number of
22957 bytes was successfully read.
22958
22959 If timeout is given, it specifies a timeout in seconds, which
22960 may be zero to poll the file descriptor. This is handled by the
22961 poll system call if available, otherwise the select system call
22962 if available.
22963
22964 If outfd is given, an attempt is made to write all the bytes
22965 just read to the file descriptor outfd. If this fails, because
22966 of a system error other than EINTR or because of an internal zsh
22967 error during an interrupt, the bytes read but not written are
22968 stored in the parameter named by param if supplied (no default
22969 is used in this case), and the number of bytes read but not
22970 written is stored in the parameter named by countvar if that is
22971 supplied. If it was successful, countvar contains the full num‐
22972 ber of bytes transferred, as usual, and param is not set.
22973
22974 The error EINTR (interrupted system call) is handled internally
22975 so that shell interrupts are transparent to the caller. Any
22976 other error causes a return.
22977
22978 The possible return statuses are
22979 0 At least one byte of data was successfully read and, if
22980 appropriate, written.
22981
22982 1 There was an error in the parameters to the command.
22983 This is the only error for which a message is printed to
22984 standard error.
22985
22986 2 There was an error on the read, or on polling the input
22987 file descriptor for a timeout. The parameter ERRNO gives
22988 the error.
22989
22990 3 Data were successfully read, but there was an error writ‐
22991 ing them to outfd. The parameter ERRNO gives the error.
22992
22993 4 The attempt to read timed out. Note this does not set
22994 ERRNO as this is not a system error.
22995
22996 5 No system error occurred, but zero bytes were read. This
22997 usually indicates end of file. The parameters are set
22998 according to the usual rules; no write to outfd is at‐
22999 tempted.
23000
23001 sysseek [ -u fd ] [ -w start|end|current ] offset
23002 The current file position at which future reads and writes will
23003 take place is adjusted to the specified byte offset. The offset
23004 is evaluated as a math expression. The -u option allows the file
23005 descriptor to be specified. By default the offset is specified
23006 relative to the start or the file but, with the -w option, it is
23007 possible to specify that the offset should be relative to the
23008 current position or the end of the file.
23009
23010 syswrite [ -c countvar ] [ -o outfd ] data
23011 The data (a single string of bytes) are written to the file de‐
23012 scriptor outfd, or 1 if that is not given, using the write sys‐
23013 tem call. Multiple write operations may be used if the first
23014 does not write all the data.
23015
23016 If countvar is given, the number of byte written is stored in
23017 the parameter named by countvar; this may not be the full length
23018 of data if an error occurred.
23019
23020 The error EINTR (interrupted system call) is handled internally
23021 by retrying; otherwise an error causes the command to return.
23022 For example, if the file descriptor is set to non-blocking out‐
23023 put, an error EAGAIN (on some systems, EWOULDBLOCK) may result
23024 in the command returning early.
23025
23026 The return status may be 0 for success, 1 for an error in the
23027 parameters to the command, or 2 for an error on the write; no
23028 error message is printed in the last case, but the parameter ER‐
23029 RNO will reflect the error that occurred.
23030
23031 zsystem flock [ -t timeout ] [ -i interval ] [ -f var ] [-er] file
23032 zsystem flock -u fd_expr
23033 The builtin zsystem's subcommand flock performs advisory file
23034 locking (via the fcntl(2) system call) over the entire contents
23035 of the given file. This form of locking requires the processes
23036 accessing the file to cooperate; its most obvious use is between
23037 two instances of the shell itself.
23038
23039 In the first form the named file, which must already exist, is
23040 locked by opening a file descriptor to the file and applying a
23041 lock to the file descriptor. The lock terminates when the shell
23042 process that created the lock exits; it is therefore often con‐
23043 venient to create file locks within subshells, since the lock is
23044 automatically released when the subshell exits. Note that use
23045 of the print builtin with the -u option will, as a side effect,
23046 release the lock, as will redirection to the file in the shell
23047 holding the lock. To work around this use a subshell, e.g.
23048 `(print message) >> file'. Status 0 is returned if the lock
23049 succeeds, else status 1.
23050
23051 In the second form the file descriptor given by the arithmetic
23052 expression fd_expr is closed, releasing a lock. The file de‐
23053 scriptor can be queried by using the `-f var' form during the
23054 lock; on a successful lock, the shell variable var is set to the
23055 file descriptor used for locking. The lock will be released if
23056 the file descriptor is closed by any other means, for example
23057 using `exec {var}>&-'; however, the form described here performs
23058 a safety check that the file descriptor is in use for file lock‐
23059 ing.
23060
23061 By default the shell waits indefinitely for the lock to succeed.
23062 The option -t timeout specifies a timeout for the lock in sec‐
23063 onds; fractional seconds are allowed. During this period, the
23064 shell will attempt to lock the file every interval seconds if
23065 the -i interval option is given, otherwise once a second. (This
23066 interval is shortened before the last attempt if needed, so that
23067 the shell waits only until the timeout and not longer.) If the
23068 attempt times out, status 2 is returned.
23069
23070 (Note: timeout is limited to 2^30-1 seconds (about 34 years),
23071 and interval to 0.999 * LONG_MAX microseconds (only about 35
23072 minutes on 32-bit systems).)
23073
23074 If the option -e is given, the file descriptor for the lock is
23075 preserved when the shell uses exec to start a new process; oth‐
23076 erwise it is closed at that point and the lock released.
23077
23078 If the option -r is given, the lock is only for reading, other‐
23079 wise it is for reading and writing. The file descriptor is
23080 opened accordingly.
23081
23082 zsystem supports subcommand
23083 The builtin zsystem's subcommand supports tests whether a given
23084 subcommand is supported. It returns status 0 if so, else status
23085 1. It operates silently unless there was a syntax error (i.e.
23086 the wrong number of arguments), in which case status 255 is re‐
23087 turned. Status 1 can indicate one of two things: subcommand is
23088 known but not supported by the current operating system, or sub‐
23089 command is not known (possibly because this is an older version
23090 of the shell before it was implemented).
23091
23092 Math Functions
23093 systell(fd)
23094 The systell math function returns the current file position for
23095 the file descriptor passed as an argument.
23096
23097 Parameters
23098 errnos A readonly array of the names of errors defined on the system.
23099 These are typically macros defined in C by including the system
23100 header file errno.h. The index of each name (assuming the op‐
23101 tion KSH_ARRAYS is unset) corresponds to the error number. Er‐
23102 ror numbers num before the last known error which have no name
23103 are given the name Enum in the array.
23104
23105 Note that aliases for errors are not handled; only the canonical
23106 name is used.
23107
23108 sysparams
23109 A readonly associative array. The keys are:
23110
23111 pid Returns the process ID of the current process, even in
23112 subshells. Compare $$, which returns the process ID of
23113 the main shell process.
23114
23115 ppid Returns the current process ID of the parent of the cur‐
23116 rent process, even in subshells. Compare $PPID, which
23117 returns the process ID of the initial parent of the main
23118 shell process.
23119
23120 procsubstpid
23121 Returns the process ID of the last process started for
23122 process substitution, i.e. the <(...) and >(...) expan‐
23123 sions.
23124
23126 The zsh/net/tcp module makes available one builtin command:
23127
23128 ztcp [ -acflLtv ] [ -d fd ] [ args ]
23129 ztcp is implemented as a builtin to allow full use of shell com‐
23130 mand line editing, file I/O, and job control mechanisms.
23131
23132 If ztcp is run with no options, it will output the contents of
23133 its session table.
23134
23135 If it is run with only the option -L, it will output the con‐
23136 tents of the session table in a format suitable for automatic
23137 parsing. The option is ignored if given with a command to open
23138 or close a session. The output consists of a set of lines, one
23139 per session, each containing the following elements separated by
23140 spaces:
23141
23142 File descriptor
23143 The file descriptor in use for the connection. For nor‐
23144 mal inbound (I) and outbound (O) connections this may be
23145 read and written by the usual shell mechanisms. However,
23146 it should only be close with `ztcp -c'.
23147
23148 Connection type
23149 A letter indicating how the session was created:
23150
23151 Z A session created with the zftp command.
23152
23153 L A connection opened for listening with `ztcp -l'.
23154
23155 I An inbound connection accepted with `ztcp -a'.
23156
23157 O An outbound connection created with `ztcp host
23158 ...'.
23159
23160 The local host
23161 This is usually set to an all-zero IP address as the ad‐
23162 dress of the localhost is irrelevant.
23163
23164 The local port
23165 This is likely to be zero unless the connection is for
23166 listening.
23167
23168 The remote host
23169 This is the fully qualified domain name of the peer, if
23170 available, else an IP address. It is an all-zero IP ad‐
23171 dress for a session opened for listening.
23172
23173 The remote port
23174 This is zero for a connection opened for listening.
23175
23176 Outbound Connections
23177 ztcp [ -v ] [ -d fd ] host [ port ]
23178 Open a new TCP connection to host. If the port is omitted, it
23179 will default to port 23. The connection will be added to the
23180 session table and the shell parameter REPLY will be set to the
23181 file descriptor associated with that connection.
23182
23183 If -d is specified, its argument will be taken as the target
23184 file descriptor for the connection.
23185
23186 In order to elicit more verbose output, use -v.
23187
23188 Inbound Connections
23189 ztcp -l [ -v ] [ -d fd ] port
23190 ztcp -l will open a socket listening on TCP port. The socket
23191 will be added to the session table and the shell parameter REPLY
23192 will be set to the file descriptor associated with that lis‐
23193 tener.
23194
23195 If -d is specified, its argument will be taken as the target
23196 file descriptor for the connection.
23197
23198 In order to elicit more verbose output, use -v.
23199
23200 ztcp -a [ -tv ] [ -d targetfd ] listenfd
23201 ztcp -a will accept an incoming connection to the port associ‐
23202 ated with listenfd. The connection will be added to the session
23203 table and the shell parameter REPLY will be set to the file de‐
23204 scriptor associated with the inbound connection.
23205
23206 If -d is specified, its argument will be taken as the target
23207 file descriptor for the connection.
23208
23209 If -t is specified, ztcp will return if no incoming connection
23210 is pending. Otherwise it will wait for one.
23211
23212 In order to elicit more verbose output, use -v.
23213
23214 Closing Connections
23215 ztcp -cf [ -v ] [ fd ]
23216 ztcp -c [ -v ] [ fd ]
23217 ztcp -c will close the socket associated with fd. The socket
23218 will be removed from the session table. If fd is not specified,
23219 ztcp will close everything in the session table.
23220
23221 Normally, sockets registered by zftp (see zshmodules(1) ) cannot
23222 be closed this way. In order to force such a socket closed, use
23223 -f.
23224
23225 In order to elicit more verbose output, use -v.
23226
23227 Example
23228 Here is how to create a TCP connection between two instances of zsh.
23229 We need to pick an unassigned port; here we use the randomly chosen
23230 5123.
23231
23232 On host1,
23233 zmodload zsh/net/tcp
23234 ztcp -l 5123
23235 listenfd=$REPLY
23236 ztcp -a $listenfd
23237 fd=$REPLY
23238 The second from last command blocks until there is an incoming connec‐
23239 tion.
23240
23241 Now create a connection from host2 (which may, of course, be the same
23242 machine):
23243 zmodload zsh/net/tcp
23244 ztcp host1 5123
23245 fd=$REPLY
23246
23247 Now on each host, $fd contains a file descriptor for talking to the
23248 other. For example, on host1:
23249 print This is a message >&$fd
23250 and on host2:
23251 read -r line <&$fd; print -r - $line
23252 prints `This is a message'.
23253
23254 To tidy up, on host1:
23255 ztcp -c $listenfd
23256 ztcp -c $fd
23257 and on host2
23258 ztcp -c $fd
23259
23261 The zsh/termcap module makes available one builtin command:
23262
23263 echotc cap [ arg ... ]
23264 Output the termcap value corresponding to the capability cap,
23265 with optional arguments.
23266
23267 The zsh/termcap module makes available one parameter:
23268
23269 termcap
23270 An associative array that maps termcap capability codes to their
23271 values.
23272
23274 The zsh/terminfo module makes available one builtin command:
23275
23276 echoti cap [ arg ]
23277 Output the terminfo value corresponding to the capability cap,
23278 instantiated with arg if applicable.
23279
23280 The zsh/terminfo module makes available one parameter:
23281
23282 terminfo
23283 An associative array that maps terminfo capability names to
23284 their values.
23285
23287 The zsh/watch module can be used to report when specific users log in
23288 or out. This is controlled via the following parameters.
23289
23290 LOGCHECK
23291 The interval in seconds between checks for login/logout activity
23292 using the watch parameter.
23293
23294 watch <S> <Z> (WATCH <S>)
23295 An array (colon-separated list) of login/logout events to re‐
23296 port.
23297
23298 If it contains the single word `all', then all login/logout
23299 events are reported. If it contains the single word `notme',
23300 then all events are reported as with `all' except $USERNAME.
23301
23302 An entry in this list may consist of a username, an `@' followed
23303 by a remote hostname, and a `%' followed by a line (tty). Any
23304 of these may be a pattern (be sure to quote this during the as‐
23305 signment to watch so that it does not immediately perform file
23306 generation); the setting of the EXTENDED_GLOB option is re‐
23307 spected. Any or all of these components may be present in an
23308 entry; if a login/logout event matches all of them, it is re‐
23309 ported.
23310
23311 For example, with the EXTENDED_GLOB option set, the following:
23312
23313 watch=('^(pws|barts)')
23314
23315 causes reports for activity associated with any user other than
23316 pws or barts.
23317
23318 WATCHFMT
23319 The format of login/logout reports if the watch parameter is
23320 set. Default is `%n has %a %l from %m'. Recognizes the follow‐
23321 ing escape sequences:
23322
23323 %n The name of the user that logged in/out.
23324
23325 %a The observed action, i.e. "logged on" or "logged off".
23326
23327 %l The line (tty) the user is logged in on.
23328
23329 %M The full hostname of the remote host.
23330
23331 %m The hostname up to the first `.'. If only the IP address
23332 is available or the utmp field contains the name of an
23333 X-windows display, the whole name is printed.
23334
23335 NOTE: The `%m' and `%M' escapes will work only if there
23336 is a host name field in the utmp on your machine. Other‐
23337 wise they are treated as ordinary strings.
23338
23339 %F{color} (%f)
23340 Start (stop) using a different foreground color.
23341
23342 %K{color} (%k)
23343 Start (stop) using a different background color.
23344
23345 %S (%s)
23346 Start (stop) standout mode.
23347
23348 %U (%u)
23349 Start (stop) underline mode.
23350
23351 %B (%b)
23352 Start (stop) boldface mode.
23353
23354 %t
23355 %@ The time, in 12-hour, am/pm format.
23356
23357 %T The time, in 24-hour format.
23358
23359 %w The date in `day-dd' format.
23360
23361 %W The date in `mm/dd/yy' format.
23362
23363 %D The date in `yy-mm-dd' format.
23364
23365 %D{string}
23366 The date formatted as string using the strftime function,
23367 with zsh extensions as described by EXPANSION OF PROMPT
23368 SEQUENCES in zshmisc(1).
23369
23370 %(x:true-text:false-text)
23371 Specifies a ternary expression. The character following
23372 the x is arbitrary; the same character is used to sepa‐
23373 rate the text for the "true" result from that for the
23374 "false" result. Both the separator and the right paren‐
23375 thesis may be escaped with a backslash. Ternary expres‐
23376 sions may be nested.
23377
23378 The test character x may be any one of `l', `n', `m' or
23379 `M', which indicate a `true' result if the corresponding
23380 escape sequence would return a non-empty value; or it may
23381 be `a', which indicates a `true' result if the watched
23382 user has logged in, or `false' if he has logged out.
23383 Other characters evaluate to neither true nor false; the
23384 entire expression is omitted in this case.
23385
23386 If the result is `true', then the true-text is formatted
23387 according to the rules above and printed, and the
23388 false-text is skipped. If `false', the true-text is
23389 skipped and the false-text is formatted and printed. Ei‐
23390 ther or both of the branches may be empty, but both sepa‐
23391 rators must be present in any case.
23392
23393 Furthermore, the zsh/watch module makes available one builtin command:
23394
23395 log List all users currently logged in who are affected by the cur‐
23396 rent setting of the watch parameter.
23397
23399 The zsh/zftp module makes available one builtin command:
23400
23401 zftp subcommand [ args ]
23402 The zsh/zftp module is a client for FTP (file transfer proto‐
23403 col). It is implemented as a builtin to allow full use of shell
23404 command line editing, file I/O, and job control mechanisms. Of‐
23405 ten, users will access it via shell functions providing a more
23406 powerful interface; a set is provided with the zsh distribution
23407 and is described in zshzftpsys(1). However, the zftp command is
23408 entirely usable in its own right.
23409
23410 All commands consist of the command name zftp followed by the
23411 name of a subcommand. These are listed below. The return sta‐
23412 tus of each subcommand is supposed to reflect the success or
23413 failure of the remote operation. See a description of the vari‐
23414 able ZFTP_VERBOSE for more information on how responses from the
23415 server may be printed.
23416
23417 Subcommands
23418 open host[:port] [ user [ password [ account ] ] ]
23419 Open a new FTP session to host, which may be the name of a
23420 TCP/IP connected host or an IP number in the standard dot nota‐
23421 tion. If the argument is in the form host:port, open a connec‐
23422 tion to TCP port port instead of the standard FTP port 21. This
23423 may be the name of a TCP service or a number: see the descrip‐
23424 tion of ZFTP_PORT below for more information.
23425
23426 If IPv6 addresses in colon format are used, the host should be
23427 surrounded by quoted square brackets to distinguish it from the
23428 port, for example '[fe80::203:baff:fe02:8b56]'. For consistency
23429 this is allowed with all forms of host.
23430
23431 Remaining arguments are passed to the login subcommand. Note
23432 that if no arguments beyond host are supplied, open will not au‐
23433 tomatically call login. If no arguments at all are supplied,
23434 open will use the parameters set by the params subcommand.
23435
23436 After a successful open, the shell variables ZFTP_HOST,
23437 ZFTP_PORT, ZFTP_IP and ZFTP_SYSTEM are available; see `Vari‐
23438 ables' below.
23439
23440 login [ name [ password [ account ] ] ]
23441 user [ name [ password [ account ] ] ]
23442 Login the user name with parameters password and account. Any
23443 of the parameters can be omitted, and will be read from standard
23444 input if needed (name is always needed). If standard input is a
23445 terminal, a prompt for each one will be printed on standard er‐
23446 ror and password will not be echoed. If any of the parameters
23447 are not used, a warning message is printed.
23448
23449 After a successful login, the shell variables ZFTP_USER,
23450 ZFTP_ACCOUNT and ZFTP_PWD are available; see `Variables' below.
23451
23452 This command may be re-issued when a user is already logged in,
23453 and the server will first be reinitialized for a new user.
23454
23455 params [ host [ user [ password [ account ] ] ] ]
23456 params -
23457 Store the given parameters for a later open command with no ar‐
23458 guments. Only those given on the command line will be remem‐
23459 bered. If no arguments are given, the parameters currently set
23460 are printed, although the password will appear as a line of
23461 stars; the return status is one if no parameters were set, zero
23462 otherwise.
23463
23464 Any of the parameters may be specified as a `?', which may need
23465 to be quoted to protect it from shell expansion. In this case,
23466 the appropriate parameter will be read from stdin as with the
23467 login subcommand, including special handling of password. If
23468 the `?' is followed by a string, that is used as the prompt for
23469 reading the parameter instead of the default message (any neces‐
23470 sary punctuation and whitespace should be included at the end of
23471 the prompt). The first letter of the parameter (only) may be
23472 quoted with a `\'; hence an argument "\\$word" guarantees that
23473 the string from the shell parameter $word will be treated liter‐
23474 ally, whether or not it begins with a `?'.
23475
23476 If instead a single `-' is given, the existing parameters, if
23477 any, are deleted. In that case, calling open with no arguments
23478 will cause an error.
23479
23480 The list of parameters is not deleted after a close, however it
23481 will be deleted if the zsh/zftp module is unloaded.
23482
23483 For example,
23484
23485 zftp params ftp.elsewhere.xx juser '?Password for juser: '
23486
23487 will store the host ftp.elsewhere.xx and the user juser and then
23488 prompt the user for the corresponding password with the given
23489 prompt.
23490
23491 test Test the connection; if the server has reported that it has
23492 closed the connection (maybe due to a timeout), return status 2;
23493 if no connection was open anyway, return status 1; else return
23494 status 0. The test subcommand is silent, apart from messages
23495 printed by the $ZFTP_VERBOSE mechanism, or error messages if the
23496 connection closes. There is no network overhead for this test.
23497
23498 The test is only supported on systems with either the select(2)
23499 or poll(2) system calls; otherwise the message `not supported on
23500 this system' is printed instead.
23501
23502 The test subcommand will automatically be called at the start of
23503 any other subcommand for the current session when a connection
23504 is open.
23505
23506 cd directory
23507 Change the remote directory to directory. Also alters the shell
23508 variable ZFTP_PWD.
23509
23510 cdup Change the remote directory to the one higher in the directory
23511 tree. Note that cd .. will also work correctly on non-UNIX sys‐
23512 tems.
23513
23514 dir [ arg ... ]
23515 Give a (verbose) listing of the remote directory. The args are
23516 passed directly to the server. The command's behaviour is imple‐
23517 mentation dependent, but a UNIX server will typically interpret
23518 args as arguments to the ls command and with no arguments return
23519 the result of `ls -l'. The directory is listed to standard out‐
23520 put.
23521
23522 ls [ arg ... ]
23523 Give a (short) listing of the remote directory. With no arg,
23524 produces a raw list of the files in the directory, one per line.
23525 Otherwise, up to vagaries of the server implementation, behaves
23526 similar to dir.
23527
23528 type [ type ]
23529 Change the type for the transfer to type, or print the current
23530 type if type is absent. The allowed values are `A' (ASCII), `I'
23531 (Image, i.e. binary), or `B' (a synonym for `I').
23532
23533 The FTP default for a transfer is ASCII. However, if zftp finds
23534 that the remote host is a UNIX machine with 8-bit byes, it will
23535 automatically switch to using binary for file transfers upon
23536 open. This can subsequently be overridden.
23537
23538 The transfer type is only passed to the remote host when a data
23539 connection is established; this command involves no network
23540 overhead.
23541
23542 ascii The same as type A.
23543
23544 binary The same as type I.
23545
23546 mode [ S | B ]
23547 Set the mode type to stream (S) or block (B). Stream mode is
23548 the default; block mode is not widely supported.
23549
23550 remote file ...
23551 local [ file ... ]
23552 Print the size and last modification time of the remote or local
23553 files. If there is more than one item on the list, the name of
23554 the file is printed first. The first number is the file size,
23555 the second is the last modification time of the file in the for‐
23556 mat CCYYMMDDhhmmSS consisting of year, month, date, hour, min‐
23557 utes and seconds in GMT. Note that this format, including the
23558 length, is guaranteed, so that time strings can be directly com‐
23559 pared via the [[ builtin's < and > operators, even if they are
23560 too long to be represented as integers.
23561
23562 Not all servers support the commands for retrieving this infor‐
23563 mation. In that case, the remote command will print nothing and
23564 return status 2, compared with status 1 for a file not found.
23565
23566 The local command (but not remote) may be used with no argu‐
23567 ments, in which case the information comes from examining file
23568 descriptor zero. This is the same file as seen by a put command
23569 with no further redirection.
23570
23571 get file ...
23572 Retrieve all files from the server, concatenating them and send‐
23573 ing them to standard output.
23574
23575 put file ...
23576 For each file, read a file from standard input and send that to
23577 the remote host with the given name.
23578
23579 append file ...
23580 As put, but if the remote file already exists, data is appended
23581 to it instead of overwriting it.
23582
23583 getat file point
23584 putat file point
23585 appendat file point
23586 Versions of get, put and append which will start the transfer at
23587 the given point in the remote file. This is useful for append‐
23588 ing to an incomplete local file. However, note that this abil‐
23589 ity is not universally supported by servers (and is not quite
23590 the behaviour specified by the standard).
23591
23592 delete file ...
23593 Delete the list of files on the server.
23594
23595 mkdir directory
23596 Create a new directory directory on the server.
23597
23598 rmdir directory
23599 Delete the directory directory on the server.
23600
23601 rename old-name new-name
23602 Rename file old-name to new-name on the server.
23603
23604 site arg ...
23605 Send a host-specific command to the server. You will probably
23606 only need this if instructed by the server to use it.
23607
23608 quote arg ...
23609 Send the raw FTP command sequence to the server. You should be
23610 familiar with the FTP command set as defined in RFC959 before
23611 doing this. Useful commands may include STAT and HELP. Note
23612 also the mechanism for returning messages as described for the
23613 variable ZFTP_VERBOSE below, in particular that all messages
23614 from the control connection are sent to standard error.
23615
23616 close
23617 quit Close the current data connection. This unsets the shell param‐
23618 eters ZFTP_HOST, ZFTP_PORT, ZFTP_IP, ZFTP_SYSTEM, ZFTP_USER,
23619 ZFTP_ACCOUNT, ZFTP_PWD, ZFTP_TYPE and ZFTP_MODE.
23620
23621 session [ sessname ]
23622 Allows multiple FTP sessions to be used at once. The name of
23623 the session is an arbitrary string of characters; the default
23624 session is called `default'. If this command is called without
23625 an argument, it will list all the current sessions; with an ar‐
23626 gument, it will either switch to the existing session called
23627 sessname, or create a new session of that name.
23628
23629 Each session remembers the status of the connection, the set of
23630 connection-specific shell parameters (the same set as are unset
23631 when a connection closes, as given in the description of close),
23632 and any user parameters specified with the params subcommand.
23633 Changing to a previous session restores those values; changing
23634 to a new session initialises them in the same way as if zftp had
23635 just been loaded. The name of the current session is given by
23636 the parameter ZFTP_SESSION.
23637
23638 rmsession [ sessname ]
23639 Delete a session; if a name is not given, the current session is
23640 deleted. If the current session is deleted, the earliest exist‐
23641 ing session becomes the new current session, otherwise the cur‐
23642 rent session is not changed. If the session being deleted is
23643 the only one, a new session called `default' is created and be‐
23644 comes the current session; note that this is a new session even
23645 if the session being deleted is also called `default'. It is
23646 recommended that sessions not be deleted while background com‐
23647 mands which use zftp are still active.
23648
23649 Parameters
23650 The following shell parameters are used by zftp. Currently none of
23651 them are special.
23652
23653 ZFTP_TMOUT
23654 Integer. The time in seconds to wait for a network operation to
23655 complete before returning an error. If this is not set when the
23656 module is loaded, it will be given the default value 60. A
23657 value of zero turns off timeouts. If a timeout occurs on the
23658 control connection it will be closed. Use a larger value if
23659 this occurs too frequently.
23660
23661 ZFTP_IP
23662 Readonly. The IP address of the current connection in dot nota‐
23663 tion.
23664
23665 ZFTP_HOST
23666 Readonly. The hostname of the current remote server. If the
23667 host was opened as an IP number, ZFTP_HOST contains that in‐
23668 stead; this saves the overhead for a name lookup, as IP numbers
23669 are most commonly used when a nameserver is unavailable.
23670
23671 ZFTP_PORT
23672 Readonly. The number of the remote TCP port to which the con‐
23673 nection is open (even if the port was originally specified as a
23674 named service). Usually this is the standard FTP port, 21.
23675
23676 In the unlikely event that your system does not have the appro‐
23677 priate conversion functions, this appears in network byte order.
23678 If your system is little-endian, the port then consists of two
23679 swapped bytes and the standard port will be reported as 5376.
23680 In that case, numeric ports passed to zftp open will also need
23681 to be in this format.
23682
23683 ZFTP_SYSTEM
23684 Readonly. The system type string returned by the server in re‐
23685 sponse to an FTP SYST request. The most interesting case is a
23686 string beginning "UNIX Type: L8", which ensures maximum compati‐
23687 bility with a local UNIX host.
23688
23689 ZFTP_TYPE
23690 Readonly. The type to be used for data transfers , either `A'
23691 or `I'. Use the type subcommand to change this.
23692
23693 ZFTP_USER
23694 Readonly. The username currently logged in, if any.
23695
23696 ZFTP_ACCOUNT
23697 Readonly. The account name of the current user, if any. Most
23698 servers do not require an account name.
23699
23700 ZFTP_PWD
23701 Readonly. The current directory on the server.
23702
23703 ZFTP_CODE
23704 Readonly. The three digit code of the last FTP reply from the
23705 server as a string. This can still be read after the connection
23706 is closed, and is not changed when the current session changes.
23707
23708 ZFTP_REPLY
23709 Readonly. The last line of the last reply sent by the server.
23710 This can still be read after the connection is closed, and is
23711 not changed when the current session changes.
23712
23713 ZFTP_SESSION
23714 Readonly. The name of the current FTP session; see the descrip‐
23715 tion of the session subcommand.
23716
23717 ZFTP_PREFS
23718 A string of preferences for altering aspects of zftp's behav‐
23719 iour. Each preference is a single character. The following are
23720 defined:
23721
23722 P Passive: attempt to make the remote server initiate data
23723 transfers. This is slightly more efficient than sendport
23724 mode. If the letter S occurs later in the string, zftp
23725 will use sendport mode if passive mode is not available.
23726
23727 S Sendport: initiate transfers by the FTP PORT command.
23728 If this occurs before any P in the string, passive mode
23729 will never be attempted.
23730
23731 D Dumb: use only the bare minimum of FTP commands. This
23732 prevents the variables ZFTP_SYSTEM and ZFTP_PWD from be‐
23733 ing set, and will mean all connections default to ASCII
23734 type. It may prevent ZFTP_SIZE from being set during a
23735 transfer if the server does not send it anyway (many
23736 servers do).
23737
23738 If ZFTP_PREFS is not set when zftp is loaded, it will be set to
23739 a default of `PS', i.e. use passive mode if available, otherwise
23740 fall back to sendport mode.
23741
23742 ZFTP_VERBOSE
23743 A string of digits between 0 and 5 inclusive, specifying which
23744 responses from the server should be printed. All responses go
23745 to standard error. If any of the numbers 1 to 5 appear in the
23746 string, raw responses from the server with reply codes beginning
23747 with that digit will be printed to standard error. The first
23748 digit of the three digit reply code is defined by RFC959 to cor‐
23749 respond to:
23750
23751 1. A positive preliminary reply.
23752
23753 2. A positive completion reply.
23754
23755 3. A positive intermediate reply.
23756
23757 4. A transient negative completion reply.
23758
23759 5. A permanent negative completion reply.
23760
23761 It should be noted that, for unknown reasons, the reply `Service
23762 not available', which forces termination of a connection, is
23763 classified as 421, i.e. `transient negative', an interesting in‐
23764 terpretation of the word `transient'.
23765
23766 The code 0 is special: it indicates that all but the last line
23767 of multiline replies read from the server will be printed to
23768 standard error in a processed format. By convention, servers
23769 use this mechanism for sending information for the user to read.
23770 The appropriate reply code, if it matches the same response,
23771 takes priority.
23772
23773 If ZFTP_VERBOSE is not set when zftp is loaded, it will be set
23774 to the default value 450, i.e., messages destined for the user
23775 and all errors will be printed. A null string is valid and
23776 specifies that no messages should be printed.
23777
23778 Functions
23779 zftp_chpwd
23780 If this function is set by the user, it is called every time the
23781 directory changes on the server, including when a user is logged
23782 in, or when a connection is closed. In the last case, $ZFTP_PWD
23783 will be unset; otherwise it will reflect the new directory.
23784
23785 zftp_progress
23786 If this function is set by the user, it will be called during a
23787 get, put or append operation each time sufficient data has been
23788 received from the host. During a get, the data is sent to stan‐
23789 dard output, so it is vital that this function should write to
23790 standard error or directly to the terminal, not to standard out‐
23791 put.
23792
23793 When it is called with a transfer in progress, the following ad‐
23794 ditional shell parameters are set:
23795
23796 ZFTP_FILE
23797 The name of the remote file being transferred from or to.
23798
23799 ZFTP_TRANSFER
23800 A G for a get operation and a P for a put operation.
23801
23802 ZFTP_SIZE
23803 The total size of the complete file being transferred:
23804 the same as the first value provided by the remote and
23805 local subcommands for a particular file. If the server
23806 cannot supply this value for a remote file being re‐
23807 trieved, it will not be set. If input is from a pipe the
23808 value may be incorrect and correspond simply to a full
23809 pipe buffer.
23810
23811 ZFTP_COUNT
23812 The amount of data so far transferred; a number between
23813 zero and $ZFTP_SIZE, if that is set. This number is al‐
23814 ways available.
23815
23816 The function is initially called with ZFTP_TRANSFER set appro‐
23817 priately and ZFTP_COUNT set to zero. After the transfer is fin‐
23818 ished, the function will be called one more time with
23819 ZFTP_TRANSFER set to GF or PF, in case it wishes to tidy up. It
23820 is otherwise never called twice with the same value of
23821 ZFTP_COUNT.
23822
23823 Sometimes the progress meter may cause disruption. It is up to
23824 the user to decide whether the function should be defined and to
23825 use unfunction when necessary.
23826
23827 Problems
23828 A connection may not be opened in the left hand side of a pipe as this
23829 occurs in a subshell and the file information is not updated in the
23830 main shell. In the case of type or mode changes or closing the connec‐
23831 tion in a subshell, the information is returned but variables are not
23832 updated until the next call to zftp. Other status changes in subshells
23833 will not be reflected by changes to the variables (but should be other‐
23834 wise harmless).
23835
23836 Deleting sessions while a zftp command is active in the background can
23837 have unexpected effects, even if it does not use the session being
23838 deleted. This is because all shell subprocesses share information on
23839 the state of all connections, and deleting a session changes the order‐
23840 ing of that information.
23841
23842 On some operating systems, the control connection is not valid after a
23843 fork(), so that operations in subshells, on the left hand side of a
23844 pipeline, or in the background are not possible, as they should be.
23845 This is presumably a bug in the operating system.
23846
23848 The zsh/zle module contains the Zsh Line Editor. See zshzle(1).
23849
23851 The zsh/zleparameter module defines two special parameters that can be
23852 used to access internal information of the Zsh Line Editor (see zsh‐
23853 zle(1)).
23854
23855 keymaps
23856 This array contains the names of the keymaps currently defined.
23857
23858 widgets
23859 This associative array contains one entry per widget. The name
23860 of the widget is the key and the value gives information about
23861 the widget. It is either
23862 the string `builtin' for builtin widgets,
23863 a string of the form `user:name' for user-defined widgets,
23864 where name is the name of the shell function implementing
23865 the widget,
23866 a string of the form `completion:type:name'
23867 for completion widgets,
23868 or a null value if the widget is not yet fully defined. In
23869 the penultimate case, type is the name of the builtin widget the
23870 completion widget imitates in its behavior and name is the name
23871 of the shell function implementing the completion widget.
23872
23874 When loaded, the zsh/zprof causes shell functions to be profiled. The
23875 profiling results can be obtained with the zprof builtin command made
23876 available by this module. There is no way to turn profiling off other
23877 than unloading the module.
23878
23879 zprof [ -c ]
23880 Without the -c option, zprof lists profiling results to standard
23881 output. The format is comparable to that of commands like
23882 gprof.
23883
23884 At the top there is a summary listing all functions that were
23885 called at least once. This summary is sorted in decreasing or‐
23886 der of the amount of time spent in each. The lines contain the
23887 number of the function in order, which is used in other parts of
23888 the list in suffixes of the form `[num]', then the number of
23889 calls made to the function. The next three columns list the
23890 time in milliseconds spent in the function and its descendants,
23891 the average time in milliseconds spent in the function and its
23892 descendants per call and the percentage of time spent in all
23893 shell functions used in this function and its descendants. The
23894 following three columns give the same information, but counting
23895 only the time spent in the function itself. The final column
23896 shows the name of the function.
23897
23898 After the summary, detailed information about every function
23899 that was invoked is listed, sorted in decreasing order of the
23900 amount of time spent in each function and its descendants. Each
23901 of these entries consists of descriptions for the functions that
23902 called the function described, the function itself, and the
23903 functions that were called from it. The description for the
23904 function itself has the same format as in the summary (and shows
23905 the same information). The other lines don't show the number of
23906 the function at the beginning and have their function named in‐
23907 dented to make it easier to distinguish the line showing the
23908 function described in the section from the surrounding lines.
23909
23910 The information shown in this case is almost the same as in the
23911 summary, but only refers to the call hierarchy being displayed.
23912 For example, for a calling function the column showing the total
23913 running time lists the time spent in the described function and
23914 its descendants only for the times when it was called from that
23915 particular calling function. Likewise, for a called function,
23916 this columns lists the total time spent in the called function
23917 and its descendants only for the times when it was called from
23918 the function described.
23919
23920 Also in this case, the column showing the number of calls to a
23921 function also shows a slash and then the total number of invoca‐
23922 tions made to the called function.
23923
23924 As long as the zsh/zprof module is loaded, profiling will be
23925 done and multiple invocations of the zprof builtin command will
23926 show the times and numbers of calls since the module was loaded.
23927 With the -c option, the zprof builtin command will reset its in‐
23928 ternal counters and will not show the listing.
23929
23931 The zsh/zpty module offers one builtin:
23932
23933 zpty [ -e ] [ -b ] name [ arg ... ]
23934 The arguments following name are concatenated with spaces be‐
23935 tween, then executed as a command, as if passed to the eval
23936 builtin. The command runs under a newly assigned pseudo-termi‐
23937 nal; this is useful for running commands non-interactively which
23938 expect an interactive environment. The name is not part of the
23939 command, but is used to refer to this command in later calls to
23940 zpty.
23941
23942 With the -e option, the pseudo-terminal is set up so that input
23943 characters are echoed.
23944
23945 With the -b option, input to and output from the pseudo-terminal
23946 are made non-blocking.
23947
23948 The shell parameter REPLY is set to the file descriptor assigned
23949 to the master side of the pseudo-terminal. This allows the ter‐
23950 minal to be monitored with ZLE descriptor handlers (see zsh‐
23951 zle(1)) or manipulated with sysread and syswrite (see THE
23952 ZSH/SYSTEM MODULE in zshmodules(1)). Warning: Use of sysread
23953 and syswrite is not recommended; use zpty -r and zpty -w unless
23954 you know exactly what you are doing.
23955
23956 zpty -d [ name ... ]
23957 The second form, with the -d option, is used to delete commands
23958 previously started, by supplying a list of their names. If no
23959 name is given, all commands are deleted. Deleting a command
23960 causes the HUP signal to be sent to the corresponding process.
23961
23962 zpty -w [ -n ] name [ string ... ]
23963 The -w option can be used to send the to command name the given
23964 strings as input (separated by spaces). If the -n option is not
23965 given, a newline is added at the end.
23966
23967 If no string is provided, the standard input is copied to the
23968 pseudo-terminal; this may stop before copying the full input if
23969 the pseudo-terminal is non-blocking. The exact input is always
23970 copied: the -n option is not applied.
23971
23972 Note that the command under the pseudo-terminal sees this input
23973 as if it were typed, so beware when sending special tty driver
23974 characters such as word-erase, line-kill, and end-of-file.
23975
23976 zpty -r [ -mt ] name [ param [ pattern ] ]
23977 The -r option can be used to read the output of the command
23978 name. With only a name argument, the output read is copied to
23979 the standard output. Unless the pseudo-terminal is non-block‐
23980 ing, copying continues until the command under the pseudo-termi‐
23981 nal exits; when non-blocking, only as much output as is immedi‐
23982 ately available is copied. The return status is zero if any
23983 output is copied.
23984
23985 When also given a param argument, at most one line is read and
23986 stored in the parameter named param. Less than a full line may
23987 be read if the pseudo-terminal is non-blocking. The return sta‐
23988 tus is zero if at least one character is stored in param.
23989
23990 If a pattern is given as well, output is read until the whole
23991 string read matches the pattern, even in the non-blocking case.
23992 The return status is zero if the string read matches the pat‐
23993 tern, or if the command has exited but at least one character
23994 could still be read. If the option -m is present, the return
23995 status is zero only if the pattern matches. As of this writing,
23996 a maximum of one megabyte of output can be consumed this way; if
23997 a full megabyte is read without matching the pattern, the return
23998 status is non-zero.
23999
24000 In all cases, the return status is non-zero if nothing could be
24001 read, and is 2 if this is because the command has finished.
24002
24003 If the -r option is combined with the -t option, zpty tests
24004 whether output is available before trying to read. If no output
24005 is available, zpty immediately returns the status 1. When used
24006 with a pattern, the behaviour on a failed poll is similar to
24007 when the command has exited: the return value is zero if at
24008 least one character could still be read even if the pattern
24009 failed to match.
24010
24011 zpty -t name
24012 The -t option without the -r option can be used to test whether
24013 the command name is still running. It returns a zero status if
24014 the command is running and a non-zero value otherwise.
24015
24016 zpty [ -L ]
24017 The last form, without any arguments, is used to list the com‐
24018 mands currently defined. If the -L option is given, this is
24019 done in the form of calls to the zpty builtin.
24020
24022 The zsh/zselect module makes available one builtin command:
24023
24024 zselect [ -rwe ] [ -t timeout ] [ -a array ] [ -A assoc ] [ fd ... ]
24025 The zselect builtin is a front-end to the `select' system call,
24026 which blocks until a file descriptor is ready for reading or
24027 writing, or has an error condition, with an optional timeout.
24028 If this is not available on your system, the command prints an
24029 error message and returns status 2 (normal errors return status
24030 1). For more information, see your system's documentation for
24031 select(3). Note there is no connection with the shell builtin
24032 of the same name.
24033
24034 Arguments and options may be intermingled in any order. Non-op‐
24035 tion arguments are file descriptors, which must be decimal inte‐
24036 gers. By default, file descriptors are to be tested for read‐
24037 ing, i.e. zselect will return when data is available to be read
24038 from the file descriptor, or more precisely, when a read opera‐
24039 tion from the file descriptor will not block. After a -r, -w
24040 and -e, the given file descriptors are to be tested for reading,
24041 writing, or error conditions. These options and an arbitrary
24042 list of file descriptors may be given in any order.
24043
24044 (The presence of an `error condition' is not well defined in the
24045 documentation for many implementations of the select system
24046 call. According to recent versions of the POSIX specification,
24047 it is really an exception condition, of which the only standard
24048 example is out-of-band data received on a socket. So zsh users
24049 are unlikely to find the -e option useful.)
24050
24051 The option `-t timeout' specifies a timeout in hundredths of a
24052 second. This may be zero, in which case the file descriptors
24053 will simply be polled and zselect will return immediately. It
24054 is possible to call zselect with no file descriptors and a
24055 non-zero timeout for use as a finer-grained replacement for
24056 `sleep'; note, however, the return status is always 1 for a
24057 timeout.
24058
24059 The option `-a array' indicates that array should be set to in‐
24060 dicate the file descriptor(s) which are ready. If the option is
24061 not given, the array reply will be used for this purpose. The
24062 array will contain a string similar to the arguments for zse‐
24063 lect. For example,
24064
24065 zselect -t 0 -r 0 -w 1
24066
24067 might return immediately with status 0 and $reply containing `-r
24068 0 -w 1' to show that both file descriptors are ready for the re‐
24069 quested operations.
24070
24071 The option `-A assoc' indicates that the associative array assoc
24072 should be set to indicate the file descriptor(s) which are
24073 ready. This option overrides the option -a, nor will reply be
24074 modified. The keys of assoc are the file descriptors, and the
24075 corresponding values are any of the characters `rwe' to indicate
24076 the condition.
24077
24078 The command returns status 0 if some file descriptors are ready
24079 for reading. If the operation timed out, or a timeout of 0 was
24080 given and no file descriptors were ready, or there was an error,
24081 it returns status 1 and the array will not be set (nor modified
24082 in any way). If there was an error in the select operation the
24083 appropriate error message is printed.
24084
24086 The zsh/zutil module only adds some builtins:
24087
24088 zstyle [ -L [ metapattern [ style ] ] ]
24089 zstyle [ -e | - | -- ] pattern style string ...
24090 zstyle -d [ pattern [ style ... ] ]
24091 zstyle -g name [ pattern [ style ] ]
24092 zstyle -{a|b|s} context style name [ sep ]
24093 zstyle -{T|t} context style [ string ... ]
24094 zstyle -m context style pattern
24095 This builtin command is used to define and lookup styles.
24096 Styles are pairs of names and values, where the values consist
24097 of any number of strings. They are stored together with pat‐
24098 terns and lookup is done by giving a string, called the `con‐
24099 text', which is matched against the patterns. The definition
24100 stored for the most specific pattern that matches will be re‐
24101 turned.
24102
24103 A pattern is considered to be more specific than another if it
24104 contains more components (substrings separated by colons) or if
24105 the patterns for the components are more specific, where simple
24106 strings are considered to be more specific than patterns and
24107 complex patterns are considered to be more specific than the
24108 pattern `*'. A `*' in the pattern will match zero or more char‐
24109 acters in the context; colons are not treated specially in this
24110 regard. If two patterns are equally specific, the tie is broken
24111 in favour of the pattern that was defined first.
24112
24113 Example
24114
24115 For example, a fictional `weather' plugin might state in its
24116 documentation that it looks up the preferred-precipitation style
24117 under the `:weather:continent:day-of-the-week:phase-of-the-moon'
24118 context. According to this, you might set the following in your
24119 zshrc:
24120
24121 zstyle ':weather:europe:*' preferred-precipitation rain
24122 zstyle ':weather:*:Sunday:*' preferred-precipitation snow
24123
24124 Then the plugin would run under the hood a command such as
24125
24126 zstyle -s ":weather:${continent}:${day_of_week}:${moon_phase}" preferred-precipitation REPLY
24127
24128 in order to retrieve your preference into the scalar variable
24129 $REPLY. On Sundays $REPLY would be set to `snow'; in Europe it
24130 would be set to `rain'; and on Sundays in Europe it would be set
24131 to `snow' again, because the patterns `:weather:europe:*' and
24132 `:weather:*:Sunday:*' both match the context argument to zstyle
24133 -s, are equally specific, and the latter is more specific (be‐
24134 cause it has more colon-separated components).
24135
24136 Usage
24137
24138 The forms that operate on patterns are the following.
24139
24140 zstyle [ -L [ metapattern [ style ] ] ]
24141 Without arguments, lists style definitions. Styles are
24142 shown in alphabetic order and patterns are shown in the
24143 order zstyle will test them.
24144
24145 If the -L option is given, listing is done in the form of
24146 calls to zstyle. The optional first argument, metapat‐
24147 tern, is a pattern which will be matched against the
24148 string supplied as pattern when the style was defined.
24149 Note: this means, for example, `zstyle -L ":comple‐
24150 tion:*"' will match any supplied pattern beginning `:com‐
24151 pletion:', not just ":completion:*": use ':comple‐
24152 tion:\*' to match that. The optional second argument
24153 limits the output to a specific style (not a pattern).
24154 -L is not compatible with any other options.
24155
24156 zstyle [ - | -- | -e ] pattern style string ...
24157 Defines the given style for the pattern with the strings
24158 as the value. If the -e option is given, the strings
24159 will be concatenated (separated by spaces) and the re‐
24160 sulting string will be evaluated (in the same way as it
24161 is done by the eval builtin command) when the style is
24162 looked up. In this case the parameter `reply' must be
24163 assigned to set the strings returned after the evalua‐
24164 tion. Before evaluating the value, reply is unset, and
24165 if it is still unset after the evaluation, the style is
24166 treated as if it were not set.
24167
24168 zstyle -d [ pattern [ style ... ] ]
24169 Delete style definitions. Without arguments all defini‐
24170 tions are deleted, with a pattern all definitions for
24171 that pattern are deleted and if any styles are given,
24172 then only those styles are deleted for the pattern.
24173
24174 zstyle -g name [ pattern [ style ] ]
24175 Retrieve a style definition. The name is used as the name
24176 of an array in which the results are stored. Without any
24177 further arguments, all patterns defined are returned.
24178 With a pattern the styles defined for that pattern are
24179 returned and with both a pattern and a style, the value
24180 strings of that combination is returned.
24181
24182 The other forms can be used to look up or test styles for a
24183 given context.
24184
24185 zstyle -s context style name [ sep ]
24186 The parameter name is set to the value of the style in‐
24187 terpreted as a string. If the value contains several
24188 strings they are concatenated with spaces (or with the
24189 sep string if that is given) between them.
24190
24191 Return 0 if the style is set, 1 otherwise.
24192
24193 zstyle -b context style name
24194 The value is stored in name as a boolean, i.e. as the
24195 string `yes' if the value has only one string and that
24196 string is equal to one of `yes', `true', `on', or `1'. If
24197 the value is any other string or has more than one
24198 string, the parameter is set to `no'.
24199
24200 Return 0 if name is set to `yes', 1 otherwise.
24201
24202 zstyle -a context style name
24203 The value is stored in name as an array. If name is de‐
24204 clared as an associative array, the first, third, etc.
24205 strings are used as the keys and the other strings are
24206 used as the values.
24207
24208 Return 0 if the style is set, 1 otherwise.
24209
24210 zstyle -t context style [ string ... ]
24211 zstyle -T context style [ string ... ]
24212 Test the value of a style, i.e. the -t option only re‐
24213 turns a status (sets $?). Without any string the return
24214 status is zero if the style is defined for at least one
24215 matching pattern, has only one string in its value, and
24216 that is equal to one of `true', `yes', `on' or `1'. If
24217 any strings are given the status is zero if and only if
24218 at least one of the strings is equal to at least one of
24219 the strings in the value. If the style is defined but
24220 doesn't match, the return status is 1. If the style is
24221 not defined, the status is 2.
24222
24223 The -T option tests the values of the style like -t, but
24224 it returns status zero (rather than 2) if the style is
24225 not defined for any matching pattern.
24226
24227 zstyle -m context style pattern
24228 Match a value. Returns status zero if the pattern matches
24229 at least one of the strings in the value.
24230
24231 zformat -f param format spec ...
24232 zformat -F param format spec ...
24233 zformat -a array sep spec ...
24234 This builtin provides different forms of formatting. The first
24235 form is selected with the -f option. In this case the format
24236 string will be modified by replacing sequences starting with a
24237 percent sign in it with strings from the specs. Each spec
24238 should be of the form `char:string' which will cause every ap‐
24239 pearance of the sequence `%char' in format to be replaced by the
24240 string. The `%' sequence may also contain optional minimum and
24241 maximum field width specifications between the `%' and the
24242 `char' in the form `%min.maxc', i.e. the minimum field width is
24243 given first and if the maximum field width is used, it has to be
24244 preceded by a dot. Specifying a minimum field width makes the
24245 result be padded with spaces to the right if the string is
24246 shorter than the requested width. Padding to the left can be
24247 achieved by giving a negative minimum field width. If a maximum
24248 field width is specified, the string will be truncated after
24249 that many characters. After all `%' sequences for the given
24250 specs have been processed, the resulting string is stored in the
24251 parameter param.
24252
24253 The %-escapes also understand ternary expressions in the form
24254 used by prompts. The % is followed by a `(' and then an ordi‐
24255 nary format specifier character as described above. There may
24256 be a set of digits either before or after the `('; these specify
24257 a test number, which defaults to zero. Negative numbers are
24258 also allowed. An arbitrary delimiter character follows the for‐
24259 mat specifier, which is followed by a piece of `true' text, the
24260 delimiter character again, a piece of `false' text, and a clos‐
24261 ing parenthesis. The complete expression (without the digits)
24262 thus looks like `%(X.text1.text2)', except that the `.' charac‐
24263 ter is arbitrary. The value given for the format specifier in
24264 the char:string expressions is evaluated as a mathematical ex‐
24265 pression, and compared with the test number. If they are the
24266 same, text1 is output, else text2 is output. A parenthesis may
24267 be escaped in text2 as %). Either of text1 or text2 may contain
24268 nested %-escapes.
24269
24270 For example:
24271
24272 zformat -f REPLY "The answer is '%3(c.yes.no)'." c:3
24273
24274 outputs "The answer is 'yes'." to REPLY since the value for the
24275 format specifier c is 3, agreeing with the digit argument to the
24276 ternary expression.
24277
24278 With -F instead of -f, ternary expressions choose between the
24279 `true' or `false' text on the basis of whether the format speci‐
24280 fier is present and non-empty. A test number indicates a mini‐
24281 mum width for the value given in the format specifier. Negative
24282 numbers reverse this, so the test is for whether the value ex‐
24283 ceeds a maximum width.
24284
24285 The form, using the -a option, can be used for aligning strings.
24286 Here, the specs are of the form `left:right' where `left' and
24287 `right' are arbitrary strings. These strings are modified by
24288 replacing the colons by the sep string and padding the left
24289 strings with spaces to the right so that the sep strings in the
24290 result (and hence the right strings after them) are all aligned
24291 if the strings are printed below each other. All strings with‐
24292 out a colon are left unchanged and all strings with an empty
24293 right string have the trailing colon removed. In both cases the
24294 lengths of the strings are not used to determine how the other
24295 strings are to be aligned. A colon in the left string can be
24296 escaped with a backslash. The resulting strings are stored in
24297 the array.
24298
24299 zregexparse
24300 This implements some internals of the _regex_arguments function.
24301
24302 zparseopts [ -D -E -F -K -M ] [ -a array ] [ -A assoc ] [ - ] spec ...
24303 This builtin simplifies the parsing of options in positional pa‐
24304 rameters, i.e. the set of arguments given by $*. Each spec de‐
24305 scribes one option and must be of the form `opt[=array]'. If an
24306 option described by opt is found in the positional parameters it
24307 is copied into the array specified with the -a option; if the
24308 optional `=array' is given, it is instead copied into that ar‐
24309 ray, which should be declared as a normal array and never as an
24310 associative array.
24311
24312 Note that it is an error to give any spec without an `=array'
24313 unless one of the -a or -A options is used.
24314
24315 Unless the -E option is given, parsing stops at the first string
24316 that isn't described by one of the specs. Even with -E, parsing
24317 always stops at a positional parameter equal to `-' or `--'. See
24318 also -F.
24319
24320 The opt description must be one of the following. Any of the
24321 special characters can appear in the option name provided it is
24322 preceded by a backslash.
24323
24324 name
24325 name+ The name is the name of the option without the leading
24326 `-'. To specify a GNU-style long option, one of the
24327 usual two leading `-' must be included in name; for exam‐
24328 ple, a `--file' option is represented by a name of
24329 `-file'.
24330
24331 If a `+' appears after name, the option is appended to
24332 array each time it is found in the positional parameters;
24333 without the `+' only the last occurrence of the option is
24334 preserved.
24335
24336 If one of these forms is used, the option takes no argu‐
24337 ment, so parsing stops if the next positional parameter
24338 does not also begin with `-' (unless the -E option is
24339 used).
24340
24341 name:
24342 name:-
24343 name:: If one or two colons are given, the option takes an argu‐
24344 ment; with one colon, the argument is mandatory and with
24345 two colons it is optional. The argument is appended to
24346 the array after the option itself.
24347
24348 An optional argument is put into the same array element
24349 as the option name (note that this makes empty strings as
24350 arguments indistinguishable). A mandatory argument is
24351 added as a separate element unless the `:-' form is used,
24352 in which case the argument is put into the same element.
24353
24354 A `+' as described above may appear between the name and
24355 the first colon.
24356
24357 In all cases, option-arguments must appear either immediately
24358 following the option in the same positional parameter or in the
24359 next one. Even an optional argument may appear in the next pa‐
24360 rameter, unless it begins with a `-'. There is no special han‐
24361 dling of `=' as with GNU-style argument parsers; given the spec
24362 `-foo:', the positional parameter `--foo=bar' is parsed as
24363 `--foo' with an argument of `=bar'.
24364
24365 When the names of two options that take no arguments overlap,
24366 the longest one wins, so that parsing for the specs `-foo -foo‐
24367 bar' (for example) is unambiguous. However, due to the aforemen‐
24368 tioned handling of option-arguments, ambiguities may arise when
24369 at least one overlapping spec takes an argument, as in `-foo:
24370 -foobar'. In that case, the last matching spec wins.
24371
24372 The options of zparseopts itself cannot be stacked because, for
24373 example, the stack `-DEK' is indistinguishable from a spec for
24374 the GNU-style long option `--DEK'. The options of zparseopts
24375 itself are:
24376
24377 -a array
24378 As described above, this names the default array in which
24379 to store the recognised options.
24380
24381 -A assoc
24382 If this is given, the options and their values are also
24383 put into an associative array with the option names as
24384 keys and the arguments (if any) as the values.
24385
24386 -D If this option is given, all options found are removed
24387 from the positional parameters of the calling shell or
24388 shell function, up to but not including any not described
24389 by the specs. If the first such parameter is `-' or
24390 `--', it is removed as well. This is similar to using
24391 the shift builtin.
24392
24393 -E This changes the parsing rules to not stop at the first
24394 string that isn't described by one of the specs. It can
24395 be used to test for or (if used together with -D) extract
24396 options and their arguments, ignoring all other options
24397 and arguments that may be in the positional parameters.
24398 As indicated above, parsing still stops at the first `-'
24399 or `--' not described by a spec, but it is not removed
24400 when used with -D.
24401
24402 -F If this option is given, zparseopts immediately stops at
24403 the first option-like parameter not described by one of
24404 the specs, prints an error message, and returns status 1.
24405 Removal (-D) and extraction (-E) are not performed, and
24406 option arrays are not updated. This provides basic vali‐
24407 dation for the given options.
24408
24409 Note that the appearance in the positional parameters of
24410 an option without its required argument always aborts
24411 parsing and returns an error as described above regard‐
24412 less of whether this option is used.
24413
24414 -K With this option, the arrays specified with the -a option
24415 and with the `=array' forms are kept unchanged when none
24416 of the specs for them is used. Otherwise the entire ar‐
24417 ray is replaced when any of the specs is used. Individ‐
24418 ual elements of associative arrays specified with the -A
24419 option are preserved by -K. This allows assignment of
24420 default values to arrays before calling zparseopts.
24421
24422 -M This changes the assignment rules to implement a map
24423 among equivalent option names. If any spec uses the
24424 `=array' form, the string array is interpreted as the
24425 name of another spec, which is used to choose where to
24426 store the values. If no other spec is found, the values
24427 are stored as usual. This changes only the way the val‐
24428 ues are stored, not the way $* is parsed, so results may
24429 be unpredictable if the `name+' specifier is used incon‐
24430 sistently.
24431
24432 For example,
24433
24434 set -- -a -bx -c y -cz baz -cend
24435 zparseopts a=foo b:=bar c+:=bar
24436
24437 will have the effect of
24438
24439 foo=(-a)
24440 bar=(-b x -c y -c z)
24441
24442 The arguments from `baz' on will not be used.
24443
24444 As an example for the -E option, consider:
24445
24446 set -- -a x -b y -c z arg1 arg2
24447 zparseopts -E -D b:=bar
24448
24449 will have the effect of
24450
24451 bar=(-b y)
24452 set -- -a x -c z arg1 arg2
24453
24454 I.e., the option -b and its arguments are taken from the posi‐
24455 tional parameters and put into the array bar.
24456
24457 The -M option can be used like this:
24458
24459 set -- -a -bx -c y -cz baz -cend
24460 zparseopts -A bar -M a=foo b+: c:=b
24461
24462 to have the effect of
24463
24464 foo=(-a)
24465 bar=(-a '' -b xyz)
24466
24467
24468
24469ZSHCALSYS(1) General Commands Manual ZSHCALSYS(1)
24470
24471
24472
24474 zshcalsys - zsh calendar system
24475
24477 The shell is supplied with a series of functions to replace and enhance
24478 the traditional Unix calendar programme, which warns the user of immi‐
24479 nent or future events, details of which are stored in a text file (typ‐
24480 ically calendar in the user's home directory). The version provided
24481 here includes a mechanism for alerting the user when an event is due.
24482
24483 In addition functions age, before and after are provided that can be
24484 used in a glob qualifier; they allow files to be selected based on
24485 their modification times.
24486
24487 The format of the calendar file and the dates used there in and in the
24488 age function are described first, then the functions that can be called
24489 to examine and modify the calendar file.
24490
24491 The functions here depend on the availability of the zsh/datetime mod‐
24492 ule which is usually installed with the shell. The library function
24493 strptime() must be available; it is present on most recent operating
24494 systems.
24495
24497 Calendar File Format
24498 The calendar file is by default ~/calendar. This can be configured by
24499 the calendar-file style, see the section STYLES below. The basic for‐
24500 mat consists of a series of separate lines, with no indentation, each
24501 including a date and time specification followed by a description of
24502 the event.
24503
24504 Various enhancements to this format are supported, based on the syntax
24505 of Emacs calendar mode. An indented line indicates a continuation line
24506 that continues the description of the event from the preceding line
24507 (note the date may not be continued in this way). An initial ampersand
24508 (&) is ignored for compatibility.
24509
24510 An indented line on which the first non-whitespace character is # is
24511 not displayed with the calendar entry, but is still scanned for infor‐
24512 mation. This can be used to hide information useful to the calendar
24513 system but not to the user, such as the unique identifier used by cal‐
24514 endar_add.
24515
24516 The Emacs extension that a date with no description may refer to a num‐
24517 ber of succeeding events at different times is not supported.
24518
24519 Unless the done-file style has been altered, any events which have been
24520 processed are appended to the file with the same name as the calendar
24521 file with the suffix .done, hence ~/calendar.done by default.
24522
24523 An example is shown below.
24524
24525 Date Format
24526 The format of the date and time is designed to allow flexibility with‐
24527 out admitting ambiguity. (The words `date' and `time' are both used in
24528 the documentation below; except where specifically noted this implies a
24529 string that may include both a date and a time specification.) Note
24530 that there is no localization support; month and day names must be in
24531 English and separator characters are fixed. Matching is case insensi‐
24532 tive, and only the first three letters of the names are significant,
24533 although as a special case a form beginning "month" does not match
24534 "Monday". Furthermore, time zones are not handled; all times are as‐
24535 sumed to be local.
24536
24537 It is recommended that, rather than exploring the intricacies of the
24538 system, users find a date format that is natural to them and stick to
24539 it. This will avoid unexpected effects. Various key facts should be
24540 noted.
24541
24542 • In particular, note the confusion between month/day/year and
24543 day/month/year when the month is numeric; these formats should
24544 be avoided if at all possible. Many alternatives are available.
24545
24546 • The year must be given in full to avoid confusion, and only
24547 years from 1900 to 2099 inclusive are matched.
24548
24549 The following give some obvious examples; users finding here a format
24550 they like and not subject to vagaries of style may skip the full de‐
24551 scription. As dates and times are matched separately (even though the
24552 time may be embedded in the date), any date format may be mixed with
24553 any format for the time of day provide the separators are clear (white‐
24554 space, colons, commas).
24555
24556 2007/04/03 13:13
24557 2007/04/03:13:13
24558 2007/04/03 1:13 pm
24559 3rd April 2007, 13:13
24560 April 3rd 2007 1:13 p.m.
24561 Apr 3, 2007 13:13
24562 Tue Apr 03 13:13:00 2007
24563 13:13 2007/apr/3
24564
24565 More detailed rules follow.
24566
24567 Times are parsed and extracted before dates. They must use colons to
24568 separate hours and minutes, though a dot is allowed before seconds if
24569 they are present. This limits time formats to the following:
24570
24571 • HH:MM[:SS[.FFFFF]] [am|pm|a.m.|p.m.]
24572
24573 • HH:MM.SS[.FFFFF] [am|pm|a.m.|p.m.]
24574
24575 Here, square brackets indicate optional elements, possibly with alter‐
24576 natives. Fractions of a second are recognised but ignored. For abso‐
24577 lute times (the normal format require by the calendar file and the age,
24578 before and after functions) a date is mandatory but a time of day is
24579 not; the time returned is at the start of the date. One variation is
24580 allowed: if a.m. or p.m. or one of their variants is present, an hour
24581 without a minute is allowed, e.g. 3 p.m..
24582
24583 Time zones are not handled, though if one is matched following a time
24584 specification it will be removed to allow a surrounding date to be
24585 parsed. This only happens if the format of the timezone is not too un‐
24586 usual. The following are examples of forms that are understood:
24587
24588 +0100
24589 GMT
24590 GMT-7
24591 CET+1CDT
24592
24593 Any part of the timezone that is not numeric must have exactly three
24594 capital letters in the name.
24595
24596 Dates suffer from the ambiguity between DD/MM/YYYY and MM/DD/YYYY. It
24597 is recommended this form is avoided with purely numeric dates, but use
24598 of ordinals, eg. 3rd/04/2007, will resolve the ambiguity as the ordinal
24599 is always parsed as the day of the month. Years must be four digits
24600 (and the first two must be 19 or 20); 03/04/08 is not recognised.
24601 Other numbers may have leading zeroes, but they are not required. The
24602 following are handled:
24603
24604 • YYYY/MM/DD
24605
24606 • YYYY-MM-DD
24607
24608 • YYYY/MNM/DD
24609
24610 • YYYY-MNM-DD
24611
24612 • DD[th|st|rd] MNM[,] [ YYYY ]
24613
24614 • MNM DD[th|st|rd][,] [ YYYY ]
24615
24616 • DD[th|st|rd]/MM[,] YYYY
24617
24618 • DD[th|st|rd]/MM/YYYY
24619
24620 • MM/DD[th|st|rd][,] YYYY
24621
24622 • MM/DD[th|st|rd]/YYYY
24623
24624 Here, MNM is at least the first three letters of a month name, matched
24625 case-insensitively. The remainder of the month name may appear but its
24626 contents are irrelevant, so janissary, febrile, martial, apricot,
24627 maybe, junta, etc. are happily handled.
24628
24629 Where the year is shown as optional, the current year is assumed.
24630 There are only two such cases, the form Jun 20 or 14 September (the
24631 only two commonly occurring forms, apart from a "the" in some forms of
24632 English, which isn't currently supported). Such dates will of course
24633 become ambiguous in the future, so should ideally be avoided.
24634
24635 Times may follow dates with a colon, e.g. 1965/07/12:09:45; this is in
24636 order to provide a format with no whitespace. A comma and whitespace
24637 are allowed, e.g. 1965/07/12, 09:45. Currently the order of these sep‐
24638 arators is not checked, so illogical formats such as 1965/07/12, :
24639 ,09:45 will also be matched. For simplicity such variations are not
24640 shown in the list above. Otherwise, a time is only recognised as being
24641 associated with a date if there is only whitespace in between, or if
24642 the time was embedded in the date.
24643
24644 Days of the week are not normally scanned, but will be ignored if they
24645 occur at the start of the date pattern only. However, in contexts
24646 where it is useful to specify dates relative to today, days of the week
24647 with no other date specification may be given. The day is assumed to
24648 be either today or within the past week. Likewise, the words yester‐
24649 day, today and tomorrow are handled. All matches are case-insensitive.
24650 Hence if today is Monday, then Sunday is equivalent to yesterday, Mon‐
24651 day is equivalent to today, but Tuesday gives a date six days ago.
24652 This is not generally useful within the calendar file. Dates in this
24653 format may be combined with a time specification; for example Tomorrow,
24654 8 p.m..
24655
24656 For example, the standard date format:
24657
24658 Fri Aug 18 17:00:48 BST 2006
24659
24660 is handled by matching HH:MM:SS and removing it together with the
24661 matched (but unused) time zone. This leaves the following:
24662
24663 Fri Aug 18 2006
24664
24665 Fri is ignored and the rest is matched according to the standard rules.
24666
24667 Relative Time Format
24668 In certain places relative times are handled. Here, a date is not al‐
24669 lowed; instead a combination of various supported periods are allowed,
24670 together with an optional time. The periods must be in order from most
24671 to least significant.
24672
24673 In some cases, a more accurate calculation is possible when there is an
24674 anchor date: offsets of months or years pick the correct day, rather
24675 than being rounded, and it is possible to pick a particular day in a
24676 month as `(1st Friday)', etc., as described in more detail below.
24677
24678 Anchors are available in the following cases. If one or two times are
24679 passed to the function calendar, the start time acts an anchor for the
24680 end time when the end time is relative (even if the start time is im‐
24681 plicit). When examining calendar files, the scheduled event being ex‐
24682 amined anchors the warning time when it is given explicitly by means of
24683 the WARN keyword; likewise, the scheduled event anchors a repetition
24684 period when given by the RPT keyword, so that specifications such as
24685 RPT 2 months, 3rd Thursday are handled properly. Finally, the -R argu‐
24686 ment to calendar_scandate directly provides an anchor for relative cal‐
24687 culations.
24688
24689 The periods handled, with possible abbreviations are:
24690
24691 Years years, yrs, ys, year, yr, y, yearly. A year is 365.25 days un‐
24692 less there is an anchor.
24693
24694 Months months, mons, mnths, mths, month, mon, mnth, mth, monthly. Note
24695 that m, ms, mn, mns are ambiguous and are not handled. A month
24696 is a period of 30 days rather than a calendar month unless there
24697 is an anchor.
24698
24699 Weeks weeks, wks, ws, week, wk, w, weekly
24700
24701 Days days, dys, ds, day, dy, d, daily
24702
24703 Hours hours, hrs, hs, hour, hr, h, hourly
24704
24705 Minutes
24706 minutes, mins, minute, min, but not m, ms, mn or mns
24707
24708 Seconds
24709 seconds, secs, ss, second, sec, s
24710
24711 Spaces between the numbers are optional, but are required between
24712 items, although a comma may be used (with or without spaces).
24713
24714 The forms yearly to hourly allow the number to be omitted; it is as‐
24715 sumed to be 1. For example, 1 d and daily are equivalent. Note that
24716 using those forms with plurals is confusing; 2 yearly is the same as 2
24717 years, not twice yearly, so it is recommended they only be used without
24718 numbers.
24719
24720 When an anchor time is present, there is an extension to handle regular
24721 events in the form of the nth someday of the month. Such a specifica‐
24722 tion must occur immediately after any year and month specification, but
24723 before any time of day, and must be in the form n(th|st|rd) day, for
24724 example 1st Tuesday or 3rd Monday. As in other places, days are
24725 matched case insensitively, must be in English, and only the first
24726 three letters are significant except that a form beginning `month' does
24727 not match `Monday'. No attempt is made to sanitize the resulting date;
24728 attempts to squeeze too many occurrences into a month will push the day
24729 into the next month (but in the obvious fashion, retaining the correct
24730 day of the week).
24731
24732 Here are some examples:
24733
24734 30 years 3 months 4 days 3:42:41
24735 14 days 5 hours
24736 Monthly, 3rd Thursday
24737 4d,10hr
24738
24739 Example
24740 Here is an example calendar file. It uses a consistent date format, as
24741 recommended above.
24742
24743 Feb 1, 2006 14:30 Pointless bureaucratic meeting
24744 Mar 27, 2006 11:00 Mutual recrimination and finger pointing
24745 Bring water pistol and waterproofs
24746 Mar 31, 2006 14:00 Very serious managerial pontification
24747 # UID 12C7878A9A50
24748 Apr 10, 2006 13:30 Even more pointless blame assignment exercise WARN 30 mins
24749 May 18, 2006 16:00 Regular moaning session RPT monthly, 3rd Thursday
24750
24751 The second entry has a continuation line. The third entry has a con‐
24752 tinuation line that will not be shown when the entry is displayed, but
24753 the unique identifier will be used by the calendar_add function when
24754 updating the event. The fourth entry will produce a warning 30 minutes
24755 before the event (to allow you to equip yourself appropriately). The
24756 fifth entry repeats after a month on the 3rd Thursday, i.e. June 15,
24757 2006, at the same time.
24758
24760 This section describes functions that are designed to be called di‐
24761 rectly by the user. The first part describes those functions associ‐
24762 ated with the user's calendar; the second part describes the use in
24763 glob qualifiers.
24764
24765 Calendar system functions
24766 calendar [ -abdDsv ] [ -C calfile ] [ -n num ] [ -S showprog ]
24767 [ [ start ] end ]
24768 calendar -r [ -abdDrsv ] [ -C calfile ] [ -n num ] [ -S showprog ]
24769 [ start ]
24770 Show events in the calendar.
24771
24772 With no arguments, show events from the start of today until the
24773 end of the next working day after today. In other words, if to‐
24774 day is Friday, Saturday, or Sunday, show up to the end of the
24775 following Monday, otherwise show today and tomorrow.
24776
24777 If end is given, show events from the start of today up to the
24778 time and date given, which is in the format described in the
24779 previous section. Note that if this is a date the time is as‐
24780 sumed to be midnight at the start of the date, so that effec‐
24781 tively this shows all events before the given date.
24782
24783 end may start with a +, in which case the remainder of the spec‐
24784 ification is a relative time format as described in the previous
24785 section indicating the range of time from the start time that is
24786 to be included.
24787
24788 If start is also given, show events starting from that time and
24789 date. The word now can be used to indicate the current time.
24790
24791 To implement an alert when events are due, include calendar -s
24792 in your ~/.zshrc file.
24793
24794 Options:
24795
24796 -a Show all items in the calendar, regardless of the start
24797 and end.
24798
24799 -b Brief: don't display continuation lines (i.e. indented
24800 lines following the line with the date/time), just the
24801 first line.
24802
24803 -B lines
24804 Brief: display at most the first lines lines of the cal‐
24805 endar entry. `-B 1' is equivalent to `-b'.
24806
24807 -C calfile
24808 Explicitly specify a calendar file instead of the value
24809 of the calendar-file style or the default ~/calendar.
24810
24811 -d Move any events that have passed from the calendar file
24812 to the "done" file, as given by the done-file style or
24813 the default which is the calendar file with .done ap‐
24814 pended. This option is implied by the -s option.
24815
24816 -D Turns off the option -d, even if the -s option is also
24817 present.
24818
24819 -n num, -num
24820 Show at least num events, if present in the calendar
24821 file, regardless of the start and end.
24822
24823 -r Show all the remaining options in the calendar, ignoring
24824 the given end time. The start time is respected; any ar‐
24825 gument given is treated as a start time.
24826
24827 -s Use the shell's sched command to schedule a timed event
24828 that will warn the user when an event is due. Note that
24829 the sched command only runs if the shell is at an inter‐
24830 active prompt; a foreground task blocks the scheduled
24831 task from running until it is finished.
24832
24833 The timed event usually runs the programme calendar_show
24834 to show the event, as described in the section UTILITY
24835 FUNCTIONS below.
24836
24837 By default, a warning of the event is shown five minutes
24838 before it is due. The warning period can be configured
24839 by the style warn-time or for a single calendar entry by
24840 including WARN reltime in the first line of the entry,
24841 where reltime is one of the usual relative time formats.
24842
24843 A repeated event may be indicated by including RPT rel‐
24844 date in the first line of the entry. After the scheduled
24845 event has been displayed it will be re-entered into the
24846 calendar file at a time reldate after the existing event.
24847 Note that this is currently the only use made of the re‐
24848 peat count, so that it is not possible to query the
24849 schedule for a recurrence of an event in the calendar un‐
24850 til the previous event has passed.
24851
24852 If RPT is used, it is also possible to specify that cer‐
24853 tain recurrences of an event are rescheduled or can‐
24854 celled. This is done with the OCCURRENCE keyword, fol‐
24855 lowed by whitespace and the date and time of the occur‐
24856 rence in the regular sequence, followed by whitespace and
24857 either the date and time of the rescheduled event or the
24858 exact string CANCELLED. In this case the date and time
24859 must be in exactly the "date with local time" format used
24860 by the text/calendar MIME type (RFC 2445),
24861 <YYYY><MM><DD>T<hh><mm><ss> (note the presence of the
24862 literal character T). The first word (the regular recur‐
24863 rence) may be something other than a proper date/time to
24864 indicate that the event is additional to the normal se‐
24865 quence; a convention that retains the formatting appear‐
24866 ance is XXXXXXXXTXXXXXX.
24867
24868 Furthermore, it is useful to record the next regular re‐
24869 currence (as then the displayed date may be for a
24870 rescheduled event so cannot be used for calculating the
24871 regular sequence). This is specified by RECURRENCE and a
24872 time or date in the same format. calendar_add adds such
24873 an indication when it encounters a recurring event that
24874 does not include one, based on the headline date/time.
24875
24876 If calendar_add is used to update occurrences the UID
24877 keyword described there should be present in both the ex‐
24878 isting entry and the added occurrence in order to iden‐
24879 tify recurring event sequences.
24880
24881 For example,
24882
24883 Thu May 6, 2010 11:00 Informal chat RPT 1 week
24884 # RECURRENCE 20100506T110000
24885 # OCCURRENCE 20100513T110000 20100513T120000
24886 # OCCURRENCE 20100520T110000 CANCELLED
24887
24888 The event that occurs at 11:00 on 13th May 2010 is
24889 rescheduled an hour later. The event that occurs a week
24890 later is cancelled. The occurrences are given on a con‐
24891 tinuation line starting with a # character so will not
24892 usually be displayed as part of the event. As elsewhere,
24893 no account of time zones is taken with the times. After
24894 the next event occurs the headline date/time will be `Thu
24895 May 13, 2010 12:00' while the RECURRENCE date/time will
24896 be `20100513T110000' (note that cancelled and moved
24897 events are not taken account of in the RECURRENCE, which
24898 records what the next regular recurrence is, but they are
24899 accounted for in the headline date/time).
24900
24901 It is safe to run calendar -s to reschedule an existing
24902 event (if the calendar file has changed, for example),
24903 and also to have it running in multiples instances of the
24904 shell since the calendar file is locked when in use.
24905
24906 By default, expired events are moved to the "done" file;
24907 see the -d option. Use -D to prevent this.
24908
24909 -S showprog
24910 Explicitly specify a programme to be used for showing
24911 events instead of the value of the show-prog style or the
24912 default calendar_show.
24913
24914 -v Verbose: show more information about stages of process‐
24915 ing. This is useful for confirming that the function has
24916 successfully parsed the dates in the calendar file.
24917
24918 calendar_add [ -BL ] event ...
24919 Adds a single event to the calendar in the appropriate location.
24920 The event can contain multiple lines, as described in the sec‐
24921 tion `Calendar File Format' above. Using this function ensures
24922 that the calendar file is sorted in date and time order. It
24923 also makes special arrangements for locking the file while it is
24924 altered. The old calendar is left in a file with the suffix
24925 .old.
24926
24927 The option -B indicates that backing up the calendar file will
24928 be handled by the caller and should not be performed by calen‐
24929 dar_add. The option -L indicates that calendar_add does not
24930 need to lock the calendar file as it is already locked. These
24931 options will not usually be needed by users.
24932
24933 If the style reformat-date is true, the date and time of the new
24934 entry will be rewritten into the standard date format: see the
24935 descriptions of this style and the style date-format.
24936
24937 The function can use a unique identifier stored with each event
24938 to ensure that updates to existing events are treated correctly.
24939 The entry should contain the word UID, followed by whitespace,
24940 followed by a word consisting entirely of hexadecimal digits of
24941 arbitrary length (all digits are significant, including leading
24942 zeroes). As the UID is not directly useful to the user, it is
24943 convenient to hide it on an indented continuation line starting
24944 with a #, for example:
24945
24946 Aug 31, 2007 09:30 Celebrate the end of the holidays
24947 # UID 045B78A0
24948
24949 The second line will not be shown by the calendar function.
24950
24951 It is possible to specify the RPT keyword followed by CANCELLED
24952 instead of a relative time. This causes any matched event or
24953 series of events to be cancelled (the original event does not
24954 have to be marked as recurring in order to be cancelled by this
24955 method). A UID is required in order to match an existing event
24956 in the calendar.
24957
24958 calendar_add will attempt to manage recurrences and occurrences
24959 of repeating events as described for event scheduling by calen‐
24960 dar -s above. To reschedule or cancel a single event calen‐
24961 dar_add should be called with an entry that includes the correct
24962 UID but does not include the RPT keyword as this is taken to
24963 mean the entry applies to a series of repeating events and hence
24964 replaces all existing information. Each rescheduled or can‐
24965 celled occurrence must have an OCCURRENCE keyword in the entry
24966 passed to calendar_add which will be merged into the calendar
24967 file. Any existing reference to the occurrence is replaced. An
24968 occurrence that does not refer to a valid existing event is
24969 added as a one-off occurrence to the same calendar entry.
24970
24971 calendar_edit
24972 This calls the user's editor to edit the calendar file. If
24973 there are arguments, they are taken as the editor to use (the
24974 file name is appended to the commands); otherwise, the editor is
24975 given by the variable VISUAL, if set, else the variable EDITOR.
24976
24977 If the calendar scheduler was running, then after editing the
24978 file calendar -s is called to update it.
24979
24980 This function locks out the calendar system during the edit.
24981 Hence it should be used to edit the calendar file if there is
24982 any possibility of a calendar event occurring meanwhile. Note
24983 this can lead to another shell with calendar functions enabled
24984 hanging waiting for a lock, so it is necessary to quit the edi‐
24985 tor as soon as possible.
24986
24987 calendar_parse calendar-entry
24988 This is the internal function that analyses the parts of a cal‐
24989 endar entry, which is passed as the only argument. The function
24990 returns status 1 if the argument could not be parsed as a calen‐
24991 dar entry and status 2 if the wrong number of arguments were
24992 passed; it also sets the parameter reply to an empty associative
24993 array. Otherwise, it returns status 0 and sets elements of the
24994 associative array reply as follows:
24995
24996 time The time as a string of digits in the same units as
24997 $EPOCHSECONDS
24998 schedtime
24999 The regularly scheduled time. This may differ from the
25000 actual event time time if this is a recurring event and
25001 the next occurrence has been rescheduled. Then time
25002 gives the actual time and schedtime the time of the regu‐
25003 lar recurrence before modification.
25004 text1 The text from the line not including the date and time of
25005 the event, but including any WARN or RPT keywords and
25006 values.
25007 warntime
25008 Any warning time given by the WARN keyword as a string of
25009 digits containing the time at which to warn in the same
25010 units as $EPOCHSECONDS. (Note this is an absolute time,
25011 not the relative time passed down.) Not set no WARN key‐
25012 word and value were matched.
25013 warnstr
25014 The raw string matched after the WARN keyword, else un‐
25015 set.
25016 rpttime
25017 Any recurrence time given by the RPT keyword as a string
25018 of digits containing the time of the recurrence in the
25019 same units as $EPOCHSECONDS. (Note this is an absolute
25020 time.) Not set if no RPT keyword and value were matched.
25021 schedrpttime
25022 The next regularly scheduled occurrence of a recurring
25023 event before modification. This may differ from rpttime,
25024 which is the actual time of the event that may have been
25025 rescheduled from the regular time.
25026 rptstr The raw string matched after the RPT keyword, else unset.
25027 text2 The text from the line after removal of the date and any
25028 keywords and values.
25029
25030 calendar_showdate [ -r ] [ -f fmt ] date-spec ...
25031 The given date-spec is interpreted and the corresponding date
25032 and time printed. If the initial date-spec begins with a + or -
25033 it is treated as relative to the current time; date-specs after
25034 the first are treated as relative to the date calculated so far
25035 and a leading + is optional in that case. This allows one to
25036 use the system as a date calculator. For example, calen‐
25037 dar_showdate '+1 month, 1st Friday' shows the date of the first
25038 Friday of next month.
25039
25040 With the option -r nothing is printed but the value of the date
25041 and time in seconds since the epoch is stored in the parameter
25042 REPLY.
25043
25044 With the option -f fmt the given date/time conversion format is
25045 passed to strftime; see notes on the date-format style below.
25046
25047 In order to avoid ambiguity with negative relative date specifi‐
25048 cations, options must occur in separate words; in other words,
25049 -r and -f should not be combined in the same word.
25050
25051 calendar_sort
25052 Sorts the calendar file into date and time order. The old
25053 calendar is left in a file with the suffix .old.
25054
25055 Glob qualifiers
25056 age The function age can be autoloaded and use separately from the
25057 calendar system, although it uses the function calendar_scandate
25058 for date formatting. It requires the zsh/stat builtin, but uses
25059 only the builtin zstat.
25060
25061 age selects files having a given modification time for use as a
25062 glob qualifier. The format of the date is the same as that un‐
25063 derstood by the calendar system, described in the section FILE
25064 AND DATE FORMATS above.
25065
25066 The function can take one or two arguments, which can be sup‐
25067 plied either directly as command or arguments, or separately as
25068 shell parameters.
25069
25070 print *(e:age 2006/10/04 2006/10/09:)
25071
25072 The example above matches all files modified between the start
25073 of those dates. The second argument may alternatively be a rel‐
25074 ative time introduced by a +:
25075
25076 print *(e:age 2006/10/04 +5d:)
25077
25078 The example above is equivalent to the previous example.
25079
25080 In addition to the special use of days of the week, today and
25081 yesterday, times with no date may be specified; these apply to
25082 today. Obviously such uses become problematic around midnight.
25083
25084 print *(e-age 12:00 13:30-)
25085
25086 The example above shows files modified between 12:00 and 13:00
25087 today.
25088
25089 print *(e:age 2006/10/04:)
25090
25091 The example above matches all files modified on that date. If
25092 the second argument is omitted it is taken to be exactly 24
25093 hours after the first argument (even if the first argument con‐
25094 tains a time).
25095
25096 print *(e-age 2006/10/04:10:15 2006/10/04:10:45-)
25097
25098 The example above supplies times. Note that whitespace within
25099 the time and date specification must be quoted to ensure age re‐
25100 ceives the correct arguments, hence the use of the additional
25101 colon to separate the date and time.
25102
25103 AGEREF=2006/10/04:10:15
25104 AGEREF2=2006/10/04:10:45
25105 print *(+age)
25106
25107 This shows the same example before using another form of argu‐
25108 ment passing. The dates and times in the parameters AGEREF and
25109 AGEREF2 stay in effect until unset, but will be overridden if
25110 any argument is passed as an explicit argument to age. Any ex‐
25111 plicit argument causes both parameters to be ignored.
25112
25113 Instead of an explicit date and time, it's possible to use the
25114 modification time of a file as the date and time for either ar‐
25115 gument by introducing the file name with a colon:
25116
25117 print *(e-age :file1-)
25118
25119 matches all files created on the same day (24 hours starting
25120 from midnight) as file1.
25121
25122 print *(e-age :file1 :file2-)
25123
25124 matches all files modified no earlier than file1 and no later
25125 than file2; precision here is to the nearest second.
25126
25127 after
25128 before The functions after and before are simpler versions of age that
25129 take just one argument. The argument is parsed similarly to an
25130 argument of age; if it is not given the variable AGEREF is con‐
25131 sulted. As the names of the functions suggest, a file matches
25132 if its modification time is after or before the time and date
25133 specified. If a time only is given the date is today.
25134
25135 The two following examples are therefore equivalent:
25136 print *(e-after 12:00-)
25137 print *(e-after today:12:00-)
25138
25140 The zsh style mechanism using the zstyle command is describe in zshmod‐
25141 ules(1). This is the same mechanism used in the completion system.
25142
25143 The styles below are all examined in the context :datetime:function:,
25144 for example :datetime:calendar:.
25145
25146 calendar-file
25147 The location of the main calendar. The default is ~/calendar.
25148
25149 date-format
25150 A strftime format string (see strftime(3)) with the zsh exten‐
25151 sions providing various numbers with no leading zero or space if
25152 the number is a single digit as described for the %D{string}
25153 prompt format in the section EXPANSION OF PROMPT SEQUENCES in
25154 zshmisc(1).
25155
25156 This is used for outputting dates in calendar, both to support
25157 the -v option and when adding recurring events back to the cal‐
25158 endar file, and in calendar_showdate as the final output format.
25159
25160 If the style is not set, the default used is similar the stan‐
25161 dard system format as output by the date command (also known as
25162 `ctime format'): `%a %b %d %H:%M:%S %Z %Y'.
25163
25164 done-file
25165 The location of the file to which events which have passed are
25166 appended. The default is the calendar file location with the
25167 suffix .done. The style may be set to an empty string in which
25168 case a "done" file will not be maintained.
25169
25170 reformat-date
25171 Boolean, used by calendar_add. If it is true, the date and time
25172 of new entries added to the calendar will be reformatted to the
25173 format given by the style date-format or its default. Only the
25174 date and time of the event itself is reformatted; any subsidiary
25175 dates and times such as those associated with repeat and warning
25176 times are left alone.
25177
25178 show-prog
25179 The programme run by calendar for showing events. It will be
25180 passed the start time and stop time of the events requested in
25181 seconds since the epoch followed by the event text. Note that
25182 calendar -s uses a start time and stop time equal to one another
25183 to indicate alerts for specific events.
25184
25185 The default is the function calendar_show.
25186
25187 warn-time
25188 The time before an event at which a warning will be displayed,
25189 if the first line of the event does not include the text EVENT
25190 reltime. The default is 5 minutes.
25191
25193 calendar_lockfiles
25194 Attempt to lock the files given in the argument. To prevent
25195 problems with network file locking this is done in an ad hoc
25196 fashion by attempting to create a symbolic link to the file with
25197 the name file.lockfile. No other system level functions are
25198 used for locking, i.e. the file can be accessed and modified by
25199 any utility that does not use this mechanism. In particular,
25200 the user is not prevented from editing the calendar file at the
25201 same time unless calendar_edit is used.
25202
25203 Three attempts are made to lock the file before giving up. If
25204 the module zsh/zselect is available, the times of the attempts
25205 are jittered so that multiple instances of the calling function
25206 are unlikely to retry at the same time.
25207
25208 The files locked are appended to the array lockfiles, which
25209 should be local to the caller.
25210
25211 If all files were successfully locked, status zero is returned,
25212 else status one.
25213
25214 This function may be used as a general file locking function,
25215 although this will only work if only this mechanism is used to
25216 lock files.
25217
25218 calendar_read
25219 This is a backend used by various other functions to parse the
25220 calendar file, which is passed as the only argument. The array
25221 calendar_entries is set to the list of events in the file; no
25222 pruning is done except that ampersands are removed from the
25223 start of the line. Each entry may contain multiple lines.
25224
25225 calendar_scandate
25226 This is a generic function to parse dates and times that may be
25227 used separately from the calendar system. The argument is a
25228 date or time specification as described in the section FILE AND
25229 DATE FORMATS above. The parameter REPLY is set to the number of
25230 seconds since the epoch corresponding to that date or time. By
25231 default, the date and time may occur anywhere within the given
25232 argument.
25233
25234 Returns status zero if the date and time were successfully
25235 parsed, else one.
25236
25237 Options:
25238 -a The date and time are anchored to the start of the argu‐
25239 ment; they will not be matched if there is preceding
25240 text.
25241
25242 -A The date and time are anchored to both the start and end
25243 of the argument; they will not be matched if the is any
25244 other text in the argument.
25245
25246 -d Enable additional debugging output.
25247
25248 -m Minus. When -R anchor_time is also given the relative
25249 time is calculated backwards from anchor_time.
25250
25251 -r The argument passed is to be parsed as a relative time.
25252
25253 -R anchor_time
25254 The argument passed is to be parsed as a relative time.
25255 The time is relative to anchor_time, a time in seconds
25256 since the epoch, and the returned value is the absolute
25257 time corresponding to advancing anchor_time by the rela‐
25258 tive time given. This allows lengths of months to be
25259 correctly taken into account. If the final day does not
25260 exist in the given month, the last day of the final month
25261 is given. For example, if the anchor time is during 31st
25262 January 2007 and the relative time is 1 month, the final
25263 time is the same time of day during 28th February 2007.
25264
25265 -s In addition to setting REPLY, set REPLY2 to the remainder
25266 of the argument after the date and time have been
25267 stripped. This is empty if the option -A was given.
25268
25269 -t Allow a time with no date specification. The date is as‐
25270 sumed to be today. The behaviour is unspecified if the
25271 iron tongue of midnight is tolling twelve.
25272
25273 calendar_show
25274 The function used by default to display events. It accepts a
25275 start time and end time for events, both in epoch seconds, and
25276 an event description.
25277
25278 The event is always printed to standard output. If the command
25279 line editor is active (which will usually be the case) the com‐
25280 mand line will be redisplayed after the output.
25281
25282 If the parameter DISPLAY is set and the start and end times are
25283 the same (indicating a scheduled event), the function uses the
25284 command xmessage to display a window with the event details.
25285
25287 As the system is based entirely on shell functions (with a little sup‐
25288 port from the zsh/datetime module) the mechanisms used are not as ro‐
25289 bust as those provided by a dedicated calendar utility. Consequently
25290 the user should not rely on the shell for vital alerts.
25291
25292 There is no calendar_delete function.
25293
25294 There is no localization support for dates and times, nor any support
25295 for the use of time zones.
25296
25297 Relative periods of months and years do not take into account the vari‐
25298 able number of days.
25299
25300 The calendar_show function is currently hardwired to use xmessage for
25301 displaying alerts on X Window System displays. This should be config‐
25302 urable and ideally integrate better with the desktop.
25303
25304 calendar_lockfiles hangs the shell while waiting for a lock on a file.
25305 If called from a scheduled task, it should instead reschedule the event
25306 that caused it.
25307
25308
25309
25310ZSHTCPSYS(1) General Commands Manual ZSHTCPSYS(1)
25311
25312
25313
25315 zshtcpsys - zsh tcp system
25316
25318 A module zsh/net/tcp is provided to provide network I/O over TCP/IP
25319 from within the shell; see its description in zshmodules(1). This man‐
25320 ual page describes a function suite based on the module. If the module
25321 is installed, the functions are usually installed at the same time, in
25322 which case they will be available for autoloading in the default func‐
25323 tion search path. In addition to the zsh/net/tcp module, the zsh/zse‐
25324 lect module is used to implement timeouts on read operations. For
25325 troubleshooting tips, consult the corresponding advice for the zftp
25326 functions described in zshzftpsys(1).
25327
25328 There are functions corresponding to the basic I/O operations open,
25329 close, read and send, named tcp_open etc., as well as a function
25330 tcp_expect for pattern match analysis of data read as input. The sys‐
25331 tem makes it easy to receive data from and send data to multiple named
25332 sessions at once. In addition, it can be linked with the shell's line
25333 editor in such a way that input data is automatically shown at the ter‐
25334 minal. Other facilities available including logging, filtering and
25335 configurable output prompts.
25336
25337 To use the system where it is available, it should be enough to `au‐
25338 toload -U tcp_open' and run tcp_open as documented below to start a
25339 session. The tcp_open function will autoload the remaining functions.
25340
25342 Basic I/O
25343 tcp_open [ -qz ] host port [ sess ]
25344 tcp_open [ -qz ] [ -s sess | -l sess[,...] ] ...
25345 tcp_open [ -qz ] [ -a fd | -f fd ] [ sess ]
25346 Open a new session. In the first and simplest form, open a TCP
25347 connection to host host at port port; numeric and symbolic forms
25348 are understood for both.
25349
25350 If sess is given, this becomes the name of the session which can
25351 be used to refer to multiple different TCP connections. If sess
25352 is not given, the function will invent a numeric name value
25353 (note this is not the same as the file descriptor to which the
25354 session is attached). It is recommended that session names not
25355 include `funny' characters, where funny characters are not
25356 well-defined but certainly do not include alphanumerics or un‐
25357 derscores, and certainly do include whitespace.
25358
25359 In the second case, one or more sessions to be opened are given
25360 by name. A single session name is given after -s and a
25361 comma-separated list after -l; both options may be repeated as
25362 many times as necessary. A failure to open any session causes
25363 tcp_open to abort. The host and port are read from the file
25364 .ztcp_sessions in the same directory as the user's zsh initiali‐
25365 sation files, i.e. usually the home directory, but $ZDOTDIR if
25366 that is set. The file consists of lines each giving a session
25367 name and the corresponding host and port, in that order (note
25368 the session name comes first, not last), separated by white‐
25369 space.
25370
25371 The third form allows passive and fake TCP connections. If the
25372 option -a is used, its argument is a file descriptor open for
25373 listening for connections. No function front-end is provided to
25374 open such a file descriptor, but a call to `ztcp -l port' will
25375 create one with the file descriptor stored in the parameter $RE‐
25376 PLY. The listening port can be closed with `ztcp -c fd'. A
25377 call to `tcp_open -a fd' will block until a remote TCP connec‐
25378 tion is made to port on the local machine. At this point, a
25379 session is created in the usual way and is largely indistin‐
25380 guishable from an active connection created with one of the
25381 first two forms.
25382
25383 If the option -f is used, its argument is a file descriptor
25384 which is used directly as if it were a TCP session. How well
25385 the remainder of the TCP function system copes with this depends
25386 on what actually underlies this file descriptor. A regular file
25387 is likely to be unusable; a FIFO (pipe) of some sort will work
25388 better, but note that it is not a good idea for two different
25389 sessions to attempt to read from the same FIFO at once.
25390
25391 If the option -q is given with any of the three forms, tcp_open
25392 will not print informational messages, although it will in any
25393 case exit with an appropriate status.
25394
25395 If the line editor (zle) is in use, which is typically the case
25396 if the shell is interactive, tcp_open installs a handler inside
25397 zle which will check for new data at the same time as it checks
25398 for keyboard input. This is convenient as the shell consumes no
25399 CPU time while waiting; the test is performed by the operating
25400 system. Giving the option -z to any of the forms of tcp_open
25401 prevents the handler from being installed, so data must be read
25402 explicitly. Note, however, this is not necessary for executing
25403 complete sets of send and read commands from a function, as zle
25404 is not active at this point. Generally speaking, the handler is
25405 only active when the shell is waiting for input at a command
25406 prompt or in the vared builtin. The option has no effect if zle
25407 is not active; `[[ -o zle]]' will test for this.
25408
25409 The first session to be opened becomes the current session and
25410 subsequent calls to tcp_open do not change it. The current ses‐
25411 sion is stored in the parameter $TCP_SESS; see below for more
25412 detail about the parameters used by the system.
25413
25414 The function tcp_on_open, if defined, is called when a session
25415 is opened. See the description below.
25416
25417 tcp_close [ -qn ] [ -a | -l sess[,...] | sess ... ]
25418 Close the named sessions, or the current session if none is
25419 given, or all open sessions if -a is given. The options -l and
25420 -s are both handled for consistency with tcp_open, although the
25421 latter is redundant.
25422
25423 If the session being closed is the current one, $TCP_SESS is un‐
25424 set, leaving no current session, even if there are other ses‐
25425 sions still open.
25426
25427 If the session was opened with tcp_open -f, the file descriptor
25428 is closed so long as it is in the range 0 to 9 accessible di‐
25429 rectly from the command line. If the option -n is given, no at‐
25430 tempt will be made to close file descriptors in this case. The
25431 -n option is not used for genuine ztcp session; the file de‐
25432 scriptors are always closed with the session.
25433
25434 If the option -q is given, no informational messages will be
25435 printed.
25436
25437
25438 tcp_read [ -bdq ] [ -t TO ] [ -T TO ]
25439 [ -a | -u fd[,...] | -l sess[,...] | -s sess ... ]
25440 Perform a read operation on the current session, or on a list of
25441 sessions if any are given with -u, -l or -s, or all open ses‐
25442 sions if the option -a is given. Any of the -u, -l or -s op‐
25443 tions may be repeated or mixed together. The -u option speci‐
25444 fies a file descriptor directly (only those managed by this sys‐
25445 tem are useful), the other two specify sessions as described for
25446 tcp_open above.
25447
25448 The function checks for new data available on all the sessions
25449 listed. Unless the -b option is given, it will not block wait‐
25450 ing for new data. Any one line of data from any of the avail‐
25451 able sessions will be read, stored in the parameter $TCP_LINE,
25452 and displayed to standard output unless $TCP_SILENT contains a
25453 non-empty string. When printed to standard output the string
25454 $TCP_PROMPT will be shown at the start of the line; the default
25455 form for this includes the name of the session being read. See
25456 below for more information on these parameters. In this mode,
25457 tcp_read can be called repeatedly until it returns status 2
25458 which indicates all pending input from all specified sessions
25459 has been handled.
25460
25461 With the option -b, equivalent to an infinite timeout, the func‐
25462 tion will block until a line is available to read from one of
25463 the specified sessions. However, only a single line is re‐
25464 turned.
25465
25466 The option -d indicates that all pending input should be
25467 drained. In this case tcp_read may process multiple lines in
25468 the manner given above; only the last is stored in $TCP_LINE,
25469 but the complete set is stored in the array $tcp_lines. This is
25470 cleared at the start of each call to tcp_read.
25471
25472 The options -t and -T specify a timeout in seconds, which may be
25473 a floating point number for increased accuracy. With -t the
25474 timeout is applied before each line read. With -T, the timeout
25475 applies to the overall operation, possibly including multiple
25476 read operations if the option -d is present; without this op‐
25477 tion, there is no distinction between -t and -T.
25478
25479 The function does not print informational messages, but if the
25480 option -q is given, no error message is printed for a non-exis‐
25481 tent session.
25482
25483 A return status of 2 indicates a timeout or no data to read.
25484 Any other non-zero return status indicates some error condition.
25485
25486 See tcp_log for how to control where data is sent by tcp_read.
25487
25488 tcp_send [ -cnq ] [ -s sess | -l sess[,...] ] data ...
25489 tcp_send [ -cnq ] -a data ...
25490 Send the supplied data strings to all the specified sessions in
25491 turn. The underlying operation differs little from a `print -r'
25492 to the session's file descriptor, although it attempts to pre‐
25493 vent the shell from dying owing to a SIGPIPE caused by an at‐
25494 tempt to write to a defunct session.
25495
25496 The option -c causes tcp_send to behave like cat. It reads
25497 lines from standard input until end of input and sends them in
25498 turn to the specified session(s) exactly as if they were given
25499 as data arguments to individual tcp_send commands.
25500
25501 The option -n prevents tcp_send from putting a newline at the
25502 end of the data strings.
25503
25504 The remaining options all behave as for tcp_read.
25505
25506 The data arguments are not further processed once they have been
25507 passed to tcp_send; they are simply passed down to print -r.
25508
25509 If the parameter $TCP_OUTPUT is a non-empty string and logging
25510 is enabled then the data sent to each session will be echoed to
25511 the log file(s) with $TCP_OUTPUT in front where appropriate,
25512 much in the manner of $TCP_PROMPT.
25513
25514 Session Management
25515 tcp_alias [ -q ] alias=sess ...
25516 tcp_alias [ -q ] [ alias ... ]
25517 tcp_alias -d [ -q ] alias ...
25518 This function is not particularly well tested.
25519
25520 The first form creates an alias for a session name; alias can
25521 then be used to refer to the existing session sess. As many
25522 aliases may be listed as required.
25523
25524 The second form lists any aliases specified, or all aliases if
25525 none.
25526
25527 The third form deletes all the aliases listed. The underlying
25528 sessions are not affected.
25529
25530 The option -q suppresses an inconsistently chosen subset of er‐
25531 ror messages.
25532
25533 tcp_log [ -asc ] [ -n | -N ] [ logfile ]
25534 With an argument logfile, all future input from tcp_read will be
25535 logged to the named file. Unless -a (append) is given, this
25536 file will first be truncated or created empty. With no argu‐
25537 ments, show the current status of logging.
25538
25539 With the option -s, per-session logging is enabled. Input from
25540 tcp_read is output to the file logfile.sess. As the session is
25541 automatically discriminated by the filename, the contents are
25542 raw (no $TCP_PROMPT). The option -a applies as above.
25543 Per-session logging and logging of all data in one file are not
25544 mutually exclusive.
25545
25546 The option -c closes all logging, both complete and per-session
25547 logs.
25548
25549 The options -n and -N respectively turn off or restore output of
25550 data read by tcp_read to standard output; hence `tcp_log -cn'
25551 turns off all output by tcp_read.
25552
25553 The function is purely a convenient front end to setting the pa‐
25554 rameters $TCP_LOG, $TCP_LOG_SESS, $TCP_SILENT, which are de‐
25555 scribed below.
25556
25557 tcp_rename old new
25558 Rename session old to session new. The old name becomes in‐
25559 valid.
25560
25561 tcp_sess [ sess [ command [ arg ... ] ] ]
25562 With no arguments, list all the open sessions and associated
25563 file descriptors. The current session is marked with a star.
25564 For use in functions, direct access to the parameters
25565 $tcp_by_name, $tcp_by_fd and $TCP_SESS is probably more conve‐
25566 nient; see below.
25567
25568 With a sess argument, set the current session to sess. This is
25569 equivalent to changing $TCP_SESS directly.
25570
25571 With additional arguments, temporarily set the current session
25572 while executing `command arg ...'. command is re-evaluated so
25573 as to expand aliases etc., but the remaining args are passed
25574 through as that appear to tcp_sess. The original session is re‐
25575 stored when tcp_sess exits.
25576
25577 Advanced I/O
25578 tcp_command send-option ... send-argument ...
25579 This is a convenient front-end to tcp_send. All arguments are
25580 passed to tcp_send, then the function pauses waiting for data.
25581 While data is arriving at least every $TCP_TIMEOUT (default 0.3)
25582 seconds, data is handled and printed out according to the cur‐
25583 rent settings. Status 0 is always returned.
25584
25585 This is generally only useful for interactive use, to prevent
25586 the display becoming fragmented by output returned from the con‐
25587 nection. Within a programme or function it is generally better
25588 to handle reading data by a more explicit method.
25589
25590
25591 tcp_expect [ -q ] [ -p var | -P var ] [ -t TO | -T TO ]
25592 [ -a | -s sess | -l sess[,...] ] pattern ...
25593 Wait for input matching any of the given patterns from any of
25594 the specified sessions. Input is ignored until an input line
25595 matches one of the given patterns; at this point status zero is
25596 returned, the matching line is stored in $TCP_LINE, and the full
25597 set of lines read during the call to tcp_expect is stored in the
25598 array $tcp_expect_lines.
25599
25600 Sessions are specified in the same way as tcp_read: the default
25601 is to use the current session, otherwise the sessions specified
25602 by -a, -s, or -l are used.
25603
25604 Each pattern is a standard zsh extended-globbing pattern; note
25605 that it needs to be quoted to avoid it being expanded immedi‐
25606 ately by filename generation. It must match the full line, so
25607 to match a substring there must be a `*' at the start and end.
25608 The line matched against includes the $TCP_PROMPT added by
25609 tcp_read. It is possible to include the globbing flags `#b' or
25610 `#m' in the patterns to make backreferences available in the pa‐
25611 rameters $MATCH, $match, etc., as described in the base zsh doc‐
25612 umentation on pattern matching.
25613
25614 Unlike tcp_read, the default behaviour of tcp_expect is to block
25615 indefinitely until the required input is found. This can be
25616 modified by specifying a timeout with -t or -T; these function
25617 as in tcp_read, specifying a per-read or overall timeout, re‐
25618 spectively, in seconds, as an integer or floating-point number.
25619 As tcp_read, the function returns status 2 if a timeout occurs.
25620
25621 The function returns as soon as any one of the patterns given
25622 match. If the caller needs to know which of the patterns
25623 matched, the option -p var can be used; on return, $var is set
25624 to the number of the pattern using ordinary zsh indexing, i.e.
25625 the first is 1, and so on. Note the absence of a `$' in front
25626 of var. To avoid clashes, the parameter cannot begin with `_ex‐
25627 pect'. The index -1 is used if there is a timeout and 0 if
25628 there is no match.
25629
25630 The option -P var works similarly to -p, but instead of numeri‐
25631 cal indexes the regular arguments must begin with a prefix fol‐
25632 lowed by a colon: that prefix is then used as a tag to which var
25633 is set when the argument matches. The tag timeout is used if
25634 there is a timeout and the empty string if there is no match.
25635 Note it is acceptable for different arguments to start with the
25636 same prefix if the matches do not need to be distinguished.
25637
25638 The option -q is passed directly down to tcp_read.
25639
25640 As all input is done via tcp_read, all the usual rules about
25641 output of lines read apply. One exception is that the parameter
25642 $tcp_lines will only reflect the line actually matched by
25643 tcp_expect; use $tcp_expect_lines for the full set of lines read
25644 during the function call.
25645
25646 tcp_proxy
25647 This is a simple-minded function to accept a TCP connection and
25648 execute a command with I/O redirected to the connection. Ex‐
25649 treme caution should be taken as there is no security whatsoever
25650 and this can leave your computer open to the world. Ideally, it
25651 should only be used behind a firewall.
25652
25653 The first argument is a TCP port on which the function will lis‐
25654 ten.
25655
25656 The remaining arguments give a command and its arguments to exe‐
25657 cute with standard input, standard output and standard error
25658 redirected to the file descriptor on which the TCP session has
25659 been accepted. If no command is given, a new zsh is started.
25660 This gives everyone on your network direct access to your ac‐
25661 count, which in many cases will be a bad thing.
25662
25663 The command is run in the background, so tcp_proxy can then ac‐
25664 cept new connections. It continues to accept new connections
25665 until interrupted.
25666
25667 tcp_spam [ -ertv ] [ -a | -s sess | -l sess[,...] ] cmd [ arg ... ]
25668 Execute `cmd [ arg ... ]' for each session in turn. Note this
25669 executes the command and arguments; it does not send the command
25670 line as data unless the -t (transmit) option is given.
25671
25672 The sessions may be selected explicitly with the standard -a, -s
25673 or -l options, or may be chosen implicitly. If none of the
25674 three options is given the rules are: first, if the array
25675 $tcp_spam_list is set, this is taken as the list of sessions,
25676 otherwise all sessions are taken. Second, any sessions given in
25677 the array $tcp_no_spam_list are removed from the list of ses‐
25678 sions.
25679
25680 Normally, any sessions added by the `-a' flag or when all ses‐
25681 sions are chosen implicitly are spammed in alphabetic order;
25682 sessions given by the $tcp_spam_list array or on the command
25683 line are spammed in the order given. The -r flag reverses the
25684 order however it was arrived it.
25685
25686 The -v flag specifies that a $TCP_PROMPT will be output before
25687 each session. This is output after any modification to TCP_SESS
25688 by the user-defined tcp_on_spam function described below. (Ob‐
25689 viously that function is able to generate its own output.)
25690
25691 If the option -e is present, the line given as `cmd [ arg ... ]'
25692 is executed using eval, otherwise it is executed without any
25693 further processing.
25694
25695 tcp_talk
25696 This is a fairly simple-minded attempt to force input to the
25697 line editor to go straight to the default TCP_SESS.
25698
25699 An escape string, $TCP_TALK_ESCAPE, default `:', is used to al‐
25700 low access to normal shell operation. If it is on its own at
25701 the start of the line, or followed only by whitespace, the line
25702 editor returns to normal operation. Otherwise, the string and
25703 any following whitespace are skipped and the remainder of the
25704 line executed as shell input without any change of the line edi‐
25705 tor's operating mode.
25706
25707 The current implementation is somewhat deficient in terms of use
25708 of the command history. For this reason, many users will prefer
25709 to use some form of alternative approach for sending data easily
25710 to the current session. One simple approach is to alias some
25711 special character (such as `%') to `tcp_command --'.
25712
25713 tcp_wait
25714 The sole argument is an integer or floating point number which
25715 gives the seconds to delay. The shell will do nothing for that
25716 period except wait for input on all TCP sessions by calling
25717 tcp_read -a. This is similar to the interactive behaviour at
25718 the command prompt when zle handlers are installed.
25719
25720 `One-shot' file transfer
25721 tcp_point port
25722 tcp_shoot host port
25723 This pair of functions provide a simple way to transfer a file
25724 between two hosts within the shell. Note, however, that bulk
25725 data transfer is currently done using cat. tcp_point reads any
25726 data arriving at port and sends it to standard output; tcp_shoot
25727 connects to port on host and sends its standard input. Any un‐
25728 used port may be used; the standard mechanism for picking a port
25729 is to think of a random four-digit number above 1024 until one
25730 works.
25731
25732 To transfer a file from host woodcock to host springes, on
25733 springes:
25734
25735 tcp_point 8091 >output_file
25736
25737 and on woodcock:
25738
25739 tcp_shoot springes 8091 <input_file
25740
25741 As these two functions do not require tcp_open to set up a TCP
25742 connection first, they may need to be autoloaded separately.
25743
25745 Certain functions, if defined by the user, will be called by the func‐
25746 tion system in certain contexts. This facility depends on the module
25747 zsh/parameter, which is usually available in interactive shells as the
25748 completion system depends on it. None of the functions need be de‐
25749 fined; they simply provide convenient hooks when necessary.
25750
25751 Typically, these are called after the requested action has been taken,
25752 so that the various parameters will reflect the new state.
25753
25754 tcp_on_alias alias fd
25755 When an alias is defined, this function will be called with two
25756 arguments: the name of the alias, and the file descriptor of the
25757 corresponding session.
25758
25759 tcp_on_awol sess fd
25760 If the function tcp_fd_handler is handling input from the line
25761 editor and detects that the file descriptor is no longer reus‐
25762 able, by default it removes it from the list of file descriptors
25763 handled by this method and prints a message. If the function
25764 tcp_on_awol is defined it is called immediately before this
25765 point. It may return status 100, which indicates that the nor‐
25766 mal handling should still be performed; any other return status
25767 indicates that no further action should be taken and the
25768 tcp_fd_handler should return immediately with the given status.
25769 Typically the action of tcp_on_awol will be to close the ses‐
25770 sion.
25771
25772 The variable TCP_INVALIDATE_ZLE will be a non-empty string if it
25773 is necessary to invalidate the line editor display using `zle
25774 -I' before printing output from the function.
25775
25776 (`AWOL' is military jargon for `absent without leave' or some
25777 variation. It has no pre-existing technical meaning known to
25778 the author.)
25779
25780 tcp_on_close sess fd
25781 This is called with the name of a session being closed and the
25782 file descriptor which corresponded to that session. Both will
25783 be invalid by the time the function is called.
25784
25785 tcp_on_open sess fd
25786 This is called after a new session has been defined with the
25787 session name and file descriptor as arguments. If it returns a
25788 non-zero status, opening the session is assumed to fail and the
25789 session is closed again; however, tcp_open will continue to at‐
25790 tempt to open any remaining sessions given on the command line.
25791
25792 tcp_on_rename oldsess fd newsess
25793 This is called after a session has been renamed with the three
25794 arguments old session name, file descriptor, new session name.
25795
25796 tcp_on_spam sess command ...
25797 This is called once for each session spammed, just before a com‐
25798 mand is executed for a session by tcp_spam. The arguments are
25799 the session name followed by the command list to be executed.
25800 If tcp_spam was called with the option -t, the first command
25801 will be tcp_send.
25802
25803 This function is called after $TCP_SESS is set to reflect the
25804 session to be spammed, but before any use of it is made. Hence
25805 it is possible to alter the value of $TCP_SESS within this func‐
25806 tion. For example, the session arguments to tcp_spam could in‐
25807 clude extra information to be stripped off and processed in
25808 tcp_on_spam.
25809
25810 If the function sets the parameter $REPLY to `done', the command
25811 line is not executed; in addition, no prompt is printed for the
25812 -v option to tcp_spam.
25813
25814 tcp_on_unalias alias fd
25815 This is called with the name of an alias and the corresponding
25816 session's file descriptor after an alias has been deleted.
25817
25819 The following functions are used by the TCP function system but will
25820 rarely if ever need to be called directly.
25821
25822 tcp_fd_handler
25823 This is the function installed by tcp_open for handling input
25824 from within the line editor, if that is required. It is in the
25825 format documented for the builtin `zle -F' in zshzle(1) .
25826
25827 While active, the function sets the parameter TCP_HANDLER_ACTIVE
25828 to 1. This allows shell code called internally (for example, by
25829 setting tcp_on_read) to tell if is being called when the shell
25830 is otherwise idle at the editor prompt.
25831
25832 tcp_output [ -q ] -P prompt -F fd -S sess
25833 This function is used for both logging and handling output to
25834 standard output, from within tcp_read and (if $TCP_OUTPUT is
25835 set) tcp_send.
25836
25837 The prompt to use is specified by -P; the default is the empty
25838 string. It can contain:
25839 %c Expands to 1 if the session is the current session, oth‐
25840 erwise 0. Used with ternary expressions such as
25841 `%(c.-.+)' to output `+' for the current session and `-'
25842 otherwise.
25843
25844 %f Replaced by the session's file descriptor.
25845
25846 %s Replaced by the session name.
25847
25848 %% Replaced by a single `%'.
25849
25850 The option -q suppresses output to standard output, but not to
25851 any log files which are configured.
25852
25853 The -S and -F options are used to pass in the session name and
25854 file descriptor for possible replacement in the prompt.
25855
25857 Parameters follow the usual convention that uppercase is used for
25858 scalars and integers, while lowercase is used for normal and associa‐
25859 tive array. It is always safe for user code to read these parameters.
25860 Some parameters may also be set; these are noted explicitly. Others
25861 are included in this group as they are set by the function system for
25862 the user's benefit, i.e. setting them is typically not useful but is
25863 benign.
25864
25865 It is often also useful to make settable parameters local to a func‐
25866 tion. For example, `local TCP_SILENT=1' specifies that data read dur‐
25867 ing the function call will not be printed to standard output, regard‐
25868 less of the setting outside the function. Likewise, `local
25869 TCP_SESS=sess' sets a session for the duration of a function, and `lo‐
25870 cal TCP_PROMPT=' specifies that no prompt is used for input during the
25871 function.
25872
25873 tcp_expect_lines
25874 Array. The set of lines read during the last call to tcp_ex‐
25875 pect, including the last ($TCP_LINE).
25876
25877 tcp_filter
25878 Array. May be set directly. A set of extended globbing patterns
25879 which, if matched in tcp_output, will cause the line not to be
25880 printed to standard output. The patterns should be defined as
25881 described for the arguments to tcp_expect. Output of line to
25882 log files is not affected.
25883
25884 TCP_HANDLER_ACTIVE
25885 Scalar. Set to 1 within tcp_fd_handler to indicate to functions
25886 called recursively that they have been called during an editor
25887 session. Otherwise unset.
25888
25889 TCP_LINE
25890 The last line read by tcp_read, and hence also tcp_expect.
25891
25892 TCP_LINE_FD
25893 The file descriptor from which $TCP_LINE was read.
25894 ${tcp_by_fd[$TCP_LINE_FD]} will give the corresponding session
25895 name.
25896
25897 tcp_lines
25898 Array. The set of lines read during the last call to tcp_read,
25899 including the last ($TCP_LINE).
25900
25901 TCP_LOG
25902 May be set directly, although it is also controlled by tcp_log.
25903 The name of a file to which output from all sessions will be
25904 sent. The output is proceeded by the usual $TCP_PROMPT. If it
25905 is not an absolute path name, it will follow the user's current
25906 directory.
25907
25908 TCP_LOG_SESS
25909 May be set directly, although it is also controlled by tcp_log.
25910 The prefix for a set of files to which output from each session
25911 separately will be sent; the full filename is
25912 ${TCP_LOG_SESS}.sess. Output to each file is raw; no prompt is
25913 added. If it is not an absolute path name, it will follow the
25914 user's current directory.
25915
25916 tcp_no_spam_list
25917 Array. May be set directly. See tcp_spam for how this is used.
25918
25919 TCP_OUTPUT
25920 May be set directly. If a non-empty string, any data sent to a
25921 session by tcp_send will be logged. This parameter gives the
25922 prompt to be used in a file specified by $TCP_LOG but not in a
25923 file generated from $TCP_LOG_SESS. The prompt string has the
25924 same format as TCP_PROMPT and the same rules for its use apply.
25925
25926 TCP_PROMPT
25927 May be set directly. Used as the prefix for data read by
25928 tcp_read which is printed to standard output or to the log file
25929 given by $TCP_LOG, if any. Any `%s', `%f' or `%%' occurring in
25930 the string will be replaced by the name of the session, the ses‐
25931 sion's underlying file descriptor, or a single `%', respec‐
25932 tively. The expression `%c' expands to 1 if the session being
25933 read is the current session, else 0; this is most useful in
25934 ternary expressions such as `%(c.-.+)' which outputs `+' if the
25935 session is the current one, else `-'.
25936
25937 If the prompt starts with %P, this is stripped and the complete
25938 result of the previous stage is passed through standard prompt
25939 %-style formatting before being output.
25940
25941 TCP_READ_DEBUG
25942 May be set directly. If this has non-zero length, tcp_read will
25943 give some limited diagnostics about data being read.
25944
25945 TCP_SECONDS_START
25946 This value is created and initialised to zero by tcp_open.
25947
25948 The functions tcp_read and tcp_expect use the shell's SECONDS
25949 parameter for their own timing purposes. If that parameter is
25950 not of floating point type on entry to one of the functions, it
25951 will create a local parameter SECONDS which is floating point
25952 and set the parameter TCP_SECONDS_START to the previous value of
25953 $SECONDS. If the parameter is already floating point, it is
25954 used without a local copy being created and TCP_SECONDS_START is
25955 not set. As the global value is zero, the shell elapsed time is
25956 guaranteed to be the sum of $SECONDS and $TCP_SECONDS_START.
25957
25958 This can be avoided by setting SECONDS globally to a floating
25959 point value using `typeset -F SECONDS'; then the TCP functions
25960 will never make a local copy and never set TCP_SECONDS_START to
25961 a non-zero value.
25962
25963 TCP_SESS
25964 May be set directly. The current session; must refer to one of
25965 the sessions established by tcp_open.
25966
25967 TCP_SILENT
25968 May be set directly, although it is also controlled by tcp_log.
25969 If of non-zero length, data read by tcp_read will not be written
25970 to standard output, though may still be written to a log file.
25971
25972 tcp_spam_list
25973 Array. May be set directly. See the description of the func‐
25974 tion tcp_spam for how this is used.
25975
25976 TCP_TALK_ESCAPE
25977 May be set directly. See the description of the function
25978 tcp_talk for how this is used.
25979
25980 TCP_TIMEOUT
25981 May be set directly. Currently this is only used by the func‐
25982 tion tcp_command, see above.
25983
25985 The following parameters are not set by the function system, but have a
25986 special effect if set by the user.
25987
25988 tcp_on_read
25989 This should be an associative array; if it is not, the behaviour
25990 is undefined. Each key is the name of a shell function or other
25991 command, and the corresponding value is a shell pattern (using
25992 EXTENDED_GLOB). Every line read from a TCP session directly or
25993 indirectly using tcp_read (which includes lines read by tcp_ex‐
25994 pect) is compared against the pattern. If the line matches, the
25995 command given in the key is called with two arguments: the name
25996 of the session from which the line was read, and the line it‐
25997 self.
25998
25999 If any function called to handle a line returns a non-zero sta‐
26000 tus, the line is not output. Thus a tcp_on_read handler con‐
26001 taining only the instruction `return 1' can be used to suppress
26002 output of particular lines (see, however, tcp_filter above).
26003 However, the line is still stored in TCP_LINE and tcp_lines;
26004 this occurs after all tcp_on_read processing.
26005
26007 These parameters are controlled by the function system; they may be
26008 read directly, but should not usually be set by user code.
26009
26010 tcp_aliases
26011 Associative array. The keys are the names of sessions estab‐
26012 lished with tcp_open; each value is a space-separated list of
26013 aliases which refer to that session.
26014
26015 tcp_by_fd
26016 Associative array. The keys are session file descriptors; each
26017 value is the name of that session.
26018
26019 tcp_by_name
26020 Associative array. The keys are the names of sessions; each
26021 value is the file descriptor associated with that session.
26022
26024 Here is a trivial example using a remote calculator.
26025
26026 To create a calculator server on port 7337 (see the dc manual page for
26027 quite how infuriating the underlying command is):
26028
26029 tcp_proxy 7337 dc
26030
26031 To connect to this from the same host with a session also named `dc':
26032
26033 tcp_open localhost 7337 dc
26034
26035 To send a command to the remote session and wait a short while for out‐
26036 put (assuming dc is the current session):
26037
26038 tcp_command 2 4 + p
26039
26040 To close the session:
26041
26042 tcp_close
26043
26044 The tcp_proxy needs to be killed to be stopped. Note this will not
26045 usually kill any connections which have already been accepted, and also
26046 that the port is not immediately available for reuse.
26047
26048 The following chunk of code puts a list of sessions into an xterm
26049 header, with the current session followed by a star.
26050
26051 print -n "\033]2;TCP:" ${(k)tcp_by_name:/$TCP_SESS/$TCP_SESS\*} "\a"
26052
26054 The function tcp_read uses the shell's normal read builtin. As this
26055 reads a complete line at once, data arriving without a terminating new‐
26056 line can cause the function to block indefinitely.
26057
26058 Though the function suite works well for interactive use and for data
26059 arriving in small amounts, the performance when large amounts of data
26060 are being exchanged is likely to be extremely poor.
26061
26062
26063
26064ZSHZFTPSYS(1) General Commands Manual ZSHZFTPSYS(1)
26065
26066
26067
26069 zshzftpsys - zftp function front-end
26070
26072 This describes the set of shell functions supplied with the source dis‐
26073 tribution as an interface to the zftp builtin command, allowing you to
26074 perform FTP operations from the shell command line or within functions
26075 or scripts. The interface is similar to a traditional FTP client (e.g.
26076 the ftp command itself, see ftp(1)), but as it is entirely done within
26077 the shell all the familiar completion, editing and globbing features,
26078 and so on, are present, and macros are particularly simple to write as
26079 they are just ordinary shell functions.
26080
26081 The prerequisite is that the zftp command, as described in zshmod‐
26082 ules(1) , must be available in the version of zsh installed at your
26083 site. If the shell is configured to load new commands at run time, it
26084 probably is: typing `zmodload zsh/zftp' will make sure (if that runs
26085 silently, it has worked). If this is not the case, it is possible zftp
26086 was linked into the shell anyway: to test this, type `which zftp' and
26087 if zftp is available you will get the message `zftp: shell built-in
26088 command'.
26089
26090 Commands given directly with zftp builtin may be interspersed between
26091 the functions in this suite; in a few cases, using zftp directly may
26092 cause some of the status information stored in shell parameters to be‐
26093 come invalid. Note in particular the description of the variables
26094 $ZFTP_TMOUT, $ZFTP_PREFS and $ZFTP_VERBOSE for zftp.
26095
26097 You should make sure all the functions from the Functions/Zftp direc‐
26098 tory of the source distribution are available; they all begin with the
26099 two letters `zf'. They may already have been installed on your system;
26100 otherwise, you will need to find them and copy them. The directory
26101 should appear as one of the elements of the $fpath array (this should
26102 already be the case if they were installed), and at least the function
26103 zfinit should be autoloaded; it will autoload the rest. Finally, to
26104 initialize the use of the system you need to call the zfinit function.
26105 The following code in your .zshrc will arrange for this; assume the
26106 functions are stored in the directory ~/myfns:
26107
26108 fpath=(~/myfns $fpath)
26109 autoload -U zfinit
26110 zfinit
26111
26112 Note that zfinit assumes you are using the zmodload method to load the
26113 zftp command. If it is already built into the shell, change zfinit to
26114 zfinit -n. It is helpful (though not essential) if the call to zfinit
26115 appears after any code to initialize the new completion system, else
26116 unnecessary compctl commands will be given.
26117
26119 The sequence of operations in performing a file transfer is essentially
26120 the same as that in a standard FTP client. Note that, due to a quirk
26121 of the shell's getopts builtin, for those functions that handle options
26122 you must use `--' rather than `-' to ensure the remaining arguments are
26123 treated literally (a single `-' is treated as an argument).
26124
26125 Opening a connection
26126 zfparams [ host [ user [ password ... ] ] ]
26127 Set or show the parameters for a future zfopen with no argu‐
26128 ments. If no arguments are given, the current parameters are
26129 displayed (the password will be shown as a line of asterisks).
26130 If a host is given, and either the user or password is not, they
26131 will be prompted for; also, any parameter given as `?' will be
26132 prompted for, and if the `?' is followed by a string, that will
26133 be used as the prompt. As zfopen calls zfparams to store the
26134 parameters, this usually need not be called directly.
26135
26136 A single argument `-' will delete the stored parameters. This
26137 will also cause the memory of the last directory (and so on) on
26138 the other host to be deleted.
26139
26140 zfopen [ -1 ] [ host [ user [ password [ account ] ] ] ]
26141 If host is present, open a connection to that host under user‐
26142 name user with password password (and, on the rare occasions
26143 when it is necessary, account account). If a necessary parame‐
26144 ter is missing or given as `?' it will be prompted for. If host
26145 is not present, use a previously stored set of parameters.
26146
26147 If the command was successful, and the terminal is compatible
26148 with xterm or is sun-cmd, a summary will appear in the title
26149 bar, giving the local host:directory and the remote host:direc‐
26150 tory; this is handled by the function zftp_chpwd, described be‐
26151 low.
26152
26153 Normally, the host, user and password are internally recorded
26154 for later re-opening, either by a zfopen with no arguments, or
26155 automatically (see below). With the option `-1', no information
26156 is stored. Also, if an open command with arguments failed, the
26157 parameters will not be retained (and any previous parameters
26158 will also be deleted). A zfopen on its own, or a zfopen -1,
26159 never alters the stored parameters.
26160
26161 Both zfopen and zfanon (but not zfparams) understand URLs of the
26162 form ftp://host/path... as meaning to connect to the host, then
26163 change directory to path (which must be a directory, not a
26164 file). The `ftp://' can be omitted; the trailing `/' is enough
26165 to trigger recognition of the path. Note prefixes other than
26166 `ftp:' are not recognized, and that all characters after the
26167 first slash beyond host are significant in path.
26168
26169 zfanon [ -1 ] host
26170 Open a connection host for anonymous FTP. The username used is
26171 `anonymous'. The password (which will be reported the first
26172 time) is generated as user@host; this is then stored in the
26173 shell parameter $EMAIL_ADDR which can alternatively be set manu‐
26174 ally to a suitable string.
26175
26176 Directory management
26177 zfcd [ dir ]
26178 zfcd -
26179 zfcd old new
26180 Change the current directory on the remote server: this is im‐
26181 plemented to have many of the features of the shell builtin cd.
26182
26183 In the first form with dir present, change to the directory dir.
26184 The command `zfcd ..' is treated specially, so is guaranteed to
26185 work on non-UNIX servers (note this is handled internally by
26186 zftp). If dir is omitted, has the effect of `zfcd ~'.
26187
26188 The second form changes to the directory previously current.
26189
26190 The third form attempts to change the current directory by re‐
26191 placing the first occurrence of the string old with the string
26192 new in the current directory.
26193
26194 Note that in this command, and indeed anywhere a remote filename
26195 is expected, the string which on the local host corresponds to
26196 `~' is converted back to a `~' before being passed to the remote
26197 machine. This is convenient because of the way expansion is
26198 performed on the command line before zfcd receives a string.
26199 For example, suppose the command is `zfcd ~/foo'. The shell
26200 will expand this to a full path such as `zfcd
26201 /home/user2/pws/foo'. At this stage, zfcd recognises the ini‐
26202 tial path as corresponding to `~' and will send the directory to
26203 the remote host as ~/foo, so that the `~' will be expanded by
26204 the server to the correct remote host directory. Other named
26205 directories of the form `~name' are not treated in this fashion.
26206
26207 zfhere Change directory on the remote server to the one corresponding
26208 to the current local directory, with special handling of `~' as
26209 in zfcd. For example, if the current local directory is
26210 ~/foo/bar, then zfhere performs the effect of `zfcd ~/foo/bar'.
26211
26212 zfdir [ -rfd ] [ - ] [ dir-options ] [ dir ]
26213 Produce a long directory listing. The arguments dir-options and
26214 dir are passed directly to the server and their effect is imple‐
26215 mentation dependent, but specifying a particular remote direc‐
26216 tory dir is usually possible. The output is passed through a
26217 pager given by the environment variable $PAGER, or `more' if
26218 that is not set.
26219
26220 The directory is usually cached for re-use. In fact, two caches
26221 are maintained. One is for use when there is no dir-options or
26222 dir, i.e. a full listing of the current remote directory; it is
26223 flushed when the current remote directory changes. The other is
26224 kept for repeated use of zfdir with the same arguments; for ex‐
26225 ample, repeated use of `zfdir /pub/gnu' will only require the
26226 directory to be retrieved on the first call. Alternatively,
26227 this cache can be re-viewed with the -r option. As relative di‐
26228 rectories will confuse zfdir, the -f option can be used to force
26229 the cache to be flushed before the directory is listed. The op‐
26230 tion -d will delete both caches without showing a directory
26231 listing; it will also delete the cache of file names in the cur‐
26232 rent remote directory, if any.
26233
26234 zfls [ ls-options ] [ dir ]
26235 List files on the remote server. With no arguments, this will
26236 produce a simple list of file names for the current remote di‐
26237 rectory. Any arguments are passed directly to the server. No
26238 pager and no caching is used.
26239
26240 Status commands
26241 zftype [ type ]
26242 With no arguments, show the type of data to be transferred, usu‐
26243 ally ASCII or binary. With an argument, change the type: the
26244 types `A' or `ASCII' for ASCII data and `B' or `BINARY', `I' or
26245 `IMAGE' for binary data are understood case-insensitively.
26246
26247 zfstat [ -v ]
26248 Show the status of the current or last connection, as well as
26249 the status of some of zftp's status variables. With the -v op‐
26250 tion, a more verbose listing is produced by querying the server
26251 for its version of events, too.
26252
26253 Retrieving files
26254 The commands for retrieving files all take at least two options. -G
26255 suppresses remote filename expansion which would otherwise be performed
26256 (see below for a more detailed description of that). -t attempts to
26257 set the modification time of the local file to that of the remote file:
26258 see the description of the function zfrtime below for more information.
26259
26260 zfget [ -Gtc ] file1 ...
26261 Retrieve all the listed files file1 ... one at a time from the
26262 remote server. If a file contains a `/', the full name is
26263 passed to the remote server, but the file is stored locally un‐
26264 der the name given by the part after the final `/'. The option
26265 -c (cat) forces all files to be sent as a single stream to stan‐
26266 dard output; in this case the -t option has no effect.
26267
26268 zfuget [ -Gvst ] file1 ...
26269 As zfget, but only retrieve files where the version on the re‐
26270 mote server is newer (has a later modification time), or where
26271 the local file does not exist. If the remote file is older but
26272 the files have different sizes, or if the sizes are the same but
26273 the remote file is newer, the user will usually be queried.
26274 With the option -s, the command runs silently and will always
26275 retrieve the file in either of those two cases. With the option
26276 -v, the command prints more information about the files while it
26277 is working out whether or not to transfer them.
26278
26279 zfcget [ -Gt ] file1 ...
26280 As zfget, but if any of the local files exists, and is shorter
26281 than the corresponding remote file, the command assumes that it
26282 is the result of a partially completed transfer and attempts to
26283 transfer the rest of the file. This is useful on a poor connec‐
26284 tion which keeps failing.
26285
26286 Note that this requires a commonly implemented, but non-stan‐
26287 dard, version of the FTP protocol, so is not guaranteed to work
26288 on all servers.
26289
26290 zfgcp [ -Gt ] remote-file local-file
26291 zfgcp [ -Gt ] rfile1 ... ldir
26292 This retrieves files from the remote server with arguments be‐
26293 having similarly to the cp command.
26294
26295 In the first form, copy remote-file from the server to the local
26296 file local-file.
26297
26298 In the second form, copy all the remote files rfile1 ... into
26299 the local directory ldir retaining the same basenames. This as‐
26300 sumes UNIX directory semantics.
26301
26302 Sending files
26303 zfput [ -r ] file1 ...
26304 Send all the file1 ... given separately to the remote server.
26305 If a filename contains a `/', the full filename is used locally
26306 to find the file, but only the basename is used for the remote
26307 file name.
26308
26309 With the option -r, if any of the files are directories they are
26310 sent recursively with all their subdirectories, including files
26311 beginning with `.'. This requires that the remote machine un‐
26312 derstand UNIX file semantics, since `/' is used as a directory
26313 separator.
26314
26315 zfuput [ -vs ] file1 ...
26316 As zfput, but only send files which are newer than their remote
26317 equivalents, or if the remote file does not exist. The logic is
26318 the same as for zfuget, but reversed between local and remote
26319 files.
26320
26321 zfcput file1 ...
26322 As zfput, but if any remote file already exists and is shorter
26323 than the local equivalent, assume it is the result of an incom‐
26324 plete transfer and send the rest of the file to append to the
26325 existing part. As the FTP append command is part of the stan‐
26326 dard set, this is in principle more likely to work than zfcget.
26327
26328 zfpcp local-file remote-file
26329 zfpcp lfile1 ... rdir
26330 This sends files to the remote server with arguments behaving
26331 similarly to the cp command.
26332
26333 With two arguments, copy local-file to the server as re‐
26334 mote-file.
26335
26336 With more than two arguments, copy all the local files lfile1
26337 ... into the existing remote directory rdir retaining the same
26338 basenames. This assumes UNIX directory semantics.
26339
26340 A problem arises if you attempt to use zfpcp lfile1 rdir, i.e.
26341 the second form of copying but with two arguments, as the com‐
26342 mand has no simple way of knowing if rdir corresponds to a di‐
26343 rectory or a filename. It attempts to resolve this in various
26344 ways. First, if the rdir argument is `.' or `..' or ends in a
26345 slash, it is assumed to be a directory. Secondly, if the opera‐
26346 tion of copying to a remote file in the first form failed, and
26347 the remote server sends back the expected failure code 553 and a
26348 reply including the string `Is a directory', then zfpcp will
26349 retry using the second form.
26350
26351 Closing the connection
26352 zfclose
26353 Close the connection.
26354
26355 Session management
26356 zfsession [ -lvod ] [ sessname ]
26357 Allows you to manage multiple FTP sessions at once. By default,
26358 connections take place in a session called `default'; by giving
26359 the command `zfsession sessname' you can change to a new or ex‐
26360 isting session with a name of your choice. The new session re‐
26361 members its own connection, as well as associated shell parame‐
26362 ters, and also the host/user parameters set by zfparams. Hence
26363 you can have different sessions set up to connect to different
26364 hosts, each remembering the appropriate host, user and password.
26365
26366 With no arguments, zfsession prints the name of the current ses‐
26367 sion; with the option -l it lists all sessions which currently
26368 exist, and with the option -v it gives a verbose list showing
26369 the host and directory for each session, where the current ses‐
26370 sion is marked with an asterisk. With -o, it will switch to the
26371 most recent previous session.
26372
26373 With -d, the given session (or else the current one) is removed;
26374 everything to do with it is completely forgotten. If it was the
26375 only session, a new session called `default' is created and made
26376 current. It is safest not to delete sessions while background
26377 commands using zftp are active.
26378
26379 zftransfer sess1:file1 sess2:file2
26380 Transfer files between two sessions; no local copy is made. The
26381 file is read from the session sess1 as file1 and written to ses‐
26382 sion sess2 as file file2; file1 and file2 may be relative to the
26383 current directories of the session. Either sess1 or sess2 may
26384 be omitted (though the colon should be retained if there is a
26385 possibility of a colon appearing in the file name) and defaults
26386 to the current session; file2 may be omitted or may end with a
26387 slash, in which case the basename of file1 will be added. The
26388 sessions sess1 and sess2 must be distinct.
26389
26390 The operation is performed using pipes, so it is required that
26391 the connections still be valid in a subshell, which is not the
26392 case under versions of some operating systems, presumably due to
26393 a system bug.
26394
26395 Bookmarks
26396 The two functions zfmark and zfgoto allow you to `bookmark' the present
26397 location (host, user and directory) of the current FTP connection for
26398 later use. The file to be used for storing and retrieving bookmarks is
26399 given by the parameter $ZFTP_BMFILE; if not set when one of the two
26400 functions is called, it will be set to the file .zfbkmarks in the di‐
26401 rectory where your zsh startup files live (usually ~).
26402
26403 zfmark [ bookmark ]
26404 If given an argument, mark the current host, user and directory
26405 under the name bookmark for later use by zfgoto. If there is no
26406 connection open, use the values for the last connection immedi‐
26407 ately before it was closed; it is an error if there was none.
26408 Any existing bookmark under the same name will be silently re‐
26409 placed.
26410
26411 If not given an argument, list the existing bookmarks and the
26412 points to which they refer in the form user@host:directory; this
26413 is the format in which they are stored, and the file may be
26414 edited directly.
26415
26416 zfgoto [ -n ] bookmark
26417 Return to the location given by bookmark, as previously set by
26418 zfmark. If the location has user `ftp' or `anonymous', open the
26419 connection with zfanon, so that no password is required. If the
26420 user and host parameters match those stored for the current ses‐
26421 sion, if any, those will be used, and again no password is re‐
26422 quired. Otherwise a password will be prompted for.
26423
26424 With the option -n, the bookmark is taken to be a nickname
26425 stored by the ncftp program in its bookmark file, which is as‐
26426 sumed to be ~/.ncftp/bookmarks. The function works identically
26427 in other ways. Note that there is no mechanism for adding or
26428 modifying ncftp bookmarks from the zftp functions.
26429
26430 Other functions
26431 Mostly, these functions will not be called directly (apart from
26432 zfinit), but are described here for completeness. You may wish to al‐
26433 ter zftp_chpwd and zftp_progress, in particular.
26434
26435 zfinit [ -n ]
26436 As described above, this is used to initialize the zftp function
26437 system. The -n option should be used if the zftp command is al‐
26438 ready built into the shell.
26439
26440 zfautocheck [ -dn ]
26441 This function is called to implement automatic reopening behav‐
26442 iour, as described in more detail below. The options must ap‐
26443 pear in the first argument; -n prevents the command from chang‐
26444 ing to the old directory, while -d prevents it from setting the
26445 variable do_close, which it otherwise does as a flag for auto‐
26446 matically closing the connection after a transfer. The host and
26447 directory for the last session are stored in the variable
26448 $zflastsession, but the internal host/user/password parameters
26449 must also be correctly set.
26450
26451 zfcd_match prefix suffix
26452 This performs matching for completion of remote directory names.
26453 If the remote server is UNIX, it will attempt to persuade the
26454 server to list the remote directory with subdirectories marked,
26455 which usually works but is not guaranteed. On other hosts it
26456 simply calls zfget_match and hence completes all files, not just
26457 directories. On some systems, directories may not even look
26458 like filenames.
26459
26460 zfget_match prefix suffix
26461 This performs matching for completion of remote filenames. It
26462 caches files for the current directory (only) in the shell pa‐
26463 rameter $zftp_fcache. It is in the form to be called by the -K
26464 option of compctl, but also works when called from a wid‐
26465 get-style completion function with prefix and suffix set appro‐
26466 priately.
26467
26468 zfrglob varname
26469 Perform remote globbing, as describes in more detail below.
26470 varname is the name of a variable containing the pattern to be
26471 expanded; if there were any matches, the same variable will be
26472 set to the expanded set of filenames on return.
26473
26474 zfrtime lfile rfile [ time ]
26475 Set the local file lfile to have the same modification time as
26476 the remote file rfile, or the explicit time time in FTP format
26477 CCYYMMDDhhmmSS for the GMT timezone. This uses the shell's
26478 zsh/datetime module to perform the conversion from GMT to local
26479 time.
26480
26481 zftp_chpwd
26482 This function is called every time a connection is opened, or
26483 closed, or the remote directory changes. This version alters
26484 the title bar of an xterm-compatible or sun-cmd terminal emula‐
26485 tor to reflect the local and remote hostnames and current direc‐
26486 tories. It works best when combined with the function chpwd.
26487 In particular, a function of the form
26488
26489 chpwd() {
26490 if [[ -n $ZFTP_USER ]]; then
26491 zftp_chpwd
26492 else
26493 # usual chpwd e.g put host:directory in title bar
26494 fi
26495 }
26496
26497 fits in well.
26498
26499 zftp_progress
26500 This function shows the status of the transfer. It will not
26501 write anything unless the output is going to a terminal; how‐
26502 ever, if you transfer files in the background, you should turn
26503 off progress reports by hand using `zstyle ':zftp:*' progress
26504 none'. Note also that if you alter it, any output must be to
26505 standard error, as standard output may be a file being received.
26506 The form of the progress meter, or whether it is used at all,
26507 can be configured without altering the function, as described in
26508 the next section.
26509
26510 zffcache
26511 This is used to implement caching of files in the current direc‐
26512 tory for each session separately. It is used by zfget_match and
26513 zfrglob.
26514
26516 Configuration
26517 Various styles are available using the standard shell style mechanism,
26518 described in zshmodules(1). Briefly, the command `zstyle ':zftp:*'
26519 style value ...'. defines the style to have value value; more than one
26520 value may be given, although that is not useful in the cases described
26521 here. These values will then be used throughout the zftp function sys‐
26522 tem. For more precise control, the first argument, which gives a pat‐
26523 tern that matches contexts in which the style applies, can be modified
26524 to include a particular function, as for example `:zftp:zfget': the
26525 style will then have the given value only in the zfget function, and
26526 will override styles set under `:zftp:*'. Note that only the top level
26527 function name, as called by the user, is used; calling of lower level
26528 functions is transparent to the user. Hence modifications to the title
26529 bar in zftp_chpwd use the contexts :zftp:zfopen, :zftp:zfcd, etc., de‐
26530 pending where it was called from. The following styles are understood:
26531
26532 progress
26533 Controls the way that zftp_progress reports on the progress of a
26534 transfer. If empty, unset, or `none', no progress report is
26535 made; if `bar' a growing bar of inverse video is shown; if `per‐
26536 cent' (or any other string, though this may change in future),
26537 the percentage of the file transferred is shown. The bar meter
26538 requires that the width of the terminal be available via the
26539 $COLUMNS parameter (normally this is set automatically). If the
26540 size of the file being transferred is not available, bar and
26541 percent meters will simply show the number of bytes transferred
26542 so far.
26543
26544 When zfinit is run, if this style is not defined for the context
26545 :zftp:*, it will be set to `bar'.
26546
26547 update Specifies the minimum time interval between updates of the
26548 progress meter in seconds. No update is made unless new data
26549 has been received, so the actual time interval is limited only
26550 by $ZFTP_TIMEOUT.
26551
26552 As described for progress, zfinit will force this to default to
26553 1.
26554
26555 remote-glob
26556 If set to `1', `yes' or `true', filename generation (globbing)
26557 is performed on the remote machine instead of by zsh itself; see
26558 below.
26559
26560 titlebar
26561 If set to `1', `yes' or `true', zftp_chpwd will put the remote
26562 host and remote directory into the titlebar of terminal emula‐
26563 tors such as xterm or sun-cmd that allow this.
26564
26565 As described for progress, zfinit will force this to default to
26566 1.
26567
26568 chpwd If set to `1' `yes' or `true', zftp_chpwd will call the function
26569 chpwd when a connection is closed. This is useful if the remote
26570 host details were put into the terminal title bar by zftp_chpwd
26571 and your usual chpwd also modifies the title bar.
26572
26573 When zfinit is run, it will determine whether chpwd exists and
26574 if so it will set the default value for the style to 1 if none
26575 exists already.
26576
26577 Note that there is also an associative array zfconfig which contains
26578 values used by the function system. This should not be modified or
26579 overwritten.
26580
26581 Remote globbing
26582 The commands for retrieving files usually perform filename generation
26583 (globbing) on their arguments; this can be turned off by passing the
26584 option -G to each of the commands. Normally this operates by retriev‐
26585 ing a complete list of files for the directory in question, then match‐
26586 ing these locally against the pattern supplied. This has the advantage
26587 that the full range of zsh patterns (respecting the setting of the op‐
26588 tion EXTENDED_GLOB) can be used. However, it means that the directory
26589 part of a filename will not be expanded and must be given exactly. If
26590 the remote server does not support the UNIX directory semantics, direc‐
26591 tory handling is problematic and it is recommended that globbing only
26592 be used within the current directory. The list of files in the current
26593 directory, if retrieved, will be cached, so that subsequent globs in
26594 the same directory without an intervening zfcd are much faster.
26595
26596 If the remote-glob style (see above) is set, globbing is instead per‐
26597 formed on the remote host: the server is asked for a list of matching
26598 files. This is highly dependent on how the server is implemented,
26599 though typically UNIX servers will provide support for basic glob pat‐
26600 terns. This may in some cases be faster, as it avoids retrieving the
26601 entire list of directory contents.
26602
26603 Automatic and temporary reopening
26604 As described for the zfopen command, a subsequent zfopen with no param‐
26605 eters will reopen the connection to the last host (this includes con‐
26606 nections made with the zfanon command). Opened in this fashion, the
26607 connection starts in the default remote directory and will remain open
26608 until explicitly closed.
26609
26610 Automatic re-opening is also available. If a connection is not cur‐
26611 rently open and a command requiring a connection is given, the last
26612 connection is implicitly reopened. In this case the directory which
26613 was current when the connection was closed again becomes the current
26614 directory (unless, of course, the command given changes it). Automatic
26615 reopening will also take place if the connection was close by the re‐
26616 mote server for whatever reason (e.g. a timeout). It is not available
26617 if the -1 option to zfopen or zfanon was used.
26618
26619 Furthermore, if the command issued is a file transfer, the connection
26620 will be closed after the transfer is finished, hence providing a
26621 one-shot mode for transfers. This does not apply to directory changing
26622 or listing commands; for example a zfdir may reopen a connection but
26623 will leave it open. Also, automatic closure will only ever happen in
26624 the same command as automatic opening, i.e a zfdir directly followed by
26625 a zfget will never close the connection automatically.
26626
26627 Information about the previous connection is given by the zfstat func‐
26628 tion. So, for example, if that reports:
26629
26630 Session: default
26631 Not connected.
26632 Last session: ftp.bar.com:/pub/textfiles
26633
26634 then the command zfget file.txt will attempt to reopen a connection to
26635 ftp.bar.com, retrieve the file /pub/textfiles/file.txt, and immediately
26636 close the connection again. On the other hand, zfcd .. will open the
26637 connection in the directory /pub and leave it open.
26638
26639 Note that all the above is local to each session; if you return to a
26640 previous session, the connection for that session is the one which will
26641 be reopened.
26642
26643 Completion
26644 Completion of local and remote files, directories, sessions and book‐
26645 marks is supported. The older, compctl-style completion is defined
26646 when zfinit is called; support for the new widget-based completion sys‐
26647 tem is provided in the function Completion/Zsh/Command/_zftp, which
26648 should be installed with the other functions of the completion system
26649 and hence should automatically be available.
26650
26651
26652
26653ZSHCONTRIB(1) General Commands Manual ZSHCONTRIB(1)
26654
26655
26656
26658 zshcontrib - user contributions to zsh
26659
26661 The Zsh source distribution includes a number of items contributed by
26662 the user community. These are not inherently a part of the shell, and
26663 some may not be available in every zsh installation. The most signifi‐
26664 cant of these are documented here. For documentation on other contrib‐
26665 uted items such as shell functions, look for comments in the function
26666 source files.
26667
26669 Accessing On-Line Help
26670 The key sequence ESC h is normally bound by ZLE to execute the run-help
26671 widget (see zshzle(1)). This invokes the run-help command with the
26672 command word from the current input line as its argument. By default,
26673 run-help is an alias for the man command, so this often fails when the
26674 command word is a shell builtin or a user-defined function. By re‐
26675 defining the run-help alias, one can improve the on-line help provided
26676 by the shell.
26677
26678 The helpfiles utility, found in the Util directory of the distribution,
26679 is a Perl program that can be used to process the zsh manual to produce
26680 a separate help file for each shell builtin and for many other shell
26681 features as well. The autoloadable run-help function, found in Func‐
26682 tions/Misc, searches for these helpfiles and performs several other
26683 tests to produce the most complete help possible for the command.
26684
26685 Help files are installed by default to a subdirectory of /usr/share/zsh
26686 or /usr/local/share/zsh.
26687
26688 To create your own help files with helpfiles, choose or create a direc‐
26689 tory where the individual command help files will reside. For example,
26690 you might choose ~/zsh_help. If you unpacked the zsh distribution in
26691 your home directory, you would use the commands:
26692
26693 mkdir ~/zsh_help
26694 perl ~/zsh-5.9/Util/helpfiles ~/zsh_help
26695
26696 The HELPDIR parameter tells run-help where to look for the help files.
26697 When unset, it uses the default installation path. To use your own set
26698 of help files, set this to the appropriate path in one of your startup
26699 files:
26700
26701 HELPDIR=~/zsh_help
26702
26703 To use the run-help function, you need to add lines something like the
26704 following to your .zshrc or equivalent startup file:
26705
26706 unalias run-help
26707 autoload run-help
26708
26709 Note that in order for `autoload run-help' to work, the run-help file
26710 must be in one of the directories named in your fpath array (see zsh‐
26711 param(1)). This should already be the case if you have a standard zsh
26712 installation; if it is not, copy Functions/Misc/run-help to an appro‐
26713 priate directory.
26714
26715 Recompiling Functions
26716 If you frequently edit your zsh functions, or periodically update your
26717 zsh installation to track the latest developments, you may find that
26718 function digests compiled with the zcompile builtin are frequently out
26719 of date with respect to the function source files. This is not usually
26720 a problem, because zsh always looks for the newest file when loading a
26721 function, but it may cause slower shell startup and function loading.
26722 Also, if a digest file is explicitly used as an element of fpath, zsh
26723 won't check whether any of its source files has changed.
26724
26725 The zrecompile autoloadable function, found in Functions/Misc, can be
26726 used to keep function digests up to date.
26727
26728 zrecompile [ -qt ] [ name ... ]
26729 zrecompile [ -qt ] -p arg ... [ -- arg ... ]
26730 This tries to find *.zwc files and automatically re-compile them
26731 if at least one of the original files is newer than the compiled
26732 file. This works only if the names stored in the compiled files
26733 are full paths or are relative to the directory that contains
26734 the .zwc file.
26735
26736 In the first form, each name is the name of a compiled file or a
26737 directory containing *.zwc files that should be checked. If no
26738 arguments are given, the directories and *.zwc files in fpath
26739 are used.
26740
26741 When -t is given, no compilation is performed, but a return sta‐
26742 tus of zero (true) is set if there are files that need to be
26743 re-compiled and non-zero (false) otherwise. The -q option qui‐
26744 ets the chatty output that describes what zrecompile is doing.
26745
26746 Without the -t option, the return status is zero if all files
26747 that needed re-compilation could be compiled and non-zero if
26748 compilation for at least one of the files failed.
26749
26750 If the -p option is given, the args are interpreted as one or
26751 more sets of arguments for zcompile, separated by `--'. For ex‐
26752 ample:
26753
26754 zrecompile -p \
26755 -R ~/.zshrc -- \
26756 -M ~/.zcompdump -- \
26757 ~/zsh/comp.zwc ~/zsh/Completion/*/_*
26758
26759 This compiles ~/.zshrc into ~/.zshrc.zwc if that doesn't exist
26760 or if it is older than ~/.zshrc. The compiled file will be
26761 marked for reading instead of mapping. The same is done for
26762 ~/.zcompdump and ~/.zcompdump.zwc, but this compiled file is
26763 marked for mapping. The last line re-creates the file
26764 ~/zsh/comp.zwc if any of the files matching the given pattern is
26765 newer than it.
26766
26767 Without the -p option, zrecompile does not create function di‐
26768 gests that do not already exist, nor does it add new functions
26769 to the digest.
26770
26771 The following shell loop is an example of a method for creating func‐
26772 tion digests for all functions in your fpath, assuming that you have
26773 write permission to the directories:
26774
26775 for ((i=1; i <= $#fpath; ++i)); do
26776 dir=$fpath[i]
26777 zwc=${dir:t}.zwc
26778 if [[ $dir == (.|..) || $dir == (.|..)/* ]]; then
26779 continue
26780 fi
26781 files=($dir/*(N-.))
26782 if [[ -w $dir:h && -n $files ]]; then
26783 files=(${${(M)files%/*/*}#/})
26784 if ( cd $dir:h &&
26785 zrecompile -p -U -z $zwc $files ); then
26786 fpath[i]=$fpath[i].zwc
26787 fi
26788 fi
26789 done
26790
26791 The -U and -z options are appropriate for functions in the default zsh
26792 installation fpath; you may need to use different options for your per‐
26793 sonal function directories.
26794
26795 Once the digests have been created and your fpath modified to refer to
26796 them, you can keep them up to date by running zrecompile with no argu‐
26797 ments.
26798
26799 Keyboard Definition
26800 The large number of possible combinations of keyboards, workstations,
26801 terminals, emulators, and window systems makes it impossible for zsh to
26802 have built-in key bindings for every situation. The zkbd utility,
26803 found in Functions/Misc, can help you quickly create key bindings for
26804 your configuration.
26805
26806 Run zkbd either as an autoloaded function, or as a shell script:
26807
26808 zsh -f ~/zsh-5.9/Functions/Misc/zkbd
26809
26810 When you run zkbd, it first asks you to enter your terminal type; if
26811 the default it offers is correct, just press return. It then asks you
26812 to press a number of different keys to determine characteristics of
26813 your keyboard and terminal; zkbd warns you if it finds anything out of
26814 the ordinary, such as a Delete key that sends neither ^H nor ^?.
26815
26816 The keystrokes read by zkbd are recorded as a definition for an asso‐
26817 ciative array named key, written to a file in the subdirectory .zkbd
26818 within either your HOME or ZDOTDIR directory. The name of the file is
26819 composed from the TERM, VENDOR and OSTYPE parameters, joined by hy‐
26820 phens.
26821
26822 You may read this file into your .zshrc or another startup file with
26823 the `source' or `.' commands, then reference the key parameter in bind‐
26824 key commands, like this:
26825
26826 source ${ZDOTDIR:-$HOME}/.zkbd/$TERM-$VENDOR-$OSTYPE
26827 [[ -n ${key[Left]} ]] && bindkey "${key[Left]}" backward-char
26828 [[ -n ${key[Right]} ]] && bindkey "${key[Right]}" forward-char
26829 # etc.
26830
26831 Note that in order for `autoload zkbd' to work, the zkdb file must be
26832 in one of the directories named in your fpath array (see zshparam(1)).
26833 This should already be the case if you have a standard zsh installa‐
26834 tion; if it is not, copy Functions/Misc/zkbd to an appropriate direc‐
26835 tory.
26836
26837 Dumping Shell State
26838 Occasionally you may encounter what appears to be a bug in the shell,
26839 particularly if you are using a beta version of zsh or a development
26840 release. Usually it is sufficient to send a description of the problem
26841 to one of the zsh mailing lists (see zsh(1)), but sometimes one of the
26842 zsh developers will need to recreate your environment in order to track
26843 the problem down.
26844
26845 The script named reporter, found in the Util directory of the distribu‐
26846 tion, is provided for this purpose. (It is also possible to autoload
26847 reporter, but reporter is not installed in fpath by default.) This
26848 script outputs a detailed dump of the shell state, in the form of an‐
26849 other script that can be read with `zsh -f' to recreate that state.
26850
26851 To use reporter, read the script into your shell with the `.' command
26852 and redirect the output into a file:
26853
26854 . ~/zsh-5.9/Util/reporter > zsh.report
26855
26856 You should check the zsh.report file for any sensitive information such
26857 as passwords and delete them by hand before sending the script to the
26858 developers. Also, as the output can be voluminous, it's best to wait
26859 for the developers to ask for this information before sending it.
26860
26861 You can also use reporter to dump only a subset of the shell state.
26862 This is sometimes useful for creating startup files for the first time.
26863 Most of the output from reporter is far more detailed than usually is
26864 necessary for a startup file, but the aliases, options, and zstyles
26865 states may be useful because they include only changes from the de‐
26866 faults. The bindings state may be useful if you have created any of
26867 your own keymaps, because reporter arranges to dump the keymap creation
26868 commands as well as the bindings for every keymap.
26869
26870 As is usual with automated tools, if you create a startup file with re‐
26871 porter, you should edit the results to remove unnecessary commands.
26872 Note that if you're using the new completion system, you should not
26873 dump the functions state to your startup files with reporter; use the
26874 compdump function instead (see zshcompsys(1)).
26875
26876 reporter [ state ... ]
26877 Print to standard output the indicated subset of the current
26878 shell state. The state arguments may be one or more of:
26879
26880 all Output everything listed below.
26881 aliases
26882 Output alias definitions.
26883 bindings
26884 Output ZLE key maps and bindings.
26885 completion
26886 Output old-style compctl commands. New completion is
26887 covered by functions and zstyles.
26888 functions
26889 Output autoloads and function definitions.
26890 limits Output limit commands.
26891 options
26892 Output setopt commands.
26893 styles Same as zstyles.
26894 variables
26895 Output shell parameter assignments, plus export commands
26896 for any environment variables.
26897 zstyles
26898 Output zstyle commands.
26899
26900 If the state is omitted, all is assumed.
26901
26902 With the exception of `all', every state can be abbreviated by any pre‐
26903 fix, even a single letter; thus a is the same as aliases, z is the same
26904 as zstyles, etc.
26905
26906 Manipulating Hook Functions
26907 add-zsh-hook [ -L | -dD ] [ -Uzk ] hook function
26908 Several functions are special to the shell, as described in the
26909 section SPECIAL FUNCTIONS, see zshmisc(1), in that they are au‐
26910 tomatically called at specific points during shell execution.
26911 Each has an associated array consisting of names of functions to
26912 be called at the same point; these are so-called `hook func‐
26913 tions'. The shell function add-zsh-hook provides a simple way
26914 of adding or removing functions from the array.
26915
26916 hook is one of chpwd, periodic, precmd, preexec, zshaddhistory,
26917 zshexit, or zsh_directory_name, the special functions in ques‐
26918 tion. Note that zsh_directory_name is called in a different way
26919 from the other functions, but may still be manipulated as a
26920 hook.
26921
26922 function is name of an ordinary shell function. If no options
26923 are given this will be added to the array of functions to be ex‐
26924 ecuted in the given context. Functions are invoked in the order
26925 they were added.
26926
26927 If the option -L is given, the current values for the hook ar‐
26928 rays are listed with typeset.
26929
26930 If the option -d is given, the function is removed from the ar‐
26931 ray of functions to be executed.
26932
26933 If the option -D is given, the function is treated as a pattern
26934 and any matching names of functions are removed from the array
26935 of functions to be executed.
26936
26937 The options -U, -z and -k are passed as arguments to autoload
26938 for function. For functions contributed with zsh, the options
26939 -Uz are appropriate.
26940
26941 add-zle-hook-widget [ -L | -dD ] [ -Uzk ] hook widgetname
26942 Several widget names are special to the line editor, as de‐
26943 scribed in the section Special Widgets, see zshzle(1), in that
26944 they are automatically called at specific points during editing.
26945 Unlike function hooks, these do not use a predefined array of
26946 other names to call at the same point; the shell function
26947 add-zle-hook-widget maintains a similar array and arranges for
26948 the special widget to invoke those additional widgets.
26949
26950 hook is one of isearch-exit, isearch-update, line-pre-redraw,
26951 line-init, line-finish, history-line-set, or keymap-select, cor‐
26952 responding to each of the special widgets zle-isearch-exit, etc.
26953 The special widget names are also accepted as the hook argument.
26954
26955 widgetname is the name of a ZLE widget. If no options are given
26956 this is added to the array of widgets to be invoked in the given
26957 hook context. Widgets are invoked in the order they were added,
26958 with
26959 zle widgetname -Nw -f "nolast" -- "$@"
26960
26961 Note that this means that the `WIDGET' special parameter tracks
26962 the widgetname when the widget function is called, rather than
26963 tracking the name of the corresponding special hook widget.
26964
26965 If the option -d is given, the widgetname is removed from the
26966 array of widgets to be executed.
26967
26968 If the option -D is given, the widgetname is treated as a pat‐
26969 tern and any matching names of widgets are removed from the ar‐
26970 ray.
26971
26972 If widgetname does not name an existing widget when added to the
26973 array, it is assumed that a shell function also named widgetname
26974 is meant to provide the implementation of the widget. This name
26975 is therefore marked for autoloading, and the options -U, -z and
26976 -k are passed as arguments to autoload as with add-zsh-hook.
26977 The widget is also created with `zle -N widgetname' to cause the
26978 corresponding function to be loaded the first time the hook is
26979 called.
26980
26981 The arrays of widgetname are currently maintained in zstyle con‐
26982 texts, one for each hook context, with a style of `widgets'. If
26983 the -L option is given, this set of styles is listed with
26984 `zstyle -L'. This implementation may change, and the special
26985 widgets that refer to the styles are created only if
26986 add-zle-hook-widget is called to add at least one widget, so if
26987 this function is used for any hooks, then all hooks should be
26988 managed only via this function.
26989
26991 The function cdr allows you to change the working directory to a previ‐
26992 ous working directory from a list maintained automatically. It is sim‐
26993 ilar in concept to the directory stack controlled by the pushd, popd
26994 and dirs builtins, but is more configurable, and as it stores all en‐
26995 tries in files it is maintained across sessions and (by default) be‐
26996 tween terminal emulators in the current session. Duplicates are auto‐
26997 matically removed, so that the list reflects the single most recent use
26998 of each directory.
26999
27000 Note that the pushd directory stack is not actually modified or used by
27001 cdr unless you configure it to do so as described in the configuration
27002 section below.
27003
27004 Installation
27005 The system works by means of a hook function that is called every time
27006 the directory changes. To install the system, autoload the required
27007 functions and use the add-zsh-hook function described above:
27008
27009 autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
27010 add-zsh-hook chpwd chpwd_recent_dirs
27011
27012 Now every time you change directly interactively, no matter which com‐
27013 mand you use, the directory to which you change will be remembered in
27014 most-recent-first order.
27015
27016 Use
27017 All direct user interaction is via the cdr function.
27018
27019 The argument to cdr is a number N corresponding to the Nth most re‐
27020 cently changed-to directory. 1 is the immediately preceding directory;
27021 the current directory is remembered but is not offered as a destina‐
27022 tion. Note that if you have multiple windows open 1 may refer to a di‐
27023 rectory changed to in another window; you can avoid this by having
27024 per-terminal files for storing directory as described for the re‐
27025 cent-dirs-file style below.
27026
27027 If you set the recent-dirs-default style described below cdr will be‐
27028 have the same as cd if given a non-numeric argument, or more than one
27029 argument. The recent directory list is updated just the same however
27030 you change directory.
27031
27032 If the argument is omitted, 1 is assumed. This is similar to pushd's
27033 behaviour of swapping the two most recent directories on the stack.
27034
27035 Completion for the argument to cdr is available if compinit has been
27036 run; menu selection is recommended, using:
27037
27038 zstyle ':completion:*:*:cdr:*:*' menu selection
27039
27040 to allow you to cycle through recent directories; the order is pre‐
27041 served, so the first choice is the most recent directory before the
27042 current one. The verbose style is also recommended to ensure the di‐
27043 rectory is shown; this style is on by default so no action is required
27044 unless you have changed it.
27045
27046 Options
27047 The behaviour of cdr may be modified by the following options.
27048
27049 -l lists the numbers and the corresponding directories in abbrevi‐
27050 ated form (i.e. with ~ substitution reapplied), one per line.
27051 The directories here are not quoted (this would only be an issue
27052 if a directory name contained a newline). This is used by the
27053 completion system.
27054
27055 -r sets the variable reply to the current set of directories.
27056 Nothing is printed and the directory is not changed.
27057
27058 -e allows you to edit the list of directories, one per line. The
27059 list can be edited to any extent you like; no sanity checking is
27060 performed. Completion is available. No quoting is necessary
27061 (except for newlines, where I have in any case no sympathy); di‐
27062 rectories are in unabbreviated form and contain an absolute
27063 path, i.e. they start with /. Usually the first entry should be
27064 left as the current directory.
27065
27066 -p 'pattern'
27067 Prunes any items in the directory list that match the given ex‐
27068 tended glob pattern; the pattern needs to be quoted from immedi‐
27069 ate expansion on the command line. The pattern is matched
27070 against each completely expanded file name in the list; the full
27071 string must match, so wildcards at the end (e.g. '*removeme*')
27072 are needed to remove entries with a given substring.
27073
27074 If output is to a terminal, then the function will print the new
27075 list after pruning and prompt for confirmation by the user.
27076 This output and confirmation step can be skipped by using -P in‐
27077 stead of -p.
27078
27079 Configuration
27080 Configuration is by means of the styles mechanism that should be famil‐
27081 iar from completion; if not, see the description of the zstyle command
27082 in see zshmodules(1). The context for setting styles should be ':ch‐
27083 pwd:*' in case the meaning of the context is extended in future, for
27084 example:
27085
27086 zstyle ':chpwd:*' recent-dirs-max 0
27087
27088 sets the value of the recent-dirs-max style to 0. In practice the
27089 style name is specific enough that a context of '*' should be fine.
27090
27091 An exception is recent-dirs-insert, which is used exclusively by the
27092 completion system and so has the usual completion system context
27093 (':completion:*' if nothing more specific is needed), though again '*'
27094 should be fine in practice.
27095
27096 recent-dirs-default
27097 If true, and the command is expecting a recent directory index,
27098 and either there is more than one argument or the argument is
27099 not an integer, then fall through to "cd". This allows the lazy
27100 to use only one command for directory changing. Completion
27101 recognises this, too; see recent-dirs-insert for how to control
27102 completion when this option is in use.
27103
27104 recent-dirs-file
27105 The file where the list of directories is saved. The default is
27106 ${ZDOTDIR:-$HOME}/.chpwd-recent-dirs, i.e. this is in your home
27107 directory unless you have set the variable ZDOTDIR to point
27108 somewhere else. Directory names are saved in $'...' quoted
27109 form, so each line in the file can be supplied directly to the
27110 shell as an argument.
27111
27112 The value of this style may be an array. In this case, the
27113 first file in the list will always be used for saving directo‐
27114 ries while any other files are left untouched. When reading the
27115 recent directory list, if there are fewer than the maximum num‐
27116 ber of entries in the first file, the contents of later files in
27117 the array will be appended with duplicates removed from the list
27118 shown. The contents of the two files are not sorted together,
27119 i.e. all the entries in the first file are shown first. The
27120 special value + can appear in the list to indicate the default
27121 file should be read at that point. This allows effects like the
27122 following:
27123
27124 zstyle ':chpwd:*' recent-dirs-file \
27125 ~/.chpwd-recent-dirs-${TTY##*/} +
27126
27127 Recent directories are read from a file numbered according to
27128 the terminal. If there are insufficient entries the list is
27129 supplemented from the default file.
27130
27131 It is possible to use zstyle -e to make the directory config‐
27132 urable at run time:
27133
27134 zstyle -e ':chpwd:*' recent-dirs-file pick-recent-dirs-file
27135 pick-recent-dirs-file() {
27136 if [[ $PWD = ~/text/writing(|/*) ]]; then
27137 reply=(~/.chpwd-recent-dirs-writing)
27138 else
27139 reply=(+)
27140 fi
27141 }
27142
27143 In this example, if the current directory is ~/text/writing or a
27144 directory under it, then use a special file for saving recent
27145 directories, else use the default.
27146
27147 recent-dirs-insert
27148 Used by completion. If recent-dirs-default is true, then set‐
27149 ting this to true causes the actual directory, rather than its
27150 index, to be inserted on the command line; this has the same ef‐
27151 fect as using the corresponding index, but makes the history
27152 clearer and the line easier to edit. With this setting, if part
27153 of an argument was already typed, normal directory completion
27154 rather than recent directory completion is done; this is because
27155 recent directory completion is expected to be done by cycling
27156 through entries menu fashion.
27157
27158 If the value of the style is always, then only recent directo‐
27159 ries will be completed; in that case, use the cd command when
27160 you want to complete other directories.
27161
27162 If the value is fallback, recent directories will be tried
27163 first, then normal directory completion is performed if recent
27164 directory completion failed to find a match.
27165
27166 Finally, if the value is both then both sets of completions are
27167 presented; the usual tag mechanism can be used to distinguish
27168 results, with recent directories tagged as recent-dirs. Note
27169 that the recent directories inserted are abbreviated with direc‐
27170 tory names where appropriate.
27171
27172 recent-dirs-max
27173 The maximum number of directories to save to the file. If this
27174 is zero or negative there is no maximum. The default is 20.
27175 Note this includes the current directory, which isn't offered,
27176 so the highest number of directories you will be offered is one
27177 less than the maximum.
27178
27179 recent-dirs-prune
27180 This style is an array determining what directories should (or
27181 should not) be added to the recent list. Elements of the array
27182 can include:
27183
27184 parent Prune parents (more accurately, ancestors) from the re‐
27185 cent list. If present, changing directly down by any
27186 number of directories causes the current directory to be
27187 overwritten. For example, changing from ~pws to
27188 ~pws/some/other/dir causes ~pws not to be left on the re‐
27189 cent directory stack. This only applies to direct
27190 changes to descendant directories; earlier directories on
27191 the list are not pruned. For example, changing from
27192 ~pws/yet/another to ~pws/some/other/dir does not cause
27193 ~pws to be pruned.
27194
27195 pattern:pattern
27196 Gives a zsh pattern for directories that should not be
27197 added to the recent list (if not already there). This
27198 element can be repeated to add different patterns. For
27199 example, 'pattern:/tmp(|/*)' stops /tmp or its descen‐
27200 dants from being added. The EXTENDED_GLOB option is al‐
27201 ways turned on for these patterns.
27202
27203 recent-dirs-pushd
27204 If set to true, cdr will use pushd instead of cd to change the
27205 directory, so the directory is saved on the directory stack. As
27206 the directory stack is completely separate from the list of
27207 files saved by the mechanism used in this file there is no obvi‐
27208 ous reason to do this.
27209
27210 Use with dynamic directory naming
27211 It is possible to refer to recent directories using the dynamic direc‐
27212 tory name syntax by using the supplied function zsh_directory_name_cdr
27213 a hook:
27214
27215 autoload -Uz add-zsh-hook
27216 add-zsh-hook -Uz zsh_directory_name zsh_directory_name_cdr
27217
27218 When this is done, ~[1] will refer to the most recent directory other
27219 than $PWD, and so on. Completion after ~[... also works.
27220
27221 Details of directory handling
27222 This section is for the curious or confused; most users will not need
27223 to know this information.
27224
27225 Recent directories are saved to a file immediately and hence are pre‐
27226 served across sessions. Note currently no file locking is applied: the
27227 list is updated immediately on interactive commands and nowhere else
27228 (unlike history), and it is assumed you are only going to change direc‐
27229 tory in one window at once. This is not safe on shared accounts, but
27230 in any case the system has limited utility when someone else is chang‐
27231 ing to a different set of directories behind your back.
27232
27233 To make this a little safer, only directory changes instituted from the
27234 command line, either directly or indirectly through shell function
27235 calls (but not through subshells, evals, traps, completion functions
27236 and the like) are saved. Shell functions should use cd -q or pushd -q
27237 to avoid side effects if the change to the directory is to be invisible
27238 at the command line. See the contents of the function chpwd_re‐
27239 cent_dirs for more details.
27240
27242 The dynamic directory naming system is described in the subsection Dy‐
27243 namic named directories of the section Filename Expansion in zsh‐
27244 expn(1). In this, a reference to ~[...] is expanded by a function
27245 found by the hooks mechanism.
27246
27247 The contributed function zsh_directory_name_generic provides a system
27248 allowing the user to refer to directories with only a limited amount of
27249 new code. It supports all three of the standard interfaces for direc‐
27250 tory naming: converting from a name to a directory, converting in the
27251 reverse direction to find a short name, and completion of names.
27252
27253 The main feature of this function is a path-like syntax, combining ab‐
27254 breviations at multiple levels separated by ":". As an example,
27255 ~[g:p:s] might specify:
27256 g The top level directory for your git area. This first component
27257 has to match, or the function will return indicating another di‐
27258 rectory name hook function should be tried.
27259
27260 p The name of a project within your git area.
27261
27262 s The source area within that project. This allows you to col‐
27263 lapse references to long hierarchies to a very compact form,
27264 particularly if the hierarchies are similar across different ar‐
27265 eas of the disk.
27266
27267 Name components may be completed: if a description is shown at the top
27268 of the list of completions, it includes the path to which previous com‐
27269 ponents expand, while the description for an individual completion
27270 shows the path segment it would add. No additional configuration is
27271 needed for this as the completion system is aware of the dynamic direc‐
27272 tory name mechanism.
27273
27274 Usage
27275 To use the function, first define a wrapper function for your specific
27276 case. We'll assume it's to be autoloaded. This can have any name but
27277 we'll refer to it as zdn_mywrapper. This wrapper function will define
27278 various variables and then call this function with the same arguments
27279 that the wrapper function gets. This configuration is described below.
27280
27281 Then arrange for the wrapper to be run as a zsh_directory_name hook:
27282
27283 autoload -Uz add-zsh-hook zsh_directory_name_generic zdn_mywrapper
27284 add-zsh-hook -U zsh_directory_name zdn_mywrapper
27285
27286 Configuration
27287 The wrapper function should define a local associative array zdn_top.
27288 Alternatively, this can be set with a style called mapping. The con‐
27289 text for the style is :zdn:wrapper-name where wrapper-name is the func‐
27290 tion calling zsh_directory_name_generic; for example:
27291
27292 zstyle :zdn:zdn_mywrapper: mapping zdn_mywrapper_top
27293
27294 The keys in this associative array correspond to the first component of
27295 the name. The values are matching directories. They may have an op‐
27296 tional suffix with a slash followed by a colon and the name of a vari‐
27297 able in the same format to give the next component. (The slash before
27298 the colon is to disambiguate the case where a colon is needed in the
27299 path for a drive. There is otherwise no syntax for escaping this, so
27300 path components whose names start with a colon are not supported.) A
27301 special component :default: specifies a variable in the form /:var (the
27302 path section is ignored and so is usually empty) that will be used for
27303 the next component if no variable is given for the path. Variables re‐
27304 ferred to within zdn_top have the same format as zdn_top itself, but
27305 contain relative paths.
27306
27307 For example,
27308
27309 local -A zdn_top=(
27310 g ~/git
27311 ga ~/alternate/git
27312 gs /scratch/$USER/git/:second2
27313 :default: /:second1
27314 )
27315
27316 This specifies the behaviour of a directory referred to as ~[g:...] or
27317 ~[ga:...] or ~[gs:...]. Later path components are optional; in that
27318 case ~[g] expands to ~/git, and so on. gs expands to
27319 /scratch/$USER/git and uses the associative array second2 to match the
27320 second component; g and ga use the associative array second1 to match
27321 the second component.
27322
27323 When expanding a name to a directory, if the first component is not g
27324 or ga or gs, it is not an error; the function simply returns 1 so that
27325 a later hook function can be tried. However, matching the first compo‐
27326 nent commits the function, so if a later component does not match, an
27327 error is printed (though this still does not stop later hooks from be‐
27328 ing executed).
27329
27330 For components after the first, a relative path is expected, but note
27331 that multiple levels may still appear. Here is an example of second1:
27332
27333 local -A second1=(
27334 p myproject
27335 s somproject
27336 os otherproject/subproject/:third
27337 )
27338
27339 The path as found from zdn_top is extended with the matching directory,
27340 so ~[g:p] becomes ~/git/myproject. The slash between is added automat‐
27341 ically (it's not possible to have a later component modify the name of
27342 a directory already matched). Only os specifies a variable for a third
27343 component, and there's no :default:, so it's an error to use a name
27344 like ~[g:p:x] or ~[ga:s:y] because there's nowhere to look up the x or
27345 y.
27346
27347 The associative arrays need to be visible within this function; the
27348 generic function therefore uses internal variable names beginning _zdn_
27349 in order to avoid clashes. Note that the variable reply needs to be
27350 passed back to the shell, so should not be local in the calling func‐
27351 tion.
27352
27353 The function does not test whether directories assembled by component
27354 actually exist; this allows the system to work across automounted file
27355 systems. The error from the command trying to use a non-existent di‐
27356 rectory should be sufficient to indicate the problem.
27357
27358 Complete example
27359 Here is a full fictitious but usable autoloadable definition of the ex‐
27360 ample function defined by the code above. So ~[gs:p:s] expands to
27361 /scratch/$USER/git/myscratchproject/top/srcdir (with $USER also ex‐
27362 panded).
27363
27364 local -A zdn_top=(
27365 g ~/git
27366 ga ~/alternate/git
27367 gs /scratch/$USER/git/:second2
27368 :default: /:second1
27369 )
27370
27371 local -A second1=(
27372 p myproject
27373 s somproject
27374 os otherproject/subproject/:third
27375 )
27376
27377 local -A second2=(
27378 p myscratchproject
27379 s somescratchproject
27380 )
27381
27382 local -A third=(
27383 s top/srcdir
27384 d top/documentation
27385 )
27386
27387 # autoload not needed if you did this at initialisation...
27388 autoload -Uz zsh_directory_name_generic
27389 zsh_directory_name_generic "$@
27390
27391 It is also possible to use global associative arrays, suitably named,
27392 and set the style for the context of your wrapper function to refer to
27393 this. Then your set up code would contain the following:
27394
27395 typeset -A zdn_mywrapper_top=(...)
27396 # ... and so on for other associative arrays ...
27397 zstyle ':zdn:zdn_mywrapper:' mapping zdn_mywrapper_top
27398 autoload -Uz add-zsh-hook zsh_directory_name_generic zdn_mywrapper
27399 add-zsh-hook -U zsh_directory_name zdn_mywrapper
27400
27401 and the function zdn_mywrapper would contain only the following:
27402
27403 zsh_directory_name_generic "$@"
27404
27406 In a lot of cases, it is nice to automatically retrieve information
27407 from version control systems (VCSs), such as subversion, CVS or git, to
27408 be able to provide it to the user; possibly in the user's prompt. So
27409 that you can instantly tell which branch you are currently on, for ex‐
27410 ample.
27411
27412 In order to do that, you may use the vcs_info function.
27413
27414 The following VCSs are supported, showing the abbreviated name by which
27415 they are referred to within the system:
27416 Bazaar (bzr)
27417 https://bazaar.canonical.com/
27418 Codeville (cdv)
27419 http://freecode.com/projects/codeville/
27420 Concurrent Versioning System (cvs)
27421 https://www.nongnu.org/cvs/
27422 Darcs (darcs)
27423 http://darcs.net/
27424 Fossil (fossil)
27425 https://fossil-scm.org/
27426 Git (git)
27427 https://git-scm.com/
27428 GNU arch (tla)
27429 https://www.gnu.org/software/gnu-arch/
27430 Mercurial (hg)
27431 https://www.mercurial-scm.org/
27432 Monotone (mtn)
27433 https://monotone.ca/
27434 Perforce (p4)
27435 https://www.perforce.com/
27436 Subversion (svn)
27437 https://subversion.apache.org/
27438 SVK (svk)
27439 https://svk.bestpractical.com/
27440
27441 There is also support for the patch management system quilt
27442 (https://savannah.nongnu.org/projects/quilt). See Quilt Support below
27443 for details.
27444
27445 To load vcs_info:
27446
27447 autoload -Uz vcs_info
27448
27449 It can be used in any existing prompt, because it does not require any
27450 specific $psvar entries to be available.
27451
27452 Quickstart
27453 To get this feature working quickly (including colors), you can do the
27454 following (assuming, you loaded vcs_info properly - see above):
27455
27456 zstyle ':vcs_info:*' actionformats \
27457 '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f '
27458 zstyle ':vcs_info:*' formats \
27459 '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{5}]%f '
27460 zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r'
27461 precmd () { vcs_info }
27462 PS1='%F{5}[%F{2}%n%F{5}] %F{3}%3~ ${vcs_info_msg_0_}%f%# '
27463
27464 Obviously, the last two lines are there for demonstration. You need to
27465 call vcs_info from your precmd function. Once that is done you need a
27466 single quoted '${vcs_info_msg_0_}' in your prompt.
27467
27468 To be able to use '${vcs_info_msg_0_}' directly in your prompt like
27469 this, you will need to have the PROMPT_SUBST option enabled.
27470
27471 Now call the vcs_info_printsys utility from the command line:
27472
27473 % vcs_info_printsys
27474 ## list of supported version control backends:
27475 ## disabled systems are prefixed by a hash sign (#)
27476 bzr
27477 cdv
27478 cvs
27479 darcs
27480 fossil
27481 git
27482 hg
27483 mtn
27484 p4
27485 svk
27486 svn
27487 tla
27488 ## flavours (cannot be used in the enable or disable styles; they
27489 ## are enabled and disabled with their master [git-svn -> git])
27490 ## they *can* be used in contexts: ':vcs_info:git-svn:*'.
27491 git-p4
27492 git-svn
27493 hg-git
27494 hg-hgsubversion
27495 hg-hgsvn
27496
27497 You may not want all of these because there is no point in running the
27498 code to detect systems you do not use. So there is a way to disable
27499 some backends altogether:
27500
27501 zstyle ':vcs_info:*' disable bzr cdv darcs mtn svk tla
27502
27503 You may also pick a few from that list and enable only those:
27504
27505 zstyle ':vcs_info:*' enable git cvs svn
27506
27507 If you rerun vcs_info_printsys after one of these commands, you will
27508 see the backends listed in the disable style (or backends not in the
27509 enable style - if you used that) marked as disabled by a hash sign.
27510 That means the detection of these systems is skipped completely. No
27511 wasted time there.
27512
27513 Configuration
27514 The vcs_info feature can be configured via zstyle.
27515
27516 First, the context in which we are working:
27517 :vcs_info:vcs-string:user-context:repo-root-name
27518
27519 vcs-string
27520 is one of: git, git-svn, git-p4, hg, hg-git, hg-hgsubversion,
27521 hg-hgsvn, darcs, bzr, cdv, mtn, svn, cvs, svk, tla, p4 or fos‐
27522 sil. This is followed by `.quilt-quilt-mode' in Quilt mode (see
27523 Quilt Support for details) and by `+hook-name' while hooks are
27524 active (see Hooks in vcs_info for details).
27525
27526 Currently, hooks in quilt mode don't add the `.quilt-quilt-mode'
27527 information. This may change in the future.
27528
27529 user-context
27530 is a freely configurable string, assignable by the user as the
27531 first argument to vcs_info (see its description below).
27532
27533 repo-root-name
27534 is the name of a repository in which you want a style to match.
27535 So, if you want a setting specific to /usr/src/zsh, with that
27536 being a CVS checkout, you can set repo-root-name to zsh to make
27537 it so.
27538
27539 There are three special values for vcs-string: The first is named
27540 -init-, that is in effect as long as there was no decision what VCS
27541 backend to use. The second is -preinit-; it is used before vcs_info is
27542 run, when initializing the data exporting variables. The third special
27543 value is formats and is used by the vcs_info_lastmsg for looking up its
27544 styles.
27545
27546 The initial value of repo-root-name is -all- and it is replaced with
27547 the actual name, as soon as it is known. Only use this part of the con‐
27548 text for defining the formats, actionformats or branchformat styles, as
27549 it is guaranteed that repo-root-name is set up correctly for these
27550 only. For all other styles, just use '*' instead.
27551
27552 There are two pre-defined values for user-context:
27553 default
27554 the one used if none is specified
27555 command
27556 used by vcs_info_lastmsg to lookup its styles
27557
27558 You can of course use ':vcs_info:*' to match all VCSs in all user-con‐
27559 texts at once.
27560
27561 This is a description of all styles that are looked up.
27562
27563 formats
27564 A list of formats, used when actionformats is not used (which is
27565 most of the time).
27566
27567 actionformats
27568 A list of formats, used if there is a special action going on in
27569 your current repository; like an interactive rebase or a merge
27570 conflict.
27571
27572 branchformat
27573 Some backends replace %b in the formats and actionformats styles
27574 above, not only by a branch name but also by a revision number.
27575 This style lets you modify how that string should look.
27576
27577 nvcsformats
27578 These "formats" are set when we didn't detect a version control
27579 system for the current directory or vcs_info was disabled. This
27580 is useful if you want vcs_info to completely take over the gen‐
27581 eration of your prompt. You would do something like
27582 PS1='${vcs_info_msg_0_}' to accomplish that.
27583
27584 hgrevformat
27585 hg uses both a hash and a revision number to reference a spe‐
27586 cific changeset in a repository. With this style you can format
27587 the revision string (see branchformat) to include either or
27588 both. It's only useful when get-revision is true. Note, the full
27589 40-character revision id is not available (except when using the
27590 use-simple option) because executing hg more than once per
27591 prompt is too slow; you may customize this behavior using hooks.
27592
27593 max-exports
27594 Defines the maximum number of vcs_info_msg_*_ variables vcs_info
27595 will set.
27596
27597 enable A list of backends you want to use. Checked in the -init- con‐
27598 text. If this list contains an item called NONE no backend is
27599 used at all and vcs_info will do nothing. If this list contains
27600 ALL, vcs_info will use all known backends. Only with ALL in en‐
27601 able will the disable style have any effect. ALL and NONE are
27602 case insensitive.
27603
27604 disable
27605 A list of VCSs you don't want vcs_info to test for repositories
27606 (checked in the -init- context, too). Only used if enable con‐
27607 tains ALL.
27608
27609 disable-patterns
27610 A list of patterns that are checked against $PWD. If a pattern
27611 matches, vcs_info will be disabled. This style is checked in the
27612 :vcs_info:-init-:*:-all- context.
27613
27614 Say, ~/.zsh is a directory under version control, in which you
27615 do not want vcs_info to be active, do:
27616 zstyle ':vcs_info:*' disable-patterns "${(b)HOME}/.zsh(|/*)"
27617
27618 use-quilt
27619 If enabled, the quilt support code is active in `addon' mode.
27620 See Quilt Support for details.
27621
27622 quilt-standalone
27623 If enabled, `standalone' mode detection is attempted if no VCS
27624 is active in a given directory. See Quilt Support for details.
27625
27626 quilt-patch-dir
27627 Overwrite the value of the $QUILT_PATCHES environment variable.
27628 See Quilt Support for details.
27629
27630 quiltcommand
27631 When quilt itself is called in quilt support, the value of this
27632 style is used as the command name.
27633
27634 check-for-changes
27635 If enabled, this style causes the %c and %u format escapes to
27636 show when the working directory has uncommitted changes. The
27637 strings displayed by these escapes can be controlled via the
27638 stagedstr and unstagedstr styles. The only backends that cur‐
27639 rently support this option are git, hg, and bzr (the latter two
27640 only support unstaged).
27641
27642 For this style to be evaluated with the hg backend, the get-re‐
27643 vision style needs to be set and the use-simple style needs to
27644 be unset. The latter is the default; the former is not.
27645
27646 With the bzr backend, lightweight checkouts only honor this
27647 style if the use-server style is set.
27648
27649 Note, the actions taken if this style is enabled are potentially
27650 expensive (read: they may be slow, depending on how big the cur‐
27651 rent repository is). Therefore, it is disabled by default.
27652
27653 check-for-staged-changes
27654 This style is like check-for-changes, but it never checks the
27655 worktree files, only the metadata in the .${vcs} dir. There‐
27656 fore, this style initializes only the %c escape (with stagedstr)
27657 but not the %u escape. This style is faster than
27658 check-for-changes.
27659
27660 In the git backend, this style checks for changes in the index.
27661 Other backends do not currently implement this style.
27662
27663 This style is disabled by default.
27664
27665 stagedstr
27666 This string will be used in the %c escape if there are staged
27667 changes in the repository.
27668
27669 unstagedstr
27670 This string will be used in the %u escape if there are unstaged
27671 changes in the repository.
27672
27673 command
27674 This style causes vcs_info to use the supplied string as the
27675 command to use as the VCS's binary. Note, that setting this in
27676 ':vcs_info:*' is not a good idea.
27677
27678 If the value of this style is empty (which is the default), the
27679 used binary name is the name of the backend in use (e.g. svn is
27680 used in an svn repository).
27681
27682 The repo-root-name part in the context is always the default
27683 -all- when this style is looked up.
27684
27685 For example, this style can be used to use binaries from non-de‐
27686 fault installation directories. Assume, git is installed in
27687 /usr/bin but your sysadmin installed a newer version in /usr/lo‐
27688 cal/bin. Instead of changing the order of your $PATH parameter,
27689 you can do this:
27690 zstyle ':vcs_info:git:*:-all-' command /usr/local/bin/git
27691
27692 use-server
27693 This is used by the Perforce backend (p4) to decide if it should
27694 contact the Perforce server to find out if a directory is man‐
27695 aged by Perforce. This is the only reliable way of doing this,
27696 but runs the risk of a delay if the server name cannot be found.
27697 If the server (more specifically, the host:port pair describing
27698 the server) cannot be contacted, its name is put into the asso‐
27699 ciative array vcs_info_p4_dead_servers and is not contacted
27700 again during the session until it is removed by hand. If you do
27701 not set this style, the p4 backend is only usable if you have
27702 set the environment variable P4CONFIG to a file name and have
27703 corresponding files in the root directories of each Perforce
27704 client. See comments in the function VCS_INFO_detect_p4 for
27705 more detail.
27706
27707 The Bazaar backend (bzr) uses this to permit contacting the
27708 server about lightweight checkouts, see the check-for-changes
27709 style.
27710
27711 use-simple
27712 If there are two different ways of gathering information, you
27713 can select the simpler one by setting this style to true; the
27714 default is to use the not-that-simple code, which is potentially
27715 a lot slower but might be more accurate in all possible cases.
27716 This style is used by the bzr, hg, and git backends. In the case
27717 of hg it will invoke the external hexdump program to parse the
27718 binary dirstate cache file; this method will not return the lo‐
27719 cal revision number.
27720
27721 get-revision
27722 If set to true, vcs_info goes the extra mile to figure out the
27723 revision of a repository's work tree (currently for the git and
27724 hg backends, where this kind of information is not always vi‐
27725 tal). For git, the hash value of the currently checked out com‐
27726 mit is available via the %i expansion. With hg, the local revi‐
27727 sion number and the corresponding global hash are available via
27728 %i.
27729
27730 get-mq If set to true, the hg backend will look for a Mercurial Queue
27731 (mq) patch directory. Information will be available via the `%m'
27732 replacement.
27733
27734 get-bookmarks
27735 If set to true, the hg backend will try to get a list of current
27736 bookmarks. They will be available via the `%m' replacement.
27737
27738 The default is to generate a comma-separated list of all book‐
27739 mark names that refer to the currently checked out revision. If
27740 a bookmark is active, its name is suffixed an asterisk and
27741 placed first in the list.
27742
27743 use-prompt-escapes
27744 Determines if we assume that the assembled string from vcs_info
27745 includes prompt escapes. (Used by vcs_info_lastmsg.)
27746
27747 debug Enable debugging output to track possible problems. Currently
27748 this style is only used by vcs_info's hooks system.
27749
27750 hooks A list style that defines hook-function names. See Hooks in
27751 vcs_info below for details.
27752
27753 patch-format
27754 nopatch-format
27755 This pair of styles format the patch information used by the %m
27756 expando in formats and actionformats for the git and hg back‐
27757 ends. The value is subject to certain %-expansions described
27758 below. The expanded value is made available in the global back‐
27759 end_misc array as ${backend_misc[patches]} (also if a
27760 set-patch-format hook is used).
27761
27762 get-unapplied
27763 This boolean style controls whether a backend should attempt to
27764 gather a list of unapplied patches (for example with Mercurial
27765 Queue patches).
27766
27767 Used by the quilt, hg, and git backends.
27768
27769 The default values for these styles in all contexts are:
27770
27771 formats
27772 " (%s)-[%b]%u%c-"
27773 actionformats
27774 " (%s)-[%b|%a]%u%c-"
27775 branchformat
27776 "%b:%r" (for bzr, svn, svk and hg)
27777 nvcsformats
27778 ""
27779 hgrevformat
27780 "%r:%h"
27781 max-exports
27782 2
27783 enable ALL
27784 disable
27785 (empty list)
27786 disable-patterns
27787 (empty list)
27788 check-for-changes
27789 false
27790 check-for-staged-changes
27791 false
27792 stagedstr
27793 (string: "S")
27794 unstagedstr
27795 (string: "U")
27796 command
27797 (empty string)
27798 use-server
27799 false
27800 use-simple
27801 false
27802 get-revision
27803 false
27804 get-mq true
27805 get-bookmarks
27806 false
27807 use-prompt-escapes
27808 true
27809 debug false
27810 hooks (empty list)
27811 use-quilt
27812 false
27813 quilt-standalone
27814 false
27815 quilt-patch-dir
27816 empty - use $QUILT_PATCHES
27817 quiltcommand
27818 quilt
27819 patch-format
27820 backend dependent
27821 nopatch-format
27822 backend dependent
27823 get-unapplied
27824 false
27825
27826 In normal formats and actionformats the following replacements are
27827 done:
27828
27829 %s The VCS in use (git, hg, svn, etc.).
27830 %b Information about the current branch.
27831 %a An identifier that describes the action. Only makes sense in ac‐
27832 tionformats.
27833 %i The current revision number or identifier. For hg the hgrevfor‐
27834 mat style may be used to customize the output.
27835 %c The string from the stagedstr style if there are staged changes
27836 in the repository.
27837 %u The string from the unstagedstr style if there are unstaged
27838 changes in the repository.
27839 %R The base directory of the repository.
27840 %r The repository name. If %R is /foo/bar/repoXY, %r is repoXY.
27841 %S A subdirectory within a repository. If $PWD is /foo/bar/re‐
27842 poXY/beer/tasty, %S is beer/tasty.
27843 %m A "misc" replacement. It is at the discretion of the backend to
27844 decide what this replacement expands to.
27845
27846 The hg and git backends use this expando to display patch infor‐
27847 mation. hg sources patch information from the mq extensions;
27848 git from in-progress rebase and cherry-pick operations and from
27849 the stgit extension. The patch-format and nopatch-format styles
27850 control the generated string. The former is used when at least
27851 one patch from the patch queue has been applied, and the latter
27852 otherwise.
27853
27854 The hg backend displays bookmark information in this expando (in
27855 addition to mq information). See the get-mq and get-bookmarks
27856 styles. Both of these styles may be enabled at the same time.
27857 If both are enabled, both resulting strings will be shown sepa‐
27858 rated by a semicolon (that cannot currently be customized).
27859
27860 The quilt `standalone' backend sets this expando to the same
27861 value as the %Q expando.
27862
27863 %Q Quilt series information. When quilt is used (either in `addon'
27864 mode or as a `standalone' backend), this expando is set to the
27865 quilt series' patch-format string. The set-patch-format hook
27866 and nopatch-format style are honoured.
27867
27868 See Quilt Support below for details.
27869
27870 In branchformat these replacements are done:
27871
27872 %b The branch name. For hg, the branch name can include a topic
27873 name.
27874 %r The current revision number or the hgrevformat style for hg.
27875
27876 In hgrevformat these replacements are done:
27877
27878 %r The current local revision number.
27879 %h The current global revision identifier.
27880
27881 In patch-format and nopatch-format these replacements are done:
27882
27883 %p The name of the top-most applied patch; may be overridden by the
27884 applied-string hook.
27885 %u The number of unapplied patches; may be overridden by the unap‐
27886 plied-string hook.
27887 %n The number of applied patches.
27888 %c The number of unapplied patches.
27889 %a The number of all patches (%a = %n + %c).
27890 %g The names of active mq guards (hg backend).
27891 %G The number of active mq guards (hg backend).
27892
27893 Not all VCS backends have to support all replacements. For nvcsformats
27894 no replacements are performed at all, it is just a string.
27895
27896 Oddities
27897 If you want to use the %b (bold off) prompt expansion in formats, which
27898 expands %b itself, use %%b. That will cause the vcs_info expansion to
27899 replace %%b with %b, so that zsh's prompt expansion mechanism can han‐
27900 dle it. Similarly, to hand down %b from branchformat, use %%%%b. Sorry
27901 for this inconvenience, but it cannot be easily avoided. Luckily we do
27902 not clash with a lot of prompt expansions and this only needs to be
27903 done for those.
27904
27905 When one of the gen-applied-string, gen-unapplied-string, and
27906 set-patch-format hooks is defined, applying %-escaping
27907 (`foo=${foo//'%'/%%}') to the interpolated values for use in the prompt
27908 is the responsibility of those hooks (jointly); when neither of those
27909 hooks is defined, vcs_info handles escaping by itself. We regret this
27910 coupling, but it was required for backwards compatibility.
27911
27912 Quilt Support
27913 Quilt is not a version control system, therefore this is not imple‐
27914 mented as a backend. It can help keeping track of a series of patches.
27915 People use it to keep a set of changes they want to use on top of soft‐
27916 ware packages (which is tightly integrated into the package build
27917 process - the Debian project does this for a large number of packages).
27918 Quilt can also help individual developers keep track of their own
27919 patches on top of real version control systems.
27920
27921 The vcs_info integration tries to support both ways of using quilt by
27922 having two slightly different modes of operation: `addon' mode and
27923 `standalone' mode).
27924
27925 Quilt integration is off by default; to enable it, set the use-quilt
27926 style, and add %Q to your formats or actionformats style:
27927 zstyle ':vcs_info:*' use-quilt true
27928
27929 Styles looked up from the Quilt support code include
27930 `.quilt-quilt-mode' in the vcs-string part of the context, where
27931 quilt-mode is either addon or standalone. Example:
27932 :vcs_info:git.quilt-addon:default:repo-root-name.
27933
27934 For `addon' mode to become active vcs_info must have already detected a
27935 real version control system controlling the directory. If that is the
27936 case, a directory that holds quilt's patches needs to be found. That
27937 directory is configurable via the `QUILT_PATCHES' environment variable.
27938 If that variable exists its value is used, otherwise the value
27939 `patches' is assumed. The value from $QUILT_PATCHES can be overwritten
27940 using the `quilt-patch-dir' style. (Note: you can use vcs_info to keep
27941 the value of $QUILT_PATCHES correct all the time via the post-quilt
27942 hook).
27943
27944 When the directory in question is found, quilt is assumed to be active.
27945 To gather more information, vcs_info looks for a directory called
27946 `.pc'; Quilt uses that directory to track its current state. If this
27947 directory does not exist we know that quilt has not done anything to
27948 the working directory (read: no patches have been applied yet).
27949
27950 If patches are applied, vcs_info will try to find out which. If you
27951 want to know which patches of a series are not yet applied, you need to
27952 activate the get-unapplied style in the appropriate context.
27953
27954 vcs_info allows for very detailed control over how the gathered infor‐
27955 mation is presented (see the Configuration and Hooks in vcs_info sec‐
27956 tions), all of which are documented below. Note there are a number of
27957 other patch tracking systems that work on top of a certain version con‐
27958 trol system (like stgit for git, or mq for hg); the configuration for
27959 systems like that are generally configured the same way as the quilt
27960 support.
27961
27962 If the quilt support is working in `addon' mode, the produced string is
27963 available as a simple format replacement (%Q to be precise), which can
27964 be used in formats and actionformats; see below for details).
27965
27966 If, on the other hand, the support code is working in `standalone'
27967 mode, vcs_info will pretend as if quilt were an actual version control
27968 system. That means that the version control system identifier (which
27969 otherwise would be something like `svn' or `cvs') will be set to
27970 `-quilt-'. This has implications on the used style context where this
27971 identifier is the second element. vcs_info will have filled in a proper
27972 value for the "repository's" root directory and the string containing
27973 the information about quilt's state will be available as the `misc' re‐
27974 placement (and %Q for compatibility with `addon' mode).
27975
27976 What is left to discuss is how `standalone' mode is detected. The de‐
27977 tection itself is a series of searches for directories. You can have
27978 this detection enabled all the time in every directory that is not oth‐
27979 erwise under version control. If you know there is only a limited set
27980 of trees where you would like vcs_info to try and look for Quilt in
27981 `standalone' mode to minimise the amount of searching on every call to
27982 vcs_info, there are a number of ways to do that:
27983
27984 Essentially, `standalone' mode detection is controlled by a style
27985 called `quilt-standalone'. It is a string style and its value can have
27986 different effects. The simplest values are: `always' to run detection
27987 every time vcs_info is run, and `never' to turn the detection off en‐
27988 tirely.
27989
27990 If the value of quilt-standalone is something else, it is interpreted
27991 differently. If the value is the name of a scalar variable the value of
27992 that variable is checked and that value is used in the same `al‐
27993 ways'/`never' way as described above.
27994
27995 If the value of quilt-standalone is an array, the elements of that ar‐
27996 ray are used as directory names under which you want the detection to
27997 be active.
27998
27999 If quilt-standalone is an associative array, the keys are taken as di‐
28000 rectory names under which you want the detection to be active, but only
28001 if the corresponding value is the string `true'.
28002
28003 Last, but not least, if the value of quilt-standalone is the name of a
28004 function, the function is called without arguments and the return value
28005 decides whether detection should be active. A `0' return value is true;
28006 a non-zero return value is interpreted as false.
28007
28008 Note, if there is both a function and a variable by the name of
28009 quilt-standalone, the function will take precedence.
28010
28011 Function Descriptions (Public API)
28012 vcs_info [user-context]
28013 The main function, that runs all backends and assembles all data
28014 into ${vcs_info_msg_*_}. This is the function you want to call
28015 from precmd if you want to include up-to-date information in
28016 your prompt (see Variable Description below). If an argument is
28017 given, that string will be used instead of default in the
28018 user-context field of the style context.
28019
28020 vcs_info_hookadd
28021 Statically registers a number of functions to a given hook. The
28022 hook needs to be given as the first argument; what follows is a
28023 list of hook-function names to register to the hook. The `+vi-'
28024 prefix needs to be left out here. See Hooks in vcs_info below
28025 for details.
28026
28027 vcs_info_hookdel
28028 Remove hook-functions from a given hook. The hook needs to be
28029 given as the first non-option argument; what follows is a list
28030 of hook-function names to un-register from the hook. If `-a' is
28031 used as the first argument, all occurrences of the functions are
28032 unregistered. Otherwise only the last occurrence is removed (if
28033 a function was registered to a hook more than once). The `+vi-'
28034 prefix needs to be left out here. See Hooks in vcs_info below
28035 for details.
28036
28037 vcs_info_lastmsg
28038 Outputs the current values of ${vcs_info_msg_*_}. Takes into
28039 account the value of the use-prompt-escapes style in
28040 ':vcs_info:formats:command:-all-'. It also only prints max-ex‐
28041 ports values.
28042
28043 vcs_info_printsys [user-context]
28044 Prints a list of all supported version control systems. Useful
28045 to find out possible contexts (and which of them are enabled) or
28046 values for the disable style.
28047
28048 vcs_info_setsys
28049 Initializes vcs_info's internal list of available backends. With
28050 this function, you can add support for new VCSs without restart‐
28051 ing the shell.
28052
28053 All functions named VCS_INFO_* are for internal use only.
28054
28055 Variable Description
28056 ${vcs_info_msg_N_} (Note the trailing underscore)
28057 Where N is an integer, e.g., vcs_info_msg_0_. These variables
28058 are the storage for the informational message the last vcs_info
28059 call has assembled. These are strongly connected to the formats,
28060 actionformats and nvcsformats styles described above. Those
28061 styles are lists. The first member of that list gets expanded
28062 into ${vcs_info_msg_0_}, the second into ${vcs_info_msg_1_} and
28063 the Nth into ${vcs_info_msg_N-1_}. (See the max-exports style
28064 above.)
28065
28066 All variables named VCS_INFO_* are for internal use only.
28067
28068 Hooks in vcs_info
28069 Hooks are places in vcs_info where you can run your own code. That code
28070 can communicate with the code that called it and through that, change
28071 the system's behaviour.
28072
28073 For configuration, hooks change the style context:
28074 :vcs_info:vcs-string+hook-name:user-context:repo-root-name
28075
28076 To register functions to a hook, you need to list them in the hooks
28077 style in the appropriate context.
28078
28079 Example:
28080 zstyle ':vcs_info:*+foo:*' hooks bar baz
28081
28082 This registers functions to the hook `foo' for all backends. In order
28083 to avoid namespace problems, all registered function names are
28084 prepended by a `+vi-', so the actual functions called for the `foo'
28085 hook are `+vi-bar' and `+vi-baz'.
28086
28087 If you would like to register a function to a hook regardless of the
28088 current context, you may use the vcs_info_hookadd function. To remove a
28089 function that was added like that, the vcs_info_hookdel function can be
28090 used.
28091
28092 If something seems weird, you can enable the `debug' boolean style in
28093 the proper context and the hook-calling code will print what it tried
28094 to execute and whether the function in question existed.
28095
28096 When you register more than one function to a hook, all functions are
28097 executed one after another until one function returns non-zero or until
28098 all functions have been called. Context-sensitive hook functions are
28099 executed before statically registered ones (the ones added by
28100 vcs_info_hookadd).
28101
28102 You may pass data between functions via an associative array,
28103 user_data. For example:
28104 +vi-git-myfirsthook(){
28105 user_data[myval]=$myval
28106 }
28107 +vi-git-mysecondhook(){
28108 # do something with ${user_data[myval]}
28109 }
28110
28111 There are a number of variables that are special in hook contexts:
28112
28113 ret The return value that the hooks system will return to the
28114 caller. The default is an integer `zero'. If and how a changed
28115 ret value changes the execution of the caller depends on the
28116 specific hook. See the hook documentation below for details.
28117
28118 hook_com
28119 An associated array which is used for bidirectional communica‐
28120 tion from the caller to hook functions. The used keys depend on
28121 the specific hook.
28122
28123 context
28124 The active context of the hook. Functions that wish to change
28125 this variable should make it local scope first.
28126
28127 vcs The current VCS after it was detected. The same values as in the
28128 enable/disable style are used. Available in all hooks except
28129 start-up.
28130
28131 Finally, the full list of currently available hooks:
28132
28133 start-up
28134 Called after starting vcs_info but before the VCS in this direc‐
28135 tory is determined. It can be used to deactivate vcs_info tempo‐
28136 rarily if necessary. When ret is set to 1, vcs_info aborts and
28137 does nothing; when set to 2, vcs_info sets up everything as if
28138 no version control were active and exits.
28139
28140 pre-get-data
28141 Same as start-up but after the VCS was detected.
28142
28143 gen-hg-bookmark-string
28144 Called in the Mercurial backend when a bookmark string is gener‐
28145 ated; the get-revision and get-bookmarks styles must be true.
28146
28147 This hook gets the names of the Mercurial bookmarks that
28148 vcs_info collected from `hg'.
28149
28150 If a bookmark is active, the key ${hook_com[hg-active-bookmark]}
28151 is set to its name. The key is otherwise unset.
28152
28153 When setting ret to non-zero, the string in ${hook_com[hg-book‐
28154 mark-string]} will be used in the %m escape in formats and ac‐
28155 tionformats and will be available in the global backend_misc ar‐
28156 ray as ${backend_misc[bookmarks]}.
28157
28158 gen-applied-string
28159 Called in the git (with stgit or during rebase or merge), and hg
28160 (with mq) backends and in quilt support when the applied-string
28161 is generated; the use-quilt zstyle must be true for quilt (the
28162 mq and stgit backends are active by default).
28163
28164 The arguments to this hook describe applied patches in the oppo‐
28165 site order, which means that the first argument is the top-most
28166 patch and so forth.
28167
28168 When the patches' log messages can be extracted, those are em‐
28169 bedded within each argument after a space, so each argument is
28170 of the form `patch-name first line of the log message', where
28171 patch-name contains no whitespace. The mq backend passes argu‐
28172 ments of the form `patch name', with possible embedded spaces,
28173 but without extracting the patch's log message.
28174
28175 When setting ret to non-zero, the string in ${hook_com[ap‐
28176 plied-string]} will be available as %p in the patch-format and
28177 nopatch-format styles. This hook is, in concert with
28178 set-patch-format, responsible for %-escaping that value for use
28179 in the prompt. (See the Oddities section.)
28180
28181 The quilt backend passes to this hook the inputs
28182 ${hook_com[quilt-patches-dir]} and, if it has been determined,
28183 ${hook_com[quilt-pc-dir]}.
28184
28185 gen-unapplied-string
28186 Called in the git (with stgit or during rebase), and hg (with
28187 mq) backend and in quilt support when the unapplied-string is
28188 generated; the get-unapplied style must be true.
28189
28190 This hook gets the names of all unapplied patches which vcs_info
28191 in order, which means that the first argument is the patch
28192 next-in-line to be applied and so forth.
28193
28194 The format of each argument is as for gen-applied-string, above.
28195
28196 When setting ret to non-zero, the string in ${hook_com[unap‐
28197 plied-string]} will be available as %u in the patch-format and
28198 nopatch-format styles. This hook is, in concert with
28199 set-patch-format, responsible for %-escaping that value for use
28200 in the prompt. (See the Oddities section.)
28201
28202 The quilt backend passes to this hook the inputs
28203 ${hook_com[quilt-patches-dir]} and, if it has been determined,
28204 ${hook_com[quilt-pc-dir]}.
28205
28206 gen-mqguards-string
28207 Called in the hg backend when guards-string is generated; the
28208 get-mq style must be true (default).
28209
28210 This hook gets the names of any active mq guards.
28211
28212 When setting ret to non-zero, the string in
28213 ${hook_com[guards-string]} will be used in the %g escape in the
28214 patch-format and nopatch-format styles.
28215
28216 no-vcs This hooks is called when no version control system was de‐
28217 tected.
28218
28219 The `hook_com' parameter is not used.
28220
28221 post-backend
28222 Called as soon as the backend has finished collecting informa‐
28223 tion.
28224
28225 The `hook_com' keys available are as for the set-message hook.
28226
28227 post-quilt
28228 Called after the quilt support is done. The following informa‐
28229 tion is passed as arguments to the hook: 1. the quilt-support
28230 mode (`addon' or `standalone'); 2. the directory that contains
28231 the patch series; 3. the directory that holds quilt's status in‐
28232 formation (the `.pc' directory) or the string "-nopc-" if that
28233 directory wasn't found.
28234
28235 The `hook_com' parameter is not used.
28236
28237 set-branch-format
28238 Called before `branchformat' is set. The only argument to the
28239 hook is the format that is configured at this point.
28240
28241 The `hook_com' keys considered are `branch' and `revision'.
28242 They are set to the values figured out so far by vcs_info and
28243 any change will be used directly when the actual replacement is
28244 done.
28245
28246 If ret is set to non-zero, the string in ${hook_com[branch-re‐
28247 place]} will be used unchanged as the `%b' replacement in the
28248 variables set by vcs_info.
28249
28250 set-hgrev-format
28251 Called before a `hgrevformat' is set. The only argument to the
28252 hook is the format that is configured at this point.
28253
28254 The `hook_com' keys considered are `hash' and `localrev'. They
28255 are set to the values figured out so far by vcs_info and any
28256 change will be used directly when the actual replacement is
28257 done.
28258
28259 If ret is set to non-zero, the string in ${hook_com[rev-re‐
28260 place]} will be used unchanged as the `%i' replacement in the
28261 variables set by vcs_info.
28262
28263 pre-addon-quilt
28264 This hook is used when vcs_info's quilt functionality is active
28265 in "addon" mode (quilt used on top of a real version control
28266 system). It is activated right before any quilt specific action
28267 is taken.
28268
28269 Setting the `ret' variable in this hook to a non-zero value
28270 avoids any quilt specific actions from being run at all.
28271
28272 set-patch-format
28273 This hook is used to control some of the possible expansions in
28274 patch-format and nopatch-format styles with patch queue systems
28275 such as quilt, mqueue and the like.
28276
28277 This hook is used in the git, hg and quilt backends.
28278
28279 The hook allows the control of the %p (${hook_com[applied]}) and
28280 %u (${hook_com[unapplied]}) expansion in all backends that use
28281 the hook. With the mercurial backend, the %g
28282 (${hook_com[guards]}) expansion is controllable in addition to
28283 that.
28284
28285 If ret is set to non-zero, the string in ${hook_com[patch-re‐
28286 place]} will be used unchanged instead of an expanded format
28287 from patch-format or nopatch-format.
28288
28289 This hook is, in concert with the gen-applied-string or gen-un‐
28290 applied-string hooks if they are defined, responsible for %-es‐
28291 caping the final patch-format value for use in the prompt. (See
28292 the Oddities section.)
28293
28294 The quilt backend passes to this hook the inputs
28295 ${hook_com[quilt-patches-dir]} and, if it has been determined,
28296 ${hook_com[quilt-pc-dir]}.
28297
28298 set-message
28299 Called each time before a `vcs_info_msg_N_' message is set. It
28300 takes two arguments; the first being the `N' in the message
28301 variable name, the second is the currently configured formats or
28302 actionformats.
28303
28304 There are a number of `hook_com' keys, that are used here: `ac‐
28305 tion', `branch', `base', `base-name', `subdir', `staged', `un‐
28306 staged', `revision', `misc', `vcs' and one `miscN' entry for
28307 each backend-specific data field (N starting at zero). They are
28308 set to the values figured out so far by vcs_info and any change
28309 will be used directly when the actual replacement is done.
28310
28311 Since this hook is triggered multiple times (once for each con‐
28312 figured formats or actionformats), each of the `hook_com' keys
28313 mentioned above (except for the miscN entries) has an `_orig'
28314 counterpart, so even if you changed a value to your liking you
28315 can still get the original value in the next run. Changing the
28316 `_orig' values is probably not a good idea.
28317
28318 If ret is set to non-zero, the string in ${hook_com[message]}
28319 will be used unchanged as the message by vcs_info.
28320
28321 If all of this sounds rather confusing, take a look at the Examples
28322 section below and also in the Misc/vcs_info-examples file in the Zsh
28323 source. They contain some explanatory code.
28324
28325 Examples
28326 Don't use vcs_info at all (even though it's in your prompt):
28327 zstyle ':vcs_info:*' enable NONE
28328
28329 Disable the backends for bzr and svk:
28330 zstyle ':vcs_info:*' disable bzr svk
28331
28332 Disable everything but bzr and svk:
28333 zstyle ':vcs_info:*' enable bzr svk
28334
28335 Provide a special formats for git:
28336 zstyle ':vcs_info:git:*' formats ' GIT, BABY! [%b]'
28337 zstyle ':vcs_info:git:*' actionformats ' GIT ACTION! [%b|%a]'
28338
28339 All %x expansion in all sorts of formats (formats, actionformats,
28340 branchformat, you name it) are done using the `zformat' builtin from
28341 the `zsh/zutil' module. That means you can do everything with these %x
28342 items what zformat supports. In particular, if you want something that
28343 is really long to have a fixed width, like a hash in a mercurial
28344 branchformat, you can do this: %12.12i. That'll shrink the 40 character
28345 hash to its 12 leading characters. The form is actually `%min.maxx'.
28346 More is possible. See the section `The zsh/zutil Module' in zshmod‐
28347 ules(1) for details.
28348
28349 Use the quicker bzr backend
28350 zstyle ':vcs_info:bzr:*' use-simple true
28351
28352 If you do use use-simple, please report if it does
28353 `the-right-thing[tm]'.
28354
28355 Display the revision number in yellow for bzr and svn:
28356 zstyle ':vcs_info:(svn|bzr):*' \
28357 branchformat '%b%%F{yellow}:%r'
28358
28359 The doubled percent sign is explained in the Oddities section.
28360
28361 Alternatively, one can use the raw colour codes directly:
28362
28363 zstyle ':vcs_info:(svn|bzr):*' \
28364 branchformat '%b%{'${fg[yellow]}'%}:%r'
28365
28366 Normally when a variable is interpolated into a format string, the
28367 variable needs to be %-escaped. In this example we skipped that because
28368 we assume the value of ${fg[yellow]} doesn't contain any % signs.
28369
28370 Make sure you enclose the color codes in %{...%} if you want to use the
28371 string provided by vcs_info in prompts.
28372
28373 Here is how to print the VCS information as a command (not in a
28374 prompt):
28375 vcsi() { vcs_info interactive; vcs_info_lastmsg }
28376
28377 This way, you can even define different formats for output via
28378 vcs_info_lastmsg in the ':vcs_info:*:interactive:*' namespace.
28379
28380 Now as promised, some code that uses hooks: say, you'd like to replace
28381 the string `svn' by `subversion' in vcs_info's %s formats replacement.
28382
28383 First, we will tell vcs_info to call a function when populating the
28384 message variables with the gathered information:
28385 zstyle ':vcs_info:*+set-message:*' hooks svn2subversion
28386
28387 Nothing happens. Which is reasonable, since we didn't define the actual
28388 function yet. To see what the hooks subsystem is trying to do, enable
28389 the `debug' style:
28390 zstyle ':vcs_info:*+*:*' debug true
28391
28392 That should give you an idea what is going on. Specifically, the func‐
28393 tion that we are looking for is `+vi-svn2subversion'. Note, the `+vi-'
28394 prefix. So, everything is in order, just as documented. When you are
28395 done checking out the debugging output, disable it again:
28396 zstyle ':vcs_info:*+*:*' debug false
28397
28398 Now, let's define the function:
28399 function +vi-svn2subversion() {
28400 [[ ${hook_com[vcs_orig]} == svn ]] && hook_com[vcs]=subversion
28401 }
28402
28403 Simple enough. And it could have even been simpler, if only we had reg‐
28404 istered our function in a less generic context. If we do it only in the
28405 `svn' backend's context, we don't need to test which the active backend
28406 is:
28407 zstyle ':vcs_info:svn+set-message:*' hooks svn2subversion
28408 function +vi-svn2subversion() {
28409 hook_com[vcs]=subversion
28410 }
28411
28412 And finally a little more elaborate example, that uses a hook to create
28413 a customised bookmark string for the hg backend.
28414
28415 Again, we start off by registering a function:
28416 zstyle ':vcs_info:hg+gen-hg-bookmark-string:*' hooks hgbookmarks
28417
28418 And then we define the `+vi-hgbookmarks' function:
28419 function +vi-hgbookmarks() {
28420 # The default is to connect all bookmark names by
28421 # commas. This mixes things up a little.
28422 # Imagine, there's one type of bookmarks that is
28423 # special to you. Say, because it's *your* work.
28424 # Those bookmarks look always like this: "sh/*"
28425 # (because your initials are sh, for example).
28426 # This makes the bookmarks string use only those
28427 # bookmarks. If there's more than one, it
28428 # concatenates them using commas.
28429 # The bookmarks returned by `hg' are available in
28430 # the function's positional parameters.
28431 local s="${(Mj:,:)@:#sh/*}"
28432 # Now, the communication with the code that calls
28433 # the hook functions is done via the hook_com[]
28434 # hash. The key at which the `gen-hg-bookmark-string'
28435 # hook looks is `hg-bookmark-string'. So:
28436 hook_com[hg-bookmark-string]=$s
28437 # And to signal that we want to use the string we
28438 # just generated, set the special variable `ret' to
28439 # something other than the default zero:
28440 ret=1
28441 return 0
28442 }
28443
28444 Some longer examples and code snippets which might be useful are avail‐
28445 able in the examples file located at Misc/vcs_info-examples in the Zsh
28446 source directory.
28447
28448 This concludes our guided tour through zsh's vcs_info.
28449
28451 Installation
28452 You should make sure all the functions from the Functions/Prompts di‐
28453 rectory of the source distribution are available; they all begin with
28454 the string `prompt_' except for the special function `promptinit'. You
28455 also need the `colors' and `add-zsh-hook' functions from Func‐
28456 tions/Misc. All these functions may already be installed on your sys‐
28457 tem; if not, you will need to find them and copy them. The directory
28458 should appear as one of the elements of the fpath array (this should
28459 already be the case if they were installed), and at least the function
28460 promptinit should be autoloaded; it will autoload the rest. Finally,
28461 to initialize the use of the system you need to call the promptinit
28462 function. The following code in your .zshrc will arrange for this; as‐
28463 sume the functions are stored in the directory ~/myfns:
28464
28465 fpath=(~/myfns $fpath)
28466 autoload -U promptinit
28467 promptinit
28468
28469 Theme Selection
28470 Use the prompt command to select your preferred theme. This command
28471 may be added to your .zshrc following the call to promptinit in order
28472 to start zsh with a theme already selected.
28473
28474 prompt [ -c | -l ]
28475 prompt [ -p | -h ] [ theme ... ]
28476 prompt [ -s ] theme [ arg ... ]
28477 Set or examine the prompt theme. With no options and a theme
28478 argument, the theme with that name is set as the current theme.
28479 The available themes are determined at run time; use the -l op‐
28480 tion to see a list. The special theme `random' selects at ran‐
28481 dom one of the available themes and sets your prompt to that.
28482
28483 In some cases the theme may be modified by one or more argu‐
28484 ments, which should be given after the theme name. See the help
28485 for each theme for descriptions of these arguments.
28486
28487 Options are:
28488
28489 -c Show the currently selected theme and its parameters, if
28490 any.
28491 -l List all available prompt themes.
28492 -p Preview the theme named by theme, or all themes if no
28493 theme is given.
28494 -h Show help for the theme named by theme, or for the prompt
28495 function if no theme is given.
28496 -s Set theme as the current theme and save state.
28497
28498 prompt_theme_setup
28499 Each available theme has a setup function which is called by the
28500 prompt function to install that theme. This function may define
28501 other functions as necessary to maintain the prompt, including
28502 functions used to preview the prompt or provide help for its
28503 use. You should not normally call a theme's setup function di‐
28504 rectly.
28505
28506 Utility Themes
28507 prompt off
28508 The theme `off' sets all the prompt variables to minimal values
28509 with no special effects.
28510
28511 prompt default
28512 The theme `default' sets all prompt variables to the same state
28513 as if an interactive zsh was started with no initialization
28514 files.
28515
28516 prompt restore
28517 The special theme `restore' erases all theme settings and sets
28518 prompt variables to their state before the first time the
28519 `prompt' function was run, provided each theme has properly de‐
28520 fined its cleanup (see below).
28521
28522 Note that you can undo `prompt off' and `prompt default' with
28523 `prompt restore', but a second restore does not undo the first.
28524
28525 Writing Themes
28526 The first step for adding your own theme is to choose a name for it,
28527 and create a file `prompt_name_setup' in a directory in your fpath,
28528 such as ~/myfns in the example above. The file should at minimum con‐
28529 tain assignments for the prompt variables that your theme wishes to
28530 modify. By convention, themes use PS1, PS2, RPS1, etc., rather than
28531 the longer PROMPT and RPROMPT.
28532
28533 The file is autoloaded as a function in the current shell context, so
28534 it may contain any necessary commands to customize your theme, includ‐
28535 ing defining additional functions. To make some complex tasks easier,
28536 your setup function may also do any of the following:
28537
28538 Assign prompt_opts
28539 The array prompt_opts may be assigned any of "bang", "cr", "per‐
28540 cent", "sp", and/or "subst" as values. The corresponding se‐
28541 topts (promptbang, etc.) are turned on, all other prompt-related
28542 options are turned off. The prompt_opts array preserves setopts
28543 even beyond the scope of localoptions, should your function need
28544 that.
28545
28546 Modify hooks
28547 Use of add-zsh-hook and add-zle-hook-widget is recommended (see
28548 the Manipulating Hook Functions section above). All hooks that
28549 follow the naming pattern prompt_theme_hook are automatically
28550 removed when the prompt theme changes or is disabled.
28551
28552 Declare cleanup
28553 If your function makes any other changes that should be undone
28554 when the theme is disabled, your setup function may call
28555
28556 prompt_cleanup command
28557
28558 where command should be suitably quoted. If your theme is ever
28559 disabled or replaced by another, command is executed with eval.
28560 You may declare more than one such cleanup hook.
28561
28562 Define preview
28563 Define or autoload a function prompt_name_preview to display a
28564 simulated version of your prompt. A simple default previewer is
28565 defined by promptinit for themes that do not define their own.
28566 This preview function is called by `prompt -p'.
28567
28568 Provide help
28569 Define or autoload a function prompt_name_help to display docu‐
28570 mentation or help text for your theme. This help function is
28571 called by `prompt -h'.
28572
28574 Widgets
28575 These functions all implement user-defined ZLE widgets (see zshzle(1))
28576 which can be bound to keystrokes in interactive shells. To use them,
28577 your .zshrc should contain lines of the form
28578
28579 autoload function
28580 zle -N function
28581
28582 followed by an appropriate bindkey command to associate the function
28583 with a key sequence. Suggested bindings are described below.
28584
28585 bash-style word functions
28586 If you are looking for functions to implement moving over and
28587 editing words in the manner of bash, where only alphanumeric
28588 characters are considered word characters, you can use the func‐
28589 tions described in the next section. The following is suffi‐
28590 cient:
28591
28592 autoload -U select-word-style
28593 select-word-style bash
28594
28595 forward-word-match, backward-word-match
28596 kill-word-match, backward-kill-word-match
28597 transpose-words-match, capitalize-word-match
28598 up-case-word-match, down-case-word-match
28599 delete-whole-word-match, select-word-match
28600 select-word-style, match-word-context, match-words-by-style
28601 The first eight `-match' functions are drop-in replacements for
28602 the builtin widgets without the suffix. By default they behave
28603 in a similar way. However, by the use of styles and the func‐
28604 tion select-word-style, the way words are matched can be al‐
28605 tered. select-word-match is intended to be used as a text object
28606 in vi mode but with custom word styles. For comparison, the wid‐
28607 gets described in zshzle(1) under Text Objects use fixed defini‐
28608 tions of words, compatible with the vim editor.
28609
28610 The simplest way of configuring the functions is to use se‐
28611 lect-word-style, which can either be called as a normal function
28612 with the appropriate argument, or invoked as a user-defined wid‐
28613 get that will prompt for the first character of the word style
28614 to be used. The first time it is invoked, the first eight
28615 -match functions will automatically replace the builtin ver‐
28616 sions, so they do not need to be loaded explicitly.
28617
28618 The word styles available are as follows. Only the first char‐
28619 acter is examined.
28620
28621 bash Word characters are alphanumeric characters only.
28622
28623 normal As in normal shell operation: word characters are al‐
28624 phanumeric characters plus any characters present in the
28625 string given by the parameter $WORDCHARS.
28626
28627 shell Words are complete shell command arguments, possibly in‐
28628 cluding complete quoted strings, or any tokens special to
28629 the shell.
28630
28631 whitespace
28632 Words are any set of characters delimited by whitespace.
28633
28634 default
28635 Restore the default settings; this is usually the same as
28636 `normal'.
28637
28638 All but `default' can be input as an upper case character, which
28639 has the same effect but with subword matching turned on. In
28640 this case, words with upper case characters are treated spe‐
28641 cially: each separate run of upper case characters, or an upper
28642 case character followed by any number of other characters, is
28643 considered a word. The style subword-range can supply an alter‐
28644 native character range to the default `[:upper:]'; the value of
28645 the style is treated as the contents of a `[...]' pattern (note
28646 that the outer brackets should not be supplied, only those sur‐
28647 rounding named ranges).
28648
28649 More control can be obtained using the zstyle command, as de‐
28650 scribed in zshmodules(1). Each style is looked up in the con‐
28651 text :zle:widget where widget is the name of the user-defined
28652 widget, not the name of the function implementing it, so in the
28653 case of the definitions supplied by select-word-style the appro‐
28654 priate contexts are :zle:forward-word, and so on. The function
28655 select-word-style itself always defines styles for the context
28656 `:zle:*' which can be overridden by more specific (longer) pat‐
28657 terns as well as explicit contexts.
28658
28659 The style word-style specifies the rules to use. This may have
28660 the following values.
28661
28662 normal Use the standard shell rules, i.e. alphanumerics and
28663 $WORDCHARS, unless overridden by the styles word-chars or
28664 word-class.
28665
28666 specified
28667 Similar to normal, but only the specified characters, and
28668 not also alphanumerics, are considered word characters.
28669
28670 unspecified
28671 The negation of specified. The given characters are
28672 those which will not be considered part of a word.
28673
28674 shell Words are obtained by using the syntactic rules for gen‐
28675 erating shell command arguments. In addition, special
28676 tokens which are never command arguments such as `()' are
28677 also treated as words.
28678
28679 whitespace
28680 Words are whitespace-delimited strings of characters.
28681
28682 The first three of those rules usually use $WORDCHARS, but the
28683 value in the parameter can be overridden by the style
28684 word-chars, which works in exactly the same way as $WORDCHARS.
28685 In addition, the style word-class uses character class syntax to
28686 group characters and takes precedence over word-chars if both
28687 are set. The word-class style does not include the surrounding
28688 brackets of the character class; for example, `-:[:alnum:]' is a
28689 valid word-class to include all alphanumerics plus the charac‐
28690 ters `-' and `:'. Be careful including `]', `^' and `-' as
28691 these are special inside character classes.
28692
28693 word-style may also have `-subword' appended to its value to
28694 turn on subword matching, as described above.
28695
28696 The style skip-chars is mostly useful for transpose-words and
28697 similar functions. If set, it gives a count of characters
28698 starting at the cursor position which will not be considered
28699 part of the word and are treated as space, regardless of what
28700 they actually are. For example, if
28701
28702 zstyle ':zle:transpose-words' skip-chars 1
28703
28704 has been set, and transpose-words-match is called with the cur‐
28705 sor on the X of fooXbar, where X can be any character, then the
28706 resulting expression is barXfoo.
28707
28708 Finer grained control can be obtained by setting the style
28709 word-context to an array of pairs of entries. Each pair of en‐
28710 tries consists of a pattern and a subcontext. The shell argu‐
28711 ment the cursor is on is matched against each pattern in turn
28712 until one matches; if it does, the context is extended by a
28713 colon and the corresponding subcontext. Note that the test is
28714 made against the original word on the line, with no stripping of
28715 quotes. Special handling is done between words: the current
28716 context is examined and if it contains the string between the
28717 word is set to a single space; else if it is contains the string
28718 back, the word before the cursor is considered, else the word
28719 after cursor is considered. Some examples are given below.
28720
28721 The style skip-whitespace-first is only used with the for‐
28722 ward-word widget. If it is set to true, then forward-word skips
28723 any non-word-characters, followed by any non-word-characters:
28724 this is similar to the behaviour of other word-orientated wid‐
28725 gets, and also that used by other editors, however it differs
28726 from the standard zsh behaviour. When using select-word-style
28727 the widget is set in the context :zle:* to true if the word
28728 style is bash and false otherwise. It may be overridden by set‐
28729 ting it in the more specific context :zle:forward-word*.
28730
28731 It is possible to create widgets with specific behaviour by
28732 defining a new widget implemented by the appropriate generic
28733 function, then setting a style for the context of the specific
28734 widget. For example, the following defines a widget back‐
28735 ward-kill-space-word using backward-kill-word-match, the generic
28736 widget implementing backward-kill-word behaviour, and ensures
28737 that the new widget always implements space-delimited behaviour.
28738
28739 zle -N backward-kill-space-word backward-kill-word-match
28740 zstyle :zle:backward-kill-space-word word-style space
28741
28742 The widget backward-kill-space-word can now be bound to a key.
28743
28744 Here are some further examples of use of the styles, actually
28745 taken from the simplified interface in select-word-style:
28746
28747 zstyle ':zle:*' word-style standard
28748 zstyle ':zle:*' word-chars ''
28749
28750 Implements bash-style word handling for all widgets, i.e. only
28751 alphanumerics are word characters; equivalent to setting the pa‐
28752 rameter WORDCHARS empty for the given context.
28753
28754 style ':zle:*kill*' word-style space
28755
28756 Uses space-delimited words for widgets with the word `kill' in
28757 the name. Neither of the styles word-chars nor word-class is
28758 used in this case.
28759
28760 Here are some examples of use of the word-context style to ex‐
28761 tend the context.
28762
28763 zstyle ':zle:*' word-context \
28764 "*/*" filename "[[:space:]]" whitespace
28765 zstyle ':zle:transpose-words:whitespace' word-style shell
28766 zstyle ':zle:transpose-words:filename' word-style normal
28767 zstyle ':zle:transpose-words:filename' word-chars ''
28768
28769 This provides two different ways of using transpose-words de‐
28770 pending on whether the cursor is on whitespace between words or
28771 on a filename, here any word containing a /. On whitespace,
28772 complete arguments as defined by standard shell rules will be
28773 transposed. In a filename, only alphanumerics will be trans‐
28774 posed. Elsewhere, words will be transposed using the default
28775 style for :zle:transpose-words.
28776
28777 The word matching and all the handling of zstyle settings is ac‐
28778 tually implemented by the function match-words-by-style. This
28779 can be used to create new user-defined widgets. The calling
28780 function should set the local parameter curcontext to :zle:wid‐
28781 get, create the local parameter matched_words and call
28782 match-words-by-style with no arguments. On return,
28783 matched_words will be set to an array with the elements: (1) the
28784 start of the line (2) the word before the cursor (3) any
28785 non-word characters between that word and the cursor (4) any
28786 non-word character at the cursor position plus any remaining
28787 non-word characters before the next word, including all charac‐
28788 ters specified by the skip-chars style, (5) the word at or fol‐
28789 lowing the cursor (6) any non-word characters following that
28790 word (7) the remainder of the line. Any of the elements may be
28791 an empty string; the calling function should test for this to
28792 decide whether it can perform its function.
28793
28794 If the variable matched_words is defined by the caller to
28795 match-words-by-style as an associative array (local -A
28796 matched_words), then the seven values given above should be re‐
28797 trieved from it as elements named start, word-before-cursor,
28798 ws-before-cursor, ws-after-cursor, word-after-cursor, ws-af‐
28799 ter-word, and end. In addition the element is-word-start is 1
28800 if the cursor is on the start of a word or subword, or on white
28801 space before it (the cases can be distinguished by testing the
28802 ws-after-cursor element) and 0 otherwise. This form is recom‐
28803 mended for future compatibility.
28804
28805 It is possible to pass options with arguments to
28806 match-words-by-style to override the use of styles. The options
28807 are:
28808 -w word-style
28809 -s skip-chars
28810 -c word-class
28811 -C word-chars
28812 -r subword-range
28813
28814 For example, match-words-by-style -w shell -c 0 may be used to
28815 extract the command argument around the cursor.
28816
28817 The word-context style is implemented by the function
28818 match-word-context. This should not usually need to be called
28819 directly.
28820
28821 bracketed-paste-magic
28822 The bracketed-paste widget (see the subsection `Miscellaneous'
28823 in zshzle(1)) inserts pasted text literally into the editor buf‐
28824 fer rather than interpret it as keystrokes. This disables some
28825 common usages where the self-insert widget is replaced in order
28826 to accomplish some extra processing. An example is the contrib‐
28827 uted url-quote-magic widget described below.
28828
28829 The bracketed-paste-magic widget is meant to replace brack‐
28830 eted-paste with a wrapper that re-enables these self-insert ac‐
28831 tions, and other actions as selected by zstyles. Therefore this
28832 widget is installed with
28833
28834 autoload -Uz bracketed-paste-magic
28835 zle -N bracketed-paste bracketed-paste-magic
28836
28837 Other than enabling some widget processing, brack‐
28838 eted-paste-magic attempts to replicate bracketed-paste as faith‐
28839 fully as possible.
28840
28841 The following zstyles may be set to control processing of pasted
28842 text. All are looked up in the context `:brack‐
28843 eted-paste-magic'.
28844
28845 active-widgets
28846 A list of patterns matching widget names that should be
28847 activated during the paste. All other key sequences are
28848 processed as self-insert-unmeta. The default is `self-*'
28849 so any user-defined widgets named with that prefix are
28850 active along with the builtin self-insert.
28851
28852 If this style is not set (explicitly deleted) or set to
28853 an empty value, no widgets are active and the pasted text
28854 is inserted literally. If the value includes `unde‐
28855 fined-key', any unknown sequences are discarded from the
28856 pasted text.
28857
28858 inactive-keys
28859 The inverse of active-widgets, a list of key sequences
28860 that always use self-insert-unmeta even when bound to an
28861 active widget. Note that this is a list of literal key
28862 sequences, not patterns.
28863
28864 paste-init
28865 A list of function names, called in widget context (but
28866 not as widgets). The functions are called in order until
28867 one of them returns a non-zero status. The parameter
28868 `PASTED' contains the initial state of the pasted text.
28869 All other ZLE parameters such as `BUFFER' have their nor‐
28870 mal values and side-effects, and full history is avail‐
28871 able, so for example paste-init functions may move words
28872 from BUFFER into PASTED to make those words visible to
28873 the active-widgets.
28874
28875 A non-zero return from a paste-init function does not
28876 prevent the paste itself from proceeding.
28877
28878 Loading bracketed-paste-magic defines backward-ex‐
28879 tend-paste, a helper function for use in paste-init.
28880
28881 zstyle :bracketed-paste-magic paste-init \
28882 backward-extend-paste
28883
28884 When a paste would insert into the middle of a word or
28885 append text to a word already on the line, backward-ex‐
28886 tend-paste moves the prefix from LBUFFER into PASTED so
28887 that the active-widgets see the full word so far. This
28888 may be useful with url-quote-magic.
28889
28890 paste-finish
28891 Another list of function names called in order until one
28892 returns non-zero. These functions are called after the
28893 pasted text has been processed by the active-widgets, but
28894 before it is inserted into `BUFFER'. ZLE parameters have
28895 their normal values and side-effects.
28896
28897 A non-zero return from a paste-finish function does not
28898 prevent the paste itself from proceeding.
28899
28900 Loading bracketed-paste-magic also defines quote-paste, a
28901 helper function for use in paste-finish.
28902
28903 zstyle :bracketed-paste-magic paste-finish \
28904 quote-paste
28905 zstyle :bracketed-paste-magic:finish quote-style \
28906 qqq
28907
28908 When the pasted text is inserted into BUFFER, it is
28909 quoted per the quote-style value. To forcibly turn off
28910 the built-in numeric prefix quoting of bracketed-paste,
28911 use:
28912
28913 zstyle :bracketed-paste-magic:finish quote-style \
28914 none
28915
28916 Important: During active-widgets processing of the paste (after
28917 paste-init and before paste-finish), BUFFER starts empty and
28918 history is restricted, so cursor motions, etc., may not pass
28919 outside of the pasted content. Text assigned to BUFFER by the
28920 active widgets is copied back into PASTED before paste-finish.
28921
28922 copy-earlier-word
28923 This widget works like a combination of insert-last-word and
28924 copy-prev-shell-word. Repeated invocations of the widget re‐
28925 trieve earlier words on the relevant history line. With a nu‐
28926 meric argument N, insert the Nth word from the history line; N
28927 may be negative to count from the end of the line.
28928
28929 If insert-last-word has been used to retrieve the last word on a
28930 previous history line, repeated invocations will replace that
28931 word with earlier words from the same line.
28932
28933 Otherwise, the widget applies to words on the line currently be‐
28934 ing edited. The widget style can be set to the name of another
28935 widget that should be called to retrieve words. This widget
28936 must accept the same three arguments as insert-last-word.
28937
28938 cycle-completion-positions
28939 After inserting an unambiguous string into the command line, the
28940 new function based completion system may know about multiple
28941 places in this string where characters are missing or differ
28942 from at least one of the possible matches. It will then place
28943 the cursor on the position it considers to be the most interest‐
28944 ing one, i.e. the one where one can disambiguate between as many
28945 matches as possible with as little typing as possible.
28946
28947 This widget allows the cursor to be easily moved to the other
28948 interesting spots. It can be invoked repeatedly to cycle be‐
28949 tween all positions reported by the completion system.
28950
28951 delete-whole-word-match
28952 This is another function which works like the -match functions
28953 described immediately above, i.e. using styles to decide the
28954 word boundaries. However, it is not a replacement for any ex‐
28955 isting function.
28956
28957 The basic behaviour is to delete the word around the cursor.
28958 There is no numeric argument handling; only the single word
28959 around the cursor is considered. If the widget contains the
28960 string kill, the removed text will be placed in the cutbuffer
28961 for future yanking. This can be obtained by defining
28962 kill-whole-word-match as follows:
28963
28964 zle -N kill-whole-word-match delete-whole-word-match
28965
28966 and then binding the widget kill-whole-word-match.
28967
28968 up-line-or-beginning-search, down-line-or-beginning-search
28969 These widgets are similar to the builtin functions
28970 up-line-or-search and down-line-or-search: if in a multiline
28971 buffer they move up or down within the buffer, otherwise they
28972 search for a history line matching the start of the current
28973 line. In this case, however, they search for a line which
28974 matches the current line up to the current cursor position, in
28975 the manner of history-beginning-search-backward and -forward,
28976 rather than the first word on the line.
28977
28978 edit-command-line
28979 Edit the command line using your visual editor, as in ksh.
28980
28981 bindkey -M vicmd v edit-command-line
28982
28983 The editor to be used can also be specified using the editor
28984 style in the context of the widget. It is specified as an array
28985 of command and arguments:
28986
28987 zstyle :zle:edit-command-line editor gvim -f
28988
28989 expand-absolute-path
28990 Expand the file name under the cursor to an absolute path, re‐
28991 solving symbolic links. Where possible, the initial path seg‐
28992 ment is turned into a named directory or reference to a user's
28993 home directory.
28994
28995 history-search-end
28996 This function implements the widgets history-begin‐
28997 ning-search-backward-end and history-beginning-search-for‐
28998 ward-end. These commands work by first calling the correspond‐
28999 ing builtin widget (see `History Control' in zshzle(1)) and then
29000 moving the cursor to the end of the line. The original cursor
29001 position is remembered and restored before calling the builtin
29002 widget a second time, so that the same search is repeated to
29003 look farther through the history.
29004
29005 Although you autoload only one function, the commands to use it
29006 are slightly different because it implements two widgets.
29007
29008 zle -N history-beginning-search-backward-end \
29009 history-search-end
29010 zle -N history-beginning-search-forward-end \
29011 history-search-end
29012 bindkey '\e^P' history-beginning-search-backward-end
29013 bindkey '\e^N' history-beginning-search-forward-end
29014
29015 history-beginning-search-menu
29016 This function implements yet another form of history searching.
29017 The text before the cursor is used to select lines from the his‐
29018 tory, as for history-beginning-search-backward except that all
29019 matches are shown in a numbered menu. Typing the appropriate
29020 digits inserts the full history line. Note that leading zeroes
29021 must be typed (they are only shown when necessary for removing
29022 ambiguity). The entire history is searched; there is no dis‐
29023 tinction between forwards and backwards.
29024
29025 With a numeric argument, the search is not anchored to the start
29026 of the line; the string typed by the use may appear anywhere in
29027 the line in the history.
29028
29029 If the widget name contains `-end' the cursor is moved to the
29030 end of the line inserted. If the widget name contains `-space'
29031 any space in the text typed is treated as a wildcard and can
29032 match anything (hence a leading space is equivalent to giving a
29033 numeric argument). Both forms can be combined, for example:
29034
29035 zle -N history-beginning-search-menu-space-end \
29036 history-beginning-search-menu
29037
29038 history-pattern-search
29039 The function history-pattern-search implements widgets which
29040 prompt for a pattern with which to search the history backwards
29041 or forwards. The pattern is in the usual zsh format, however
29042 the first character may be ^ to anchor the search to the start
29043 of the line, and the last character may be $ to anchor the
29044 search to the end of the line. If the search was not anchored
29045 to the end of the line the cursor is positioned just after the
29046 pattern found.
29047
29048 The commands to create bindable widgets are similar to those in
29049 the example immediately above:
29050
29051 autoload -U history-pattern-search
29052 zle -N history-pattern-search-backward history-pattern-search
29053 zle -N history-pattern-search-forward history-pattern-search
29054
29055 incarg Typing the keystrokes for this widget with the cursor placed on
29056 or to the left of an integer causes that integer to be incre‐
29057 mented by one. With a numeric argument, the number is incre‐
29058 mented by the amount of the argument (decremented if the numeric
29059 argument is negative). The shell parameter incarg may be set to
29060 change the default increment to something other than one.
29061
29062 bindkey '^X+' incarg
29063
29064 incremental-complete-word
29065 This allows incremental completion of a word. After starting
29066 this command, a list of completion choices can be shown after
29067 every character you type, which you can delete with ^H or DEL.
29068 Pressing return accepts the completion so far and returns you to
29069 normal editing (that is, the command line is not immediately ex‐
29070 ecuted). You can hit TAB to do normal completion, ^G to abort
29071 back to the state when you started, and ^D to list the matches.
29072
29073 This works only with the new function based completion system.
29074
29075 bindkey '^Xi' incremental-complete-word
29076
29077 insert-composed-char
29078 This function allows you to compose characters that don't appear
29079 on the keyboard to be inserted into the command line. The com‐
29080 mand is followed by two keys corresponding to ASCII characters
29081 (there is no prompt). For accented characters, the two keys are
29082 a base character followed by a code for the accent, while for
29083 other special characters the two characters together form a mne‐
29084 monic for the character to be inserted. The two-character codes
29085 are a subset of those given by RFC 1345 (see for example
29086 http://www.faqs.org/rfcs/rfc1345.html).
29087
29088 The function may optionally be followed by up to two characters
29089 which replace one or both of the characters read from the key‐
29090 board; if both characters are supplied, no input is read. For
29091 example, insert-composed-char a: can be used within a widget to
29092 insert an a with umlaut into the command line. This has the ad‐
29093 vantages over use of a literal character that it is more porta‐
29094 ble.
29095
29096 For best results zsh should have been built with support for
29097 multibyte characters (configured with --enable-multibyte); how‐
29098 ever, the function works for the limited range of characters
29099 available in single-byte character sets such as ISO-8859-1.
29100
29101 The character is converted into the local representation and in‐
29102 serted into the command line at the cursor position. (The con‐
29103 version is done within the shell, using whatever facilities the
29104 C library provides.) With a numeric argument, the character and
29105 its code are previewed in the status line
29106
29107 The function may be run outside zle in which case it prints the
29108 character (together with a newline) to standard output. Input
29109 is still read from keystrokes.
29110
29111 See insert-unicode-char for an alternative way of inserting Uni‐
29112 code characters using their hexadecimal character number.
29113
29114 The set of accented characters is reasonably complete up to Uni‐
29115 code character U+0180, the set of special characters less so.
29116 However, it is very sporadic from that point. Adding new char‐
29117 acters is easy, however; see the function define-composed-chars.
29118 Please send any additions to zsh-workers@zsh.org.
29119
29120 The codes for the second character when used to accent the first
29121 are as follows. Note that not every character can take every
29122 accent.
29123 ! Grave.
29124 ' Acute.
29125 > Circumflex.
29126 ? Tilde. (This is not ~ as RFC 1345 does not assume that
29127 character is present on the keyboard.)
29128 - Macron. (A horizontal bar over the base character.)
29129 ( Breve. (A shallow dish shape over the base character.)
29130 . Dot above the base character, or in the case of i no dot,
29131 or in the case of L and l a centered dot.
29132 : Diaeresis (Umlaut).
29133 c Cedilla.
29134 _ Underline, however there are currently no underlined
29135 characters.
29136 / Stroke through the base character.
29137 " Double acute (only supported on a few letters).
29138 ; Ogonek. (A little forward facing hook at the bottom
29139 right of the character.)
29140 < Caron. (A little v over the letter.)
29141 0 Circle over the base character.
29142 2 Hook over the base character.
29143 9 Horn over the base character.
29144
29145 The most common characters from the Arabic, Cyrillic, Greek and
29146 Hebrew alphabets are available; consult RFC 1345 for the appro‐
29147 priate sequences. In addition, a set of two letter codes not in
29148 RFC 1345 are available for the double-width characters corre‐
29149 sponding to ASCII characters from ! to ~ (0x21 to 0x7e) by pre‐
29150 ceding the character with ^, for example ^A for a double-width
29151 A.
29152
29153 The following other two-character sequences are understood.
29154
29155 ASCII characters
29156 These are already present on most keyboards:
29157 <( Left square bracket
29158 // Backslash (solidus)
29159 )> Right square bracket
29160 (! Left brace (curly bracket)
29161 !! Vertical bar (pipe symbol)
29162 !) Right brace (curly bracket)
29163 '? Tilde
29164
29165 Special letters
29166 Characters found in various variants of the Latin alpha‐
29167 bet:
29168 ss Eszett (scharfes S)
29169 D-, d- Eth
29170 TH, th Thorn
29171 kk Kra
29172 'n 'n
29173 NG, ng Ng
29174 OI, oi Oi
29175 yr yr
29176 ED ezh
29177
29178 Currency symbols
29179 Ct Cent
29180 Pd Pound sterling (also lira and others)
29181 Cu Currency
29182 Ye Yen
29183 Eu Euro (N.B. not in RFC 1345)
29184
29185 Punctuation characters
29186 References to "right" quotes indicate the shape (like a 9
29187 rather than 6) rather than their grammatical use. (For
29188 example, a "right" low double quote is used to open quo‐
29189 tations in German.)
29190 !I Inverted exclamation mark
29191 BB Broken vertical bar
29192 SE Section
29193 Co Copyright
29194 -a Spanish feminine ordinal indicator
29195 << Left guillemet
29196 -- Soft hyphen
29197 Rg Registered trade mark
29198 PI Pilcrow (paragraph)
29199 -o Spanish masculine ordinal indicator
29200 >> Right guillemet
29201 ?I Inverted question mark
29202 -1 Hyphen
29203 -N En dash
29204 -M Em dash
29205 -3 Horizontal bar
29206 :3 Vertical ellipsis
29207 .3 Horizontal midline ellipsis
29208 !2 Double vertical line
29209 =2 Double low line
29210 '6 Left single quote
29211 '9 Right single quote
29212 .9 "Right" low quote
29213 9' Reversed "right" quote
29214 "6 Left double quote
29215 "9 Right double quote
29216 :9 "Right" low double quote
29217 9" Reversed "right" double quote
29218 /- Dagger
29219 /= Double dagger
29220
29221 Mathematical symbols
29222 DG Degree
29223 -2, +-, -+
29224 - sign, +/- sign, -/+ sign
29225 2S Superscript 2
29226 3S Superscript 3
29227 1S Superscript 1
29228 My Micro
29229 .M Middle dot
29230 14 Quarter
29231 12 Half
29232 34 Three quarters
29233 *X Multiplication
29234 -: Division
29235 %0 Per mille
29236 FA, TE, /0
29237 For all, there exists, empty set
29238 dP, DE, NB
29239 Partial derivative, delta (increment), del (nabla)
29240 (-, -) Element of, contains
29241 *P, +Z Product, sum
29242 *-, Ob, Sb
29243 Asterisk, ring, bullet
29244 RT, 0(, 00
29245 Root sign, proportional to, infinity
29246
29247 Other symbols
29248 cS, cH, cD, cC
29249 Card suits: spades, hearts, diamonds, clubs
29250 Md, M8, M2, Mb, Mx, MX
29251 Musical notation: crotchet (quarter note), quaver (eighth
29252 note), semiquavers (sixteenth notes), flag sign, natural
29253 sign, sharp sign
29254 Fm, Ml Female, male
29255
29256 Accents on their own
29257 '> Circumflex (same as caret, ^)
29258 '! Grave (same as backtick, `)
29259 ', Cedilla
29260 ': Diaeresis (Umlaut)
29261 'm Macron
29262 '' Acute
29263
29264 insert-files
29265 This function allows you type a file pattern, and see the re‐
29266 sults of the expansion at each step. When you hit return, all
29267 expansions are inserted into the command line.
29268
29269 bindkey '^Xf' insert-files
29270
29271 insert-unicode-char
29272 When first executed, the user inputs a set of hexadecimal dig‐
29273 its. This is terminated with another call to insert-uni‐
29274 code-char. The digits are then turned into the corresponding
29275 Unicode character. For example, if the widget is bound to ^XU,
29276 the character sequence `^XU 4 c ^XU' inserts L (Unicode U+004c).
29277
29278 See insert-composed-char for a way of inserting characters using
29279 a two-character mnemonic.
29280
29281
29282 narrow-to-region [ -p pre ] [ -P post ]
29283 [ -S statepm | -R statepm | [ -l lbufvar ] [ -r rbuf‐
29284 var ] ]
29285 [ -n ] [ start end ]
29286 narrow-to-region-invisible
29287 Narrow the editable portion of the buffer to the region between
29288 the cursor and the mark, which may be in either order. The re‐
29289 gion may not be empty.
29290
29291 narrow-to-region may be used as a widget or called as a function
29292 from a user-defined widget; by default, the text outside the ed‐
29293 itable area remains visible. A recursive-edit is performed and
29294 the original widening status is then restored. Various options
29295 and arguments are available when it is called as a function.
29296
29297 The options -p pretext and -P posttext may be used to replace
29298 the text before and after the display for the duration of the
29299 function; either or both may be an empty string.
29300
29301 If the option -n is also given, pretext or posttext will only be
29302 inserted if there is text before or after the region respec‐
29303 tively which will be made invisible.
29304
29305 Two numeric arguments may be given which will be used instead of
29306 the cursor and mark positions.
29307
29308 The option -S statepm is used to narrow according to the other
29309 options while saving the original state in the parameter with
29310 name statepm, while the option -R statepm is used to restore the
29311 state from the parameter; note in both cases the name of the pa‐
29312 rameter is required. In the second case, other options and ar‐
29313 guments are irrelevant. When this method is used, no recur‐
29314 sive-edit is performed; the calling widget should call this
29315 function with the option -S, perform its own editing on the com‐
29316 mand line or pass control to the user via `zle recursive-edit',
29317 then call this function with the option -R. The argument
29318 statepm must be a suitable name for an ordinary parameter, ex‐
29319 cept that parameters beginning with the prefix _ntr_ are re‐
29320 served for use within narrow-to-region. Typically the parameter
29321 will be local to the calling function.
29322
29323 The options -l lbufvar and -r rbufvar may be used to specify pa‐
29324 rameters where the widget will store the resulting text from the
29325 operation. The parameter lbufvar will contain LBUFFER and rbuf‐
29326 var will contain RBUFFER. Neither of these two options may be
29327 used with -S or -R.
29328
29329 narrow-to-region-invisible is a simple widget which calls nar‐
29330 row-to-region with arguments which replace any text outside the
29331 region with `...'. It does not take any arguments.
29332
29333 The display is restored (and the widget returns) upon any zle
29334 command which would usually cause the line to be accepted or
29335 aborted. Hence an additional such command is required to accept
29336 or abort the current line.
29337
29338 The return status of both widgets is zero if the line was ac‐
29339 cepted, else non-zero.
29340
29341 Here is a trivial example of a widget using this feature.
29342 local state
29343 narrow-to-region -p $'Editing restricted region\n' \
29344 -P '' -S state
29345 zle recursive-edit
29346 narrow-to-region -R state
29347
29348 predict-on
29349 This set of functions implements predictive typing using history
29350 search. After predict-on, typing characters causes the editor
29351 to look backward in the history for the first line beginning
29352 with what you have typed so far. After predict-off, editing re‐
29353 turns to normal for the line found. In fact, you often don't
29354 even need to use predict-off, because if the line doesn't match
29355 something in the history, adding a key performs standard comple‐
29356 tion, and then inserts itself if no completions were found.
29357 However, editing in the middle of a line is liable to confuse
29358 prediction; see the toggle style below.
29359
29360 With the function based completion system (which is needed for
29361 this), you should be able to type TAB at almost any point to ad‐
29362 vance the cursor to the next ``interesting'' character position
29363 (usually the end of the current word, but sometimes somewhere in
29364 the middle of the word). And of course as soon as the entire
29365 line is what you want, you can accept with return, without need‐
29366 ing to move the cursor to the end first.
29367
29368 The first time predict-on is used, it creates several additional
29369 widget functions:
29370
29371 delete-backward-and-predict
29372 Replaces the backward-delete-char widget. You do not
29373 need to bind this yourself.
29374 insert-and-predict
29375 Implements predictive typing by replacing the self-insert
29376 widget. You do not need to bind this yourself.
29377 predict-off
29378 Turns off predictive typing.
29379
29380 Although you autoload only the predict-on function, it is neces‐
29381 sary to create a keybinding for predict-off as well.
29382
29383 zle -N predict-on
29384 zle -N predict-off
29385 bindkey '^X^Z' predict-on
29386 bindkey '^Z' predict-off
29387
29388 read-from-minibuffer
29389 This is most useful when called as a function from inside a wid‐
29390 get, but will work correctly as a widget in its own right. It
29391 prompts for a value below the current command line; a value may
29392 be input using all of the standard zle operations (and not
29393 merely the restricted set available when executing, for example,
29394 execute-named-cmd). The value is then returned to the calling
29395 function in the parameter $REPLY and the editing buffer restored
29396 to its previous state. If the read was aborted by a keyboard
29397 break (typically ^G), the function returns status 1 and $REPLY
29398 is not set.
29399
29400 If one argument is supplied to the function it is taken as a
29401 prompt, otherwise `? ' is used. If two arguments are supplied,
29402 they are the prompt and the initial value of $LBUFFER, and if a
29403 third argument is given it is the initial value of $RBUFFER.
29404 This provides a default value and starting cursor placement.
29405 Upon return the entire buffer is the value of $REPLY.
29406
29407 One option is available: `-k num' specifies that num characters
29408 are to be read instead of a whole line. The line editor is not
29409 invoked recursively in this case, so depending on the terminal
29410 settings the input may not be visible, and only the input keys
29411 are placed in $REPLY, not the entire buffer. Note that unlike
29412 the read builtin num must be given; there is no default.
29413
29414 The name is a slight misnomer, as in fact the shell's own
29415 minibuffer is not used. Hence it is still possible to call exe‐
29416 cuted-named-cmd and similar functions while reading a value.
29417
29418 replace-argument, replace-argument-edit
29419 The function replace-argument can be used to replace a command
29420 line argument in the current command line or, if the current
29421 command line is empty, in the last command line executed (the
29422 new command line is not executed). Arguments are as delimited
29423 by standard shell syntax,
29424
29425 If a numeric argument is given, that specifies the argument to
29426 be replaced. 0 means the command name, as in history expansion.
29427 A negative numeric argument counts backward from the last word.
29428
29429 If no numeric argument is given, the current argument is re‐
29430 placed; this is the last argument if the previous history line
29431 is being used.
29432
29433 The function prompts for a replacement argument.
29434
29435 If the widget contains the string edit, for example is defined
29436 as
29437
29438 zle -N replace-argument-edit replace-argument
29439
29440 then the function presents the current value of the argument for
29441 editing, otherwise the editing buffer for the replacement is
29442 initially empty.
29443
29444 replace-string, replace-pattern
29445 replace-string-again, replace-pattern-again
29446 The function replace-string implements three widgets. If de‐
29447 fined under the same name as the function, it prompts for two
29448 strings; the first (source) string will be replaced by the sec‐
29449 ond everywhere it occurs in the line editing buffer.
29450
29451 If the widget name contains the word `pattern', for example by
29452 defining the widget using the command `zle -N replace-pattern
29453 replace-string', then the matching is performed using zsh pat‐
29454 terns. All zsh extended globbing patterns can be used in the
29455 source string; note that unlike filename generation the pattern
29456 does not need to match an entire word, nor do glob qualifiers
29457 have any effect. In addition, the replacement string can con‐
29458 tain parameter or command substitutions. Furthermore, a `&' in
29459 the replacement string will be replaced with the matched source
29460 string, and a backquoted digit `\N' will be replaced by the Nth
29461 parenthesised expression matched. The form `\{N}' may be used
29462 to protect the digit from following digits.
29463
29464 If the widget instead contains the word `regex' (or `regexp'),
29465 then the matching is performed using regular expressions, re‐
29466 specting the setting of the option RE_MATCH_PCRE (see the de‐
29467 scription of the function regexp-replace below). The special
29468 replacement facilities described above for pattern matching are
29469 available.
29470
29471 By default the previous source or replacement string will not be
29472 offered for editing. However, this feature can be activated by
29473 setting the style edit-previous in the context :zle:widget (for
29474 example, :zle:replace-string) to true. In addition, a positive
29475 numeric argument forces the previous values to be offered, a
29476 negative or zero argument forces them not to be.
29477
29478 The function replace-string-again can be used to repeat the pre‐
29479 vious replacement; no prompting is done. As with re‐
29480 place-string, if the name of the widget contains the word `pat‐
29481 tern' or `regex', pattern or regular expression matching is per‐
29482 formed, else a literal string replacement. Note that the previ‐
29483 ous source and replacement text are the same whether pattern,
29484 regular expression or string matching is used.
29485
29486 In addition, replace-string shows the previous replacement above
29487 the prompt, so long as there was one during the current session;
29488 if the source string is empty, that replacement will be repeated
29489 without the widget prompting for a replacement string.
29490
29491 For example, starting from the line:
29492
29493 print This line contains fan and fond
29494
29495 and invoking replace-pattern with the source string `f(?)n' and
29496 the replacement string `c\1r' produces the not very useful line:
29497
29498 print This line contains car and cord
29499
29500 The range of the replacement string can be limited by using the
29501 narrow-to-region-invisible widget. One limitation of the cur‐
29502 rent version is that undo will cycle through changes to the re‐
29503 placement and source strings before undoing the replacement it‐
29504 self.
29505
29506 send-invisible
29507 This is similar to read-from-minibuffer in that it may be called
29508 as a function from a widget or as a widget of its own, and in‐
29509 teractively reads input from the keyboard. However, the input
29510 being typed is concealed and a string of asterisks (`*') is
29511 shown instead. The value is saved in the parameter $INVISIBLE
29512 to which a reference is inserted into the editing buffer at the
29513 restored cursor position. If the read was aborted by a keyboard
29514 break (typically ^G) or another escape from editing such as
29515 push-line, $INVISIBLE is set to empty and the original buffer is
29516 restored unchanged.
29517
29518 If one argument is supplied to the function it is taken as a
29519 prompt, otherwise `Non-echoed text: ' is used (as in emacs). If
29520 a second and third argument are supplied they are used to begin
29521 and end the reference to $INVISIBLE that is inserted into the
29522 buffer. The default is to open with ${, then INVISIBLE, and
29523 close with }, but many other effects are possible.
29524
29525 smart-insert-last-word
29526 This function may replace the insert-last-word widget, like so:
29527
29528 zle -N insert-last-word smart-insert-last-word
29529
29530 With a numeric argument, or when passed command line arguments
29531 in a call from another widget, it behaves like insert-last-word,
29532 except that words in comments are ignored when INTERACTIVE_COM‐
29533 MENTS is set.
29534
29535 Otherwise, the rightmost ``interesting'' word from the previous
29536 command is found and inserted. The default definition of ``in‐
29537 teresting'' is that the word contains at least one alphabetic
29538 character, slash, or backslash. This definition may be overrid‐
29539 den by use of the match style. The context used to look up the
29540 style is the widget name, so usually the context is :in‐
29541 sert-last-word. However, you can bind this function to differ‐
29542 ent widgets to use different patterns:
29543
29544 zle -N insert-last-assignment smart-insert-last-word
29545 zstyle :insert-last-assignment match '[[:alpha:]][][[:alnum:]]#=*'
29546 bindkey '\e=' insert-last-assignment
29547
29548 If no interesting word is found and the auto-previous style is
29549 set to a true value, the search continues upward through the
29550 history. When auto-previous is unset or false (the default),
29551 the widget must be invoked repeatedly in order to search earlier
29552 history lines.
29553
29554 transpose-lines
29555 Only useful with a multi-line editing buffer; the lines here are
29556 lines within the current on-screen buffer, not history lines.
29557 The effect is similar to the function of the same name in Emacs.
29558
29559 Transpose the current line with the previous line and move the
29560 cursor to the start of the next line. Repeating this (which can
29561 be done by providing a positive numeric argument) has the effect
29562 of moving the line above the cursor down by a number of lines.
29563
29564 With a negative numeric argument, requires two lines above the
29565 cursor. These two lines are transposed and the cursor moved to
29566 the start of the previous line. Using a numeric argument less
29567 than -1 has the effect of moving the line above the cursor up by
29568 minus that number of lines.
29569
29570 url-quote-magic
29571 This widget replaces the built-in self-insert to make it easier
29572 to type URLs as command line arguments. As you type, the input
29573 character is analyzed and, if it may need quoting, the current
29574 word is checked for a URI scheme. If one is found and the cur‐
29575 rent word is not already in quotes, a backslash is inserted be‐
29576 fore the input character.
29577
29578 Styles to control quoting behavior:
29579
29580 url-metas
29581 This style is looked up in the context
29582 `:url-quote-magic:scheme' (where scheme is that of the
29583 current URL, e.g. "ftp"). The value is a string listing
29584 the characters to be treated as globbing metacharacters
29585 when appearing in a URL using that scheme. The default
29586 is to quote all zsh extended globbing characters, exclud‐
29587 ing '<' and '>' but including braces (as in brace expan‐
29588 sion). See also url-seps.
29589
29590 url-seps
29591 Like url-metas, but lists characters that should be con‐
29592 sidered command separators, redirections, history refer‐
29593 ences, etc. The default is to quote the standard set of
29594 shell separators, excluding those that overlap with the
29595 extended globbing characters, but including '<' and '>'
29596 and the first character of $histchars.
29597
29598 url-globbers
29599 This style is looked up in the context
29600 `:url-quote-magic'. The values form a list of command
29601 names that are expected to do their own globbing on the
29602 URL string. This implies that they are aliased to use
29603 the `noglob' modifier. When the first word on the line
29604 matches one of the values and the URL refers to a local
29605 file (see url-local-schema), only the url-seps characters
29606 are quoted; the url-metas are left alone, allowing them
29607 to affect command-line parsing, completion, etc. The de‐
29608 fault values are a literal `noglob' plus (when the
29609 zsh/parameter module is available) any commands aliased
29610 to the helper function `urlglobber' or its alias
29611 `globurl'.
29612
29613 url-local-schema
29614 This style is always looked up in the context `:urlglob‐
29615 ber', even though it is used by both url-quote-magic and
29616 urlglobber. The values form a list of URI schema that
29617 should be treated as referring to local files by their
29618 real local path names, as opposed to files which are
29619 specified relative to a web-server-defined document root.
29620 The defaults are "ftp" and "file".
29621
29622 url-other-schema
29623 Like url-local-schema, but lists all other URI schema
29624 upon which urlglobber and url-quote-magic should act. If
29625 the URI on the command line does not have a scheme ap‐
29626 pearing either in this list or in url-local-schema, it is
29627 not magically quoted. The default values are "http",
29628 "https", and "ftp". When a scheme appears both here and
29629 in url-local-schema, it is quoted differently depending
29630 on whether the command name appears in url-globbers.
29631
29632 Loading url-quote-magic also defines a helper function `urlglob‐
29633 ber' and aliases `globurl' to `noglob urlglobber'. This func‐
29634 tion takes a local URL apart, attempts to pattern-match the lo‐
29635 cal file portion of the URL path, and then puts the results back
29636 into URL format again.
29637
29638 vi-pipe
29639 This function reads a movement command from the keyboard and
29640 then prompts for an external command. The part of the buffer
29641 covered by the movement is piped to the external command and
29642 then replaced by the command's output. If the movement command
29643 is bound to vi-pipe, the current line is used.
29644
29645 The function serves as an example for reading a vi movement com‐
29646 mand from within a user-defined widget.
29647
29648 which-command
29649 This function is a drop-in replacement for the builtin widget
29650 which-command. It has enhanced behaviour, in that it correctly
29651 detects whether or not the command word needs to be expanded as
29652 an alias; if so, it continues tracing the command word from the
29653 expanded alias until it reaches the command that will be exe‐
29654 cuted.
29655
29656 The style whence is available in the context :zle:$WIDGET; this
29657 may be set to an array to give the command and options that will
29658 be used to investigate the command word found. The default is
29659 whence -c.
29660
29661 zcalc-auto-insert
29662 This function is useful together with the zcalc function de‐
29663 scribed in the section `Mathematical Functions'. It should be
29664 bound to a key representing a binary operator such as `+', `-',
29665 `*' or `/'. When running in zcalc, if the key occurs at the
29666 start of the line or immediately following an open parenthesis,
29667 the text "ans " is inserted before the representation of the key
29668 itself. This allows easy use of the answer from the previous
29669 calculation in the current line. The text to be inserted before
29670 the symbol typed can be modified by setting the variable
29671 ZCALC_AUTO_INSERT_PREFIX.
29672
29673 Hence, for example, typing `+12' followed by return adds 12 to
29674 the previous result.
29675
29676 If zcalc is in RPN mode (-r option) the effect of this binding
29677 is automatically suppressed as operators alone on a line are
29678 meaningful.
29679
29680 When not in zcalc, the key simply inserts the symbol itself.
29681
29682 Utility Functions
29683 These functions are useful in constructing widgets. They should be
29684 loaded with `autoload -U function' and called as indicated from
29685 user-defined widgets.
29686
29687 split-shell-arguments
29688 This function splits the line currently being edited into shell
29689 arguments and whitespace. The result is stored in the array re‐
29690 ply. The array contains all the parts of the line in order,
29691 starting with any whitespace before the first argument, and fin‐
29692 ishing with any whitespace after the last argument. Hence (so
29693 long as the option KSH_ARRAYS is not set) whitespace is given by
29694 odd indices in the array and arguments by even indices. Note
29695 that no stripping of quotes is done; joining together all the
29696 elements of reply in order is guaranteed to produce the original
29697 line.
29698
29699 The parameter REPLY is set to the index of the word in reply
29700 which contains the character after the cursor, where the first
29701 element has index 1. The parameter REPLY2 is set to the index
29702 of the character under the cursor in that word, where the first
29703 character has index 1.
29704
29705 Hence reply, REPLY and REPLY2 should all be made local to the
29706 enclosing function.
29707
29708 See the function modify-current-argument, described below, for
29709 an example of how to call this function.
29710
29711 modify-current-argument [ expr-using-$ARG | func ]
29712 This function provides a simple method of allowing user-defined
29713 widgets to modify the command line argument under the cursor (or
29714 immediately to the left of the cursor if the cursor is between
29715 arguments).
29716
29717 The argument can be an expression which when evaluated operates
29718 on the shell parameter ARG, which will have been set to the com‐
29719 mand line argument under the cursor. The expression should be
29720 suitably quoted to prevent it being evaluated too early.
29721
29722 Alternatively, if the argument does not contain the string ARG,
29723 it is assumed to be a shell function, to which the current com‐
29724 mand line argument is passed as the only argument. The function
29725 should set the variable REPLY to the new value for the command
29726 line argument. If the function returns non-zero status, so does
29727 the calling function.
29728
29729 For example, a user-defined widget containing the following code
29730 converts the characters in the argument under the cursor into
29731 all upper case:
29732
29733 modify-current-argument '${(U)ARG}'
29734
29735 The following strips any quoting from the current word (whether
29736 backslashes or one of the styles of quotes), and replaces it
29737 with single quoting throughout:
29738
29739 modify-current-argument '${(qq)${(Q)ARG}}'
29740
29741 The following performs directory expansion on the command line
29742 argument and replaces it by the absolute path:
29743
29744 expand-dir() {
29745 REPLY=${~1}
29746 REPLY=${REPLY:a}
29747 }
29748 modify-current-argument expand-dir
29749
29750 In practice the function expand-dir would probably not be de‐
29751 fined within the widget where modify-current-argument is called.
29752
29753 Styles
29754 The behavior of several of the above widgets can be controlled by the
29755 use of the zstyle mechanism. In particular, widgets that interact with
29756 the completion system pass along their context to any completions that
29757 they invoke.
29758
29759 break-keys
29760 This style is used by the incremental-complete-word widget. Its
29761 value should be a pattern, and all keys matching this pattern
29762 will cause the widget to stop incremental completion without the
29763 key having any further effect. Like all styles used directly by
29764 incremental-complete-word, this style is looked up using the
29765 context `:incremental'.
29766
29767 completer
29768 The incremental-complete-word and insert-and-predict widgets set
29769 up their top-level context name before calling completion. This
29770 allows one to define different sets of completer functions for
29771 normal completion and for these widgets. For example, to use
29772 completion, approximation and correction for normal completion,
29773 completion and correction for incremental completion and only
29774 completion for prediction one could use:
29775
29776 zstyle ':completion:*' completer \
29777 _complete _correct _approximate
29778 zstyle ':completion:incremental:*' completer \
29779 _complete _correct
29780 zstyle ':completion:predict:*' completer \
29781 _complete
29782
29783 It is a good idea to restrict the completers used in prediction,
29784 because they may be automatically invoked as you type. The
29785 _list and _menu completers should never be used with prediction.
29786 The _approximate, _correct, _expand, and _match completers may
29787 be used, but be aware that they may change characters anywhere
29788 in the word behind the cursor, so you need to watch carefully
29789 that the result is what you intended.
29790
29791 cursor The insert-and-predict widget uses this style, in the context
29792 `:predict', to decide where to place the cursor after completion
29793 has been tried. Values are:
29794
29795 complete
29796 The cursor is left where it was when completion finished,
29797 but only if it is after a character equal to the one just
29798 inserted by the user. If it is after another character,
29799 this value is the same as `key'.
29800
29801 key The cursor is left after the nth occurrence of the char‐
29802 acter just inserted, where n is the number of times that
29803 character appeared in the word before completion was at‐
29804 tempted. In short, this has the effect of leaving the
29805 cursor after the character just typed even if the comple‐
29806 tion code found out that no other characters need to be
29807 inserted at that position.
29808
29809 Any other value for this style unconditionally leaves the cursor
29810 at the position where the completion code left it.
29811
29812 list When using the incremental-complete-word widget, this style says
29813 if the matches should be listed on every key press (if they fit
29814 on the screen). Use the context prefix `:completion:incremen‐
29815 tal'.
29816
29817 The insert-and-predict widget uses this style to decide if the
29818 completion should be shown even if there is only one possible
29819 completion. This is done if the value of this style is the
29820 string always. In this case the context is `:predict' (not
29821 `:completion:predict').
29822
29823 match This style is used by smart-insert-last-word to provide a pat‐
29824 tern (using full EXTENDED_GLOB syntax) that matches an interest‐
29825 ing word. The context is the name of the widget to which
29826 smart-insert-last-word is bound (see above). The default behav‐
29827 ior of smart-insert-last-word is equivalent to:
29828
29829 zstyle :insert-last-word match '*[[:alpha:]/\\]*'
29830
29831 However, you might want to include words that contain spaces:
29832
29833 zstyle :insert-last-word match '*[[:alpha:][:space:]/\\]*'
29834
29835 Or include numbers as long as the word is at least two charac‐
29836 ters long:
29837
29838 zstyle :insert-last-word match '*([[:digit:]]?|[[:alpha:]/\\])*'
29839
29840 The above example causes redirections like "2>" to be included.
29841
29842 prompt The incremental-complete-word widget shows the value of this
29843 style in the status line during incremental completion. The
29844 string value may contain any of the following substrings in the
29845 manner of the PS1 and other prompt parameters:
29846
29847 %c Replaced by the name of the completer function that gen‐
29848 erated the matches (without the leading underscore).
29849
29850 %l When the list style is set, replaced by `...' if the list
29851 of matches is too long to fit on the screen and with an
29852 empty string otherwise. If the list style is `false' or
29853 not set, `%l' is always removed.
29854
29855 %n Replaced by the number of matches generated.
29856
29857 %s Replaced by `-no match-', `-no prefix-', or an empty
29858 string if there is no completion matching the word on the
29859 line, if the matches have no common prefix different from
29860 the word on the line, or if there is such a common pre‐
29861 fix, respectively.
29862
29863 %u Replaced by the unambiguous part of all matches, if there
29864 is any, and if it is different from the word on the line.
29865
29866 Like `break-keys', this uses the `:incremental' context.
29867
29868 stop-keys
29869 This style is used by the incremental-complete-word widget. Its
29870 value is treated similarly to the one for the break-keys style
29871 (and uses the same context: `:incremental'). However, in this
29872 case all keys matching the pattern given as its value will stop
29873 incremental completion and will then execute their usual func‐
29874 tion.
29875
29876 toggle This boolean style is used by predict-on and its related widgets
29877 in the context `:predict'. If set to one of the standard `true'
29878 values, predictive typing is automatically toggled off in situa‐
29879 tions where it is unlikely to be useful, such as when editing a
29880 multi-line buffer or after moving into the middle of a line and
29881 then deleting a character. The default is to leave prediction
29882 turned on until an explicit call to predict-off.
29883
29884 verbose
29885 This boolean style is used by predict-on and its related widgets
29886 in the context `:predict'. If set to one of the standard `true'
29887 values, these widgets display a message below the prompt when
29888 the predictive state is toggled. This is most useful in combi‐
29889 nation with the toggle style. The default does not display
29890 these messages.
29891
29892 widget This style is similar to the command style: For widget functions
29893 that use zle to call other widgets, this style can sometimes be
29894 used to override the widget which is called. The context for
29895 this style is the name of the calling widget (not the name of
29896 the calling function, because one function may be bound to mul‐
29897 tiple widget names).
29898
29899 zstyle :copy-earlier-word widget smart-insert-last-word
29900
29901 Check the documentation for the calling widget or function to
29902 determine whether the widget style is used.
29903
29905 Two functions are provided to enable zsh to provide exception handling
29906 in a form that should be familiar from other languages.
29907
29908 throw exception
29909 The function throw throws the named exception. The name is an
29910 arbitrary string and is only used by the throw and catch func‐
29911 tions. An exception is for the most part treated the same as a
29912 shell error, i.e. an unhandled exception will cause the shell to
29913 abort all processing in a function or script and to return to
29914 the top level in an interactive shell.
29915
29916 catch exception-pattern
29917 The function catch returns status zero if an exception was
29918 thrown and the pattern exception-pattern matches its name. Oth‐
29919 erwise it returns status 1. exception-pattern is a standard
29920 shell pattern, respecting the current setting of the EX‐
29921 TENDED_GLOB option. An alias catch is also defined to prevent
29922 the argument to the function from matching filenames, so pat‐
29923 terns may be used unquoted. Note that as exceptions are not
29924 fundamentally different from other shell errors it is possible
29925 to catch shell errors by using an empty string as the exception
29926 name. The shell variable CAUGHT is set by catch to the name of
29927 the exception caught. It is possible to rethrow an exception by
29928 calling the throw function again once an exception has been
29929 caught.
29930
29931 The functions are designed to be used together with the always con‐
29932 struct described in zshmisc(1). This is important as only this con‐
29933 struct provides the required support for exceptions. A typical example
29934 is as follows.
29935
29936 {
29937 # "try" block
29938 # ... nested code here calls "throw MyExcept"
29939 } always {
29940 # "always" block
29941 if catch MyExcept; then
29942 print "Caught exception MyExcept"
29943 elif catch ''; then
29944 print "Caught a shell error. Propagating..."
29945 throw ''
29946 fi
29947 # Other exceptions are not handled but may be caught further
29948 # up the call stack.
29949 }
29950
29951 If all exceptions should be caught, the following idiom might be
29952 preferable.
29953
29954 {
29955 # ... nested code here throws an exception
29956 } always {
29957 if catch *; then
29958 case $CAUGHT in
29959 (MyExcept)
29960 print "Caught my own exception"
29961 ;;
29962 (*)
29963 print "Caught some other exception"
29964 ;;
29965 esac
29966 fi
29967 }
29968
29969 In common with exception handling in other languages, the exception may
29970 be thrown by code deeply nested inside the `try' block. However, note
29971 that it must be thrown inside the current shell, not in a subshell
29972 forked for a pipeline, parenthesised current-shell construct, or some
29973 form of command or process substitution.
29974
29975 The system internally uses the shell variable EXCEPTION to record the
29976 name of the exception between throwing and catching. One drawback of
29977 this scheme is that if the exception is not handled the variable EXCEP‐
29978 TION remains set and may be incorrectly recognised as the name of an
29979 exception if a shell error subsequently occurs. Adding unset EXCEPTION
29980 at the start of the outermost layer of any code that uses exception
29981 handling will eliminate this problem.
29982
29984 Three functions are available to provide handling of files recognised
29985 by extension, for example to dispatch a file text.ps when executed as a
29986 command to an appropriate viewer.
29987
29988 zsh-mime-setup [ -fv ] [ -l [ suffix ... ] ]
29989 zsh-mime-handler [ -l ] command argument ...
29990 These two functions use the files ~/.mime.types and
29991 /etc/mime.types, which associate types and extensions, as well
29992 as ~/.mailcap and /etc/mailcap files, which associate types and
29993 the programs that handle them. These are provided on many sys‐
29994 tems with the Multimedia Internet Mail Extensions.
29995
29996 To enable the system, the function zsh-mime-setup should be au‐
29997 toloaded and run. This allows files with extensions to be
29998 treated as executable; such files be completed by the function
29999 completion system. The function zsh-mime-handler should not
30000 need to be called by the user.
30001
30002 The system works by setting up suffix aliases with `alias -s'.
30003 Suffix aliases already installed by the user will not be over‐
30004 written.
30005
30006 For suffixes defined in lower case, upper case variants will
30007 also automatically be handled (e.g. PDF is automatically handled
30008 if handling for the suffix pdf is defined), but not vice versa.
30009
30010 Repeated calls to zsh-mime-setup do not override the existing
30011 mapping between suffixes and executable files unless the option
30012 -f is given. Note, however, that this does not override exist‐
30013 ing suffix aliases assigned to handlers other than zsh-mime-han‐
30014 dler.
30015
30016 Calling zsh-mime-setup with the option -l lists the existing
30017 mappings without altering them. Suffixes to list (which may
30018 contain pattern characters that should be quoted from immediate
30019 interpretation on the command line) may be given as additional
30020 arguments, otherwise all suffixes are listed.
30021
30022 Calling zsh-mime-setup with the option -v causes verbose output
30023 to be shown during the setup operation.
30024
30025 The system respects the mailcap flags needsterminal and copi‐
30026 ousoutput; see mailcap(4) or mailcap(5) (the man page's name
30027 varies across platforms).
30028
30029 The functions use the following styles, which are defined with
30030 the zstyle builtin command (see zshmodules(1)). They should be
30031 defined before zsh-mime-setup is run. The contexts used all
30032 start with :mime:, with additional components in some cases. It
30033 is recommended that a trailing * (suitably quoted) be appended
30034 to style patterns in case the system is extended in future.
30035 Some examples are given below.
30036
30037 For files that have multiple suffixes, e.g. .pdf.gz, where the
30038 context includes the suffix it will be looked up starting with
30039 the longest possible suffix until a match for the style is
30040 found. For example, if .pdf.gz produces a match for the han‐
30041 dler, that will be used; otherwise the handler for .gz will be
30042 used. Note that, owing to the way suffix aliases work, it is
30043 always required that there be a handler for the shortest possi‐
30044 ble suffix, so in this example .pdf.gz can only be handled if
30045 .gz is also handled (though not necessarily in the same way).
30046 Alternatively, if no handling for .gz on its own is needed, sim‐
30047 ply adding the command
30048
30049 alias -s gz=zsh-mime-handler
30050
30051 to the initialisation code is sufficient; .gz will not be han‐
30052 dled on its own, but may be in combination with other suffixes.
30053
30054 current-shell
30055 If this boolean style is true, the mailcap handler for
30056 the context in question is run using the eval builtin in‐
30057 stead of by starting a new sh process. This is more ef‐
30058 ficient, but may not work in the occasional cases where
30059 the mailcap handler uses strict POSIX syntax.
30060
30061 disown If this boolean style is true, mailcap handlers started
30062 in the background will be disowned, i.e. not subject to
30063 job control within the parent shell. Such handlers
30064 nearly always produce their own windows, so the only
30065 likely harmful side effect of setting the style is that
30066 it becomes harder to kill jobs from within the shell.
30067
30068 execute-as-is
30069 This style gives a list of patterns to be matched against
30070 files passed for execution with a handler program. If
30071 the file matches the pattern, the entire command line is
30072 executed in its current form, with no handler. This is
30073 useful for files which might have suffixes but nonethe‐
30074 less be executable in their own right. If the style is
30075 not set, the pattern *(*) *(/) is used; hence executable
30076 files are executed directly and not passed to a handler,
30077 and the option AUTO_CD may be used to change to directo‐
30078 ries that happen to have MIME suffixes.
30079
30080 execute-never
30081 This style is useful in combination with execute-as-is.
30082 It is set to an array of patterns corresponding to full
30083 paths to files that should never be treated as exe‐
30084 cutable, even if the file passed to the MIME handler
30085 matches execute-as-is. This is useful for file systems
30086 that don't handle execute permission or that contain exe‐
30087 cutables from another operating system. For example, if
30088 /mnt/windows is a Windows mount, then
30089
30090 zstyle ':mime:*' execute-never '/mnt/windows/*'
30091
30092 will ensure that any files found in that area will be ex‐
30093 ecuted as MIME types even if they are executable. As
30094 this example shows, the complete file name is matched
30095 against the pattern, regardless of how the file was
30096 passed to the handler. The file is resolved to a full
30097 path using the :P modifier described in the subsection
30098 `Modifiers' in zshexpn(1); this means that symbolic links
30099 are resolved where possible, so that links into other
30100 file systems behave in the correct fashion.
30101
30102 file-path
30103 Used if the style find-file-in-path is true for the same
30104 context. Set to an array of directories that are used
30105 for searching for the file to be handled; the default is
30106 the command path given by the special parameter path.
30107 The shell option PATH_DIRS is respected; if that is set,
30108 the appropriate path will be searched even if the name of
30109 the file to be handled as it appears on the command line
30110 contains a `/'. The full context is :mime:.suffix:, as
30111 described for the style handler.
30112
30113 find-file-in-path
30114 If set, allows files whose names do not contain absolute
30115 paths to be searched for in the command path or the path
30116 specified by the file-path style. If the file is not
30117 found in the path, it is looked for locally (whether or
30118 not the current directory is in the path); if it is not
30119 found locally, the handler will abort unless the han‐
30120 dle-nonexistent style is set. Files found in the path
30121 are tested as described for the style execute-as-is. The
30122 full context is :mime:.suffix:, as described for the
30123 style handler.
30124
30125 flags Defines flags to go with a handler; the context is as for
30126 the handler style, and the format is as for the flags in
30127 mailcap.
30128
30129 handle-nonexistent
30130 By default, arguments that don't correspond to files are
30131 not passed to the MIME handler in order to prevent it
30132 from intercepting commands found in the path that happen
30133 to have suffixes. This style may be set to an array of
30134 extended glob patterns for arguments that will be passed
30135 to the handler even if they don't exist. If it is not
30136 explicitly set it defaults to [[:alpha:]]#:/* which al‐
30137 lows URLs to be passed to the MIME handler even though
30138 they don't exist in that format in the file system. The
30139 full context is :mime:.suffix:, as described for the
30140 style handler.
30141
30142 handler
30143 Specifies a handler for a suffix; the suffix is given by
30144 the context as :mime:.suffix:, and the format of the han‐
30145 dler is exactly that in mailcap. Note in particular the
30146 `.' and trailing colon to distinguish this use of the
30147 context. This overrides any handler specified by the
30148 mailcap files. If the handler requires a terminal, the
30149 flags style should be set to include the word needstermi‐
30150 nal, or if the output is to be displayed through a pager
30151 (but not if the handler is itself a pager), it should in‐
30152 clude copiousoutput.
30153
30154 mailcap
30155 A list of files in the format of ~/.mailcap and
30156 /etc/mailcap to be read during setup, replacing the de‐
30157 fault list which consists of those two files. The con‐
30158 text is :mime:. A + in the list will be replaced by the
30159 default files.
30160
30161 mailcap-priorities
30162 This style is used to resolve multiple mailcap entries
30163 for the same MIME type. It consists of an array of the
30164 following elements, in descending order of priority;
30165 later entries will be used if earlier entries are unable
30166 to resolve the entries being compared. If none of the
30167 tests resolve the entries, the first entry encountered is
30168 retained.
30169
30170 files The order of files (entries in the mailcap style)
30171 read. Earlier files are preferred. (Note this
30172 does not resolve entries in the same file.)
30173
30174 priority
30175 The priority flag from the mailcap entry. The
30176 priority is an integer from 0 to 9 with the de‐
30177 fault value being 5.
30178
30179 flags The test given by the mailcap-prio-flags option is
30180 used to resolve entries.
30181
30182 place Later entries are preferred; as the entries are
30183 strictly ordered, this test always succeeds.
30184
30185 Note that as this style is handled during initialisation,
30186 the context is always :mime:, with no discrimination by
30187 suffix.
30188
30189 mailcap-prio-flags
30190 This style is used when the keyword flags is encountered
30191 in the list of tests specified by the mailcap-priorities
30192 style. It should be set to a list of patterns, each of
30193 which is tested against the flags specified in the mail‐
30194 cap entry (in other words, the sets of assignments found
30195 with some entries in the mailcap file). Earlier patterns
30196 in the list are preferred to later ones, and matched pat‐
30197 terns are preferred to unmatched ones.
30198
30199 mime-types
30200 A list of files in the format of ~/.mime.types and
30201 /etc/mime.types to be read during setup, replacing the
30202 default list which consists of those two files. The con‐
30203 text is :mime:. A + in the list will be replaced by the
30204 default files.
30205
30206 never-background
30207 If this boolean style is set, the handler for the given
30208 context is always run in the foreground, even if the
30209 flags provided in the mailcap entry suggest it need not
30210 be (for example, it doesn't require a terminal).
30211
30212 pager If set, will be used instead of $PAGER or more to handle
30213 suffixes where the copiousoutput flag is set. The con‐
30214 text is as for handler, i.e. :mime:.suffix: for handling
30215 a file with the given suffix.
30216
30217 Examples:
30218
30219 zstyle ':mime:*' mailcap ~/.mailcap /usr/local/etc/mailcap
30220 zstyle ':mime:.txt:' handler less %s
30221 zstyle ':mime:.txt:' flags needsterminal
30222
30223 When zsh-mime-setup is subsequently run, it will look for mail‐
30224 cap entries in the two files given. Files of suffix .txt will
30225 be handled by running `less file.txt'. The flag needsterminal
30226 is set to show that this program must run attached to a termi‐
30227 nal.
30228
30229 As there are several steps to dispatching a command, the follow‐
30230 ing should be checked if attempting to execute a file by exten‐
30231 sion .ext does not have the expected effect.
30232
30233 The command `alias -s ext' should show `ps=zsh-mime-handler'.
30234 If it shows something else, another suffix alias was already in‐
30235 stalled and was not overwritten. If it shows nothing, no han‐
30236 dler was installed: this is most likely because no handler was
30237 found in the .mime.types and mailcap combination for .ext files.
30238 In that case, appropriate handling should be added to
30239 ~/.mime.types and mailcap.
30240
30241 If the extension is handled by zsh-mime-handler but the file is
30242 not opened correctly, either the handler defined for the type is
30243 incorrect, or the flags associated with it are in appropriate.
30244 Running zsh-mime-setup -l will show the handler and, if there
30245 are any, the flags. A %s in the handler is replaced by the file
30246 (suitably quoted if necessary). Check that the handler program
30247 listed lists and can be run in the way shown. Also check that
30248 the flags needsterminal or copiousoutput are set if the handler
30249 needs to be run under a terminal; the second flag is used if the
30250 output should be sent to a pager. An example of a suitable
30251 mailcap entry for such a program is:
30252
30253 text/html; /usr/bin/lynx '%s'; needsterminal
30254
30255 Running `zsh-mime-handler -l command line' prints the command
30256 line that would be executed, simplified to remove the effect of
30257 any flags, and quoted so that the output can be run as a com‐
30258 plete zsh command line. This is used by the completion system
30259 to decide how to complete after a file handled by
30260 zsh-mime-setup.
30261
30262 pick-web-browser
30263 This function is separate from the two MIME functions described
30264 above and can be assigned directly to a suffix:
30265
30266 autoload -U pick-web-browser
30267 alias -s html=pick-web-browser
30268
30269 It is provided as an intelligent front end to dispatch a web
30270 browser. It may be run as either a function or a shell script.
30271 The status 255 is returned if no browser could be started.
30272
30273 Various styles are available to customize the choice of
30274 browsers:
30275
30276 browser-style
30277 The value of the style is an array giving preferences in
30278 decreasing order for the type of browser to use. The
30279 values of elements may be
30280
30281 running
30282 Use a GUI browser that is already running when an
30283 X Window display is available. The browsers
30284 listed in the x-browsers style are tried in order
30285 until one is found; if it is, the file will be
30286 displayed in that browser, so the user may need to
30287 check whether it has appeared. If no running
30288 browser is found, one is not started. Browsers
30289 other than Firefox, Opera and Konqueror are as‐
30290 sumed to understand the Mozilla syntax for opening
30291 a URL remotely.
30292
30293 x Start a new GUI browser when an X Window display
30294 is available. Search for the availability of one
30295 of the browsers listed in the x-browsers style and
30296 start the first one that is found. No check is
30297 made for an already running browser.
30298
30299 tty Start a terminal-based browser. Search for the
30300 availability of one of the browsers listed in the
30301 tty-browsers style and start the first one that is
30302 found.
30303
30304 If the style is not set the default running x tty is
30305 used.
30306
30307 x-browsers
30308 An array in decreasing order of preference of browsers to
30309 use when running under the X Window System. The array
30310 consists of the command name under which to start the
30311 browser. They are looked up in the context :mime: (which
30312 may be extended in future, so appending `*' is recom‐
30313 mended). For example,
30314
30315 zstyle ':mime:*' x-browsers opera konqueror firefox
30316
30317 specifies that pick-web-browser should first look for a
30318 running instance of Opera, Konqueror or Firefox, in that
30319 order, and if it fails to find any should attempt to
30320 start Opera. The default is firefox mozilla netscape
30321 opera konqueror.
30322
30323 tty-browsers
30324 An array similar to x-browsers, except that it gives
30325 browsers to use when no X Window display is available.
30326 The default is elinks links lynx.
30327
30328 command
30329 If it is set this style is used to pick the command used
30330 to open a page for a browser. The context is
30331 :mime:browser:new:$browser: to start a new browser or
30332 :mime:browser:running:$browser: to open a URL in a
30333 browser already running on the current X display, where
30334 $browser is the value matched in the x-browsers or
30335 tty-browsers style. The escape sequence %b in the
30336 style's value will be replaced by the browser, while %u
30337 will be replaced by the URL. If the style is not set,
30338 the default for all new instances is equivalent to %b %u
30339 and the defaults for using running browsers are equiva‐
30340 lent to the values kfmclient openURL %u for Konqueror,
30341 firefox -new-tab %u for Firefox, opera -newpage %u for
30342 Opera, and %b -remote "openUrl(%u)" for all others.
30343
30345 zcalc [ -erf ] [ expression ... ]
30346 A reasonably powerful calculator based on zsh's arithmetic eval‐
30347 uation facility. The syntax is similar to that of formulae in
30348 most programming languages; see the section `Arithmetic Evalua‐
30349 tion' in zshmisc(1) for details.
30350
30351 Non-programmers should note that, as in many other programming
30352 languages, expressions involving only integers (whether con‐
30353 stants without a `.', variables containing such constants as
30354 strings, or variables declared to be integers) are by default
30355 evaluated using integer arithmetic, which is not how an ordinary
30356 desk calculator operates. To force floating point operation,
30357 pass the option -f; see further notes below.
30358
30359 If the file ~/.zcalcrc exists it will be sourced inside the
30360 function once it is set up and about to process the command
30361 line. This can be used, for example, to set shell options; emu‐
30362 late -L zsh and setopt extendedglob are in effect at this point.
30363 Any failure to source the file if it exists is treated as fatal.
30364 As with other initialisation files, the directory $ZDOTDIR is
30365 used instead of $HOME if it is set.
30366
30367 The mathematical library zsh/mathfunc will be loaded if it is
30368 available; see the section `The zsh/mathfunc Module' in zshmod‐
30369 ules(1). The mathematical functions correspond to the raw sys‐
30370 tem libraries, so trigonometric functions are evaluated using
30371 radians, and so on.
30372
30373 Each line typed is evaluated as an expression. The prompt shows
30374 a number, which corresponds to a positional parameter where the
30375 result of that calculation is stored. For example, the result
30376 of the calculation on the line preceded by `4> ' is available as
30377 $4. The last value calculated is available as ans. Full com‐
30378 mand line editing, including the history of previous calcula‐
30379 tions, is available; the history is saved in the file
30380 ~/.zcalc_history. To exit, enter a blank line or type `:q' on
30381 its own (`q' is allowed for historical compatibility).
30382
30383 A line ending with a single backslash is treated in the same
30384 fashion as it is in command line editing: the backslash is re‐
30385 moved, the function prompts for more input (the prompt is pre‐
30386 ceded by `...' to indicate this), and the lines are combined
30387 into one to get the final result. In addition, if the input so
30388 far contains more open than close parentheses zcalc will prompt
30389 for more input.
30390
30391 If arguments are given to zcalc on start up, they are used to
30392 prime the first few positional parameters. A visual indication
30393 of this is given when the calculator starts.
30394
30395 The constants PI (3.14159...) and E (2.71828...) are provided.
30396 Parameter assignment is possible, but note that all parameters
30397 will be put into the global namespace unless the :local special
30398 command is used. The function creates local variables whose
30399 names start with _, so users should avoid doing so. The vari‐
30400 ables ans (the last answer) and stack (the stack in RPN mode)
30401 may be referred to directly; stack is an array but elements of
30402 it are numeric. Various other special variables are used lo‐
30403 cally with their standard meaning, for example compcontext,
30404 match, mbegin, mend, psvar.
30405
30406 The output base can be initialised by passing the option
30407 `-#base', for example `zcalc -#16' (the `#' may have to be
30408 quoted, depending on the globbing options set).
30409
30410 If the option `-e' is set, the function runs non-interactively:
30411 the arguments are treated as expressions to be evaluated as if
30412 entered interactively line by line.
30413
30414 If the option `-f' is set, all numbers are treated as floating
30415 point, hence for example the expression `3/4' evaluates to 0.75
30416 rather than 0. Options must appear in separate words.
30417
30418 If the option `-r' is set, RPN (Reverse Polish Notation) mode is
30419 entered. This has various additional properties:
30420 Stack Evaluated values are maintained in a stack; this is con‐
30421 tained in an array named stack with the most recent value
30422 in ${stack[1]}.
30423
30424 Operators and functions
30425 If the line entered matches an operator (+, -, *, /, **,
30426 ^, | or &) or a function supplied by the zsh/mathfunc li‐
30427 brary, the bottom element or elements of the stack are
30428 popped to use as the argument or arguments. The higher
30429 elements of stack (least recent) are used as earlier ar‐
30430 guments. The result is then pushed into ${stack[1]}.
30431
30432 Expressions
30433 Other expressions are evaluated normally, printed, and
30434 added to the stack as numeric values. The syntax within
30435 expressions on a single line is normal shell arithmetic
30436 (not RPN).
30437
30438 Stack listing
30439 If an integer follows the option -r with no space, then
30440 on every evaluation that many elements of the stack,
30441 where available, are printed instead of just the most re‐
30442 cent result. Hence, for example, zcalc -r4 shows
30443 $stack[4] to $stack[1] each time results are printed.
30444
30445 Duplication: =
30446 The pseudo-operator = causes the most recent element of
30447 the stack to be duplicated onto the stack.
30448
30449 pop The pseudo-function pop causes the most recent element of
30450 the stack to be popped. A `>' on its own has the same
30451 effect.
30452
30453 >ident The expression > followed (with no space) by a shell
30454 identifier causes the most recent element of the stack to
30455 be popped and assigned to the variable with that name.
30456 The variable is local to the zcalc function.
30457
30458 <ident The expression < followed (with no space) by a shell
30459 identifier causes the value of the variable with that
30460 name to be pushed onto the stack. ident may be an inte‐
30461 ger, in which case the previous result with that number
30462 (as shown before the > in the standard zcalc prompt) is
30463 put on the stack.
30464
30465 Exchange: xy
30466 The pseudo-function xy causes the most recent two ele‐
30467 ments of the stack to be exchanged. `<>' has the same
30468 effect.
30469
30470 The prompt is configurable via the parameter ZCALCPROMPT, which
30471 undergoes standard prompt expansion. The index of the current
30472 entry is stored locally in the first element of the array psvar,
30473 which can be referred to in ZCALCPROMPT as `%1v'. The default
30474 prompt is `%1v> '.
30475
30476 The variable ZCALC_ACTIVE is set within the function and can be
30477 tested by nested functions; it has the value rpn if RPN mode is
30478 active, else 1.
30479
30480 A few special commands are available; these are introduced by a
30481 colon. For backward compatibility, the colon may be omitted for
30482 certain commands. Completion is available if compinit has been
30483 run.
30484
30485 The output precision may be specified within zcalc by special
30486 commands familiar from many calculators.
30487 :norm The default output format. It corresponds to the printf
30488 %g specification. Typically this shows six decimal dig‐
30489 its.
30490
30491 :sci digits
30492 Scientific notation, corresponding to the printf %g out‐
30493 put format with the precision given by digits. This pro‐
30494 duces either fixed point or exponential notation depend‐
30495 ing on the value output.
30496
30497 :fix digits
30498 Fixed point notation, corresponding to the printf %f out‐
30499 put format with the precision given by digits.
30500
30501 :eng digits
30502 Exponential notation, corresponding to the printf %E out‐
30503 put format with the precision given by digits.
30504
30505 :raw Raw output: this is the default form of the output from
30506 a math evaluation. This may show more precision than the
30507 number actually possesses.
30508
30509 Other special commands:
30510 :!line...
30511 Execute line... as a normal shell command line. Note
30512 that it is executed in the context of the function, i.e.
30513 with local variables. Space is optional after :!.
30514
30515 :local arg ...
30516 Declare variables local to the function. Other variables
30517 may be used, too, but they will be taken from or put into
30518 the global scope.
30519
30520 :function name [ body ]
30521 Define a mathematical function or (with no body) delete
30522 it. :function may be abbreviated to :func or simply :f.
30523 The name may contain the same characters as a shell func‐
30524 tion name. The function is defined using zmathfuncdef,
30525 see below.
30526
30527 Note that zcalc takes care of all quoting. Hence for ex‐
30528 ample:
30529
30530 :f cube $1 * $1 * $1
30531
30532 defines a function to cube the sole argument. Functions
30533 so defined, or indeed any functions defined directly or
30534 indirectly using functions -M, are available to execute
30535 by typing only the name on the line in RPN mode; this
30536 pops the appropriate number of arguments off the stack to
30537 pass to the function, i.e. 1 in the case of the example
30538 cube function. If there are optional arguments only the
30539 mandatory arguments are supplied by this means.
30540
30541 [#base]
30542 This is not a special command, rather part of normal
30543 arithmetic syntax; however, when this form appears on a
30544 line by itself the default output radix is set to base.
30545 Use, for example, `[#16]' to display hexadecimal output
30546 preceded by an indication of the base, or `[##16]' just
30547 to display the raw number in the given base. Bases them‐
30548 selves are always specified in decimal. `[#]' restores
30549 the normal output format. Note that setting an output
30550 base suppresses floating point output; use `[#]' to re‐
30551 turn to normal operation.
30552
30553 $var Print out the value of var literally; does not affect the
30554 calculation. To use the value of var, omit the leading
30555 `$'.
30556
30557 See the comments in the function for a few extra tips.
30558
30559 min(arg, ...)
30560 max(arg, ...)
30561 sum(arg, ...)
30562 zmathfunc
30563 The function zmathfunc defines the three mathematical functions
30564 min, max, and sum. The functions min and max take one or more
30565 arguments. The function sum takes zero or more arguments. Ar‐
30566 guments can be of different types (ints and floats).
30567
30568 Not to be confused with the zsh/mathfunc module, described in
30569 the section `The zsh/mathfunc Module' in zshmodules(1).
30570
30571 zmathfuncdef [ mathfunc [ body ] ]
30572 A convenient front end to functions -M.
30573
30574 With two arguments, define a mathematical function named math‐
30575 func which can be used in any form of arithmetic evaluation.
30576 body is a mathematical expression to implement the function. It
30577 may contain references to position parameters $1, $2, ... to
30578 refer to mandatory parameters and ${1:-defvalue} ... to refer
30579 to optional parameters. Note that the forms must be strictly
30580 adhered to for the function to calculate the correct number of
30581 arguments. The implementation is held in a shell function named
30582 zsh_math_func_mathfunc; usually the user will not need to refer
30583 to the shell function directly. Any existing function of the
30584 same name is silently replaced.
30585
30586 With one argument, remove the mathematical function mathfunc as
30587 well as the shell function implementation.
30588
30589 With no arguments, list all mathfunc functions in a form suit‐
30590 able for restoring the definition. The functions have not nec‐
30591 essarily been defined by zmathfuncdef.
30592
30594 The zsh/newuser module comes with a function to aid in configuring
30595 shell options for new users. If the module is installed, this function
30596 can also be run by hand. It is available even if the module's default
30597 behaviour, namely running the function for a new user logging in with‐
30598 out startup files, is inhibited.
30599
30600 zsh-newuser-install [ -f ]
30601 The function presents the user with various options for cus‐
30602 tomizing their initialization scripts. Currently only ~/.zshrc
30603 is handled. $ZDOTDIR/.zshrc is used instead if the parameter
30604 ZDOTDIR is set; this provides a way for the user to configure a
30605 file without altering an existing .zshrc.
30606
30607 By default the function exits immediately if it finds any of the
30608 files .zshenv, .zprofile, .zshrc, or .zlogin in the appropriate
30609 directory. The option -f is required in order to force the
30610 function to continue. Note this may happen even if .zshrc it‐
30611 self does not exist.
30612
30613 As currently configured, the function will exit immediately if
30614 the user has root privileges; this behaviour cannot be overrid‐
30615 den.
30616
30617 Once activated, the function's behaviour is supposed to be
30618 self-explanatory. Menus are present allowing the user to alter
30619 the value of options and parameters. Suggestions for improve‐
30620 ments are always welcome.
30621
30622 When the script exits, the user is given the opportunity to save
30623 the new file or not; changes are not irreversible until this
30624 point. However, the script is careful to restrict changes to
30625 the file only to a group marked by the lines `# Lines configured
30626 by zsh-newuser-install' and `# End of lines configured by
30627 zsh-newuser-install'. In addition, the old version of .zshrc is
30628 saved to a file with the suffix .zni appended.
30629
30630 If the function edits an existing .zshrc, it is up to the user
30631 to ensure that the changes made will take effect. For example,
30632 if control usually returns early from the existing .zshrc the
30633 lines will not be executed; or a later initialization file may
30634 override options or parameters, and so on. The function itself
30635 does not attempt to detect any such conflicts.
30636
30638 There are a large number of helpful functions in the Functions/Misc di‐
30639 rectory of the zsh distribution. Most are very simple and do not re‐
30640 quire documentation here, but a few are worthy of special mention.
30641
30642 Descriptions
30643 colors This function initializes several associative arrays to map
30644 color names to (and from) the ANSI standard eight-color terminal
30645 codes. These are used by the prompt theme system (see above).
30646 You seldom should need to run colors more than once.
30647
30648 The eight base colors are: black, red, green, yellow, blue, ma‐
30649 genta, cyan, and white. Each of these has codes for foreground
30650 and background. In addition there are seven intensity at‐
30651 tributes: bold, faint, standout, underline, blink, reverse, and
30652 conceal. Finally, there are seven codes used to negate at‐
30653 tributes: none (reset all attributes to the defaults), normal
30654 (neither bold nor faint), no-standout, no-underline, no-blink,
30655 no-reverse, and no-conceal.
30656
30657 Some terminals do not support all combinations of colors and in‐
30658 tensities.
30659
30660 The associative arrays are:
30661
30662 color
30663 colour Map all the color names to their integer codes, and inte‐
30664 ger codes to the color names. The eight base names map
30665 to the foreground color codes, as do names prefixed with
30666 `fg-', such as `fg-red'. Names prefixed with `bg-', such
30667 as `bg-blue', refer to the background codes. The reverse
30668 mapping from code to color yields base name for fore‐
30669 ground codes and the bg- form for backgrounds.
30670
30671 Although it is a misnomer to call them `colors', these
30672 arrays also map the other fourteen attributes from names
30673 to codes and codes to names.
30674
30675 fg
30676 fg_bold
30677 fg_no_bold
30678 Map the eight basic color names to ANSI terminal escape
30679 sequences that set the corresponding foreground text
30680 properties. The fg sequences change the color without
30681 changing the eight intensity attributes.
30682
30683 bg
30684 bg_bold
30685 bg_no_bold
30686 Map the eight basic color names to ANSI terminal escape
30687 sequences that set the corresponding background proper‐
30688 ties. The bg sequences change the color without changing
30689 the eight intensity attributes.
30690
30691 In addition, the scalar parameters reset_color and bold_color
30692 are set to the ANSI terminal escapes that turn off all at‐
30693 tributes and turn on bold intensity, respectively.
30694
30695 fned [ -x num ] name
30696 Same as zed -f. This function does not appear in the zsh dis‐
30697 tribution, but can be created by linking zed to the name fned in
30698 some directory in your fpath.
30699
30700 histed [ [ name ] size ]
30701 Same as zed -h. This function does not appear in the zsh dis‐
30702 tribution, but can be created by linking zed to the name histed
30703 in some directory in your fpath.
30704
30705 is-at-least needed [ present ]
30706 Perform a greater-than-or-equal-to comparison of two strings
30707 having the format of a zsh version number; that is, a string of
30708 numbers and text with segments separated by dots or dashes. If
30709 the present string is not provided, $ZSH_VERSION is used. Seg‐
30710 ments are paired left-to-right in the two strings with leading
30711 non-number parts ignored. If one string has fewer segments than
30712 the other, the missing segments are considered zero.
30713
30714 This is useful in startup files to set options and other state
30715 that are not available in all versions of zsh.
30716
30717 is-at-least 3.1.6-15 && setopt NO_GLOBAL_RCS
30718 is-at-least 3.1.0 && setopt HIST_REDUCE_BLANKS
30719 is-at-least 2.6-17 || print "You can't use is-at-least here."
30720
30721 nslookup [ arg ... ]
30722 This wrapper function for the nslookup command requires the
30723 zsh/zpty module (see zshmodules(1)). It behaves exactly like
30724 the standard nslookup except that it provides customizable
30725 prompts (including a right-side prompt) and completion of
30726 nslookup commands, host names, etc. (if you use the func‐
30727 tion-based completion system). Completion styles may be set
30728 with the context prefix `:completion:nslookup'.
30729
30730 See also the pager, prompt and rprompt styles below.
30731
30732 regexp-replace var regexp replace
30733 Use regular expressions to perform a global search and replace
30734 operation on a variable. POSIX extended regular expressions
30735 (ERE) are used, unless the option RE_MATCH_PCRE has been set, in
30736 which case Perl-compatible regular expressions are used (this
30737 requires the shell to be linked against the pcre library).
30738
30739 var is the name of the variable containing the string to be
30740 matched. The variable will be modified directly by the func‐
30741 tion. The variables MATCH, MBEGIN, MEND, match, mbegin, mend
30742 should be avoided as these are used by the regular expression
30743 code.
30744
30745 regexp is the regular expression to match against the string.
30746
30747 replace is the replacement text. This can contain parameter,
30748 command and arithmetic expressions which will be replaced: in
30749 particular, a reference to $MATCH will be replaced by the text
30750 matched by the pattern.
30751
30752 The return status is 0 if at least one match was performed, else
30753 1.
30754
30755 Note that if using POSIX EREs, the ^ or word boundary operators
30756 (where available) may not work properly.
30757
30758 run-help cmd
30759 This function is designed to be invoked by the run-help ZLE wid‐
30760 get, in place of the default alias. See `Accessing On-Line
30761 Help' above for setup instructions.
30762
30763 In the discussion which follows, if cmd is a file system path,
30764 it is first reduced to its rightmost component (the file name).
30765
30766 Help is first sought by looking for a file named cmd in the di‐
30767 rectory named by the HELPDIR parameter. If no file is found, an
30768 assistant function, alias, or command named run-help-cmd is
30769 sought. If found, the assistant is executed with the rest of
30770 the current command line (everything after the command name cmd)
30771 as its arguments. When neither file nor assistant is found, the
30772 external command `man cmd' is run.
30773
30774 An example assistant for the "ssh" command:
30775
30776 run-help-ssh() {
30777 emulate -LR zsh
30778 local -a args
30779 # Delete the "-l username" option
30780 zparseopts -D -E -a args l:
30781 # Delete other options, leaving: host command
30782 args=(${@:#-*})
30783 if [[ ${#args} -lt 2 ]]; then
30784 man ssh
30785 else
30786 run-help $args[2]
30787 fi
30788 }
30789
30790 Several of these assistants are provided in the Functions/Misc
30791 directory. These must be autoloaded, or placed as executable
30792 scripts in your search path, in order to be found and used by
30793 run-help.
30794
30795 run-help-btrfs
30796 run-help-git
30797 run-help-ip
30798 run-help-openssl
30799 run-help-p4
30800 run-help-sudo
30801 run-help-svk
30802 run-help-svn
30803 Assistant functions for the btrfs, git, ip, openssl, p4,
30804 sudo, svk, and svn, commands.
30805
30806 tetris Zsh was once accused of not being as complete as Emacs, because
30807 it lacked a Tetris game. This function was written to refute
30808 this vicious slander.
30809
30810 This function must be used as a ZLE widget:
30811
30812 autoload -U tetris
30813 zle -N tetris
30814 bindkey keys tetris
30815
30816 To start a game, execute the widget by typing the keys. What‐
30817 ever command line you were editing disappears temporarily, and
30818 your keymap is also temporarily replaced by the Tetris control
30819 keys. The previous editor state is restored when you quit the
30820 game (by pressing `q') or when you lose.
30821
30822 If you quit in the middle of a game, the next invocation of the
30823 tetris widget will continue where you left off. If you lost, it
30824 will start a new game.
30825
30826 tetriscurses
30827 This is a port of the above to zcurses. The input handling is
30828 improved a bit so that moving a block sideways doesn't automati‐
30829 cally advance a timestep, and the graphics use unicode block
30830 graphics.
30831
30832 This version does not save the game state between invocations,
30833 and is not invoked as a widget, but rather as:
30834
30835 autoload -U tetriscurses
30836 tetriscurses
30837
30838 zargs [ option ... -- ] [ input ... ] [ -- command [ arg ... ] ]
30839 This function has a similar purpose to GNU xargs. Instead of
30840 reading lines of arguments from the standard input, it takes
30841 them from the command line. This is useful because zsh, espe‐
30842 cially with recursive glob operators, often can construct a com‐
30843 mand line for a shell function that is longer than can be ac‐
30844 cepted by an external command.
30845
30846 The option list represents options of the zargs command itself,
30847 which are the same as those of xargs. The input list is the
30848 collection of strings (often file names) that become the argu‐
30849 ments of the command, analogous to the standard input of xargs.
30850 Finally, the arg list consists of those arguments (usually op‐
30851 tions) that are passed to the command each time it runs. The
30852 arg list precedes the elements from the input list in each run.
30853 If no command is provided, then no arg list may be provided, and
30854 in that event the default command is `print' with arguments `-r
30855 --'.
30856
30857 For example, to get a long ls listing of all non-hidden plain
30858 files in the current directory or its subdirectories:
30859
30860 autoload -U zargs
30861 zargs -- **/*(.) -- ls -ld --
30862
30863 The first and third occurrences of `--' are used to mark the end
30864 of options for zargs and ls respectively to guard against file‐
30865 names starting with `-', while the second is used to separate
30866 the list of files from the command to run (`ls -ld --').
30867
30868 The first `--' would also be needed if there was a chance the
30869 list might be empty as in:
30870
30871 zargs -r -- ./*.back(#qN) -- rm -f
30872
30873 In the event that the string `--' is or may be an input, the -e
30874 option may be used to change the end-of-inputs marker. Note
30875 that this does not change the end-of-options marker. For exam‐
30876 ple, to use `..' as the marker:
30877
30878 zargs -e.. -- **/*(.) .. ls -ld --
30879
30880 This is a good choice in that example because no plain file can
30881 be named `..', but the best end-marker depends on the circum‐
30882 stances.
30883
30884 The options -i, -I, -l, -L, and -n differ slightly from their
30885 usage in xargs. There are no input lines for zargs to count, so
30886 -l and -L count through the input list, and -n counts the number
30887 of arguments passed to each execution of command, including any
30888 arg list. Also, any time -i or -I is used, each input is pro‐
30889 cessed separately as if by `-L 1'.
30890
30891 For details of the other zargs options, see the xargs(1) man
30892 page (but note the difference in function between zargs and
30893 xargs) or run zargs with the --help option.
30894
30895 zed [ -f [ -x num ] ] name
30896 zed [ -h [ name ] size ]
30897 zed -b This function uses the ZLE editor to edit a file or function.
30898
30899 Only one name argument is allowed. If the -f option is given,
30900 the name is taken to be that of a function; if the function is
30901 marked for autoloading, zed searches for it in the fpath and
30902 loads it. Note that functions edited this way are installed
30903 into the current shell, but not written back to the autoload
30904 file. In this case the -x option specifies that leading tabs
30905 indenting the function according to syntax should be converted
30906 into the given number of spaces; `-x 2' is consistent with the
30907 layout of functions distributed with the shell.
30908
30909 Without -f, name is the path name of the file to edit, which
30910 need not exist; it is created on write, if necessary. With -h,
30911 the file is presumed to contain history events.
30912
30913 When no file name is provided for -h the current shell history
30914 is edited in place. The history is renumbered when zed exits
30915 successfully.
30916
30917 When editing history, multi-line events must have a trailing
30918 backslash on every line before the last.
30919
30920 While editing, the function sets the main keymap to zed and the
30921 vi command keymap to zed-vicmd. These will be copied from the
30922 existing main and vicmd keymaps if they do not exist the first
30923 time zed is run. They can be used to provide special key bind‐
30924 ings used only in zed.
30925
30926 If it creates the keymap, zed rebinds the return key to insert a
30927 line break and `^X^W' to accept the edit in the zed keymap, and
30928 binds `ZZ' to accept the edit in the zed-vicmd keymap.
30929
30930 The bindings alone can be installed by running `zed -b'. This
30931 is suitable for putting into a startup file. Note that, if re‐
30932 run, this will overwrite the existing zed and zed-vicmd keymaps.
30933
30934 Completion is available, and styles may be set with the context
30935 prefix `:completion:zed:'.
30936
30937 A zle widget zed-set-file-name is available. This can be called
30938 by name from within zed using `\ex zed-set-file-name' or can be
30939 bound to a key in either of the zed or zed-vicmd keymaps after
30940 `zed -b' has been run. When the widget is called, it prompts
30941 for a new name for the file being edited. When zed exits the
30942 file will be written under that name and the original file will
30943 be left alone. The widget has no effect when invoked from `zed
30944 -f'. The completion context is changed to `:comple‐
30945 tion:zed-set-file-name:'. When editing the current history with
30946 `zed -h', the history is first updated and then the file is
30947 written, but the global setting of HISTFILE is not altered.
30948
30949 While zed-set-file-name is running, zed uses the keymap zed-nor‐
30950 mal-keymap, which is linked from the main keymap in effect at
30951 the time zed initialised its bindings. (This is to make the re‐
30952 turn key operate normally.) The result is that if the main
30953 keymap has been changed, the widget won't notice. This is not a
30954 concern for most users.
30955
30956 zcp [ -finqQvwW ] srcpat dest
30957 zln [ -finqQsvwW ] srcpat dest
30958 Same as zmv -C and zmv -L, respectively. These functions do not
30959 appear in the zsh distribution, but can be created by linking
30960 zmv to the names zcp and zln in some directory in your fpath.
30961
30962 zkbd See `Keyboard Definition' above.
30963
30964
30965 zmv [ -finqQsvwW ] [ -C | -L | -M | -{p|P} program ] [ -o optstring ]
30966 srcpat dest
30967 Move (usually, rename) files matching the pattern srcpat to cor‐
30968 responding files having names of the form given by dest, where
30969 srcpat contains parentheses surrounding patterns which will be
30970 replaced in turn by $1, $2, ... in dest. For example,
30971
30972 zmv '(*).lis' '$1.txt'
30973
30974 renames `foo.lis' to `foo.txt', `my.old.stuff.lis' to
30975 `my.old.stuff.txt', and so on.
30976
30977 The pattern is always treated as an EXTENDED_GLOB pattern. Any
30978 file whose name is not changed by the substitution is simply ig‐
30979 nored. Any error (a substitution resulted in an empty string,
30980 two substitutions gave the same result, the destination was an
30981 existing regular file and -f was not given) causes the entire
30982 function to abort without doing anything.
30983
30984 In addition to pattern replacement, the variable $f can be re‐
30985 ferred to in the second (replacement) argument. This makes it
30986 possible to use variable substitution to alter the argument; see
30987 examples below.
30988
30989 Options:
30990
30991 -f Force overwriting of destination files. Not currently
30992 passed down to the mv/cp/ln command due to vagaries of
30993 implementations (but you can use -o-f to do that).
30994 -i Interactive: show each line to be executed and ask the
30995 user whether to execute it. `Y' or `y' will execute it,
30996 anything else will skip it. Note that you just need to
30997 type one character.
30998 -n No execution: print what would happen, but don't do it.
30999 -q Turn bare glob qualifiers off: now assumed by default, so
31000 this has no effect.
31001 -Q Force bare glob qualifiers on. Don't turn this on unless
31002 you are actually using glob qualifiers in a pattern.
31003 -s Symbolic, passed down to ln; only works with -L.
31004 -v Verbose: print each command as it's being executed.
31005 -w Pick out wildcard parts of the pattern, as described
31006 above, and implicitly add parentheses for referring to
31007 them.
31008 -W Just like -w, with the addition of turning wildcards in
31009 the replacement pattern into sequential ${1} .. ${N} ref‐
31010 erences.
31011 -C
31012 -L
31013 -M Force cp, ln or mv, respectively, regardless of the name
31014 of the function.
31015 -p program
31016 Call program instead of cp, ln or mv. Whatever it does,
31017 it should at least understand the form `program -- old‐
31018 name newname' where oldname and newname are filenames
31019 generated by zmv. program will be split into words, so
31020 might be e.g. the name of an archive tool plus a copy or
31021 rename subcommand.
31022 -P program
31023 As -p program, except that program does not accept a fol‐
31024 lowing -- to indicate the end of options. In this case
31025 filenames must already be in a sane form for the program
31026 in question.
31027 -o optstring
31028 The optstring is split into words and passed down verba‐
31029 tim to the cp, ln or mv command called to perform the
31030 work. It should probably begin with a `-'.
31031
31032 Further examples:
31033
31034 zmv -v '(* *)' '${1// /_}'
31035
31036 For any file in the current directory with at least one space in
31037 the name, replace every space by an underscore and display the
31038 commands executed.
31039
31040 zmv -v '* *' '${f// /_}'
31041
31042 This does exactly the same by referring to the file name stored
31043 in $f.
31044
31045 For more complete examples and other implementation details, see
31046 the zmv source file, usually located in one of the directories
31047 named in your fpath, or in Functions/Misc/zmv in the zsh distri‐
31048 bution.
31049
31050 zrecompile
31051 See `Recompiling Functions' above.
31052
31053 zstyle+ context style value [ + subcontext style value ... ]
31054 This makes defining styles a bit simpler by using a single `+'
31055 as a special token that allows you to append a context name to
31056 the previously used context name. Like this:
31057
31058 zstyle+ ':foo:bar' style1 value1 \
31059 +':baz' style2 value2 \
31060 +':frob' style3 value3
31061
31062 This defines style1 with value1 for the context :foo:bar as
31063 usual, but it also defines style2 with value2 for the context
31064 :foo:bar:baz and style3 with value3 for :foo:bar:frob. Any sub‐
31065 context may be the empty string to re-use the first context un‐
31066 changed.
31067
31068 Styles
31069 insert-tab
31070 The zed function sets this style in context `:completion:zed:*'
31071 to turn off completion when TAB is typed at the beginning of a
31072 line. You may override this by setting your own value for this
31073 context and style.
31074
31075 pager The nslookup function looks up this style in the context
31076 `:nslookup' to determine the program used to display output that
31077 does not fit on a single screen.
31078
31079 prompt
31080 rprompt
31081 The nslookup function looks up this style in the context
31082 `:nslookup' to set the prompt and the right-side prompt, respec‐
31083 tively. The usual expansions for the PS1 and RPS1 parameters
31084 may be used (see EXPANSION OF PROMPT SEQUENCES in zshmisc(1)).
31085
31086
31087
31088ZSHALL(1) General Commands Manual ZSHALL(1)
31089
31090
31091
31093 $ZDOTDIR/.zshenv
31094 $ZDOTDIR/.zprofile
31095 $ZDOTDIR/.zshrc
31096 $ZDOTDIR/.zlogin
31097 $ZDOTDIR/.zlogout
31098 ${TMPPREFIX}* (default is /tmp/zsh*)
31099 /etc/zshenv
31100 /etc/zprofile
31101 /etc/zshrc
31102 /etc/zlogin
31103 /etc/zlogout (installation-specific - /etc is the default)
31104
31106 sh(1), csh(1), tcsh(1), rc(1), bash(1), ksh(1)
31107
31108 IEEE Standard for information Technology - Portable Operating System
31109 Interface (POSIX) - Part 2: Shell and Utilities, IEEE Inc, 1993, ISBN
31110 1-55937-255-9.
31111
31112
31113
31114zsh 5.9 May 14, 2022 ZSHALL(1)