1ZSHCOMPSYS(1) General Commands Manual ZSHCOMPSYS(1)
2
3
4
6 zshcompsys - zsh completion system
7
9 This describes the shell code for the `new' completion system, referred
10 to as compsys. It is written in shell functions based on the features
11 described in zshcompwid(1).
12
13 The features are contextual, sensitive to the point at which completion
14 is started. Many completions are already provided. For this reason, a
15 user can perform a great many tasks without knowing any details beyond
16 how to initialize the system, which is described below in INITIALIZA‐
17 TION.
18
19 The context that decides what completion is to be performed may be
20 • an argument or option position: these describe the position on
21 the command line at which completion is requested. For example
22 `first argument to rmdir, the word being completed names a di‐
23 rectory';
24
25
26 • a special context, denoting an element in the shell's syntax.
27 For example `a word in command position' or `an array sub‐
28 script'.
29
30
31 A full context specification contains other elements, as we shall de‐
32 scribe.
33
34 Besides commands names and contexts, the system employs two more con‐
35 cepts, styles and tags. These provide ways for the user to configure
36 the system's behaviour.
37
38 Tags play a dual role. They serve as a classification system for the
39 matches, typically indicating a class of object that the user may need
40 to distinguish. For example, when completing arguments of the ls com‐
41 mand the user may prefer to try files before directories, so both of
42 these are tags. They also appear as the rightmost element in a context
43 specification.
44
45 Styles modify various operations of the completion system, such as out‐
46 put formatting, but also what kinds of completers are used (and in what
47 order), or which tags are examined. Styles may accept arguments and
48 are manipulated using the zstyle command described in zshmodules(1).
49
50 In summary, tags describe what the completion objects are, and style
51 how they are to be completed. At various points of execution, the com‐
52 pletion system checks what styles and/or tags are defined for the cur‐
53 rent context, and uses that to modify its behavior. The full descrip‐
54 tion of context handling, which determines how tags and other elements
55 of the context influence the behaviour of styles, is described below in
56 COMPLETION SYSTEM CONFIGURATION.
57
58 When a completion is requested, a dispatcher function is called; see
59 the description of _main_complete in the list of control functions be‐
60 low. This dispatcher decides which function should be called to produce
61 the completions, and calls it. The result is passed to one or more com‐
62 pleters, functions that implement individual completion strategies:
63 simple completion, error correction, completion with error correction,
64 menu selection, etc.
65
66 More generally, the shell functions contained in the completion system
67 are of two types:
68 • those beginning `comp' are to be called directly; there are only
69 a few of these;
70
71
72 • those beginning `_' are called by the completion code. The
73 shell functions of this set, which implement completion behav‐
74 iour and may be bound to keystrokes, are referred to as `wid‐
75 gets'. These proliferate as new completions are required.
76
77
79 If the system was installed completely, it should be enough to call the
80 shell function compinit from your initialization file; see the next
81 section. However, the function compinstall can be run by a user to
82 configure various aspects of the completion system.
83
84 Usually, compinstall will insert code into .zshrc, although if that is
85 not writable it will save it in another file and tell you that file's
86 location. Note that it is up to you to make sure that the lines added
87 to .zshrc are actually run; you may, for example, need to move them to
88 an earlier place in the file if .zshrc usually returns early. So long
89 as you keep them all together (including the comment lines at the start
90 and finish), you can rerun compinstall and it will correctly locate and
91 modify these lines. Note, however, that any code you add to this sec‐
92 tion by hand is likely to be lost if you rerun compinstall, although
93 lines using the command `zstyle' should be gracefully handled.
94
95 The new code will take effect next time you start the shell, or run
96 .zshrc by hand; there is also an option to make them take effect imme‐
97 diately. However, if compinstall has removed definitions, you will
98 need to restart the shell to see the changes.
99
100 To run compinstall you will need to make sure it is in a directory men‐
101 tioned in your fpath parameter, which should already be the case if zsh
102 was properly configured as long as your startup files do not remove the
103 appropriate directories from fpath. Then it must be autoloaded (`au‐
104 toload -U compinstall' is recommended). You can abort the installation
105 any time you are being prompted for information, and your .zshrc will
106 not be altered at all; changes only take place right at the end, where
107 you are specifically asked for confirmation.
108
109 Use of compinit
110 This section describes the use of compinit to initialize completion for
111 the current session when called directly; if you have run compinstall
112 it will be called automatically from your .zshrc.
113
114 To initialize the system, the function compinit should be in a direc‐
115 tory mentioned in the fpath parameter, and should be autoloaded (`au‐
116 toload -U compinit' is recommended), and then run simply as `compinit'.
117 This will define a few utility functions, arrange for all the necessary
118 shell functions to be autoloaded, and will then re-define all widgets
119 that do completion to use the new system. If you use the menu-select
120 widget, which is part of the zsh/complist module, you should make sure
121 that that module is loaded before the call to compinit so that that
122 widget is also re-defined. If completion styles (see below) are set up
123 to perform expansion as well as completion by default, and the TAB key
124 is bound to expand-or-complete, compinit will rebind it to com‐
125 plete-word; this is necessary to use the correct form of expansion.
126
127 Should you need to use the original completion commands, you can still
128 bind keys to the old widgets by putting a `.' in front of the widget
129 name, e.g. `.expand-or-complete'.
130
131 To speed up the running of compinit, it can be made to produce a dumped
132 configuration that will be read in on future invocations; this is the
133 default, but can be turned off by calling compinit with the option -D.
134 The dumped file is .zcompdump in the same directory as the startup
135 files (i.e. $ZDOTDIR or $HOME); alternatively, an explicit file name
136 can be given by `compinit -d dumpfile'. The next invocation of
137 compinit will read the dumped file instead of performing a full ini‐
138 tialization.
139
140 If the number of completion files changes, compinit will recognise this
141 and produce a new dump file. However, if the name of a function or the
142 arguments in the first line of a #compdef function (as described below)
143 change, it is easiest to delete the dump file by hand so that compinit
144 will re-create it the next time it is run. The check performed to see
145 if there are new functions can be omitted by giving the option -C. In
146 this case the dump file will only be created if there isn't one al‐
147 ready.
148
149 The dumping is actually done by another function, compdump, but you
150 will only need to run this yourself if you change the configuration
151 (e.g. using compdef) and then want to dump the new one. The name of
152 the old dumped file will be remembered for this purpose.
153
154 If the parameter _compdir is set, compinit uses it as a directory where
155 completion functions can be found; this is only necessary if they are
156 not already in the function search path.
157
158 For security reasons compinit also checks if the completion system
159 would use files not owned by root or by the current user, or files in
160 directories that are world- or group-writable or that are not owned by
161 root or by the current user. If such files or directories are found,
162 compinit will ask if the completion system should really be used. To
163 avoid these tests and make all files found be used without asking, use
164 the option -u, and to make compinit silently ignore all insecure files
165 and directories use the option -i. This security check is skipped en‐
166 tirely when the -C option is given, provided the dumpfile exists.
167
168 The security check can be retried at any time by running the function
169 compaudit. This is the same check used by compinit, but when it is ex‐
170 ecuted directly any changes to fpath are made local to the function so
171 they do not persist. The directories to be checked may be passed as
172 arguments; if none are given, compaudit uses fpath and _compdir to find
173 completion system directories, adding missing ones to fpath as neces‐
174 sary. To force a check of exactly the directories currently named in
175 fpath, set _compdir to an empty string before calling compaudit or
176 compinit.
177
178 The function bashcompinit provides compatibility with bash's program‐
179 mable completion system. When run it will define the functions, comp‐
180 gen and complete which correspond to the bash builtins with the same
181 names. It will then be possible to use completion specifications and
182 functions written for bash.
183
184 Autoloaded files
185 The convention for autoloaded functions used in completion is that they
186 start with an underscore; as already mentioned, the fpath/FPATH parame‐
187 ter must contain the directory in which they are stored. If zsh was
188 properly installed on your system, then fpath/FPATH automatically con‐
189 tains the required directories for the standard functions.
190
191 For incomplete installations, if compinit does not find enough files
192 beginning with an underscore (fewer than twenty) in the search path, it
193 will try to find more by adding the directory _compdir to the search
194 path. If that directory has a subdirectory named Base, all subdirecto‐
195 ries will be added to the path. Furthermore, if the subdirectory Base
196 has a subdirectory named Core, compinit will add all subdirectories of
197 the subdirectories to the path: this allows the functions to be in the
198 same format as in the zsh source distribution.
199
200 When compinit is run, it searches all such files accessible via
201 fpath/FPATH and reads the first line of each of them. This line should
202 contain one of the tags described below. Files whose first line does
203 not start with one of these tags are not considered to be part of the
204 completion system and will not be treated specially.
205
206 The tags are:
207
208 #compdef name ... [ -{p|P} pattern ... [ -N name ... ] ]
209 The file will be made autoloadable and the function defined in
210 it will be called when completing names, each of which is either
211 the name of a command whose arguments are to be completed or one
212 of a number of special contexts in the form -context- described
213 below.
214
215 Each name may also be of the form `cmd=service'. When complet‐
216 ing the command cmd, the function typically behaves as if the
217 command (or special context) service was being completed in‐
218 stead. This provides a way of altering the behaviour of func‐
219 tions that can perform many different completions. It is imple‐
220 mented by setting the parameter $service when calling the func‐
221 tion; the function may choose to interpret this how it wishes,
222 and simpler functions will probably ignore it.
223
224 If the #compdef line contains one of the options -p or -P, the
225 words following are taken to be patterns. The function will be
226 called when completion is attempted for a command or context
227 that matches one of the patterns. The options -p and -P are
228 used to specify patterns to be tried before or after other com‐
229 pletions respectively. Hence -P may be used to specify default
230 actions.
231
232 The option -N is used after a list following -p or -P; it speci‐
233 fies that remaining words no longer define patterns. It is pos‐
234 sible to toggle between the three options as many times as nec‐
235 essary.
236
237 #compdef -k style key-sequence ...
238 This option creates a widget behaving like the builtin widget
239 style and binds it to the given key-sequences, if any. The
240 style must be one of the builtin widgets that perform comple‐
241 tion, namely complete-word, delete-char-or-list, expand-or-com‐
242 plete, expand-or-complete-prefix, list-choices, menu-complete,
243 menu-expand-or-complete, or reverse-menu-complete. If the
244 zsh/complist module is loaded (see zshmodules(1)) the widget
245 menu-select is also available.
246
247 When one of the key-sequences is typed, the function in the file
248 will be invoked to generate the matches. Note that a key will
249 not be re-bound if it already was (that is, was bound to some‐
250 thing other than undefined-key). The widget created has the
251 same name as the file and can be bound to any other keys using
252 bindkey as usual.
253
254 #compdef -K widget-name style key-sequence [ name style seq ... ]
255 This is similar to -k except that only one key-sequence argument
256 may be given for each widget-name style pair. However, the en‐
257 tire set of three arguments may be repeated with a different set
258 of arguments. Note in particular that the widget-name must be
259 distinct in each set. If it does not begin with `_' this will
260 be added. The widget-name should not clash with the name of any
261 existing widget: names based on the name of the function are
262 most useful. For example,
263
264 #compdef -K _foo_complete complete-word "^X^C" \
265 _foo_list list-choices "^X^D"
266
267 (all on one line) defines a widget _foo_complete for completion,
268 bound to `^X^C', and a widget _foo_list for listing, bound to
269 `^X^D'.
270
271 #autoload [ options ]
272 Functions with the #autoload tag are marked for autoloading but
273 are not otherwise treated specially. Typically they are to be
274 called from within one of the completion functions. Any options
275 supplied will be passed to the autoload builtin; a typical use
276 is +X to force the function to be loaded immediately. Note that
277 the -U and -z flags are always added implicitly.
278
279 The # is part of the tag name and no white space is allowed after it.
280 The #compdef tags use the compdef function described below; the main
281 difference is that the name of the function is supplied implicitly.
282
283 The special contexts for which completion functions can be defined are:
284
285 -array-value-
286 The right hand side of an array-assignment (`name=(...)')
287
288 -assign-parameter-
289 The name of a parameter in an assignment, i.e. on the left hand
290 side of an `='
291
292 -brace-parameter-
293 The name of a parameter expansion within braces (`${...}')
294
295 -command-
296 A word in command position
297
298 -condition-
299 A word inside a condition (`[[...]]')
300
301 -default-
302 Any word for which no other completion is defined
303
304 -equal-
305 A word beginning with an equals sign
306
307 -first-
308 This is tried before any other completion function. The func‐
309 tion called may set the _compskip parameter to one of various
310 values: all: no further completion is attempted; a string con‐
311 taining the substring patterns: no pattern completion functions
312 will be called; a string containing default: the function for
313 the `-default-' context will not be called, but functions de‐
314 fined for commands will be.
315
316 -math- Inside mathematical contexts, such as `((...))'
317
318 -parameter-
319 The name of a parameter expansion (`$...')
320
321 -redirect-
322 The word after a redirection operator.
323
324 -subscript-
325 The contents of a parameter subscript.
326
327 -tilde-
328 After an initial tilde (`~'), but before the first slash in the
329 word.
330
331 -value-
332 On the right hand side of an assignment.
333
334 Default implementations are supplied for each of these contexts. In
335 most cases the context -context- is implemented by a corresponding
336 function _context, for example the context `-tilde-' and the function
337 `_tilde').
338
339 The contexts -redirect- and -value- allow extra context-specific infor‐
340 mation. (Internally, this is handled by the functions for each context
341 calling the function _dispatch.) The extra information is added sepa‐
342 rated by commas.
343
344 For the -redirect- context, the extra information is in the form `-re‐
345 direct-,op,command', where op is the redirection operator and command
346 is the name of the command on the line. If there is no command on the
347 line yet, the command field will be empty.
348
349 For the -value- context, the form is `-value-,name,command', where name
350 is the name of the parameter on the left hand side of the assignment.
351 In the case of elements of an associative array, for example `as‐
352 soc=(key <TAB>', name is expanded to `name-key'. In certain special
353 contexts, such as completing after `make CFLAGS=', the command part
354 gives the name of the command, here make; otherwise it is empty.
355
356 It is not necessary to define fully specific completions as the func‐
357 tions provided will try to generate completions by progressively re‐
358 placing the elements with `-default-'. For example, when completing
359 after `foo=<TAB>', _value will try the names `-value-,foo,' (note the
360 empty command part), `-value-,foo,-default-' and`-value-,-default-,-de‐
361 fault-', in that order, until it finds a function to handle the con‐
362 text.
363
364 As an example:
365
366 compdef '_files -g "*.log"' '-redirect-,2>,-default-'
367
368 completes files matching `*.log' after `2> <TAB>' for any command with
369 no more specific handler defined.
370
371 Also:
372
373 compdef _foo -value-,-default-,-default-
374
375 specifies that _foo provides completions for the values of parameters
376 for which no special function has been defined. This is usually han‐
377 dled by the function _value itself.
378
379 The same lookup rules are used when looking up styles (as described be‐
380 low); for example
381
382 zstyle ':completion:*:*:-redirect-,2>,*:*' file-patterns '*.log'
383
384 is another way to make completion after `2> <TAB>' complete files
385 matching `*.log'.
386
387 Functions
388 The following function is defined by compinit and may be called di‐
389 rectly.
390
391 compdef [ -ane ] function name ... [ -{p|P} pattern ... [ -N name ...]]
392 compdef -d name ...
393 compdef -k [ -an ] function style key-sequence [ key-sequence ... ]
394 compdef -K [ -an ] function name style key-seq [ name style seq ... ]
395 The first form defines the function to call for completion in
396 the given contexts as described for the #compdef tag above.
397
398 Alternatively, all the arguments may have the form `cmd=ser‐
399 vice'. Here service should already have been defined by
400 `cmd1=service' lines in #compdef files, as described above. The
401 argument for cmd will be completed in the same way as service.
402
403 The function argument may alternatively be a string containing
404 almost any shell code. If the string contains an equal sign,
405 the above will take precedence. The option -e may be used to
406 specify the first argument is to be evaluated as shell code even
407 if it contains an equal sign. The string will be executed using
408 the eval builtin command to generate completions. This provides
409 a way of avoiding having to define a new completion function.
410 For example, to complete files ending in `.h' as arguments to
411 the command foo:
412
413 compdef '_files -g "*.h"' foo
414
415 The option -n prevents any completions already defined for the
416 command or context from being overwritten.
417
418 The option -d deletes any completion defined for the command or
419 contexts listed.
420
421 The names may also contain -p, -P and -N options as described
422 for the #compdef tag. The effect on the argument list is iden‐
423 tical, switching between definitions of patterns tried ini‐
424 tially, patterns tried finally, and normal commands and con‐
425 texts.
426
427 The parameter $_compskip may be set by any function defined for
428 a pattern context. If it is set to a value containing the sub‐
429 string `patterns' none of the pattern-functions will be called;
430 if it is set to a value containing the substring `all', no other
431 function will be called. Setting $_compskip in this manner is
432 of particular utility when using the -p option, as otherwise the
433 dispatcher will move on to additional functions (likely the de‐
434 fault one) after calling the pattern-context one, which can man‐
435 gle the display of completion possibilities if not handled prop‐
436 erly.
437
438 The form with -k defines a widget with the same name as the
439 function that will be called for each of the key-sequences; this
440 is like the #compdef -k tag. The function should generate the
441 completions needed and will otherwise behave like the builtin
442 widget whose name is given as the style argument. The widgets
443 usable for this are: complete-word, delete-char-or-list, ex‐
444 pand-or-complete, expand-or-complete-prefix, list-choices,
445 menu-complete, menu-expand-or-complete, and reverse-menu-com‐
446 plete, as well as menu-select if the zsh/complist module is
447 loaded. The option -n prevents the key being bound if it is al‐
448 ready to bound to something other than undefined-key.
449
450 The form with -K is similar and defines multiple widgets based
451 on the same function, each of which requires the set of three
452 arguments name, style and key-sequence, where the latter two are
453 as for -k and the first must be a unique widget name beginning
454 with an underscore.
455
456 Wherever applicable, the -a option makes the function autoload‐
457 able, equivalent to autoload -U function.
458
459 The function compdef can be used to associate existing completion func‐
460 tions with new commands. For example,
461
462 compdef _pids foo
463
464 uses the function _pids to complete process IDs for the command foo.
465
466 Note also the _gnu_generic function described below, which can be used
467 to complete options for commands that understand the `--help' option.
468
470 This section gives a short overview of how the completion system works,
471 and then more detail on how users can configure how and when matches
472 are generated.
473
474 Overview
475 When completion is attempted somewhere on the command line the comple‐
476 tion system begins building the context. The context represents every‐
477 thing that the shell knows about the meaning of the command line and
478 the significance of the cursor position. This takes account of a num‐
479 ber of things including the command word (such as `grep' or `zsh') and
480 options to which the current word may be an argument (such as the `-o'
481 option to zsh which takes a shell option as an argument).
482
483 The context starts out very generic ("we are beginning a completion")
484 and becomes more specific as more is learned ("the current word is in a
485 position that is usually a command name" or "the current word might be
486 a variable name" and so on). Therefore the context will vary during
487 the same call to the completion system.
488
489 This context information is condensed into a string consisting of mul‐
490 tiple fields separated by colons, referred to simply as `the context'
491 in the remainder of the documentation. Note that a user of the comple‐
492 tion system rarely needs to compose a context string, unless for exam‐
493 ple a new function is being written to perform completion for a new
494 command. What a user may need to do is compose a style pattern, which
495 is matched against a context when needed to look up context-sensitive
496 options that configure the completion system.
497
498 The next few paragraphs explain how a context is composed within the
499 completion function suite. Following that is discussion of how styles
500 are defined. Styles determine such things as how the matches are gen‐
501 erated, similarly to shell options but with much more control. They
502 are defined with the zstyle builtin command (see zshmodules(1)).
503
504 The context string always consists of a fixed set of fields, separated
505 by colons and with a leading colon before the first. Fields which are
506 not yet known are left empty, but the surrounding colons appear anyway.
507 The fields are always in the order :completion:function:completer:com‐
508 mand:argument:tag. These have the following meaning:
509
510 • The literal string completion, saying that this style is used by
511 the completion system. This distinguishes the context from
512 those used by, for example, zle widgets and ZFTP functions.
513
514
515 • The function, if completion is called from a named widget rather
516 than through the normal completion system. Typically this is
517 blank, but it is set by special widgets such as predict-on and
518 the various functions in the Widget directory of the distribu‐
519 tion to the name of that function, often in an abbreviated form.
520
521
522 • The completer currently active, the name of the function without
523 the leading underscore and with other underscores converted to
524 hyphens. A `completer' is in overall control of how completion
525 is to be performed; `complete' is the simplest, but other com‐
526 pleters exist to perform related tasks such as correction, or to
527 modify the behaviour of a later completer. See the section
528 `Control Functions' below for more information.
529
530
531 • The command or a special -context-, just at it appears following
532 the #compdef tag or the compdef function. Completion functions
533 for commands that have sub-commands usually modify this field to
534 contain the name of the command followed by a minus sign and the
535 sub-command. For example, the completion function for the cvs
536 command sets this field to cvs-add when completing arguments to
537 the add subcommand.
538
539
540 • The argument; this indicates which command line or option argu‐
541 ment we are completing. For command arguments this generally
542 takes the form argument-n, where n is the number of the argu‐
543 ment, and for arguments to options the form option-opt-n where n
544 is the number of the argument to option opt. However, this is
545 only the case if the command line is parsed with standard
546 UNIX-style options and arguments, so many completions do not set
547 this.
548
549
550 • The tag. As described previously, tags are used to discriminate
551 between the types of matches a completion function can generate
552 in a certain context. Any completion function may use any tag
553 name it likes, but a list of the more common ones is given be‐
554 low.
555
556
557 The context is gradually put together as the functions are executed,
558 starting with the main entry point, which adds :completion: and the
559 function element if necessary. The completer then adds the completer
560 element. The contextual completion adds the command and argument op‐
561 tions. Finally, the tag is added when the types of completion are
562 known. For example, the context name
563
564 :completion::complete:dvips:option-o-1:files
565
566 says that normal completion was attempted as the first argument to the
567 option -o of the command dvips:
568
569 dvips -o ...
570
571 and the completion function will generate filenames.
572
573 Usually completion will be tried for all possible tags in an order
574 given by the completion function. However, this can be altered by us‐
575 ing the tag-order style. Completion is then restricted to the list of
576 given tags in the given order.
577
578 The _complete_help bindable command shows all the contexts and tags
579 available for completion at a particular point. This provides an easy
580 way of finding information for tag-order and other styles. It is de‐
581 scribed in the section `Bindable Commands' below.
582
583 When looking up styles the completion system uses full context names,
584 including the tag. Looking up the value of a style therefore consists
585 of two things: the context, which is matched to the most specific (best
586 fitting) pattern, and the name of the style itself, which must be
587 matched exactly. The following examples demonstrate that patterns may
588 be loosely defined for styles that apply broadly, or as tightly defined
589 as desired for styles that apply in narrower circumstances.
590
591 For example, many completion functions can generate matches in a simple
592 and a verbose form and use the verbose style to decide which form
593 should be used. To make all such functions use the verbose form, put
594
595 zstyle ':completion:*' verbose yes
596
597 in a startup file (probably .zshrc). This gives the verbose style the
598 value yes in every context inside the completion system, unless that
599 context has a more specific definition. It is best to avoid giving the
600 pattern as `*' in case the style has some meaning outside the comple‐
601 tion system.
602
603 Many such general purpose styles can be configured simply by using the
604 compinstall function.
605
606 A more specific example of the use of the verbose style is by the com‐
607 pletion for the kill builtin. If the style is set, the builtin lists
608 full job texts and process command lines; otherwise it shows the bare
609 job numbers and PIDs. To turn the style off for this use only:
610
611 zstyle ':completion:*:*:kill:*:*' verbose no
612
613 For even more control, the style can use one of the tags `jobs' or
614 `processes'. To turn off verbose display only for jobs:
615
616 zstyle ':completion:*:*:kill:*:jobs' verbose no
617
618 The -e option to zstyle even allows completion function code to appear
619 as the argument to a style; this requires some understanding of the in‐
620 ternals of completion functions (see see zshcompwid(1))). For example,
621
622 zstyle -e ':completion:*' hosts 'reply=($myhosts)'
623
624 This forces the value of the hosts style to be read from the variable
625 myhosts each time a host name is needed; this is useful if the value of
626 myhosts can change dynamically. For another useful example, see the
627 example in the description of the file-list style below. This form can
628 be slow and should be avoided for commonly examined styles such as menu
629 and list-rows-first.
630
631 Note that the order in which styles are defined does not matter; the
632 style mechanism uses the most specific possible match for a particular
633 style to determine the set of values. Strings are preferred over pat‐
634 terns (for example, `:completion::complete:::foo' is more specific than
635 `:completion::complete:::*'), and longer patterns are preferred over
636 the pattern `*'. See zmodules(1) for details.
637
638 Context patterns that use something other than a wildcard (*) to match
639 the middle parts of the context -- the completer, command, and argument
640 in :completion:function:completer:command:argument:tag -- should in‐
641 clude all six colons (:) explicitly. Without this, a pattern such as
642 :completion:*:foo:* could match foo against a component other than the
643 intended one (for example, against completer when a match against com‐
644 mand was intended).
645
646 Style names like those of tags are arbitrary and depend on the comple‐
647 tion function. However, the following two sections list some of the
648 most common tags and styles.
649
650 Standard Tags
651 Some of the following are only used when looking up particular styles
652 and do not refer to a type of match.
653
654 accounts
655 used to look up the users-hosts style
656
657 all-expansions
658 used by the _expand completer when adding the single string con‐
659 taining all possible expansions
660
661 all-files
662 for the names of all files (as distinct from a particular sub‐
663 set, see the globbed-files tag).
664
665 arguments
666 for arguments to a command
667
668 arrays for names of array parameters
669
670 association-keys
671 for keys of associative arrays; used when completing inside a
672 subscript to a parameter of this type
673
674 bookmarks
675 when completing bookmarks (e.g. for URLs and the zftp function
676 suite)
677
678 builtins
679 for names of builtin commands
680
681 characters
682 for single characters in arguments of commands such as stty.
683 Also used when completing character classes after an opening
684 bracket
685
686 colormapids
687 for X colormap ids
688
689 colors for color names
690
691 commands
692 for names of external commands. Also used by complex commands
693 such as cvs when completing names subcommands.
694
695 contexts
696 for contexts in arguments to the zstyle builtin command
697
698 corrections
699 used by the _approximate and _correct completers for possible
700 corrections
701
702 cursors
703 for cursor names used by X programs
704
705 default
706 used in some contexts to provide a way of supplying a default
707 when more specific tags are also valid. Note that this tag is
708 used when only the function field of the context name is set
709
710 descriptions
711 used when looking up the value of the format style to generate
712 descriptions for types of matches
713
714 devices
715 for names of device special files
716
717 directories
718 for names of directories -- local-directories is used instead
719 when completing arguments of cd and related builtin commands
720 when the cdpath array is set
721
722 directory-stack
723 for entries in the directory stack
724
725 displays
726 for X display names
727
728 domains
729 for network domains
730
731 email-plugin
732 for email addresses from the `_email-plugin' backend of
733 _email_addresses
734
735 expansions
736 used by the _expand completer for individual words (as opposed
737 to the complete set of expansions) resulting from the expansion
738 of a word on the command line
739
740 extensions
741 for X server extensions
742
743 file-descriptors
744 for numbers of open file descriptors
745
746 files the generic file-matching tag used by functions completing file‐
747 names
748
749 fonts for X font names
750
751 fstypes
752 for file system types (e.g. for the mount command)
753
754 functions
755 names of functions -- normally shell functions, although certain
756 commands may understand other kinds of function
757
758 globbed-files
759 for filenames when the name has been generated by pattern match‐
760 ing
761
762 groups for names of user groups
763
764 history-words
765 for words from the history
766
767 hosts for hostnames
768
769 indexes
770 for array indexes
771
772 interfaces
773 for network interfaces
774
775 jobs for jobs (as listed by the `jobs' builtin)
776
777 keymaps
778 for names of zsh keymaps
779
780 keysyms
781 for names of X keysyms
782
783 libraries
784 for names of system libraries
785
786 limits for system limits
787
788 local-directories
789 for names of directories that are subdirectories of the current
790 working directory when completing arguments of cd and related
791 builtin commands (compare path-directories) -- when the cdpath
792 array is unset, directories is used instead
793
794 mailboxes
795 for e-mail folders
796
797 manuals
798 for names of manual pages
799
800 maps for map names (e.g. NIS maps)
801
802 messages
803 used to look up the format style for messages
804
805 modifiers
806 for names of X modifiers
807
808 modules
809 for modules (e.g. zsh modules)
810
811 my-accounts
812 used to look up the users-hosts style
813
814 named-directories
815 for named directories (you wouldn't have guessed that, would
816 you?)
817
818 names for all kinds of names
819
820 newsgroups
821 for USENET groups
822
823 nicknames
824 for nicknames of NIS maps
825
826 options
827 for command options
828
829 original
830 used by the _approximate, _correct and _expand completers when
831 offering the original string as a match
832
833 other-accounts
834 used to look up the users-hosts style
835
836 packages
837 for packages (e.g. rpm or installed Debian packages)
838
839 parameters
840 for names of parameters
841
842 path-directories
843 for names of directories found by searching the cdpath array
844 when completing arguments of cd and related builtin commands
845 (compare local-directories)
846
847 paths used to look up the values of the expand, ambiguous and spe‐
848 cial-dirs styles
849
850 pods for perl pods (documentation files)
851
852 ports for communication ports
853
854 prefixes
855 for prefixes (like those of a URL)
856
857 printers
858 for print queue names
859
860 processes
861 for process identifiers
862
863 processes-names
864 used to look up the command style when generating the names of
865 processes for killall
866
867 sequences
868 for sequences (e.g. mh sequences)
869
870 sessions
871 for sessions in the zftp function suite
872
873 signals
874 for signal names
875
876 strings
877 for strings (e.g. the replacement strings for the cd builtin
878 command)
879
880 styles for styles used by the zstyle builtin command
881
882 suffixes
883 for filename extensions
884
885 tags for tags (e.g. rpm tags)
886
887 targets
888 for makefile targets
889
890 time-zones
891 for time zones (e.g. when setting the TZ parameter)
892
893 types for types of whatever (e.g. address types for the xhost command)
894
895 urls used to look up the urls and local styles when completing URLs
896
897 users for usernames
898
899 values for one of a set of values in certain lists
900
901 variant
902 used by _pick_variant to look up the command to run when deter‐
903 mining what program is installed for a particular command name.
904
905 visuals
906 for X visuals
907
908 warnings
909 used to look up the format style for warnings
910
911 widgets
912 for zsh widget names
913
914 windows
915 for IDs of X windows
916
917 zsh-options
918 for shell options
919
920 Standard Styles
921 Note that the values of several of these styles represent boolean val‐
922 ues. Any of the strings `true', `on', `yes', and `1' can be used for
923 the value `true' and any of the strings `false', `off', `no', and `0'
924 for the value `false'. The behavior for any other value is undefined
925 except where explicitly mentioned. The default value may be either
926 `true' or `false' if the style is not set.
927
928 Some of these styles are tested first for every possible tag corre‐
929 sponding to a type of match, and if no style was found, for the default
930 tag. The most notable styles of this type are menu, list-colors and
931 styles controlling completion listing such as list-packed and
932 last-prompt. When tested for the default tag, only the function field
933 of the context will be set so that a style using the default tag will
934 normally be defined along the lines of:
935
936 zstyle ':completion:*:default' menu ...
937
938 accept-exact
939 This is tested for the default tag in addition to the tags valid
940 for the current context. If it is set to `true' and any of the
941 trial matches is the same as the string on the command line,
942 this match will immediately be accepted (even if it would other‐
943 wise be considered ambiguous).
944
945 When completing pathnames (where the tag used is `paths') this
946 style accepts any number of patterns as the value in addition to
947 the boolean values. Pathnames matching one of these patterns
948 will be accepted immediately even if the command line contains
949 some more partially typed pathname components and these match no
950 file under the directory accepted.
951
952 This style is also used by the _expand completer to decide if
953 words beginning with a tilde or parameter expansion should be
954 expanded. For example, if there are parameters foo and foobar,
955 the string `$foo' will only be expanded if accept-exact is set
956 to `true'; otherwise the completion system will be allowed to
957 complete $foo to $foobar. If the style is set to `continue',
958 _expand will add the expansion as a match and the completion
959 system will also be allowed to continue.
960
961 accept-exact-dirs
962 This is used by filename completion. Unlike accept-exact it is
963 a boolean. By default, filename completion examines all compo‐
964 nents of a path to see if there are completions of that compo‐
965 nent, even if the component matches an existing directory. For
966 example, when completion after /usr/bin/, the function examines
967 possible completions to /usr.
968
969 When this style is `true', any prefix of a path that matches an
970 existing directory is accepted without any attempt to complete
971 it further. Hence, in the given example, the path /usr/bin/ is
972 accepted immediately and completion tried in that directory.
973
974 This style is also useful when completing after directories that
975 magically appear when referenced, such as ZFS .zfs directories
976 or NetApp .snapshot directories. When the style is set the
977 shell does not check for the existence of the directory within
978 the parent directory.
979
980 If you wish to inhibit this behaviour entirely, set the
981 path-completion style (see below) to `false'.
982
983 add-space
984 This style is used by the _expand completer. If it is `true'
985 (the default), a space will be inserted after all words result‐
986 ing from the expansion, or a slash in the case of directory
987 names. If the value is `file', the completer will only add a
988 space to names of existing files. Either a boolean `true' or
989 the value `file' may be combined with `subst', in which case the
990 completer will not add a space to words generated from the ex‐
991 pansion of a substitution of the form `$(...)' or `${...}'.
992
993 The _prefix completer uses this style as a simple boolean value
994 to decide if a space should be inserted before the suffix.
995
996 ambiguous
997 This applies when completing non-final components of filename
998 paths, in other words those with a trailing slash. If it is
999 set, the cursor is left after the first ambiguous component,
1000 even if menu completion is in use. The style is always tested
1001 with the paths tag.
1002
1003 assign-list
1004 When completing after an equals sign that is being treated as an
1005 assignment, the completion system normally completes only one
1006 filename. In some cases the value may be a list of filenames
1007 separated by colons, as with PATH and similar parameters. This
1008 style can be set to a list of patterns matching the names of
1009 such parameters.
1010
1011 The default is to complete lists when the word on the line al‐
1012 ready contains a colon.
1013
1014 auto-description
1015 If set, this style's value will be used as the description for
1016 options that are not described by the completion functions, but
1017 that have exactly one argument. The sequence `%d' in the value
1018 will be replaced by the description for this argument. Depend‐
1019 ing on personal preferences, it may be useful to set this style
1020 to something like `specify: %d'. Note that this may not work
1021 for some commands.
1022
1023 avoid-completer
1024 This is used by the _all_matches completer to decide if the
1025 string consisting of all matches should be added to the list
1026 currently being generated. Its value is a list of names of com‐
1027 pleters. If any of these is the name of the completer that gen‐
1028 erated the matches in this completion, the string will not be
1029 added.
1030
1031 The default value for this style is `_expand _old_list _correct
1032 _approximate', i.e. it contains the completers for which a
1033 string with all matches will almost never be wanted.
1034
1035 cache-path
1036 This style defines the path where any cache files containing
1037 dumped completion data are stored. It defaults to `$ZDOT‐
1038 DIR/.zcompcache', or `$HOME/.zcompcache' if $ZDOTDIR is not de‐
1039 fined. The completion cache will not be used unless the
1040 use-cache style is set.
1041
1042 cache-policy
1043 This style defines the function that will be used to determine
1044 whether a cache needs rebuilding. See the section on the
1045 _cache_invalid function below.
1046
1047 call-command
1048 This style is used in the function for commands such as make and
1049 ant where calling the command directly to generate matches suf‐
1050 fers problems such as being slow or, as in the case of make can
1051 potentially cause actions in the makefile to be executed. If it
1052 is set to `true' the command is called to generate matches. The
1053 default value of this style is `false'.
1054
1055 command
1056 In many places, completion functions need to call external com‐
1057 mands to generate the list of completions. This style can be
1058 used to override the command that is called in some such cases.
1059 The elements of the value are joined with spaces to form a com‐
1060 mand line to execute. The value can also start with a hyphen,
1061 in which case the usual command will be added to the end; this
1062 is most useful for putting `builtin' or `command' in front to
1063 make sure the appropriate version of a command is called, for
1064 example to avoid calling a shell function with the same name as
1065 an external command.
1066
1067 As an example, the completion function for process IDs uses this
1068 style with the processes tag to generate the IDs to complete and
1069 the list of processes to display (if the verbose style is
1070 `true'). The list produced by the command should look like the
1071 output of the ps command. The first line is not displayed, but
1072 is searched for the string `PID' (or `pid') to find the position
1073 of the process IDs in the following lines. If the line does not
1074 contain `PID', the first numbers in each of the other lines are
1075 taken as the process IDs to complete.
1076
1077 Note that the completion function generally has to call the
1078 specified command for each attempt to generate the completion
1079 list. Hence care should be taken to specify only commands that
1080 take a short time to run, and in particular to avoid any that
1081 may never terminate.
1082
1083 command-path
1084 This is a list of directories to search for commands to com‐
1085 plete. The default for this style is the value of the special
1086 parameter path.
1087
1088 commands
1089 This is used by the function completing sub-commands for the
1090 system initialisation scripts (residing in /etc/init.d or some‐
1091 where not too far away from that). Its values give the default
1092 commands to complete for those commands for which the completion
1093 function isn't able to find them out automatically. The default
1094 for this style are the two strings `start' and `stop'.
1095
1096 complete
1097 This is used by the _expand_alias function when invoked as a
1098 bindable command. If set to `true' and the word on the command
1099 line is not the name of an alias, matching alias names will be
1100 completed.
1101
1102 complete-options
1103 This is used by the completer for cd, chdir and pushd. For
1104 these commands a - is used to introduce a directory stack entry
1105 and completion of these is far more common than completing op‐
1106 tions. Hence unless the value of this style is `true' options
1107 will not be completed, even after an initial -. If it is
1108 `true', options will be completed after an initial - unless
1109 there is a preceding -- on the command line.
1110
1111 completer
1112 The strings given as the value of this style provide the names
1113 of the completer functions to use. The available completer func‐
1114 tions are described in the section `Control Functions' below.
1115
1116 Each string may be either the name of a completer function or a
1117 string of the form `function:name'. In the first case the com‐
1118 pleter field of the context will contain the name of the com‐
1119 pleter without the leading underscore and with all other under‐
1120 scores replaced by hyphens. In the second case the function is
1121 the name of the completer to call, but the context will contain
1122 the user-defined name in the completer field of the context. If
1123 the name starts with a hyphen, the string for the context will
1124 be build from the name of the completer function as in the first
1125 case with the name appended to it. For example:
1126
1127 zstyle ':completion:*' completer _complete _complete:-foo
1128
1129 Here, completion will call the _complete completer twice, once
1130 using `complete' and once using `complete-foo' in the completer
1131 field of the context. Normally, using the same completer more
1132 than once only makes sense when used with the `functions:name'
1133 form, because otherwise the context name will be the same in all
1134 calls to the completer; possible exceptions to this rule are the
1135 _ignored and _prefix completers.
1136
1137 The default value for this style is `_complete _ignored': only
1138 completion will be done, first using the ignored-patterns style
1139 and the $fignore array and then without ignoring matches.
1140
1141 condition
1142 This style is used by the _list completer function to decide if
1143 insertion of matches should be delayed unconditionally. The de‐
1144 fault is `true'.
1145
1146 delimiters
1147 This style is used when adding a delimiter for use with history
1148 modifiers or glob qualifiers that have delimited arguments. It
1149 is an array of preferred delimiters to add. Non-special charac‐
1150 ters are preferred as the completion system may otherwise become
1151 confused. The default list is :, +, /, -, %. The list may be
1152 empty to force a delimiter to be typed.
1153
1154 disabled
1155 If this is set to `true', the _expand_alias completer and bind‐
1156 able command will try to expand disabled aliases, too. The de‐
1157 fault is `false'.
1158
1159 domains
1160 A list of names of network domains for completion. If this is
1161 not set, domain names will be taken from the file /etc/re‐
1162 solv.conf.
1163
1164 environ
1165 The environ style is used when completing for `sudo'. It is set
1166 to an array of `VAR=value' assignments to be exported into the
1167 local environment before the completion for the target command
1168 is invoked.
1169 zstyle ':completion:*:sudo::' environ \
1170 PATH="/sbin:/usr/sbin:$PATH" HOME="/root"
1171
1172 expand This style is used when completing strings consisting of multi‐
1173 ple parts, such as path names.
1174
1175 If one of its values is the string `prefix', the partially typed
1176 word from the line will be expanded as far as possible even if
1177 trailing parts cannot be completed.
1178
1179 If one of its values is the string `suffix', matching names for
1180 components after the first ambiguous one will also be added.
1181 This means that the resulting string is the longest unambiguous
1182 string possible. However, menu completion can be used to cycle
1183 through all matches.
1184
1185 extra-verbose
1186 If set, the completion listing is more verbose at the cost of a
1187 probable decrease in completion speed. Completion performance
1188 will suffer if this style is set to `true'.
1189
1190 fake This style may be set for any completion context. It specifies
1191 additional strings that will always be completed in that con‐
1192 text. The form of each string is `value:description'; the colon
1193 and description may be omitted, but any literal colons in value
1194 must be quoted with a backslash. Any description provided is
1195 shown alongside the value in completion listings.
1196
1197 It is important to use a sufficiently restrictive context when
1198 specifying fake strings. Note that the styles fake-files and
1199 fake-parameters provide additional features when completing
1200 files or parameters.
1201
1202 fake-always
1203 This works identically to the fake style except that the ig‐
1204 nored-patterns style is not applied to it. This makes it possi‐
1205 ble to override a set of matches completely by setting the ig‐
1206 nored patterns to `*'.
1207
1208 The following shows a way of supplementing any tag with arbi‐
1209 trary data, but having it behave for display purposes like a
1210 separate tag. In this example we use the features of the
1211 tag-order style to divide the named-directories tag into two
1212 when performing completion with the standard completer complete
1213 for arguments of cd. The tag named-directories-normal behaves
1214 as normal, but the tag named-directories-mine contains a fixed
1215 set of directories. This has the effect of adding the match
1216 group `extra directories' with the given completions.
1217
1218 zstyle ':completion::complete:cd:*' tag-order \
1219 'named-directories:-mine:extra\ directories
1220 named-directories:-normal:named\ directories *'
1221 zstyle ':completion::complete:cd:*:named-directories-mine' \
1222 fake-always mydir1 mydir2
1223 zstyle ':completion::complete:cd:*:named-directories-mine' \
1224 ignored-patterns '*'
1225
1226 fake-files
1227 This style is used when completing files and looked up without a
1228 tag. Its values are of the form `dir:names...'. This will add
1229 the names (strings separated by spaces) as possible matches when
1230 completing in the directory dir, even if no such files really
1231 exist. The dir may be a pattern; pattern characters or colons
1232 in dir should be quoted with a backslash to be treated liter‐
1233 ally.
1234
1235 This can be useful on systems that support special file systems
1236 whose top-level pathnames can not be listed or generated with
1237 glob patterns (but see accept-exact-dirs for a more general way
1238 of dealing with this problem). It can also be used for directo‐
1239 ries for which one does not have read permission.
1240
1241 The pattern form can be used to add a certain `magic' entry to
1242 all directories on a particular file system.
1243
1244 fake-parameters
1245 This is used by the completion function for parameter names.
1246 Its values are names of parameters that might not yet be set but
1247 should be completed nonetheless. Each name may also be followed
1248 by a colon and a string specifying the type of the parameter
1249 (like `scalar', `array' or `integer'). If the type is given,
1250 the name will only be completed if parameters of that type are
1251 required in the particular context. Names for which no type is
1252 specified will always be completed.
1253
1254 file-list
1255 This style controls whether files completed using the standard
1256 builtin mechanism are to be listed with a long list similar to
1257 ls -l. Note that this feature uses the shell module zsh/stat
1258 for file information; this loads the builtin stat which will re‐
1259 place any external stat executable. To avoid this the following
1260 code can be included in an initialization file:
1261
1262 zmodload -i zsh/stat
1263 disable stat
1264
1265 The style may either be set to a `true' value (or `all'), or one
1266 of the values `insert' or `list', indicating that files are to
1267 be listed in long format in all circumstances, or when attempt‐
1268 ing to insert a file name, or when listing file names without
1269 attempting to insert one.
1270
1271 More generally, the value may be an array of any of the above
1272 values, optionally followed by =num. If num is present it gives
1273 the maximum number of matches for which long listing style will
1274 be used. For example,
1275
1276 zstyle ':completion:*' file-list list=20 insert=10
1277
1278 specifies that long format will be used when listing up to 20
1279 files or inserting a file with up to 10 matches (assuming a
1280 listing is to be shown at all, for example on an ambiguous com‐
1281 pletion), else short format will be used.
1282
1283 zstyle -e ':completion:*' file-list \
1284 '(( ${+NUMERIC} )) && reply=(true)'
1285
1286 specifies that long format will be used any time a numeric argu‐
1287 ment is supplied, else short format.
1288
1289 file-patterns
1290 This is used by the standard function for completing filenames,
1291 _files. If the style is unset up to three tags are offered,
1292 `globbed-files',`directories' and `all-files', depending on the
1293 types of files expected by the caller of _files. The first two
1294 (`globbed-files' and `directories') are normally offered to‐
1295 gether to make it easier to complete files in sub-directories.
1296
1297 The file-patterns style provides alternatives to the default
1298 tags, which are not used. Its value consists of elements of the
1299 form `pattern:tag'; each string may contain any number of such
1300 specifications separated by spaces.
1301
1302 The pattern is a pattern that is to be used to generate file‐
1303 names. Any occurrence of the sequence `%p' is replaced by any
1304 pattern(s) passed by the function calling _files. Colons in the
1305 pattern must be preceded by a backslash to make them distin‐
1306 guishable from the colon before the tag. If more than one pat‐
1307 tern is needed, the patterns can be given inside braces, sepa‐
1308 rated by commas.
1309
1310 The tags of all strings in the value will be offered by _files
1311 and used when looking up other styles. Any tags in the same
1312 word will be offered at the same time and before later words.
1313 If no `:tag' is given the `files' tag will be used.
1314
1315 The tag may also be followed by an optional second colon and a
1316 description, which will be used for the `%d' in the value of the
1317 format style (if that is set) instead of the default description
1318 supplied by the completion function. The inclusion of a de‐
1319 scription also gives precedence to associated options such as
1320 for completion grouping so it can be used where files should be
1321 separated.
1322
1323 For example, to make the rm command first complete only names of
1324 object files and then the names of all files if there is no
1325 matching object file:
1326
1327 zstyle ':completion:*:*:rm:*:*' file-patterns \
1328 '*.o:object-files' '%p:all-files'
1329
1330 To alter the default behaviour of file completion -- offer files
1331 matching a pattern and directories on the first attempt, then
1332 all files -- to offer only matching files on the first attempt,
1333 then directories, and finally all files:
1334
1335 zstyle ':completion:*' file-patterns \
1336 '%p:globbed-files' '*(-/):directories' '*:all-files'
1337
1338 This works even where there is no special pattern: _files
1339 matches all files using the pattern `*' at the first step and
1340 stops when it sees this pattern. Note also it will never try a
1341 pattern more than once for a single completion attempt.
1342
1343 To separate directories into a separate group from the files but
1344 still complete them at the first attempt, a description needs to
1345 be given. Note that directories need to be explicitly excluded
1346 from the globbed-files because `*' will match directories. For
1347 grouping, it is also necessary to set the group-name style.
1348
1349 zstyle ':completion:*' file-patterns \
1350 '%p(^-/):globbed-files *(-/):directories:location'
1351
1352 During the execution of completion functions, the EXTENDED_GLOB
1353 option is in effect, so the characters `#', `~' and `^' have
1354 special meanings in the patterns.
1355
1356 file-sort
1357 The standard filename completion function uses this style with‐
1358 out a tag to determine in which order the names should be
1359 listed; menu completion will cycle through them in the same or‐
1360 der. The possible values are: `size' to sort by the size of the
1361 file; `links' to sort by the number of links to the file; `modi‐
1362 fication' (or `time' or `date') to sort by the last modification
1363 time; `access' to sort by the last access time; and `inode' (or
1364 `change') to sort by the last inode change time. If the style
1365 is set to any other value, or is unset, files will be sorted al‐
1366 phabetically by name. If the value contains the string `re‐
1367 verse', sorting is done in the opposite order. If the value
1368 contains the string `follow', timestamps are associated with the
1369 targets of symbolic links; the default is to use the timestamps
1370 of the links themselves.
1371
1372 file-split-chars
1373 A set of characters that will cause all file completions for the
1374 given context to be split at the point where any of the charac‐
1375 ters occurs. A typical use is to set the style to :; then ev‐
1376 erything up to and including the last : in the string so far is
1377 ignored when completing files. As this is quite heavy-handed,
1378 it is usually preferable to update completion functions for con‐
1379 texts where this behaviour is useful.
1380
1381 filter The ldap plugin of email address completion (see _email_ad‐
1382 dresses) uses this style to specify the attributes to match
1383 against when filtering entries. So for example, if the style is
1384 set to `sn', matching is done against surnames. Standard LDAP
1385 filtering is used so normal completion matching is bypassed. If
1386 this style is not set, the LDAP plugin is skipped. You may also
1387 need to set the command style to specify how to connect to your
1388 LDAP server.
1389
1390 force-list
1391 This forces a list of completions to be shown at any point where
1392 listing is done, even in cases where the list would usually be
1393 suppressed. For example, normally the list is only shown if
1394 there are at least two different matches. By setting this style
1395 to `always', the list will always be shown, even if there is
1396 only a single match that will immediately be accepted. The
1397 style may also be set to a number. In this case the list will
1398 be shown if there are at least that many matches, even if they
1399 would all insert the same string.
1400
1401 This style is tested for the default tag as well as for each tag
1402 valid for the current completion. Hence the listing can be
1403 forced only for certain types of match.
1404
1405 format If this is set for the descriptions tag, its value is used as a
1406 string to display above matches in completion lists. The se‐
1407 quence `%d' in this string will be replaced with a short de‐
1408 scription of what these matches are. This string may also con‐
1409 tain the output attribute sequences understood by compadd -X
1410 (see zshcompwid(1)).
1411
1412 The style is tested with each tag valid for the current comple‐
1413 tion before it is tested for the descriptions tag. Hence dif‐
1414 ferent format strings can be defined for different types of
1415 match.
1416
1417 Note also that some completer functions define additional
1418 `%'-sequences. These are described for the completer functions
1419 that make use of them.
1420
1421 Some completion functions display messages that may be cus‐
1422 tomised by setting this style for the messages tag. Here, the
1423 `%d' is replaced with a message given by the completion func‐
1424 tion.
1425
1426 Finally, the format string is looked up with the warnings tag,
1427 for use when no matches could be generated at all. In this case
1428 the `%d' is replaced with the descriptions for the matches that
1429 were expected separated by spaces. The sequence `%D' is re‐
1430 placed with the same descriptions separated by newlines.
1431
1432 It is possible to use printf-style field width specifiers with
1433 `%d' and similar escape sequences. This is handled by the zfor‐
1434 mat builtin command from the zsh/zutil module, see zshmod‐
1435 ules(1).
1436
1437 gain-privileges
1438 If set to true, this style enables the use of commands like sudo
1439 or doas to gain extra privileges when retrieving information for
1440 completion. This is only done when a command such as sudo ap‐
1441 pears on the command-line. To force the use of, e.g. sudo or to
1442 override any prefix that might be added due to gain-privileges,
1443 the command style can be used with a value that begins with a
1444 hyphen.
1445
1446 glob This is used by the _expand completer. If it is set to `true'
1447 (the default), globbing will be attempted on the words resulting
1448 from a previous substitution (see the substitute style) or else
1449 the original string from the line.
1450
1451 global If this is set to `true' (the default), the _expand_alias com‐
1452 pleter and bindable command will try to expand global aliases.
1453
1454 group-name
1455 The completion system can group different types of matches,
1456 which appear in separate lists. This style can be used to give
1457 the names of groups for particular tags. For example, in com‐
1458 mand position the completion system generates names of builtin
1459 and external commands, names of aliases, shell functions and pa‐
1460 rameters and reserved words as possible completions. To have
1461 the external commands and shell functions listed separately:
1462
1463 zstyle ':completion:*:*:-command-:*:commands' \
1464 group-name commands
1465 zstyle ':completion:*:*:-command-:*:functions' \
1466 group-name functions
1467
1468 As a consequence, any match with the same tag will be displayed
1469 in the same group.
1470
1471 If the name given is the empty string the name of the tag for
1472 the matches will be used as the name of the group. So, to have
1473 all different types of matches displayed separately, one can
1474 just set:
1475
1476 zstyle ':completion:*' group-name ''
1477
1478 All matches for which no group name is defined will be put in a
1479 group named -default-.
1480
1481 To display the group name in the output, see the format style
1482 (q.v.) under the descriptions tag.
1483
1484 group-order
1485 This style is additional to the group-name style to specify the
1486 order for display of the groups defined by that style (compare
1487 tag-order, which determines which completions appear at all).
1488 The groups named are shown in the given order; any other groups
1489 are shown in the order defined by the completion function.
1490
1491 For example, to have names of builtin commands, shell functions
1492 and external commands appear in that order when completing in
1493 command position:
1494
1495 zstyle ':completion:*:*:-command-:*:*' group-order \
1496 builtins functions commands
1497
1498 groups A list of names of UNIX groups. If this is not set, group names
1499 are taken from the YP database or the file `/etc/group'.
1500
1501 hidden If this is set to `true', matches for the given context will not
1502 be listed, although any description for the matches set with the
1503 format style will be shown. If it is set to `all', not even the
1504 description will be displayed.
1505
1506 Note that the matches will still be completed; they are just not
1507 shown in the list. To avoid having matches considered as possi‐
1508 ble completions at all, the tag-order style can be modified as
1509 described below.
1510
1511 hosts A list of names of hosts that should be completed. If this is
1512 not set, hostnames are taken from the file `/etc/hosts'.
1513
1514 hosts-ports
1515 This style is used by commands that need or accept hostnames and
1516 network ports. The strings in the value should be of the form
1517 `host:port'. Valid ports are determined by the presence of
1518 hostnames; multiple ports for the same host may appear.
1519
1520 ignore-line
1521 This is tested for each tag valid for the current completion.
1522 If it is set to `true', none of the words that are already on
1523 the line will be considered as possible completions. If it is
1524 set to `current', the word the cursor is on will not be consid‐
1525 ered as a possible completion. The value `current-shown' is
1526 similar but only applies if the list of completions is currently
1527 shown on the screen. Finally, if the style is set to `other',
1528 all words on the line except for the current one will be ex‐
1529 cluded from the possible completions.
1530
1531 The values `current' and `current-shown' are a bit like the op‐
1532 posite of the accept-exact style: only strings with missing
1533 characters will be completed.
1534
1535 Note that you almost certainly don't want to set this to `true'
1536 or `other' for a general context such as `:completion:*'. This
1537 is because it would disallow completion of, for example, options
1538 multiple times even if the command in question accepts the op‐
1539 tion more than once.
1540
1541 ignore-parents
1542 The style is tested without a tag by the function completing
1543 pathnames in order to determine whether to ignore the names of
1544 directories already mentioned in the current word, or the name
1545 of the current working directory. The value must include one or
1546 both of the following strings:
1547
1548 parent The name of any directory whose path is already contained
1549 in the word on the line is ignored. For example, when
1550 completing after foo/../, the directory foo will not be
1551 considered a valid completion.
1552
1553 pwd The name of the current working directory will not be
1554 completed; hence, for example, completion after ../ will
1555 not use the name of the current directory.
1556
1557 In addition, the value may include one or both of:
1558
1559 .. Ignore the specified directories only when the word on
1560 the line contains the substring `../'.
1561
1562 directory
1563 Ignore the specified directories only when names of di‐
1564 rectories are completed, not when completing names of
1565 files.
1566
1567 Excluded values act in a similar fashion to values of the ig‐
1568 nored-patterns style, so they can be restored to consideration
1569 by the _ignored completer.
1570
1571 ignored-patterns
1572 A list of patterns; any trial completion matching one of the
1573 patterns will be excluded from consideration. The _ignored com‐
1574 pleter can appear in the list of completers to restore the ig‐
1575 nored matches. This is a more configurable version of the shell
1576 parameter $fignore.
1577
1578 Note that the EXTENDED_GLOB option is set during the execution
1579 of completion functions, so the characters `#', `~' and `^' have
1580 special meanings in the patterns.
1581
1582 insert This style is used by the _all_matches completer to decide
1583 whether to insert the list of all matches unconditionally in‐
1584 stead of adding the list as another match.
1585
1586 insert-ids
1587 When completing process IDs, for example as arguments to the
1588 kill and wait builtins the name of a command may be converted to
1589 the appropriate process ID. A problem arises when the process
1590 name typed is not unique. By default (or if this style is set
1591 explicitly to `menu') the name will be converted immediately to
1592 a set of possible IDs, and menu completion will be started to
1593 cycle through them.
1594
1595 If the value of the style is `single', the shell will wait until
1596 the user has typed enough to make the command unique before con‐
1597 verting the name to an ID; attempts at completion will be unsuc‐
1598 cessful until that point. If the value is any other string,
1599 menu completion will be started when the string typed by the
1600 user is longer than the common prefix to the corresponding IDs.
1601
1602 insert-sections
1603 This style is used with tags of the form `manuals.X' when com‐
1604 pleting names of manual pages. If set and the X in the tag name
1605 matches the section number of the page being completed, the sec‐
1606 tion number is inserted along with the page name. For example,
1607 given
1608
1609 zstyle ':completion:*:manuals.*' insert-sections true
1610
1611 man ssh_<TAB> may be completed to man 5 ssh_config.
1612
1613 The value may also be set to one of `prepend', or `suffix'.
1614 `prepend' behaves the same as `true' as in the above example,
1615 while `suffix' would complete man ssh_<TAB> as man ssh_config.5.
1616
1617 This is especially useful in conjunction with separate-sections,
1618 as it ensures that the page requested of man corresponds to the
1619 one displayed in the completion listing when there are multiple
1620 pages with the same name (e.g., printf(1) and printf(3)).
1621
1622 The default for this style is `false'.
1623
1624 insert-tab
1625 If this is set to `true', the completion system will insert a
1626 TAB character (assuming that was used to start completion) in‐
1627 stead of performing completion when there is no non-blank char‐
1628 acter to the left of the cursor. If it is set to `false', com‐
1629 pletion will be done even there.
1630
1631 The value may also contain the substrings `pending' or `pend‐
1632 ing=val'. In this case, the typed character will be inserted
1633 instead of starting completion when there is unprocessed input
1634 pending. If a val is given, completion will not be done if
1635 there are at least that many characters of unprocessed input.
1636 This is often useful when pasting characters into a terminal.
1637 Note however, that it relies on the $PENDING special parameter
1638 from the zsh/zle module being set properly which is not guaran‐
1639 teed on all platforms.
1640
1641 The default value of this style is `true' except for completion
1642 within vared builtin command where it is `false'.
1643
1644 insert-unambiguous
1645 This is used by the _match and _approximate completers. These
1646 completers are often used with menu completion since the word
1647 typed may bear little resemblance to the final completion. How‐
1648 ever, if this style is `true', the completer will start menu
1649 completion only if it could find no unambiguous initial string
1650 at least as long as the original string typed by the user.
1651
1652 In the case of the _approximate completer, the completer field
1653 in the context will already have been set to one of correct-num
1654 or approximate-num, where num is the number of errors that were
1655 accepted.
1656
1657 In the case of the _match completer, the style may also be set
1658 to the string `pattern'. Then the pattern on the line is left
1659 unchanged if it does not match unambiguously.
1660
1661 keep-prefix
1662 This style is used by the _expand completer. If it is `true',
1663 the completer will try to keep a prefix containing a tilde or
1664 parameter expansion. Hence, for example, the string `~/f*'
1665 would be expanded to `~/foo' instead of `/home/user/foo'. If
1666 the style is set to `changed' (the default), the prefix will
1667 only be left unchanged if there were other changes between the
1668 expanded words and the original word from the command line. Any
1669 other value forces the prefix to be expanded unconditionally.
1670
1671 The behaviour of _expand when this style is `true' is to cause
1672 _expand to give up when a single expansion with the restored
1673 prefix is the same as the original; hence any remaining com‐
1674 pleters may be called.
1675
1676 known-hosts-files
1677 This style should contain a list of files to search for host
1678 names and (if the use-ip style is set) IP addresses in a format
1679 compatible with ssh known_hosts files. If it is not set, the
1680 files /etc/ssh/ssh_known_hosts and ~/.ssh/known_hosts are used.
1681
1682 last-prompt
1683 This is a more flexible form of the ALWAYS_LAST_PROMPT option.
1684 If it is `true', the completion system will try to return the
1685 cursor to the previous command line after displaying a comple‐
1686 tion list. It is tested for all tags valid for the current com‐
1687 pletion, then the default tag. The cursor will be moved back to
1688 the previous line if this style is `true' for all types of
1689 match. Note that unlike the ALWAYS_LAST_PROMPT option this is
1690 independent of the numeric argument.
1691
1692 list This style is used by the _history_complete_word bindable com‐
1693 mand. If it is set to `true' it has no effect. If it is set to
1694 `false' matches will not be listed. This overrides the setting
1695 of the options controlling listing behaviour, in particular
1696 AUTO_LIST. The context always starts with `:completion:his‐
1697 tory-words'.
1698
1699 list-colors
1700 If the zsh/complist module is loaded, this style can be used to
1701 set color specifications. This mechanism replaces the use of
1702 the ZLS_COLORS and ZLS_COLOURS parameters described in the sec‐
1703 tion `The zsh/complist Module' in zshmodules(1), but the syntax
1704 is the same.
1705
1706 If this style is set for the default tag, the strings in the
1707 value are taken as specifications that are to be used every‐
1708 where. If it is set for other tags, the specifications are used
1709 only for matches of the type described by the tag. For this to
1710 work best, the group-name style must be set to an empty string.
1711
1712 In addition to setting styles for specific tags, it is also pos‐
1713 sible to use group names specified explicitly by the group-name
1714 tag together with the `(group)' syntax allowed by the ZLS_COLORS
1715 and ZLS_COLOURS parameters and simply using the default tag.
1716
1717 It is possible to use any color specifications already set up
1718 for the GNU version of the ls command:
1719
1720 zstyle ':completion:*:default' list-colors \
1721 ${(s.:.)LS_COLORS}
1722
1723 The default colors are the same as for the GNU ls command and
1724 can be obtained by setting the style to an empty string (i.e.
1725 '').
1726
1727 list-dirs-first
1728 This is used by file completion and corresponds to a particular
1729 setting of the file-patterns style. If set, the default direc‐
1730 tories to be completed are listed separately from and before
1731 completion for other files.
1732
1733 list-grouped
1734 If this style is `true' (the default), the completion system
1735 will try to make certain completion listings more compact by
1736 grouping matches. For example, options for commands that have
1737 the same description (shown when the verbose style is set to
1738 `true') will appear as a single entry. However, menu selection
1739 can be used to cycle through all the matches.
1740
1741 list-packed
1742 This is tested for each tag valid in the current context as well
1743 as the default tag. If it is set to `true', the corresponding
1744 matches appear in listings as if the LIST_PACKED option were
1745 set. If it is set to `false', they are listed normally.
1746
1747 list-prompt
1748 If this style is set for the default tag, completion lists that
1749 don't fit on the screen can be scrolled (see the description of
1750 the zsh/complist module in zshmodules(1)). The value, if not
1751 the empty string, will be displayed after every screenful and
1752 the shell will prompt for a key press; if the style is set to
1753 the empty string, a default prompt will be used.
1754
1755 The value may contain the escape sequences: `%l' or `%L', which
1756 will be replaced by the number of the last line displayed and
1757 the total number of lines; `%m' or `%M', the number of the last
1758 match shown and the total number of matches; and `%p' and `%P',
1759 `Top' when at the beginning of the list, `Bottom' when at the
1760 end and the position shown as a percentage of the total length
1761 otherwise. In each case the form with the uppercase letter will
1762 be replaced by a string of fixed width, padded to the right
1763 with spaces, while the lowercase form will be replaced by a
1764 variable width string. As in other prompt strings, the escape
1765 sequences `%S', `%s', `%B', `%b', `%U', `%u' for entering and
1766 leaving the display modes standout, bold and underline, and
1767 `%F', `%f', `%K', `%k' for changing the foreground background
1768 colour, are also available, as is the form `%{...%}' for enclos‐
1769 ing escape sequences which display with zero (or, with a numeric
1770 argument, some other) width.
1771
1772 After deleting this prompt the variable LISTPROMPT should be un‐
1773 set for the removal to take effect.
1774
1775 list-rows-first
1776 This style is tested in the same way as the list-packed style
1777 and determines whether matches are to be listed in a rows-first
1778 fashion as if the LIST_ROWS_FIRST option were set.
1779
1780 list-separator
1781 The value of this style is used in completion listing to sepa‐
1782 rate the string to complete from a description when possible
1783 (e.g. when completing options). It defaults to `--' (two hy‐
1784 phens).
1785
1786 list-suffixes
1787 This style is used by the function that completes filenames. If
1788 it is `true', and completion is attempted on a string containing
1789 multiple partially typed pathname components, all ambiguous com‐
1790 ponents will be shown. Otherwise, completion stops at the first
1791 ambiguous component.
1792
1793 local This is for use with functions that complete URLs for which the
1794 corresponding files are available directly from the file system.
1795 Its value should consist of three strings: a hostname, the path
1796 to the default web pages for the server, and the directory name
1797 used by a user placing web pages within their home area.
1798
1799 For example:
1800
1801 zstyle ':completion:*' local toast \
1802 /var/http/public/toast public_html
1803
1804 Completion after `http://toast/stuff/' will look for files in
1805 the directory /var/http/public/toast/stuff, while completion
1806 after `http://toast/~yousir/' will look for files in the direc‐
1807 tory ~yousir/public_html.
1808
1809 mail-directory
1810 If set, zsh will assume that mailbox files can be found in the
1811 directory specified. It defaults to `~/Mail'.
1812
1813 match-original
1814 This is used by the _match completer. If it is set to only,
1815 _match will try to generate matches without inserting a `*' at
1816 the cursor position. If set to any other non-empty value, it
1817 will first try to generate matches without inserting the `*' and
1818 if that yields no matches, it will try again with the `*' in‐
1819 serted. If it is unset or set to the empty string, matching
1820 will only be performed with the `*' inserted.
1821
1822 matcher
1823 This style is tested separately for each tag valid in the cur‐
1824 rent context. Its value is placed before any match specifica‐
1825 tions given by the matcher-list style so can override them via
1826 the use of an x: specification. The value should be in the form
1827 described in the section `Completion Matching Control' in zsh‐
1828 compwid(1). For examples of this, see the description of the
1829 tag-order style.
1830
1831 For notes comparing the use of this and the matcher-list style,
1832 see under the description of the tag-order style.
1833
1834 matcher-list
1835 This style can be set to a list of match specifications that are
1836 to be applied everywhere. Match specifications are described in
1837 the section `Completion Matching Control' in zshcompwid(1). The
1838 completion system will try them one after another for each com‐
1839 pleter selected. For example, to try first simple completion
1840 and, if that generates no matches, case-insensitive completion:
1841
1842 zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}'
1843
1844 By default each specification replaces the previous one; how‐
1845 ever, if a specification is prefixed with +, it is added to the
1846 existing list. Hence it is possible to create increasingly gen‐
1847 eral specifications without repetition:
1848
1849 zstyle ':completion:*' matcher-list \
1850 '' '+m:{a-z}={A-Z}' '+m:{A-Z}={a-z}'
1851
1852 It is possible to create match specifications valid for particu‐
1853 lar completers by using the third field of the context. This
1854 applies only to completers that override the global
1855 matcher-list, which as of this writing includes only _prefix and
1856 _ignored. For example, to use the completers _complete and
1857 _prefix but allow case-insensitive completion only with _com‐
1858 plete:
1859
1860 zstyle ':completion:*' completer _complete _prefix
1861 zstyle ':completion:*:complete:*:*:*' matcher-list \
1862 '' 'm:{a-zA-Z}={A-Za-z}'
1863
1864 User-defined names, as explained for the completer style, are
1865 available. This makes it possible to try the same completer
1866 more than once with different match specifications each time.
1867 For example, to try normal completion without a match specifica‐
1868 tion, then normal completion with case-insensitive matching,
1869 then correction, and finally partial-word completion:
1870
1871 zstyle ':completion:*' completer \
1872 _complete _correct _complete:foo
1873 zstyle ':completion:*:complete:*:*:*' matcher-list \
1874 '' 'm:{a-zA-Z}={A-Za-z}'
1875 zstyle ':completion:*:foo:*:*:*' matcher-list \
1876 'm:{a-zA-Z}={A-Za-z} r:|[-_./]=* r:|=*'
1877
1878 If the style is unset in any context no match specification is
1879 applied. Note also that some completers such as _correct and
1880 _approximate do not use the match specifications at all, though
1881 these completers will only ever be called once even if the
1882 matcher-list contains more than one element.
1883
1884 Where multiple specifications are useful, note that the entire
1885 completion is done for each element of matcher-list, which can
1886 quickly reduce the shell's performance. As a rough rule of
1887 thumb, one to three strings will give acceptable performance.
1888 On the other hand, putting multiple space-separated values into
1889 the same string does not have an appreciable impact on perfor‐
1890 mance.
1891
1892 If there is no current matcher or it is empty, and the option
1893 NO_CASE_GLOB is in effect, the matching for files is performed
1894 case-insensitively in any case. However, any matcher must ex‐
1895 plicitly specify case-insensitive matching if that is required.
1896
1897 For notes comparing the use of this and the matcher style, see
1898 under the description of the tag-order style.
1899
1900 max-errors
1901 This is used by the _approximate and _correct completer func‐
1902 tions to determine the maximum number of errors to allow. The
1903 completer will try to generate completions by first allowing one
1904 error, then two errors, and so on, until either a match or
1905 matches were found or the maximum number of errors given by this
1906 style has been reached.
1907
1908 If the value for this style contains the string `numeric', the
1909 completer function will take any numeric argument as the maximum
1910 number of errors allowed. For example, with
1911
1912 zstyle ':completion:*:approximate:::' max-errors 2 numeric
1913
1914 two errors are allowed if no numeric argument is given, but with
1915 a numeric argument of six (as in `ESC-6 TAB'), up to six errors
1916 are accepted. Hence with a value of `0 numeric', no correcting
1917 completion will be attempted unless a numeric argument is given.
1918
1919 If the value contains the string `not-numeric', the completer
1920 will not try to generate corrected completions when given a nu‐
1921 meric argument, so in this case the number given should be
1922 greater than zero. For example, `2 not-numeric' specifies that
1923 correcting completion with two errors will usually be performed,
1924 but if a numeric argument is given, correcting completion will
1925 not be performed.
1926
1927 The default value for this style is `2 numeric'.
1928
1929 max-matches-width
1930 This style is used to determine the trade off between the width
1931 of the display used for matches and the width used for their de‐
1932 scriptions when the verbose style is in effect. The value gives
1933 the number of display columns to reserve for the matches. The
1934 default is half the width of the screen.
1935
1936 This has the most impact when several matches have the same de‐
1937 scription and so will be grouped together. Increasing the style
1938 will allow more matches to be grouped together; decreasing it
1939 will allow more of the description to be visible.
1940
1941 menu If this is `true' in the context of any of the tags defined for
1942 the current completion menu completion will be used. The value
1943 for a specific tag will take precedence over that for the `de‐
1944 fault' tag.
1945
1946 If none of the values found in this way is `true' but at least
1947 one is set to `auto', the shell behaves as if the AUTO_MENU op‐
1948 tion is set.
1949
1950 If one of the values is explicitly set to `false', menu comple‐
1951 tion will be explicitly turned off, overriding the MENU_COMPLETE
1952 option and other settings.
1953
1954 In the form `yes=num', where `yes' may be any of the `true' val‐
1955 ues (`yes', `true', `on' and `1'), menu completion will be
1956 turned on if there are at least num matches. In the form
1957 `yes=long', menu completion will be turned on if the list does
1958 not fit on the screen. This does not activate menu completion
1959 if the widget normally only lists completions, but menu comple‐
1960 tion can be activated in that case with the value
1961 `yes=long-list' (Typically, the value `select=long-list' de‐
1962 scribed later is more useful as it provides control over
1963 scrolling.)
1964
1965 Similarly, with any of the `false' values (as in `no=10'), menu
1966 completion will not be used if there are num or more matches.
1967
1968 The value of this widget also controls menu selection, as imple‐
1969 mented by the zsh/complist module. The following values may ap‐
1970 pear either alongside or instead of the values above.
1971
1972 If the value contains the string `select', menu selection will
1973 be started unconditionally.
1974
1975 In the form `select=num', menu selection will only be started if
1976 there are at least num matches. If the values for more than one
1977 tag provide a number, the smallest number is taken.
1978
1979 Menu selection can be turned off explicitly by defining a value
1980 containing the string`no-select'.
1981
1982 It is also possible to start menu selection only if the list of
1983 matches does not fit on the screen by using the value `se‐
1984 lect=long'. To start menu selection even if the current widget
1985 only performs listing, use the value `select=long-list'.
1986
1987 To turn on menu completion or menu selection when there are a
1988 certain number of matches or the list of matches does not fit on
1989 the screen, both of `yes=' and `select=' may be given twice,
1990 once with a number and once with `long' or `long-list'.
1991
1992 Finally, it is possible to activate two special modes of menu
1993 selection. The word `interactive' in the value causes interac‐
1994 tive mode to be entered immediately when menu selection is
1995 started; see the description of the zsh/complist module in zsh‐
1996 modules(1) for a description of interactive mode. Including the
1997 string `search' does the same for incremental search mode. To
1998 select backward incremental search, include the string
1999 `search-backward'.
2000
2001 muttrc If set, gives the location of the mutt configuration file. It
2002 defaults to `~/.muttrc'.
2003
2004 numbers
2005 This is used with the jobs tag. If it is `true', the shell will
2006 complete job numbers instead of the shortest unambiguous prefix
2007 of the job command text. If the value is a number, job numbers
2008 will only be used if that many words from the job descriptions
2009 are required to resolve ambiguities. For example, if the value
2010 is `1', strings will only be used if all jobs differ in the
2011 first word on their command lines.
2012
2013 old-list
2014 This is used by the _oldlist completer. If it is set to `al‐
2015 ways', then standard widgets which perform listing will retain
2016 the current list of matches, however they were generated; this
2017 can be turned off explicitly with the value `never', giving the
2018 behaviour without the _oldlist completer. If the style is un‐
2019 set, or any other value, then the existing list of completions
2020 is displayed if it is not already; otherwise, the standard com‐
2021 pletion list is generated; this is the default behaviour of
2022 _oldlist. However, if there is an old list and this style con‐
2023 tains the name of the completer function that generated the
2024 list, then the old list will be used even if it was generated by
2025 a widget which does not do listing.
2026
2027 For example, suppose you type ^Xc to use the _correct_word wid‐
2028 get, which generates a list of corrections for the word under
2029 the cursor. Usually, typing ^D would generate a standard list
2030 of completions for the word on the command line, and show that.
2031 With _oldlist, it will instead show the list of corrections al‐
2032 ready generated.
2033
2034 As another example consider the _match completer: with the in‐
2035 sert-unambiguous style set to `true' it inserts only a common
2036 prefix string, if there is any. However, this may remove parts
2037 of the original pattern, so that further completion could pro‐
2038 duce more matches than on the first attempt. By using the
2039 _oldlist completer and setting this style to _match, the list of
2040 matches generated on the first attempt will be used again.
2041
2042 old-matches
2043 This is used by the _all_matches completer to decide if an old
2044 list of matches should be used if one exists. This is selected
2045 by one of the `true' values or by the string `only'. If the
2046 value is `only', _all_matches will only use an old list and
2047 won't have any effect on the list of matches currently being
2048 generated.
2049
2050 If this style is set it is generally unwise to call the
2051 _all_matches completer unconditionally. One possible use is for
2052 either this style or the completer style to be defined with the
2053 -e option to zstyle to make the style conditional.
2054
2055 old-menu
2056 This is used by the _oldlist completer. It controls how menu
2057 completion behaves when a completion has already been inserted
2058 and the user types a standard completion key such as TAB. The
2059 default behaviour of _oldlist is that menu completion always
2060 continues with the existing list of completions. If this style
2061 is set to `false', however, a new completion is started if the
2062 old list was generated by a different completion command; this
2063 is the behaviour without the _oldlist completer.
2064
2065 For example, suppose you type ^Xc to generate a list of correc‐
2066 tions, and menu completion is started in one of the usual ways.
2067 Usually, or with this style set to `false', typing TAB at this
2068 point would start trying to complete the line as it now appears.
2069 With _oldlist, it instead continues to cycle through the list of
2070 corrections.
2071
2072 original
2073 This is used by the _approximate and _correct completers to de‐
2074 cide if the original string should be added as a possible com‐
2075 pletion. Normally, this is done only if there are at least two
2076 possible corrections, but if this style is set to `true', it is
2077 always added. Note that the style will be examined with the
2078 completer field in the context name set to correct-num or ap‐
2079 proximate-num, where num is the number of errors that were ac‐
2080 cepted.
2081
2082 packageset
2083 This style is used when completing arguments of the Debian
2084 `dpkg' program. It contains an override for the default package
2085 set for a given context. For example,
2086
2087 zstyle ':completion:*:complete:dpkg:option--status-1:*' \
2088 packageset avail
2089
2090 causes available packages, rather than only installed packages,
2091 to be completed for `dpkg --status'.
2092
2093 path The function that completes color names uses this style with the
2094 colors tag. The value should be the pathname of a file contain‐
2095 ing color names in the format of an X11 rgb.txt file. If the
2096 style is not set but this file is found in one of various stan‐
2097 dard locations it will be used as the default.
2098
2099 path-completion
2100 This is used by filename completion. By default, filename com‐
2101 pletion examines all components of a path to see if there are
2102 completions of that component. For example, /u/b/z can be com‐
2103 pleted to /usr/bin/zsh. Explicitly setting this style to
2104 `false' inhibits this behaviour for path components up to the /
2105 before the cursor; this overrides the setting of accept-ex‐
2106 act-dirs.
2107
2108 Even with the style set to `false', it is still possible to com‐
2109 plete multiple paths by setting the option COMPLETE_IN_WORD and
2110 moving the cursor back to the first component in the path to be
2111 completed. For example, /u/b/z can be completed to /usr/bin/zsh
2112 if the cursor is after the /u.
2113
2114 pine-directory
2115 If set, specifies the directory containing PINE mailbox files.
2116 There is no default, since recursively searching this directory
2117 is inconvenient for anyone who doesn't use PINE.
2118
2119 ports A list of Internet service names (network ports) to complete.
2120 If this is not set, service names are taken from the file
2121 `/etc/services'.
2122
2123 prefix-hidden
2124 This is used for certain completions which share a common pre‐
2125 fix, for example command options beginning with dashes. If it
2126 is `true', the prefix will not be shown in the list of matches.
2127
2128 The default value for this style is `false'.
2129
2130 prefix-needed
2131 This style is also relevant for matches with a common prefix.
2132 If it is set to `true' this common prefix must be typed by the
2133 user to generate the matches.
2134
2135 The style is applicable to the options, signals, jobs, func‐
2136 tions, and parameters completion tags.
2137
2138 For command options, this means that the initial `-', `+', or
2139 `--' must be typed explicitly before option names will be com‐
2140 pleted.
2141
2142 For signals, an initial `-' is required before signal names will
2143 be completed.
2144
2145 For jobs, an initial `%' is required before job names will be
2146 completed.
2147
2148 For function and parameter names, an initial `_' or `.' is re‐
2149 quired before function or parameter names starting with those
2150 characters will be completed.
2151
2152 The default value for this style is `false' for function and pa‐
2153 rameter completions, and `true' otherwise.
2154
2155 preserve-prefix
2156 This style is used when completing path names. Its value should
2157 be a pattern matching an initial prefix of the word to complete
2158 that should be left unchanged under all circumstances. For ex‐
2159 ample, on some Unices an initial `//' (double slash) has a spe‐
2160 cial meaning; setting this style to the string `//' will pre‐
2161 serve it. As another example, setting this style to `?:/' under
2162 Cygwin would allow completion after `a:/...' and so on.
2163
2164 range This is used by the _history completer and the _history_com‐
2165 plete_word bindable command to decide which words should be com‐
2166 pleted.
2167
2168 If it is a single number, only the last N words from the history
2169 will be completed.
2170
2171 If it is a range of the form `max:slice', the last slice words
2172 will be completed; then if that yields no matches, the slice
2173 words before those will be tried and so on. This process stops
2174 either when at least one match has been found, or max words have
2175 been tried.
2176
2177 The default is to complete all words from the history at once.
2178
2179 recursive-files
2180 If this style is set, its value is an array of patterns to be
2181 tested against `$PWD/': note the trailing slash, which allows
2182 directories in the pattern to be delimited unambiguously by in‐
2183 cluding slashes on both sides. If an ordinary file completion
2184 fails and the word on the command line does not yet have a di‐
2185 rectory part to its name, the style is retrieved using the same
2186 tag as for the completion just attempted, then the elements
2187 tested against $PWD/ in turn. If one matches, then the shell
2188 reattempts completion by prepending the word on the command line
2189 with each directory in the expansion of **/*(/) in turn. Typi‐
2190 cally the elements of the style will be set to restrict the num‐
2191 ber of directories beneath the current one to a manageable num‐
2192 ber, for example `*/.git/*'.
2193
2194 For example,
2195
2196 zstyle ':completion:*' recursive-files '*/zsh/*'
2197
2198 If the current directory is /home/pws/zsh/Src, then zle_tr<TAB>
2199 can be completed to Zle/zle_tricky.c.
2200
2201 regular
2202 This style is used by the _expand_alias completer and bindable
2203 command. If set to `true' (the default), regular aliases will
2204 be expanded but only in command position. If it is set to
2205 `false', regular aliases will never be expanded. If it is set
2206 to `always', regular aliases will be expanded even if not in
2207 command position.
2208
2209 rehash If this is set when completing external commands, the internal
2210 list (hash) of commands will be updated for each search by issu‐
2211 ing the rehash command. There is a speed penalty for this which
2212 is only likely to be noticeable when directories in the path
2213 have slow file access.
2214
2215 remote-access
2216 If set to `false', certain commands will be prevented from mak‐
2217 ing Internet connections to retrieve remote information. This
2218 includes the completion for the CVS command.
2219
2220 It is not always possible to know if connections are in fact to
2221 a remote site, so some may be prevented unnecessarily.
2222
2223 remove-all-dups
2224 The _history_complete_word bindable command and the _history
2225 completer use this to decide if all duplicate matches should be
2226 removed, rather than just consecutive duplicates.
2227
2228 select-prompt
2229 If this is set for the default tag, its value will be displayed
2230 during menu selection (see the menu style above) when the com‐
2231 pletion list does not fit on the screen as a whole. The same
2232 escapes as for the list-prompt style are understood, except that
2233 the numbers refer to the match or line the mark is on. A de‐
2234 fault prompt is used when the value is the empty string.
2235
2236 select-scroll
2237 This style is tested for the default tag and determines how a
2238 completion list is scrolled during a menu selection (see the
2239 menu style above) when the completion list does not fit on the
2240 screen as a whole. If the value is `0' (zero), the list is
2241 scrolled by half-screenfuls; if it is a positive integer, the
2242 list is scrolled by the given number of lines; if it is a nega‐
2243 tive number, the list is scrolled by a screenful minus the abso‐
2244 lute value of the given number of lines. The default is to
2245 scroll by single lines.
2246
2247 separate-sections
2248 This style is used with the manuals tag when completing names of
2249 manual pages. If it is `true', entries for different sections
2250 are added separately using tag names of the form `manuals.X',
2251 where X is the section number. When the group-name style is
2252 also in effect, pages from different sections will appear sepa‐
2253 rately. This style is also used similarly with the words style
2254 when completing words for the dict command. It allows words from
2255 different dictionary databases to be added separately. See also
2256 insert-sections.
2257
2258 The default for this style is `false'.
2259
2260 show-ambiguity
2261 If the zsh/complist module is loaded, this style can be used to
2262 highlight the first ambiguous character in completion lists. The
2263 value is either a color indication such as those supported by
2264 the list-colors style or, with a value of `true', a default of
2265 underlining is selected. The highlighting is only applied if the
2266 completion display strings correspond to the actual matches.
2267
2268 show-completer
2269 Tested whenever a new completer is tried. If it is `true', the
2270 completion system outputs a progress message in the listing area
2271 showing what completer is being tried. The message will be
2272 overwritten by any output when completions are found and is re‐
2273 moved after completion is finished.
2274
2275 single-ignored
2276 This is used by the _ignored completer when there is only one
2277 match. If its value is `show', the single match will be dis‐
2278 played but not inserted. If the value is `menu', then the sin‐
2279 gle match and the original string are both added as matches and
2280 menu completion is started, making it easy to select either of
2281 them.
2282
2283 sort This allows the standard ordering of matches to be overridden.
2284
2285 If its value is `true' or `false', sorting is enabled or dis‐
2286 abled. Additionally the values associated with the `-o' option
2287 to compadd can also be listed: match, nosort, numeric, reverse.
2288 If it is not set for the context, the standard behaviour of the
2289 calling widget is used.
2290
2291 The style is tested first against the full context including the
2292 tag, and if that fails to produce a value against the context
2293 without the tag.
2294
2295 In many cases where a calling widget explicitly selects a par‐
2296 ticular ordering in lieu of the default, a value of `true' is
2297 not honoured. An example of where this is not the case is for
2298 command history where the default of sorting matches chronologi‐
2299 cally may be overridden by setting the style to `true'.
2300
2301 In the _expand completer, if it is set to `true', the expansions
2302 generated will always be sorted. If it is set to `menu', then
2303 the expansions are only sorted when they are offered as single
2304 strings but not in the string containing all possible expan‐
2305 sions.
2306
2307 special-dirs
2308 Normally, the completion code will not produce the directory
2309 names `.' and `..' as possible completions. If this style is
2310 set to `true', it will add both `.' and `..' as possible comple‐
2311 tions; if it is set to `..', only `..' will be added.
2312
2313 The following example sets special-dirs to `..' when the current
2314 prefix is empty, is a single `.', or consists only of a path be‐
2315 ginning with `../'. Otherwise the value is `false'.
2316
2317 zstyle -e ':completion:*' special-dirs \
2318 '[[ $PREFIX = (../)#(|.|..) ]] && reply=(..)'
2319
2320 squeeze-slashes
2321 If set to `true', sequences of slashes in filename paths (for
2322 example in `foo//bar') will be treated as a single slash. This
2323 is the usual behaviour of UNIX paths. However, by default the
2324 file completion function behaves as if there were a `*' between
2325 the slashes.
2326
2327 stop If set to `true', the _history_complete_word bindable command
2328 will stop once when reaching the beginning or end of the his‐
2329 tory. Invoking _history_complete_word will then wrap around to
2330 the opposite end of the history. If this style is set to
2331 `false' (the default), _history_complete_word will loop immedi‐
2332 ately as in a menu completion.
2333
2334 strip-comments
2335 If set to `true', this style causes non-essential comment text
2336 to be removed from completion matches. Currently it is only
2337 used when completing e-mail addresses where it removes any dis‐
2338 play name from the addresses, cutting them down to plain
2339 user@host form.
2340
2341 subst-globs-only
2342 This is used by the _expand completer. If it is set to `true',
2343 the expansion will only be used if it resulted from globbing;
2344 hence, if expansions resulted from the use of the substitute
2345 style described below, but these were not further changed by
2346 globbing, the expansions will be rejected.
2347
2348 The default for this style is `false'.
2349
2350 substitute
2351 This boolean style controls whether the _expand completer will
2352 first try to expand all substitutions in the string (such as
2353 `$(...)' and `${...}').
2354
2355 The default is `true'.
2356
2357 suffix This is used by the _expand completer if the word starts with a
2358 tilde or contains a parameter expansion. If it is set to
2359 `true', the word will only be expanded if it doesn't have a suf‐
2360 fix, i.e. if it is something like `~foo' or `$foo' rather than
2361 `~foo/' or `$foo/bar', unless that suffix itself contains char‐
2362 acters eligible for expansion. The default for this style is
2363 `true'.
2364
2365 tag-order
2366 This provides a mechanism for sorting how the tags available in
2367 a particular context will be used.
2368
2369 The values for the style are sets of space-separated lists of
2370 tags. The tags in each value will be tried at the same time; if
2371 no match is found, the next value is used. (See the file-pat‐
2372 terns style for an exception to this behavior.)
2373
2374 For example:
2375
2376 zstyle ':completion:*:complete:-command-:*:*' tag-order \
2377 'commands functions'
2378
2379 specifies that completion in command position first offers ex‐
2380 ternal commands and shell functions. Remaining tags will be
2381 tried if no completions are found.
2382
2383 In addition to tag names, each string in the value may take one
2384 of the following forms:
2385
2386 - If any value consists of only a hyphen, then only the
2387 tags specified in the other values are generated. Nor‐
2388 mally all tags not explicitly selected are tried last if
2389 the specified tags fail to generate any matches. This
2390 means that a single value consisting only of a single hy‐
2391 phen turns off completion.
2392
2393 ! tags...
2394 A string starting with an exclamation mark specifies
2395 names of tags that are not to be used. The effect is the
2396 same as if all other possible tags for the context had
2397 been listed.
2398
2399 tag:label ...
2400 Here, tag is one of the standard tags and label is an ar‐
2401 bitrary name. Matches are generated as normal but the
2402 name label is used in contexts instead of tag. This is
2403 not useful in words starting with !.
2404
2405 If the label starts with a hyphen, the tag is prepended
2406 to the label to form the name used for lookup. This can
2407 be used to make the completion system try a certain tag
2408 more than once, supplying different style settings for
2409 each attempt; see below for an example.
2410
2411 tag:label:description
2412 As before, but description will replace the `%d' in the
2413 value of the format style instead of the default descrip‐
2414 tion supplied by the completion function. Spaces in the
2415 description must be quoted with a backslash. A `%d' ap‐
2416 pearing in description is replaced with the description
2417 given by the completion function.
2418
2419 In any of the forms above the tag may be a pattern or several
2420 patterns in the form `{pat1,pat2...}'. In this case all match‐
2421 ing tags will be used except for any given explicitly in the
2422 same string.
2423
2424 One use of these features is to try one tag more than once, set‐
2425 ting other styles differently on each attempt, but still to use
2426 all the other tags without having to repeat them all. For exam‐
2427 ple, to make completion of function names in command position
2428 ignore all the completion functions starting with an underscore
2429 the first time completion is tried:
2430
2431 zstyle ':completion:*:*:-command-:*:*' tag-order \
2432 'functions:-non-comp *' functions
2433 zstyle ':completion:*:functions-non-comp' \
2434 ignored-patterns '_*'
2435
2436 On the first attempt, all tags will be offered but the functions
2437 tag will be replaced by functions-non-comp. The ignored-pat‐
2438 terns style is set for this tag to exclude functions starting
2439 with an underscore. If there are no matches, the second value
2440 of the tag-order style is used which completes functions using
2441 the default tag, this time presumably including all function
2442 names.
2443
2444 The matches for one tag can be split into different groups. For
2445 example:
2446
2447 zstyle ':completion:*' tag-order \
2448 'options:-long:long\ options
2449 options:-short:short\ options
2450 options:-single-letter:single\ letter\ options'
2451 zstyle ':completion:*:options-long' \
2452 ignored-patterns '[-+](|-|[^-]*)'
2453 zstyle ':completion:*:options-short' \
2454 ignored-patterns '--*' '[-+]?'
2455 zstyle ':completion:*:options-single-letter' \
2456 ignored-patterns '???*'
2457
2458 With the group-names style set, options beginning with `--', op‐
2459 tions beginning with a single `-' or `+' but containing multiple
2460 characters, and single-letter options will be displayed in sepa‐
2461 rate groups with different descriptions.
2462
2463 Another use of patterns is to try multiple match specifications
2464 one after another. The matcher-list style offers something sim‐
2465 ilar, but it is tested very early in the completion system and
2466 hence can't be set for single commands nor for more specific
2467 contexts. Here is how to try normal completion without any
2468 match specification and, if that generates no matches, try again
2469 with case-insensitive matching, restricting the effect to argu‐
2470 ments of the command foo:
2471
2472 zstyle ':completion:*:*:foo:*:*' tag-order '*' '*:-case'
2473 zstyle ':completion:*-case' matcher 'm:{a-z}={A-Z}'
2474
2475 First, all the tags offered when completing after foo are tried
2476 using the normal tag name. If that generates no matches, the
2477 second value of tag-order is used, which tries all tags again
2478 except that this time each has -case appended to its name for
2479 lookup of styles. Hence this time the value for the matcher
2480 style from the second call to zstyle in the example is used to
2481 make completion case-insensitive.
2482
2483 It is possible to use the -e option of the zstyle builtin com‐
2484 mand to specify conditions for the use of particular tags. For
2485 example:
2486
2487 zstyle -e '*:-command-:*' tag-order '
2488 if [[ -n $PREFIX$SUFFIX ]]; then
2489 reply=( )
2490 else
2491 reply=( - )
2492 fi'
2493
2494 Completion in command position will be attempted only if the
2495 string typed so far is not empty. This is tested using the PRE‐
2496 FIX special parameter; see zshcompwid for a description of pa‐
2497 rameters which are special inside completion widgets. Setting
2498 reply to an empty array provides the default behaviour of trying
2499 all tags at once; setting it to an array containing only a hy‐
2500 phen disables the use of all tags and hence of all completions.
2501
2502 If no tag-order style has been defined for a context, the
2503 strings `(|*-)argument-* (|*-)option-* values' and `options'
2504 plus all tags offered by the completion function will be used to
2505 provide a sensible default behavior that causes arguments
2506 (whether normal command arguments or arguments of options) to be
2507 completed before option names for most commands.
2508
2509 urls This is used together with the urls tag by functions completing
2510 URLs.
2511
2512 If the value consists of more than one string, or if the only
2513 string does not name a file or directory, the strings are used
2514 as the URLs to complete.
2515
2516 If the value contains only one string which is the name of a
2517 normal file the URLs are taken from that file (where the URLs
2518 may be separated by white space or newlines).
2519
2520 Finally, if the only string in the value names a directory, the
2521 directory hierarchy rooted at this directory gives the comple‐
2522 tions. The top level directory should be the file access
2523 method, such as `http', `ftp', `bookmark' and so on. In many
2524 cases the next level of directories will be a filename. The di‐
2525 rectory hierarchy can descend as deep as necessary.
2526
2527 For example,
2528
2529 zstyle ':completion:*' urls ~/.urls
2530 mkdir -p ~/.urls/ftp/ftp.zsh.org/pub
2531
2532 allows completion of all the components of the URL
2533 ftp://ftp.zsh.org/pub after suitable commands such as `netscape'
2534 or `lynx'. Note, however, that access methods and files are
2535 completed separately, so if the hosts style is set hosts can be
2536 completed without reference to the urls style.
2537
2538 See the description in the function _urls itself for more infor‐
2539 mation (e.g. `more $^fpath/_urls(N)').
2540
2541 use-cache
2542 If this is set, the completion caching layer is activated for
2543 any completions which use it (via the _store_cache, _re‐
2544 trieve_cache, and _cache_invalid functions). The directory con‐
2545 taining the cache files can be changed with the cache-path
2546 style.
2547
2548 use-compctl
2549 If this style is set to a string not equal to false, 0, no, and
2550 off, the completion system may use any completion specifications
2551 defined with the compctl builtin command. If the style is un‐
2552 set, this is done only if the zsh/compctl module is loaded. The
2553 string may also contain the substring `first' to use completions
2554 defined with `compctl -T', and the substring `default' to use
2555 the completion defined with `compctl -D'.
2556
2557 Note that this is only intended to smooth the transition from
2558 compctl to the new completion system and may disappear in the
2559 future.
2560
2561 Note also that the definitions from compctl will only be used if
2562 there is no specific completion function for the command in
2563 question. For example, if there is a function _foo to complete
2564 arguments to the command foo, compctl will never be invoked for
2565 foo. However, the compctl version will be tried if foo only
2566 uses default completion.
2567
2568 use-ip By default, the function _hosts that completes host names strips
2569 IP addresses from entries read from host databases such as NIS
2570 and ssh files. If this style is `true', the corresponding IP
2571 addresses can be completed as well. This style is not use in
2572 any context where the hosts style is set; note also it must be
2573 set before the cache of host names is generated (typically the
2574 first completion attempt).
2575
2576 users This may be set to a list of usernames to be completed. If it
2577 is not set all usernames will be completed. Note that if it is
2578 set only that list of users will be completed; this is because
2579 on some systems querying all users can take a prohibitive amount
2580 of time.
2581
2582 users-hosts
2583 The values of this style should be of the form `user@host' or
2584 `user:host'. It is used for commands that need pairs of user-
2585 and hostnames. These commands will complete usernames from this
2586 style (only), and will restrict subsequent hostname completion
2587 to hosts paired with that user in one of the values of the
2588 style.
2589
2590 It is possible to group values for sets of commands which allow
2591 a remote login, such as rlogin and ssh, by using the my-accounts
2592 tag. Similarly, values for sets of commands which usually refer
2593 to the accounts of other people, such as talk and finger, can be
2594 grouped by using the other-accounts tag. More ambivalent com‐
2595 mands may use the accounts tag.
2596
2597 users-hosts-ports
2598 Like users-hosts but used for commands like telnet and contain‐
2599 ing strings of the form `user@host:port'.
2600
2601 verbose
2602 If set, as it is by default, the completion listing is more ver‐
2603 bose. In particular many commands show descriptions for options
2604 if this style is `true'.
2605
2606 word This is used by the _list completer, which prevents the inser‐
2607 tion of completions until a second completion attempt when the
2608 line has not changed. The normal way of finding out if the line
2609 has changed is to compare its entire contents between the two
2610 occasions. If this style is `true', the comparison is instead
2611 performed only on the current word. Hence if completion is per‐
2612 formed on another word with the same contents, completion will
2613 not be delayed.
2614
2616 The initialization script compinit redefines all the widgets which per‐
2617 form completion to call the supplied widget function _main_complete.
2618 This function acts as a wrapper calling the so-called `completer' func‐
2619 tions that generate matches. If _main_complete is called with argu‐
2620 ments, these are taken as the names of completer functions to be called
2621 in the order given. If no arguments are given, the set of functions to
2622 try is taken from the completer style. For example, to use normal com‐
2623 pletion and correction if that doesn't generate any matches:
2624
2625 zstyle ':completion:*' completer _complete _correct
2626
2627 after calling compinit. The default value for this style is `_complete
2628 _ignored', i.e. normally only ordinary completion is tried, first with
2629 the effect of the ignored-patterns style and then without it. The
2630 _main_complete function uses the return status of the completer func‐
2631 tions to decide if other completers should be called. If the return
2632 status is zero, no other completers are tried and the _main_complete
2633 function returns.
2634
2635 If the first argument to _main_complete is a single hyphen, the argu‐
2636 ments will not be taken as names of completers. Instead, the second
2637 argument gives a name to use in the completer field of the context and
2638 the other arguments give a command name and arguments to call to gener‐
2639 ate the matches.
2640
2641 The following completer functions are contained in the distribution,
2642 although users may write their own. Note that in contexts the leading
2643 underscore is stripped, for example basic completion is performed in
2644 the context `:completion::complete:...'.
2645
2646 _all_matches
2647 This completer can be used to add a string consisting of all
2648 other matches. As it influences later completers it must appear
2649 as the first completer in the list. The list of all matches is
2650 affected by the avoid-completer and old-matches styles described
2651 above.
2652
2653 It may be useful to use the _generic function described below to
2654 bind _all_matches to its own keystroke, for example:
2655
2656 zle -C all-matches complete-word _generic
2657 bindkey '^Xa' all-matches
2658 zstyle ':completion:all-matches:*' old-matches only
2659 zstyle ':completion:all-matches::::' completer _all_matches
2660
2661 Note that this does not generate completions by itself: first
2662 use any of the standard ways of generating a list of comple‐
2663 tions, then use ^Xa to show all matches. It is possible instead
2664 to add a standard completer to the list and request that the
2665 list of all matches should be directly inserted:
2666
2667 zstyle ':completion:all-matches::::' completer \
2668 _all_matches _complete
2669 zstyle ':completion:all-matches:*' insert true
2670
2671 In this case the old-matches style should not be set.
2672
2673 _approximate
2674 This is similar to the basic _complete completer but allows the
2675 completions to undergo corrections. The maximum number of er‐
2676 rors can be specified by the max-errors style; see the descrip‐
2677 tion of approximate matching in zshexpn(1) for how errors are
2678 counted. Normally this completer will only be tried after the
2679 normal _complete completer:
2680
2681 zstyle ':completion:*' completer _complete _approximate
2682
2683 This will give correcting completion if and only if normal com‐
2684 pletion yields no possible completions. When corrected comple‐
2685 tions are found, the completer will normally start menu comple‐
2686 tion allowing you to cycle through these strings.
2687
2688 This completer uses the tags corrections and original when gen‐
2689 erating the possible corrections and the original string. The
2690 format style for the former may contain the additional sequences
2691 `%e' and `%o' which will be replaced by the number of errors ac‐
2692 cepted to generate the corrections and the original string, re‐
2693 spectively.
2694
2695 The completer progressively increases the number of errors al‐
2696 lowed up to the limit by the max-errors style, hence if a com‐
2697 pletion is found with one error, no completions with two errors
2698 will be shown, and so on. It modifies the completer name in the
2699 context to indicate the number of errors being tried: on the
2700 first try the completer field contains `approximate-1', on the
2701 second try `approximate-2', and so on.
2702
2703 When _approximate is called from another function, the number of
2704 errors to accept may be passed with the -a option. The argument
2705 is in the same format as the max-errors style, all in one
2706 string.
2707
2708 Note that this completer (and the _correct completer mentioned
2709 below) can be quite expensive to call, especially when a large
2710 number of errors are allowed. One way to avoid this is to set
2711 up the completer style using the -e option to zstyle so that
2712 some completers are only used when completion is attempted a
2713 second time on the same string, e.g.:
2714
2715 zstyle -e ':completion:*' completer '
2716 if [[ $_last_try != "$HISTNO$BUFFER$CURSOR" ]]; then
2717 _last_try="$HISTNO$BUFFER$CURSOR"
2718 reply=(_complete _match _prefix)
2719 else
2720 reply=(_ignored _correct _approximate)
2721 fi'
2722
2723 This uses the HISTNO parameter and the BUFFER and CURSOR special
2724 parameters that are available inside zle and completion widgets
2725 to find out if the command line hasn't changed since the last
2726 time completion was tried. Only then are the _ignored, _correct
2727 and _approximate completers called.
2728
2729 _canonical_paths [ -A var ] [ -N ] [ -MJV12nfX ] tag descr [ paths ...
2730 ]
2731 This completion function completes all paths given to it, and
2732 also tries to offer completions which point to the same file as
2733 one of the paths given (relative path when an absolute path is
2734 given, and vice versa; when ..'s are present in the word to be
2735 completed; and some paths got from symlinks).
2736
2737 -A, if specified, takes the paths from the array variable speci‐
2738 fied. Paths can also be specified on the command line as shown
2739 above. -N, if specified, prevents canonicalizing the paths
2740 given before using them for completion, in case they are already
2741 so. The options -M, -J, -V, -1, -2, -n, -F, -X are passed to
2742 compadd.
2743
2744 See _description for a description of tag and descr.
2745
2746 _cmdambivalent
2747 Completes the remaining positional arguments as an external com‐
2748 mand. The external command and its arguments are completed as
2749 separate arguments (in a manner appropriate for completing
2750 /usr/bin/env) if there are two or more remaining positional ar‐
2751 guments on the command line, and as a quoted command string (in
2752 the manner of system(...)) otherwise. See also _cmdstring and
2753 _precommand.
2754
2755 This function takes no arguments.
2756
2757 _cmdstring
2758 Completes an external command as a single argument, as for sys‐
2759 tem(...).
2760
2761 _complete
2762 This completer generates all possible completions in a con‐
2763 text-sensitive manner, i.e. using the settings defined with the
2764 compdef function explained above and the current settings of all
2765 special parameters. This gives the normal completion behaviour.
2766
2767 To complete arguments of commands, _complete uses the utility
2768 function _normal, which is in turn responsible for finding the
2769 particular function; it is described below. Various contexts of
2770 the form -context- are handled specifically. These are all men‐
2771 tioned above as possible arguments to the #compdef tag.
2772
2773 Before trying to find a function for a specific context, _com‐
2774 plete checks if the parameter `compcontext' is set. Setting
2775 `compcontext' allows the usual completion dispatching to be
2776 overridden which is useful in places such as a function that
2777 uses vared for input. If it is set to an array, the elements are
2778 taken to be the possible matches which will be completed using
2779 the tag `values' and the description `value'. If it is set to an
2780 associative array, the keys are used as the possible completions
2781 and the values (if non-empty) are used as descriptions for the
2782 matches. If `compcontext' is set to a string containing colons,
2783 it should be of the form `tag:descr:action'. In this case the
2784 tag and descr give the tag and description to use and the action
2785 indicates what should be completed in one of the forms accepted
2786 by the _arguments utility function described below.
2787
2788 Finally, if `compcontext' is set to a string without colons, the
2789 value is taken as the name of the context to use and the func‐
2790 tion defined for that context will be called. For this purpose,
2791 there is a special context named -command-line- that completes
2792 whole command lines (commands and their arguments). This is not
2793 used by the completion system itself but is nonetheless handled
2794 when explicitly called.
2795
2796 _correct
2797 Generate corrections, but not completions, for the current word;
2798 this is similar to _approximate but will not allow any number of
2799 extra characters at the cursor as that completer does. The ef‐
2800 fect is similar to spell-checking. It is based on _approximate,
2801 but the completer field in the context name is correct.
2802
2803 For example, with:
2804
2805 zstyle ':completion:::::' completer \
2806 _complete _correct _approximate
2807 zstyle ':completion:*:correct:::' max-errors 2 not-numeric
2808 zstyle ':completion:*:approximate:::' max-errors 3 numeric
2809
2810 correction will accept up to two errors. If a numeric argument
2811 is given, correction will not be performed, but correcting com‐
2812 pletion will be, and will accept as many errors as given by the
2813 numeric argument. Without a numeric argument, first correction
2814 and then correcting completion will be tried, with the first one
2815 accepting two errors and the second one accepting three errors.
2816
2817 When _correct is called as a function, the number of errors to
2818 accept may be given following the -a option. The argument is in
2819 the same form a values to the accept style, all in one string.
2820
2821 This completer function is intended to be used without the _ap‐
2822 proximate completer or, as in the example, just before it. Us‐
2823 ing it after the _approximate completer is useless since _ap‐
2824 proximate will at least generate the corrected strings generated
2825 by the _correct completer -- and probably more.
2826
2827 _expand
2828 This completer function does not really perform completion, but
2829 instead checks if the word on the command line is eligible for
2830 expansion and, if it is, gives detailed control over how this
2831 expansion is done. For this to happen, the completion system
2832 needs to be invoked with complete-word, not expand-or-complete
2833 (the default binding for TAB), as otherwise the string will be
2834 expanded by the shell's internal mechanism before the completion
2835 system is started. Note also this completer should be called
2836 before the _complete completer function.
2837
2838 The tags used when generating expansions are all-expansions for
2839 the string containing all possible expansions, expansions when
2840 adding the possible expansions as single matches and original
2841 when adding the original string from the line. The order in
2842 which these strings are generated, if at all, can be controlled
2843 by the group-order and tag-order styles, as usual.
2844
2845 The format string for all-expansions and for expansions may con‐
2846 tain the sequence `%o' which will be replaced by the original
2847 string from the line.
2848
2849 The kind of expansion to be tried is controlled by the substi‐
2850 tute, glob and subst-globs-only styles.
2851
2852 It is also possible to call _expand as a function, in which case
2853 the different modes may be selected with options: -s for substi‐
2854 tute, -g for glob and -o for subst-globs-only.
2855
2856 _expand_alias
2857 If the word the cursor is on is an alias, it is expanded and no
2858 other completers are called. The types of aliases which are to
2859 be expanded can be controlled with the styles regular, global
2860 and disabled.
2861
2862 This function is also a bindable command, see the section `Bind‐
2863 able Commands' below.
2864
2865 _extensions
2866 If the cursor follows the string `*.', filename extensions are
2867 completed. The extensions are taken from files in current direc‐
2868 tory or a directory specified at the beginning of the current
2869 word. For exact matches, completion continues to allow other
2870 completers such as _expand to expand the pattern. The standard
2871 add-space and prefix-hidden styles are observed.
2872
2873 _external_pwds
2874 Completes current directories of other zsh processes belonging
2875 to the current user.
2876
2877 This is intended to be used via _generic, bound to a custom key
2878 combination. Note that pattern matching is enabled so matching
2879 is performed similar to how it works with the _match completer.
2880
2881 _history
2882 Complete words from the shell's command history. This com‐
2883 pleter can be controlled by the remove-all-dups, and sort styles
2884 as for the _history_complete_word bindable command, see the sec‐
2885 tion `Bindable Commands' below and the section `Completion Sys‐
2886 tem Configuration' above.
2887
2888 _ignored
2889 The ignored-patterns style can be set to a list of patterns
2890 which are compared against possible completions; matching ones
2891 are removed. With this completer those matches can be rein‐
2892 stated, as if no ignored-patterns style were set. The completer
2893 actually generates its own list of matches; which completers are
2894 invoked is determined in the same way as for the _prefix com‐
2895 pleter. The single-ignored style is also available as described
2896 above.
2897
2898 _list This completer allows the insertion of matches to be delayed un‐
2899 til completion is attempted a second time without the word on
2900 the line being changed. On the first attempt, only the list of
2901 matches will be shown. It is affected by the styles condition
2902 and word, see the section `Completion System Configuration'
2903 above.
2904
2905 _match This completer is intended to be used after the _complete com‐
2906 pleter. It behaves similarly but the string on the command line
2907 may be a pattern to match against trial completions. This gives
2908 the effect of the GLOB_COMPLETE option.
2909
2910 Normally completion will be performed by taking the pattern from
2911 the line, inserting a `*' at the cursor position and comparing
2912 the resulting pattern with the possible completions generated.
2913 This can be modified with the match-original style described
2914 above.
2915
2916 The generated matches will be offered in a menu completion un‐
2917 less the insert-unambiguous style is set to `true'; see the de‐
2918 scription above for other options for this style.
2919
2920 Note that matcher specifications defined globally or used by the
2921 completion functions (the styles matcher-list and matcher) will
2922 not be used.
2923
2924 _menu This completer was written as simple example function to show
2925 how menu completion can be enabled in shell code. However, it
2926 has the notable effect of disabling menu selection which can be
2927 useful with _generic based widgets. It should be used as the
2928 first completer in the list. Note that this is independent of
2929 the setting of the MENU_COMPLETE option and does not work with
2930 the other menu completion widgets such as reverse-menu-complete,
2931 or accept-and-menu-complete.
2932
2933 _oldlist
2934 This completer controls how the standard completion widgets be‐
2935 have when there is an existing list of completions which may
2936 have been generated by a special completion (i.e. a sepa‐
2937 rately-bound completion command). It allows the ordinary com‐
2938 pletion keys to continue to use the list of completions thus
2939 generated, instead of producing a new list of ordinary contex‐
2940 tual completions. It should appear in the list of completers
2941 before any of the widgets which generate matches. It uses two
2942 styles: old-list and old-menu, see the section `Completion Sys‐
2943 tem Configuration' above.
2944
2945 _precommand
2946 Complete an external command in word-separated arguments, as for
2947 exec and /usr/bin/env.
2948
2949 _prefix
2950 This completer can be used to try completion with the suffix
2951 (everything after the cursor) ignored. In other words, the suf‐
2952 fix will not be considered to be part of the word to complete.
2953 The effect is similar to the expand-or-complete-prefix command.
2954
2955 The completer style is used to decide which other completers are
2956 to be called to generate matches. If this style is unset, the
2957 list of completers set for the current context is used -- ex‐
2958 cept, of course, the _prefix completer itself. Furthermore, if
2959 this completer appears more than once in the list of completers
2960 only those completers not already tried by the last invocation
2961 of _prefix will be called.
2962
2963 For example, consider this global completer style:
2964
2965 zstyle ':completion:*' completer \
2966 _complete _prefix _correct _prefix:foo
2967
2968 Here, the _prefix completer tries normal completion but ignoring
2969 the suffix. If that doesn't generate any matches, and neither
2970 does the call to the _correct completer after it, _prefix will
2971 be called a second time and, now only trying correction with the
2972 suffix ignored. On the second invocation the completer part of
2973 the context appears as `foo'.
2974
2975 To use _prefix as the last resort and try only normal completion
2976 when it is invoked:
2977
2978 zstyle ':completion:*' completer _complete ... _prefix
2979 zstyle ':completion::prefix:*' completer _complete
2980
2981 The add-space style is also respected. If it is set to `true'
2982 then _prefix will insert a space between the matches generated
2983 (if any) and the suffix.
2984
2985 Note that this completer is only useful if the COMPLETE_IN_WORD
2986 option is set; otherwise, the cursor will be moved to the end of
2987 the current word before the completion code is called and hence
2988 there will be no suffix.
2989
2990 _user_expand
2991 This completer behaves similarly to the _expand completer but
2992 instead performs expansions defined by users. The styles
2993 add-space and sort styles specific to the _expand completer are
2994 usable with _user_expand in addition to other styles handled
2995 more generally by the completion system. The tag all-expansions
2996 is also available.
2997
2998 The expansion depends on the array style user-expand being de‐
2999 fined for the current context; remember that the context for
3000 completers is less specific than that for contextual completion
3001 as the full context has not yet been determined. Elements of
3002 the array may have one of the following forms:
3003
3004 $hash
3005
3006 hash is the name of an associative array. Note this is
3007 not a full parameter expression, merely a $, suitably
3008 quoted to prevent immediate expansion, followed by the
3009 name of an associative array. If the trial expansion
3010 word matches a key in hash, the resulting expansion is
3011 the corresponding value.
3012 _func
3013
3014 _func is the name of a shell function whose name must be‐
3015 gin with _ but is not otherwise special to the completion
3016 system. The function is called with the trial word as an
3017 argument. If the word is to be expanded, the function
3018 should set the array reply to a list of expansions. Op‐
3019 tionally, it can set REPLY to a word that will be used as
3020 a description for the set of expansions. The return sta‐
3021 tus of the function is irrelevant.
3023 In addition to the context-dependent completions provided, which are
3024 expected to work in an intuitively obvious way, there are a few widgets
3025 implementing special behaviour which can be bound separately to keys.
3026 The following is a list of these and their default bindings.
3027
3028 _bash_completions
3029 This function is used by two widgets, _bash_complete-word and
3030 _bash_list-choices. It exists to provide compatibility with
3031 completion bindings in bash. The last character of the binding
3032 determines what is completed: `!', command names; `$', environ‐
3033 ment variables; `@', host names; `/', file names; `~' user
3034 names. In bash, the binding preceded by `\e' gives completion,
3035 and preceded by `^X' lists options. As some of these bindings
3036 clash with standard zsh bindings, only `\e~' and `^X~' are bound
3037 by default. To add the rest, the following should be added to
3038 .zshrc after compinit has been run:
3039
3040 for key in '!' '$' '@' '/' '~'; do
3041 bindkey "\e$key" _bash_complete-word
3042 bindkey "^X$key" _bash_list-choices
3043 done
3044
3045 This includes the bindings for `~' in case they were already
3046 bound to something else; the completion code does not override
3047 user bindings.
3048
3049 _correct_filename (^XC)
3050 Correct the filename path at the cursor position. Allows up to
3051 six errors in the name. Can also be called with an argument to
3052 correct a filename path, independently of zle; the correction is
3053 printed on standard output.
3054
3055 _correct_word (^Xc)
3056 Performs correction of the current argument using the usual con‐
3057 textual completions as possible choices. This stores the string
3058 `correct-word' in the function field of the context name and
3059 then calls the _correct completer.
3060
3061 _expand_alias (^Xa)
3062 This function can be used as a completer and as a bindable com‐
3063 mand. It expands the word the cursor is on if it is an alias.
3064 The types of alias expanded can be controlled with the styles
3065 regular, global and disabled.
3066
3067 When used as a bindable command there is one additional feature
3068 that can be selected by setting the complete style to `true'.
3069 In this case, if the word is not the name of an alias, _ex‐
3070 pand_alias tries to complete the word to a full alias name with‐
3071 out expanding it. It leaves the cursor directly after the com‐
3072 pleted word so that invoking _expand_alias once more will expand
3073 the now-complete alias name.
3074
3075 _expand_word (^Xe)
3076 Performs expansion on the current word: equivalent to the stan‐
3077 dard expand-word command, but using the _expand completer. Be‐
3078 fore calling it, the function field of the context is set to
3079 `expand-word'.
3080
3081 _generic
3082 This function is not defined as a widget and not bound by de‐
3083 fault. However, it can be used to define a widget and will then
3084 store the name of the widget in the function field of the con‐
3085 text and call the completion system. This allows custom comple‐
3086 tion widgets with their own set of style settings to be defined
3087 easily. For example, to define a widget that performs normal
3088 completion and starts menu selection:
3089
3090 zle -C foo complete-word _generic
3091 bindkey '...' foo
3092 zstyle ':completion:foo:*' menu yes select=1
3093
3094 Note in particular that the completer style may be set for the
3095 context in order to change the set of functions used to generate
3096 possible matches. If _generic is called with arguments, those
3097 are passed through to _main_complete as the list of completers
3098 in place of those defined by the completer style.
3099
3100 _history_complete_word (\e/)
3101 Complete words from the shell's command history. This uses the
3102 list, remove-all-dups, sort, and stop styles.
3103
3104 _most_recent_file (^Xm)
3105 Complete the name of the most recently modified file matching
3106 the pattern on the command line (which may be blank). If given
3107 a numeric argument N, complete the Nth most recently modified
3108 file. Note the completion, if any, is always unique.
3109
3110 _next_tags (^Xn)
3111 This command alters the set of matches used to that for the next
3112 tag, or set of tags, either as given by the tag-order style or
3113 as set by default; these matches would otherwise not be avail‐
3114 able. Successive invocations of the command cycle through all
3115 possible sets of tags.
3116
3117 _read_comp (^X^R)
3118 Prompt the user for a string, and use that to perform completion
3119 on the current word. There are two possibilities for the
3120 string. First, it can be a set of words beginning `_', for ex‐
3121 ample `_files -/', in which case the function with any arguments
3122 will be called to generate the completions. Unambiguous parts
3123 of the function name will be completed automatically (normal
3124 completion is not available at this point) until a space is
3125 typed.
3126
3127 Second, any other string will be passed as a set of arguments to
3128 compadd and should hence be an expression specifying what should
3129 be completed.
3130
3131 A very restricted set of editing commands is available when
3132 reading the string: `DEL' and `^H' delete the last character;
3133 `^U' deletes the line, and `^C' and `^G' abort the function,
3134 while `RET' accepts the completion. Note the string is used
3135 verbatim as a command line, so arguments must be quoted in ac‐
3136 cordance with standard shell rules.
3137
3138 Once a string has been read, the next call to _read_comp will
3139 use the existing string instead of reading a new one. To force
3140 a new string to be read, call _read_comp with a numeric argu‐
3141 ment.
3142
3143 _complete_debug (^X?)
3144 This widget performs ordinary completion, but captures in a tem‐
3145 porary file a trace of the shell commands executed by the com‐
3146 pletion system. Each completion attempt gets its own file. A
3147 command to view each of these files is pushed onto the editor
3148 buffer stack.
3149
3150 _complete_help (^Xh)
3151 This widget displays information about the context names, the
3152 tags, and the completion functions used when completing at the
3153 current cursor position. If given a numeric argument other than
3154 1 (as in `ESC-2 ^Xh'), then the styles used and the contexts for
3155 which they are used will be shown, too.
3156
3157 Note that the information about styles may be incomplete; it de‐
3158 pends on the information available from the completion functions
3159 called, which in turn is determined by the user's own styles and
3160 other settings.
3161
3162 _complete_help_generic
3163 Unlike other commands listed here, this must be created as a
3164 normal ZLE widget rather than a completion widget (i.e. with zle
3165 -N). It is used for generating help with a widget bound to the
3166 _generic widget that is described above.
3167
3168 If this widget is created using the name of the function, as it
3169 is by default, then when executed it will read a key sequence.
3170 This is expected to be bound to a call to a completion function
3171 that uses the _generic widget. That widget will be executed,
3172 and information provided in the same format that the _com‐
3173 plete_help widget displays for contextual completion.
3174
3175 If the widget's name contains debug, for example if it is cre‐
3176 ated as `zle -N _complete_debug_generic _complete_help_generic',
3177 it will read and execute the keystring for a generic widget as
3178 before, but then generate debugging information as done by _com‐
3179 plete_debug for contextual completion.
3180
3181 If the widget's name contains noread, it will not read a
3182 keystring but instead arrange that the next use of a generic
3183 widget run in the same shell will have the effect as described
3184 above.
3185
3186 The widget works by setting the shell parameter
3187 ZSH_TRACE_GENERIC_WIDGET which is read by _generic. Unsetting
3188 the parameter cancels any pending effect of the noread form.
3189
3190 For example, after executing the following:
3191
3192 zle -N _complete_debug_generic _complete_help_generic
3193 bindkey '^x:' _complete_debug_generic
3194
3195 typing `C-x :' followed by the key sequence for a generic widget
3196 will cause trace output for that widget to be saved to a file.
3197
3198 _complete_tag (^Xt)
3199 This widget completes symbol tags created by the etags or ctags
3200 programmes (note there is no connection with the completion sys‐
3201 tem's tags) stored in a file TAGS, in the format used by etags,
3202 or tags, in the format created by ctags. It will look back up
3203 the path hierarchy for the first occurrence of either file; if
3204 both exist, the file TAGS is preferred. You can specify the
3205 full path to a TAGS or tags file by setting the parameter $TAGS‐
3206 FILE or $tagsfile respectively. The corresponding completion
3207 tags used are etags and vtags, after emacs and vi respectively.
3208
3210 Descriptions follow for utility functions that may be useful when writ‐
3211 ing completion functions. If functions are installed in subdirecto‐
3212 ries, most of these reside in the Base subdirectory. Like the example
3213 functions for commands in the distribution, the utility functions gen‐
3214 erating matches all follow the convention of returning status zero if
3215 they generated completions and non-zero if no matching completions
3216 could be added.
3217
3218 _absolute_command_paths
3219 This function completes external commands as absolute paths (un‐
3220 like _command_names -e which completes their basenames). It
3221 takes no arguments.
3222
3223 _all_labels [ -x ] [ -12VJ ] tag name descr [ command arg ... ]
3224 This is a convenient interface to the _next_label function be‐
3225 low, implementing the loop shown in the _next_label example.
3226 The command and its arguments are called to generate the
3227 matches. The options stored in the parameter name will automat‐
3228 ically be inserted into the args passed to the command. Nor‐
3229 mally, they are put directly after the command, but if one of
3230 the args is a single hyphen, they are inserted directly before
3231 that. If the hyphen is the last argument, it will be removed
3232 from the argument list before the command is called. This al‐
3233 lows _all_labels to be used in almost all cases where the
3234 matches can be generated by a single call to the compadd builtin
3235 command or by a call to one of the utility functions.
3236
3237 For example:
3238
3239 local expl
3240 ...
3241 if _requested foo; then
3242 ...
3243 _all_labels foo expl '...' compadd ... - $matches
3244 fi
3245
3246 Will complete the strings from the matches parameter, using com‐
3247 padd with additional options which will take precedence over
3248 those generated by _all_labels.
3249
3250 _alternative [ -O name ] [ -C name ] spec ...
3251 This function is useful in simple cases where multiple tags are
3252 available. Essentially it implements a loop like the one de‐
3253 scribed for the _tags function below.
3254
3255 The tags to use and the action to perform if a tag is requested
3256 are described using the specs which are of the form: `tag:de‐
3257 scr:action'. The tags are offered using _tags and if the tag is
3258 requested, the action is executed with the given description de‐
3259 scr. The actions are those accepted by the _arguments function
3260 (described below), with the following exceptions:
3261 • The `->state' and `=...' forms are not supported.
3262
3263
3264 • The `((a\:bar b\:baz))' form does not need the colon to
3265 be escaped, since the specs have no colon-separated
3266 fields after the action.
3267
3268
3269 For example, the action may be a simple function call:
3270
3271 _alternative \
3272 'users:user:_users' \
3273 'hosts:host:_hosts'
3274
3275 offers usernames and hostnames as possible matches, generated by
3276 the _users and _hosts functions respectively.
3277
3278 Like _arguments, this function uses _all_labels to execute the
3279 actions, which will loop over all sets of tags. Special han‐
3280 dling is only required if there is an additional valid tag, for
3281 example inside a function called from _alternative.
3282
3283 The option `-O name' is used in the same way as by the _argu‐
3284 ments function. In other words, the elements of the name array
3285 will be passed to compadd when executing an action.
3286
3287 Like _tags this function supports the -C option to give a dif‐
3288 ferent name for the argument context field.
3289
3290
3291 _arguments [ -nswWCRS ] [ -A pat ] [ -O name ] [ -M matchspec ]
3292 [ : ] spec ...
3293 _arguments [ opt ... ] -- [ -l ] [ -i pats ] [ -s pair ]
3294 [ helpspec ...]
3295 This function can be used to give a complete specification for
3296 completion for a command whose arguments follow standard UNIX
3297 option and argument conventions.
3298
3299 Options Overview
3300
3301 Options to _arguments itself must be in separate words, i.e. -s
3302 -w, not -sw. The options are followed by specs that describe
3303 options and arguments of the analyzed command. To avoid ambigu‐
3304 ity, all options to _arguments itself may be separated from the
3305 spec forms by a single colon.
3306
3307 The `--' form is used to intuit spec forms from the help output
3308 of the command being analyzed, and is described in detail below.
3309 The opts for the `--' form are otherwise the same options as the
3310 first form. Note that `-s' following `--' has a distinct mean‐
3311 ing from `-s' preceding `--', and both may appear.
3312
3313 The option switches -s, -S, -A, -w, and -W affect how _arguments
3314 parses the analyzed command line's options. These switches are
3315 useful for commands with standard argument parsing.
3316
3317 The options of _arguments have the following meanings:
3318
3319 -n With this option, _arguments sets the parameter NORMARG
3320 to the position of the first normal argument in the
3321 $words array, i.e. the position after the end of the op‐
3322 tions. If that argument has not been reached, NORMARG is
3323 set to -1. The caller should declare `integer NORMARG'
3324 if the -n option is passed; otherwise the parameter is
3325 not used.
3326
3327 -s Enable option stacking for single-letter options, whereby
3328 multiple single-letter options may be combined into a
3329 single word. For example, the two options `-x' and `-y'
3330 may be combined into a single word `-xy'. By default,
3331 every word corresponds to a single option name (`-xy' is
3332 a single option named `xy').
3333
3334 Options beginning with a single hyphen or plus sign are
3335 eligible for stacking; words beginning with two hyphens
3336 are not.
3337
3338 Note that -s after -- has a different meaning, which is
3339 documented in the segment entitled `Deriving spec forms
3340 from the help output'.
3341
3342 -w In combination with -s, allow option stacking even if one
3343 or more of the options take arguments. For example, if
3344 -x takes an argument, with no -s, `-xy' is considered as
3345 a single (unhandled) option; with -s, -xy is an option
3346 with the argument `y'; with both -s and -w, -xy is the
3347 option -x and the option -y with arguments to -x (and to
3348 -y, if it takes arguments) still to come in subsequent
3349 words.
3350
3351 -W This option takes -w a stage further: it is possible to
3352 complete single-letter options even after an argument
3353 that occurs in the same word. However, it depends on the
3354 action performed whether options will really be completed
3355 at this point. For more control, use a utility function
3356 like _guard as part of the action.
3357
3358 -C Modify the curcontext parameter for an action of the form
3359 `->state'. This is discussed in detail below.
3360
3361 -R Return status 300 instead of zero when a $state is to be
3362 handled, in the `->string' syntax.
3363
3364 -S Do not complete options after a `--' appearing on the
3365 line, and ignore the `--'. For example, with -S, in the
3366 line
3367
3368 foobar -x -- -y
3369
3370 the `-x' is considered an option, the `-y' is considered
3371 an argument, and the `--' is considered to be neither.
3372
3373 -A pat Do not complete options after the first non-option argu‐
3374 ment on the line. pat is a pattern matching all strings
3375 which are not to be taken as arguments. For example, to
3376 make _arguments stop completing options after the first
3377 normal argument, but ignoring all strings starting with a
3378 hyphen even if they are not described by one of the opt‐
3379 specs, the form is `-A "-*"'.
3380
3381 -O name
3382 Pass the elements of the array name as arguments to func‐
3383 tions called to execute actions. This is discussed in
3384 detail below.
3385
3386 -M matchspec
3387 Use the match specification matchspec for completing op‐
3388 tion names and values. The default matchspec allows par‐
3389 tial word completion after `_' and `-', such as complet‐
3390 ing `-f-b' to `-foo-bar'. The default matchspec is:
3391 r:|[_-]=* r:|=*
3392
3393 -0 When populating values of the `opt_args' associative ar‐
3394 ray, don't backslash-escape colons and backslashes and
3395 use NUL rather than colon for joining multiple values.
3396 This option is described in more detail below, under the
3397 heading specs: actions.
3398
3399 specs: overview
3400
3401 Each of the following forms is a spec describing individual sets
3402 of options or arguments on the command line being analyzed.
3403
3404 n:message:action
3405 n::message:action
3406 This describes the n'th normal argument. The message
3407 will be printed above the matches generated and the ac‐
3408 tion indicates what can be completed in this position
3409 (see below). If there are two colons before the message
3410 the argument is optional. If the message contains only
3411 white space, nothing will be printed above the matches
3412 unless the action adds an explanation string itself.
3413
3414 :message:action
3415 ::message:action
3416 Similar, but describes the next argument, whatever number
3417 that happens to be. If all arguments are specified in
3418 this form in the correct order the numbers are unneces‐
3419 sary.
3420
3421 *:message:action
3422 *::message:action
3423 *:::message:action
3424 This describes how arguments (usually non-option argu‐
3425 ments, those not beginning with - or +) are to be com‐
3426 pleted when neither of the first two forms was provided.
3427 Any number of arguments can be completed in this fashion.
3428
3429 With two colons before the message, the words special ar‐
3430 ray and the CURRENT special parameter are modified to re‐
3431 fer only to the normal arguments when the action is exe‐
3432 cuted or evaluated. With three colons before the message
3433 they are modified to refer only to the normal arguments
3434 covered by this description.
3435
3436 optspec
3437 optspec:...
3438 This describes an option. The colon indicates handling
3439 for one or more arguments to the option; if it is not
3440 present, the option is assumed to take no arguments.
3441
3442 The following forms are available for the initial opt‐
3443 spec, whether or not the option has arguments.
3444
3445 *optspec
3446 Here optspec is one of the remaining forms below.
3447 This indicates the following optspec may be re‐
3448 peated. Otherwise if the corresponding option is
3449 already present on the command line to the left of
3450 the cursor it will not be offered again.
3451
3452 -optname
3453 +optname
3454 In the simplest form the optspec is just the op‐
3455 tion name beginning with a minus or a plus sign,
3456 such as `-foo'. The first argument for the option
3457 (if any) must follow as a separate word directly
3458 after the option.
3459
3460 Either of `-+optname' and `+-optname' can be used
3461 to specify that -optname and +optname are both
3462 valid.
3463
3464 In all the remaining forms, the leading `-' may be
3465 replaced by or paired with `+' in this way.
3466
3467 -optname-
3468 The first argument of the option must come di‐
3469 rectly after the option name in the same word.
3470 For example, `-foo-:...' specifies that the com‐
3471 pleted option and argument will look like
3472 `-fooarg'.
3473
3474 -optname+
3475 The first argument may appear immediately after
3476 optname in the same word, or may appear as a sepa‐
3477 rate word after the option. For example,
3478 `-foo+:...' specifies that the completed option
3479 and argument will look like either `-fooarg' or
3480 `-foo arg'.
3481
3482 -optname=
3483 The argument may appear as the next word, or in
3484 same word as the option name provided that it is
3485 separated from it by an equals sign, for example
3486 `-foo=arg' or `-foo arg'.
3487
3488 -optname=-
3489 The argument to the option must appear after an
3490 equals sign in the same word, and may not be given
3491 in the next argument.
3492
3493 optspec[explanation]
3494 An explanation string may be appended to any of
3495 the preceding forms of optspec by enclosing it in
3496 brackets, as in `-q[query operation]'.
3497
3498 The verbose style is used to decide whether the
3499 explanation strings are displayed with the option
3500 in a completion listing.
3501
3502 If no bracketed explanation string is given but
3503 the auto-description style is set and only one ar‐
3504 gument is described for this optspec, the value of
3505 the style is displayed, with any appearance of the
3506 sequence `%d' in it replaced by the message of the
3507 first optarg that follows the optspec; see below.
3508
3509 It is possible for options with a literal `+' or `=' to
3510 appear, but that character must be quoted, for example
3511 `-\+'.
3512
3513 Each optarg following an optspec must take one of the
3514 following forms:
3515
3516 :message:action
3517 ::message:action
3518 An argument to the option; message and action are
3519 treated as for ordinary arguments. In the first
3520 form, the argument is mandatory, and in the second
3521 form it is optional.
3522
3523 This group may be repeated for options which take
3524 multiple arguments. In other words, :message1:ac‐
3525 tion1:message2:action2 specifies that the option
3526 takes two arguments.
3527
3528 :*pattern:message:action
3529 :*pattern::message:action
3530 :*pattern:::message:action
3531 This describes multiple arguments. Only the last
3532 optarg for an option taking multiple arguments may
3533 be given in this form. If the pattern is empty
3534 (i.e. :*:), all the remaining words on the line
3535 are to be completed as described by the action;
3536 otherwise, all the words up to and including a
3537 word matching the pattern are to be completed us‐
3538 ing the action.
3539
3540 Multiple colons are treated as for the `*:...'
3541 forms for ordinary arguments: when the message is
3542 preceded by two colons, the words special array
3543 and the CURRENT special parameter are modified
3544 during the execution or evaluation of the action
3545 to refer only to the words after the option. When
3546 preceded by three colons, they are modified to re‐
3547 fer only to the words covered by this description.
3548
3549 Any literal colon in an optname, message, or action must be pre‐
3550 ceded by a backslash, `\:'.
3551
3552 Each of the forms above may be preceded by a list in parentheses
3553 of option names and argument numbers. If the given option is on
3554 the command line, the options and arguments indicated in paren‐
3555 theses will not be offered. For example, `(-two -three
3556 1)-one:...' completes the option `-one'; if this appears on the
3557 command line, the options -two and -three and the first ordinary
3558 argument will not be completed after it. `(-foo):...' specifies
3559 an ordinary argument completion; -foo will not be completed if
3560 that argument is already present.
3561
3562 Other items may appear in the list of excluded options to indi‐
3563 cate various other items that should not be applied when the
3564 current specification is matched: a single star (*) for the rest
3565 arguments (i.e. a specification of the form `*:...'); a colon
3566 (:) for all normal (non-option-) arguments; and a hyphen (-) for
3567 all options. For example, if `(*)' appears before an option and
3568 the option appears on the command line, the list of remaining
3569 arguments (those shown in the above table beginning with `*:')
3570 will not be completed.
3571
3572 To aid in reuse of specifications, it is possible to precede any
3573 of the forms above with `!'; then the form will no longer be
3574 completed, although if the option or argument appears on the
3575 command line they will be skipped as normal. The main use for
3576 this is when the arguments are given by an array, and _arguments
3577 is called repeatedly for more specific contexts: on the first
3578 call `_arguments $global_options' is used, and on subsequent
3579 calls `_arguments !$^global_options'.
3580
3581 specs: actions
3582
3583
3584 In each of the forms above the action determines how completions
3585 should be generated. Except for the `->string' form below, the
3586 action will be executed by calling the _all_labels function to
3587 process all tag labels. No special handling of tags is needed
3588 unless a function call introduces a new one.
3589
3590 The functions called to execute actions will be called with the
3591 elements of the array named by the `-O name' option as argu‐
3592 ments. This can be used, for example, to pass the same set of
3593 options for the compadd builtin to all actions.
3594
3595 The forms for action are as follows.
3596
3597 (single unquoted space)
3598 This is useful where an argument is required but it is
3599 not possible or desirable to generate matches for it.
3600 The message will be displayed but no completions listed.
3601 Note that even in this case the colon at the end of the
3602 message is needed; it may only be omitted when neither a
3603 message nor an action is given.
3604
3605 (item1 item2 ...)
3606 One of a list of possible matches, for example:
3607
3608 :foo:(foo bar baz)
3609
3610 ((item1\:desc1 ...))
3611 Similar to the above, but with descriptions for each pos‐
3612 sible match. Note the backslash before the colon. For
3613 example,
3614
3615 :foo:((a\:bar b\:baz))
3616
3617 The matches will be listed together with their descrip‐
3618 tions if the description style is set with the values tag
3619 in the context.
3620
3621 ->string
3622 In this form, _arguments processes the arguments and op‐
3623 tions and then returns control to the calling function
3624 with parameters set to indicate the state of processing;
3625 the calling function then makes its own arrangements for
3626 generating completions. For example, functions that im‐
3627 plement a state machine can use this type of action.
3628
3629 Where _arguments encounters action in the `->string' for‐
3630 mat, it will strip all leading and trailing whitespace
3631 from string and set the array state to the set of all
3632 strings for which an action is to be performed. The ele‐
3633 ments of the array state_descr are assigned the corre‐
3634 sponding message field from each optarg containing such
3635 an action.
3636
3637 By default and in common with all other well behaved com‐
3638 pletion functions, _arguments returns status zero if it
3639 was able to add matches and non-zero otherwise. However,
3640 if the -R option is given, _arguments will instead return
3641 a status of 300 to indicate that $state is to be handled.
3642
3643 In addition to $state and $state_descr, _arguments also
3644 sets the global parameters `context', `line' and
3645 `opt_args' as described below, and does not reset any
3646 changes made to the special parameters such as PREFIX and
3647 words. This gives the calling function the choice of re‐
3648 setting these parameters or propagating changes in them.
3649
3650 A function calling _arguments with at least one action
3651 containing a `->string' must therefore declare appropri‐
3652 ate local parameters:
3653
3654 local context state state_descr line
3655 typeset -A opt_args
3656
3657 to prevent _arguments from altering the global environ‐
3658 ment.
3659
3660 {eval-string}
3661 A string in braces is evaluated as shell code to generate
3662 matches. If the eval-string itself does not begin with
3663 an opening parenthesis or brace it is split into separate
3664 words before execution.
3665
3666 = action
3667 If the action starts with `= ' (an equals sign followed
3668 by a space), _arguments will insert the contents of the
3669 argument field of the current context as the new first
3670 element in the words special array and increment the
3671 value of the CURRENT special parameter. This has the ef‐
3672 fect of inserting a dummy word onto the completion com‐
3673 mand line while not changing the point at which comple‐
3674 tion is taking place.
3675
3676 This is most useful with one of the specifiers that re‐
3677 strict the words on the command line on which the action
3678 is to operate (the two- and three-colon forms above).
3679 One particular use is when an action itself causes _argu‐
3680 ments on a restricted range; it is necessary to use this
3681 trick to insert an appropriate command name into the
3682 range for the second call to _arguments to be able to
3683 parse the line.
3684
3685 word...
3686 word...
3687 This covers all forms other than those above. If the ac‐
3688 tion starts with a space, the remaining list of words
3689 will be invoked unchanged.
3690
3691 Otherwise it will be invoked with some extra strings
3692 placed after the first word; these are to be passed down
3693 as options to the compadd builtin. They ensure that the
3694 state specified by _arguments, in particular the descrip‐
3695 tions of options and arguments, is correctly passed to
3696 the completion command. These additional arguments are
3697 taken from the array parameter `expl'; this will be set
3698 up before executing the action and hence may be referred
3699 to inside it, typically in an expansion of the form
3700 `$expl[@]' which preserves empty elements of the array.
3701
3702 During the performance of the action the array `line' will be
3703 set to the normal arguments from the command line, i.e. the
3704 words from the command line after the command name excluding all
3705 options and their arguments. Options are stored in the associa‐
3706 tive array `opt_args' with option names as keys and their argu‐
3707 ments as the values. By default, all colons and backslashes in
3708 the value are escaped with backslashes, and if an option has
3709 multiple arguments (for example, when using an optspec of the
3710 form `*optspec'), they are joined with (unescaped) colons. How‐
3711 ever, if the -0 option was passed, no backslash escaping is per‐
3712 formed, and multiple values are joined with NUL bytes. For ex‐
3713 ample, after `zsh -o foo:foo -o bar:bar -o <TAB>', the contents
3714 of `opt_args' would be
3715
3716 typeset -A opt_args=( [-o]='foo\:foo:bar\:bar:' )
3717
3718 by default, and
3719
3720 typeset -A opt_args=( [-o]=$'foo:foo\x00bar:bar\x00' )
3721
3722 if _arguments had been called with the -0 option.
3723
3724 The parameter `context' is set when returning to the calling
3725 function to perform an action of the form `->string'. It is set
3726 to an array of elements corresponding to the elements of $state.
3727 Each element is a suitable name for the argument field of the
3728 context: either a string of the form `option-opt-n' for the n'th
3729 argument of the option -opt, or a string of the form `argu‐
3730 ment-n' for the n'th argument. For `rest' arguments, that is
3731 those in the list at the end not handled by position, n is the
3732 string `rest'. For example, when completing the argument of the
3733 -o option, the name is `option-o-1', while for the second normal
3734 (non-option-) argument it is `argument-2'.
3735
3736 Furthermore, during the evaluation of the action the context
3737 name in the curcontext parameter is altered to append the same
3738 string that is stored in the context parameter.
3739
3740 The option -C tells _arguments to modify the curcontext parame‐
3741 ter for an action of the form `->state'. This is the standard
3742 parameter used to keep track of the current context. Here it
3743 (and not the context array) should be made local to the calling
3744 function to avoid passing back the modified value and should be
3745 initialised to the current value at the start of the function:
3746
3747 local curcontext="$curcontext"
3748
3749 This is useful where it is not possible for multiple states to
3750 be valid together.
3751
3752 Grouping Options
3753
3754 Options can be grouped to simplify exclusion lists. A group is
3755 introduced with `+' followed by a name for the group in the sub‐
3756 sequent word. Whole groups can then be referenced in an exclu‐
3757 sion list or a group name can be used to disambiguate between
3758 two forms of the same option. For example:
3759
3760 _arguments \
3761 '(group2--x)-a' \
3762 + group1 \
3763 -m \
3764 '(group2)-n' \
3765 + group2 \
3766 -x -y
3767
3768 If the name of a group is specified in the form `(name)' then
3769 only one value from that group will ever be completed; more for‐
3770 mally, all specifications are mutually exclusive to all other
3771 specifications in that group. This is useful for defining op‐
3772 tions that are aliases for each other. For example:
3773
3774 _arguments \
3775 -a -b \
3776 + '(operation)' \
3777 {-c,--compress}'[compress]' \
3778 {-d,--decompress}'[decompress]' \
3779 {-l,--list}'[list]'
3780
3781 If an option in a group appears on the command line, it is
3782 stored in the associative array `opt_args' with 'group-option'
3783 as a key. In the example above, a key `operation--c' is used if
3784 the option `-c' is present on the command line.
3785
3786 Specifying Multiple Sets of Arguments
3787
3788 It is possible to specify multiple sets of options and arguments
3789 with the sets separated by single hyphens. This differs from
3790 groups in that sets are considered to be mutually exclusive of
3791 each other.
3792
3793 Specifications before the first set and from any group are com‐
3794 mon to all sets. For example:
3795
3796 _arguments \
3797 -a \
3798 - set1 \
3799 -c \
3800 - set2 \
3801 -d \
3802 ':arg:(x2 y2)'
3803
3804 This defines two sets. When the command line contains the op‐
3805 tion `-c', the `-d' option and the argument will not be consid‐
3806 ered possible completions. When it contains `-d' or an argu‐
3807 ment, the option `-c' will not be considered. However, after
3808 `-a' both sets will still be considered valid.
3809
3810 As for groups, the name of a set may appear in exclusion lists,
3811 either alone or preceding a normal option or argument specifica‐
3812 tion.
3813
3814 The completion code has to parse the command line separately for
3815 each set. This can be slow so sets should only be used when nec‐
3816 essary. A useful alternative is often an option specification
3817 with rest-arguments (as in `-foo:*:...'); here the option -foo
3818 swallows up all remaining arguments as described by the optarg
3819 definitions.
3820
3821 Deriving spec forms from the help output
3822
3823 The option `--' allows _arguments to work out the names of long
3824 options that support the `--help' option which is standard in
3825 many GNU commands. The command word is called with the argument
3826 `--help' and the output examined for option names. Clearly, it
3827 can be dangerous to pass this to commands which may not support
3828 this option as the behaviour of the command is unspecified.
3829
3830 In addition to options, `_arguments --' will try to deduce the
3831 types of arguments available for options when the form
3832 `--opt=val' is valid. It is also possible to provide hints by
3833 examining the help text of the command and adding helpspec of
3834 the form `pattern:message:action'; note that other _arguments
3835 spec forms are not used. The pattern is matched against the
3836 help text for an option, and if it matches the message and ac‐
3837 tion are used as for other argument specifiers. The special
3838 case of `*:' means both message and action are empty, which has
3839 the effect of causing options having no description in the help
3840 output to be ordered in listings ahead of options that have a
3841 description.
3842
3843 For example:
3844
3845 _arguments -- '*\*:toggle:(yes no)' \
3846 '*=FILE*:file:_files' \
3847 '*=DIR*:directory:_files -/' \
3848 '*=PATH*:directory:_files -/'
3849
3850 Here, `yes' and `no' will be completed as the argument of op‐
3851 tions whose description ends in a star; file names will be com‐
3852 pleted for options that contain the substring `=FILE' in the de‐
3853 scription; and directories will be completed for options whose
3854 description contains `=DIR' or `=PATH'. The last three are in
3855 fact the default and so need not be given explicitly, although
3856 it is possible to override the use of these patterns. A typical
3857 help text which uses this feature is:
3858
3859 -C, --directory=DIR change to directory DIR
3860
3861 so that the above specifications will cause directories to be
3862 completed after `--directory', though not after `-C'.
3863
3864 Note also that _arguments tries to find out automatically if the
3865 argument for an option is optional. This can be specified ex‐
3866 plicitly by doubling the colon before the message.
3867
3868 If the pattern ends in `(-)', this will be removed from the pat‐
3869 tern and the action will be used only directly after the `=',
3870 not in the next word. This is the behaviour of a normal speci‐
3871 fication defined with the form `=-'.
3872
3873 By default, the command (with the option `--help') is run after
3874 resetting all the locale categories (except for LC_CTYPE) to
3875 `C'. If the localized help output is known to work, the option
3876 `-l' can be specified after the `_arguments --' so that the com‐
3877 mand is run in the current locale.
3878
3879 The `_arguments --' can be followed by the option `-i patterns'
3880 to give patterns for options which are not to be completed. The
3881 patterns can be given as the name of an array parameter or as a
3882 literal list in parentheses. For example,
3883
3884 _arguments -- -i \
3885 "(--(en|dis)able-FEATURE*)"
3886
3887 will cause completion to ignore the options `--enable-FEATURE'
3888 and `--disable-FEATURE' (this example is useful with GNU config‐
3889 ure).
3890
3891 The `_arguments --' form can also be followed by the option `-s
3892 pair' to describe option aliases. The pair consists of a list
3893 of alternating patterns and corresponding replacements, enclosed
3894 in parens and quoted so that it forms a single argument word in
3895 the _arguments call.
3896
3897 For example, some configure-script help output describes options
3898 only as `--enable-foo', but the script also accepts the negated
3899 form `--disable-foo'. To allow completion of the second form:
3900
3901 _arguments -- -s "((#s)--enable- --disable-)"
3902
3903 Miscellaneous notes
3904
3905 Finally, note that _arguments generally expects to be the pri‐
3906 mary function handling any completion for which it is used. It
3907 may have side effects which change the treatment of any matches
3908 added by other functions called after it. To combine _arguments
3909 with other functions, those functions should be called either
3910 before _arguments, as an action within a spec, or in handlers
3911 for `->state' actions.
3912
3913 Here is a more general example of the use of _arguments:
3914
3915 _arguments '-l+:left border:' \
3916 '-format:paper size:(letter A4)' \
3917 '*-copy:output file:_files::resolution:(300 600)' \
3918 ':postscript file:_files -g \*.\(ps\|eps\)' \
3919 '*:page number:'
3920
3921 This describes three options: `-l', `-format', and `-copy'. The
3922 first takes one argument described as `left border' for which no
3923 completion will be offered because of the empty action. Its ar‐
3924 gument may come directly after the `-l' or it may be given as
3925 the next word on the line.
3926
3927 The `-format' option takes one argument in the next word, de‐
3928 scribed as `paper size' for which only the strings `letter' and
3929 `A4' will be completed.
3930
3931 The `-copy' option may appear more than once on the command line
3932 and takes two arguments. The first is mandatory and will be
3933 completed as a filename. The second is optional (because of the
3934 second colon before the description `resolution') and will be
3935 completed from the strings `300' and `600'.
3936
3937 The last two descriptions say what should be completed as argu‐
3938 ments. The first describes the first argument as a `postscript
3939 file' and makes files ending in `ps' or `eps' be completed. The
3940 last description gives all other arguments the description `page
3941 number' but does not offer completions.
3942
3943 _cache_invalid cache_identifier
3944 This function returns status zero if the completions cache cor‐
3945 responding to the given cache identifier needs rebuilding. It
3946 determines this by looking up the cache-policy style for the
3947 current context. This should provide a function name which is
3948 run with the full path to the relevant cache file as the only
3949 argument.
3950
3951 Example:
3952
3953 _example_caching_policy () {
3954 # rebuild if cache is more than a week old
3955 local -a oldp
3956 oldp=( "$1"(Nm+7) )
3957 (( $#oldp ))
3958 }
3959
3960 _call_function return name [ arg ... ]
3961 If a function name exists, it is called with the arguments args.
3962 The return argument gives the name of a parameter in which the
3963 return status from the function name should be stored; if return
3964 is empty or a single hyphen it is ignored.
3965
3966 The return status of _call_function itself is zero if the func‐
3967 tion name exists and was called and non-zero otherwise.
3968
3969 _call_program [ -l ] [ -p ] tag string ...
3970 This function provides a mechanism for the user to override the
3971 use of an external command. It looks up the command style with
3972 the supplied tag. If the style is set, its value is used as the
3973 command to execute. The strings from the call to _call_program,
3974 or from the style if set, are concatenated with spaces between
3975 them and the resulting string is evaluated. The return status
3976 is the return status of the command called.
3977
3978 By default, the command is run in an environment where all the
3979 locale categories (except for LC_CTYPE) are reset to `C' by
3980 calling the utility function _comp_locale (see below). If the
3981 option `-l' is given, the command is run with the current lo‐
3982 cale.
3983
3984 If the option `-p' is supplied it indicates that the command
3985 output is influenced by the permissions it is run with. If the
3986 gain-privileges style is set to true, _call_program will make
3987 use of commands such as sudo, if present on the command-line, to
3988 match the permissions to whatever the final command is likely to
3989 run under. When looking up the gain-privileges and command
3990 styles, the command component of the zstyle context will end
3991 with a slash (`/') followed by the command that would be used to
3992 gain privileges.
3993
3994 _combination [ -s pattern ] tag style spec ... field opts ...
3995 This function is used to complete combinations of values, for
3996 example pairs of hostnames and usernames. The style argument
3997 gives the style which defines the pairs; it is looked up in a
3998 context with the tag specified.
3999
4000 The style name consists of field names separated by hyphens, for
4001 example `users-hosts-ports'. For each field for a value is al‐
4002 ready known, a spec of the form `field=pattern' is given. For
4003 example, if the command line so far specifies a user `pws', the
4004 argument `users=pws' should appear.
4005
4006 The next argument with no equals sign is taken as the name of
4007 the field for which completions should be generated (presumably
4008 not one of the fields for which the value is known).
4009
4010 The matches generated will be taken from the value of the style.
4011 These should contain the possible values for the combinations in
4012 the appropriate order (users, hosts, ports in the example
4013 above). The values for the different fields are separated by
4014 colons. This can be altered with the option -s to _combination
4015 which specifies a pattern. Typically this is a character class,
4016 as for example `-s "[:@]"' in the case of the users-hosts style.
4017 Each `field=pattern' specification restricts the completions
4018 which apply to elements of the style with appropriately matching
4019 fields.
4020
4021 If no style with the given name is defined for the given tag, or
4022 if none of the strings in style's value match, but a function
4023 name of the required field preceded by an underscore is defined,
4024 that function will be called to generate the matches. For exam‐
4025 ple, if there is no `users-hosts-ports' or no matching hostname
4026 when a host is required, the function `_hosts' will automati‐
4027 cally be called.
4028
4029 If the same name is used for more than one field, in both the
4030 `field=pattern' and the argument that gives the name of the
4031 field to be completed, the number of the field (starting with
4032 one) may be given after the fieldname, separated from it by a
4033 colon.
4034
4035 All arguments after the required field name are passed to com‐
4036 padd when generating matches from the style value, or to the
4037 functions for the fields if they are called.
4038
4039 _command_names [ -e | - ]
4040 This function completes words that are valid at command posi‐
4041 tion: names of aliases, builtins, hashed commands, functions,
4042 and so on. With the -e flag, only hashed commands are com‐
4043 pleted. The - flag is ignored.
4044
4045 _comp_locale
4046 This function resets all the locale categories other than
4047 LC_CTYPE to `C' so that the output from external commands can be
4048 easily analyzed by the completion system. LC_CTYPE retains the
4049 current value (taking LC_ALL and LANG into account), ensuring
4050 that non-ASCII characters in file names are still handled prop‐
4051 erly.
4052
4053 This function should normally be run only in a subshell, because
4054 the new locale is exported to the environment. Typical usage
4055 would be `$(_comp_locale; command ...)'.
4056
4057 _completers [ -p ]
4058 This function completes names of completers.
4059
4060 -p Include the leading underscore (`_') in the matches.
4061
4062 _default
4063 This function corresponds to the -default- special context which
4064 is applied where no completion is defined. It is useful to call
4065 it under certain error conditions such as completion after an
4066 unrecognised subcommand. This applies the concept of graceful
4067 degradation to the completion system, allowing it to fallback on
4068 basic completion of commonly useful things like filenames.
4069
4070
4071 _describe [-12JVx] [ -oO | -t tag ] descr name1 [ name2 ] [ opt ... ]
4072 [ -- name1 [ name2 ] [ opt ... ] ... ]
4073 This function associates completions with descriptions. Multi‐
4074 ple groups separated by -- can be supplied, potentially with
4075 different completion options opts.
4076
4077 The descr is taken as a string to display above the matches if
4078 the format style for the descriptions tag is set. This is fol‐
4079 lowed by one or two names of arrays followed by options to pass
4080 to compadd. The array name1 contains the possible completions
4081 with their descriptions in the form `completion:description'.
4082 Any literal colons in completion must be quoted with a back‐
4083 slash. If a name2 is given, it should have the same number of
4084 elements as name1; in this case the corresponding elements are
4085 added as possible completions instead of the completion strings
4086 from name1. The completion list will retain the descriptions
4087 from name1. Finally, a set of completion options can appear.
4088
4089 If the option `-o' appears before the first argument, the
4090 matches added will be treated as names of command options (N.B.
4091 not shell options), typically following a `-', `--' or `+' on
4092 the command line. In this case _describe uses the prefix-hid‐
4093 den, prefix-needed and verbose styles to find out if the strings
4094 should be added as completions and if the descriptions should be
4095 shown. Without the `-o' option, only the verbose style is used
4096 to decide how descriptions are shown. If `-O' is used instead
4097 of `-o', command options are completed as above but _describe
4098 will not handle the prefix-needed style.
4099
4100 With the -t option a tag can be specified. The default is `val‐
4101 ues' or, if the -o option is given, `options'.
4102
4103 The options -1, -2, -J, -V, -x are passed to _next_label.
4104
4105 If selected by the list-grouped style, strings with the same de‐
4106 scription will appear together in the list.
4107
4108 _describe uses the _all_labels function to generate the matches,
4109 so it does not need to appear inside a loop over tag labels.
4110
4111 _description [ -x ] [ -12VJ ] tag name descr [ spec ... ]
4112 This function is not to be confused with the previous one; it is
4113 used as a helper function for creating options to compadd. It
4114 is buried inside many of the higher level completion functions
4115 and so often does not need to be called directly.
4116
4117 The styles listed below are tested in the current context using
4118 the given tag. The resulting options for compadd are put into
4119 the array named name (this is traditionally `expl', but this
4120 convention is not enforced). The description for the corre‐
4121 sponding set of matches is passed to the function in descr.
4122
4123 The styles tested are: format, hidden, matcher, ignore-line, ig‐
4124 nored-patterns, group-name and sort. The format style is first
4125 tested for the given tag and then for the descriptions tag if no
4126 value was found, while the remainder are only tested for the tag
4127 given as the first argument. The function also calls _setup
4128 which tests some more styles.
4129
4130 The string returned by the format style (if any) will be modi‐
4131 fied so that the sequence `%d' is replaced by the descr given as
4132 the third argument without any leading or trailing white space.
4133 If, after removing the white space, the descr is the empty
4134 string, the format style will not be used and the options put
4135 into the name array will not contain an explanation string to be
4136 displayed above the matches.
4137
4138 If _description is called with more than three arguments, the
4139 additional specs should be of the form `char:str'. These supply
4140 escape sequence replacements for the format style: every appear‐
4141 ance of `%char' will be replaced by string. If no additional
4142 specs are given but the description in descr conforms to a com‐
4143 mon form then further escape sequences are set for elements of
4144 that description. These elements correspond to a default value
4145 (`%o'), the units (`%m') range of acceptable values (`%r') and
4146 the remaining initial part of the description (`%h'). The form
4147 the description takes consists of specifying the units and range
4148 in parentheses and the default value in square brackets, for ex‐
4149 ample:
4150
4151 _description times expl 'timeout (seconds) (0-60) [20]'
4152
4153 It is possible to use zformat conditional expressions when
4154 styling these elements. So, for example, to add `default:' as a
4155 tag but only when there is a default value to show, the format
4156 style might include `%(o.default: %o.)'.
4157
4158 If the -x option is given, the description will be passed to
4159 compadd using the -x option instead of the default -X. This
4160 means that the description will be displayed even if there are
4161 no corresponding matches.
4162
4163 The options placed in the array name take account of the
4164 group-name style, so matches are placed in a separate group
4165 where necessary. The group normally has its elements sorted (by
4166 passing the option -J to compadd), but if an option starting
4167 with `-V', `-J', `-1', or `-2' is passed to _description, that
4168 option will be included in the array. Hence it is possible for
4169 the completion group to be unsorted by giving the option `-V',
4170 `-1V', or `-2V'.
4171
4172 In most cases, the function will be used like this:
4173
4174 local expl
4175 _description files expl file
4176 compadd "$expl[@]" - "$files[@]"
4177
4178 Note the use of the parameter expl, the hyphen, and the list of
4179 matches. Almost all calls to compadd within the completion sys‐
4180 tem use a similar format; this ensures that user-specified
4181 styles are correctly passed down to the builtins which implement
4182 the internals of completion.
4183
4184 _dir_list [ -s sep ] [ -S ]
4185 Complete a list of directory names separated by colons (the same
4186 format as $PATH).
4187
4188 -s sep Use sep as separator between items. sep defaults to a
4189 colon (`:').
4190
4191 -S Add sep instead of slash (`/') as an autoremoveable suf‐
4192 fix.
4193
4194 _dispatch context string ...
4195 This sets the current context to context and looks for comple‐
4196 tion functions to handle this context by hunting through the
4197 list of command names or special contexts (as described above
4198 for compdef) given as strings. The first completion function to
4199 be defined for one of the contexts in the list is used to gener‐
4200 ate matches. Typically, the last string is -default- to cause
4201 the function for default completion to be used as a fallback.
4202
4203 The function sets the parameter $service to the string being
4204 tried, and sets the context/command field (the fourth) of the
4205 $curcontext parameter to the context given as the first argu‐
4206 ment.
4207
4208 _email_addresses [ -c ] [ -n plugin ]
4209 Complete email addresses. Addresses are provided by plugins.
4210
4211 -c Complete bare localhost@domain.tld addresses, without a
4212 name part or a comment. Without this option, RFC822
4213 `Firstname Lastname <address>' strings are completed.
4214
4215 -n plugin
4216 Complete aliases from plugin.
4217
4218 The following plugins are available by default: _email-ldap (see
4219 the filter style), _email-local (completes user@hostname Unix
4220 addresses), _email-mail (completes aliases from ~/.mailrc),
4221 _email-mush, _email-mutt, and _email-pine.
4222
4223 Addresses from the _email-foo plugin are added under the tag
4224 `email-foo'.
4225
4226 Writing plugins
4227
4228 Plugins are written as separate functions with names starting
4229 with `_email-'. They are invoked with the -c option and compadd
4230 options. They should either do their own completion or set the
4231 $reply array to a list of `alias:address' elements and return
4232 300. New plugins will be picked up and run automatically.
4233
4234 _files The function _files is a wrapper around _path_files. It supports
4235 all of the same functionality, with some enhancements -- no‐
4236 tably, it respects the list-dirs-first style, and it allows
4237 users to override the behaviour of the -g and -/ options with
4238 the file-patterns style. _files should therefore be preferred
4239 over _path_files in most cases.
4240
4241 This function accepts the full set of options allowed by
4242 _path_files, described below.
4243
4244 _gnu_generic
4245 This function is a simple wrapper around the _arguments function
4246 described above. It can be used to determine automatically the
4247 long options understood by commands that produce a list when
4248 passed the option `--help'. It is intended to be used as a
4249 top-level completion function in its own right. For example, to
4250 enable option completion for the commands foo and bar, use
4251
4252 compdef _gnu_generic foo bar
4253
4254 after the call to compinit.
4255
4256 The completion system as supplied is conservative in its use of
4257 this function, since it is important to be sure the command un‐
4258 derstands the option `--help'.
4259
4260 _guard [ options ] pattern descr
4261 This function displays descr if pattern matches the string to be
4262 completed. It is intended to be used in the action for the
4263 specifications passed to _arguments and similar functions.
4264
4265 The return status is zero if the message was displayed and the
4266 word to complete is not empty, and non-zero otherwise.
4267
4268 The pattern may be preceded by any of the options understood by
4269 compadd that are passed down from _description, namely -M, -J,
4270 -V, -1, -2, -n, -F and -X. All of these options will be ig‐
4271 nored. This fits in conveniently with the argument-passing con‐
4272 ventions of actions for _arguments.
4273
4274 As an example, consider a command taking the options -n and
4275 -none, where -n must be followed by a numeric value in the same
4276 word. By using:
4277
4278 _arguments '-n-: :_guard "[0-9]#" "numeric value"' '-none'
4279
4280 _arguments can be made to both display the message `numeric
4281 value' and complete options after `-n<TAB>'. If the `-n' is al‐
4282 ready followed by one or more digits (the pattern passed to
4283 _guard) only the message will be displayed; if the `-n' is fol‐
4284 lowed by another character, only options are completed.
4285
4286 _message [ -r12 ] [ -VJ group ] descr
4287 _message -e [ tag ] descr
4288 The descr is used in the same way as the third argument to the
4289 _description function, except that the resulting string will al‐
4290 ways be shown whether or not matches were generated. This is
4291 useful for displaying a help message in places where no comple‐
4292 tions can be generated.
4293
4294 The format style is examined with the messages tag to find a
4295 message; the usual tag, descriptions, is used only if the style
4296 is not set with the former.
4297
4298 If the -r option is given, no style is used; the descr is taken
4299 literally as the string to display. This is most useful when
4300 the descr comes from a pre-processed argument list which already
4301 contains an expanded description. Note that this option does
4302 not disable the `%'-sequence parsing done by compadd.
4303
4304 The -12VJ options and the group are passed to compadd and hence
4305 determine the group the message string is added to.
4306
4307 The second -e form gives a description for completions with the
4308 tag tag to be shown even if there are no matches for that tag.
4309 This form is called by _arguments in the event that there is no
4310 action for an option specification. The tag can be omitted and
4311 if so the tag is taken from the parameter $curtag; this is main‐
4312 tained by the completion system and so is usually correct. Note
4313 that if there are no matches at the time this function is
4314 called, compstate[insert] is cleared, so additional matches gen‐
4315 erated later are not inserted on the command line.
4316
4317 _multi_parts [ -i ] sep array
4318 The argument sep is a separator character. The array may be ei‐
4319 ther the name of an array parameter or a literal array in the
4320 form `(foo bar)', a parenthesised list of words separated by
4321 whitespace. The possible completions are the strings from the
4322 array. However, each chunk delimited by sep will be completed
4323 separately. For example, the _tar function uses `_multi_parts /
4324 patharray' to complete partial file paths from the given array
4325 of complete file paths.
4326
4327 The -i option causes _multi_parts to insert a unique match even
4328 if that requires multiple separators to be inserted. This is
4329 not usually the expected behaviour with filenames, but certain
4330 other types of completion, for example those with a fixed set of
4331 possibilities, may be more suited to this form.
4332
4333 Like other utility functions, this function accepts the `-V',
4334 `-J', `-1', `-2', `-n', `-f', `-X', `-M', `-P', `-S', `-r',
4335 `-R', and `-q' options and passes them to the compadd builtin.
4336
4337 _next_label [ -x ] [ -12VJ ] tag name descr [ option ... ]
4338 This function is used to implement the loop over different tag
4339 labels for a particular tag as described above for the tag-order
4340 style. On each call it checks to see if there are any more tag
4341 labels; if there is it returns status zero, otherwise non-zero.
4342 As this function requires a current tag to be set, it must al‐
4343 ways follow a call to _tags or _requested.
4344
4345 The -x12VJ options and the first three arguments are passed to
4346 the _description function. Where appropriate the tag will be
4347 replaced by a tag label in this call. Any description given in
4348 the tag-order style is preferred to the descr passed to
4349 _next_label.
4350
4351 The options given after the descr are set in the parameter given
4352 by name, and hence are to be passed to compadd or whatever func‐
4353 tion is called to add the matches.
4354
4355 Here is a typical use of this function for the tag foo. The
4356 call to _requested determines if tag foo is required at all; the
4357 loop over _next_label handles any labels defined for the tag in
4358 the tag-order style.
4359
4360 local expl ret=1
4361 ...
4362 if _requested foo; then
4363 ...
4364 while _next_label foo expl '...'; do
4365 compadd "$expl[@]" ... && ret=0
4366 done
4367 ...
4368 fi
4369 return ret
4370
4371 _normal [ -P | -p precommand ]
4372 This is the standard function called to handle completion out‐
4373 side any special -context-. It is called both to complete the
4374 command word and also the arguments for a command. In the sec‐
4375 ond case, _normal looks for a special completion for that com‐
4376 mand, and if there is none it uses the completion for the -de‐
4377 fault- context.
4378
4379 A second use is to reexamine the command line specified by the
4380 $words array and the $CURRENT parameter after those have been
4381 modified. For example, the function _precommand, which com‐
4382 pletes after precommand specifiers such as nohup, removes the
4383 first word from the words array, decrements the CURRENT parame‐
4384 ter, then calls `_normal -p $service'. The effect is that `no‐
4385 hup cmd ...' is treated in the same way as `cmd ...'.
4386
4387 -P Reset the list of precommands. This option should be used
4388 if completing a command line which allows internal com‐
4389 mands (e.g. builtins and functions) regardless of prior
4390 precommands (e.g. `zsh -c').
4391
4392 -p precommand
4393 Append precommand to the list of precommands. This option
4394 should be used in nearly all cases in which -P is not ap‐
4395 plicable.
4396
4397 If the command name matches one of the patterns given by one of
4398 the options -p or -P to compdef, the corresponding completion
4399 function is called and then the parameter _compskip is checked.
4400 If it is set completion is terminated at that point even if no
4401 matches have been found. This is the same effect as in the
4402 -first- context.
4403
4404 _numbers [ option ... ] [ description ] [ suffix ... ]
4405 This can be used where a number is followed by a suffix to indi‐
4406 cate the units. The unit suffixes are completed and can also be
4407 included in the description used when completion is invoked for
4408 the preceding number.
4409
4410 In addition to common compadd options, _numbers accepts the fol‐
4411 lowing options:
4412
4413 -t tag Specify a tag to use instead of the default of numbers.
4414
4415 -u units
4416 Indicate the default units for the number, e.g. bytes.
4417
4418 -l min Specify the lowest possible value for the number.
4419
4420 -m max Specify the highest possible value for the number.
4421
4422 -d default
4423 Specify the default value.
4424
4425 -N Allow negative numbers. This is implied if the range in‐
4426 cludes a negative.
4427
4428 -f Allow decimal numbers.
4429
4430 Where a particular suffix represents the default units for a
4431 number, it should be prefixed with a colon. Additionally, suf‐
4432 fixes can be followed by a colon and a description. So for ex‐
4433 ample, the following allows the age of something to be speci‐
4434 fied, either in seconds or with an optional suffix with a longer
4435 unit of time:
4436
4437 _numbers -u seconds age :s:seconds m:minutes h:hours d:days
4438
4439 It is typically helpful for units to be presented in order of
4440 magnitude when completed. To facilitate this, the order in
4441 which they are given is preserved.
4442
4443 When the format style is looked up with the descriptions tag or
4444 the tag specified with -t, the list of suffixes is available as
4445 a `%x' escape sequence. This is in addition to the usual se‐
4446 quences documented under the format style. The form this list
4447 takes can also be configured. To this end, the format style is
4448 first looked up with the tag unit-suffixes. The retrieved format
4449 is applied to each suffix in turn and the results are then con‐
4450 catenated to form the completed list. For the unit-suffixes for‐
4451 mat, `%x' expands to the individual suffix and `%X' to its de‐
4452 scription. %d' indicates a default suffix and can be used in a
4453 condition. The index and reverse index are set in `%i' and `%r'
4454 respectively and are useful for text included only with the
4455 first and last suffixes in the list. So for example, the follow‐
4456 ing joins the suffixes together as a comma-separated list:
4457
4458 zstyle ':completion:*:unit-suffixes' format '%x%(r::,)'
4459
4460 _options
4461 This can be used to complete the names of shell options. It
4462 provides a matcher specification that ignores a leading `no',
4463 ignores underscores and allows upper-case letters to match their
4464 lower-case counterparts (for example, `glob', `noglob',
4465 `NO_GLOB' are all completed). Any arguments are propagated to
4466 the compadd builtin.
4467
4468 _options_set and _options_unset
4469 These functions complete only set or unset options, with the
4470 same matching specification used in the _options function.
4471
4472 Note that you need to uncomment a few lines in the _main_com‐
4473 plete function for these functions to work properly. The lines
4474 in question are used to store the option settings in effect be‐
4475 fore the completion widget locally sets the options it needs.
4476 Hence these functions are not generally used by the completion
4477 system.
4478
4479 _parameters
4480 This is used to complete the names of shell parameters.
4481
4482 The option `-g pattern' limits the completion to parameters
4483 whose type matches the pattern. The type of a parameter is that
4484 shown by `print ${(t)param}', hence judicious use of `*' in pat‐
4485 tern is probably necessary.
4486
4487 All other arguments are passed to the compadd builtin.
4488
4489 _path_files
4490 This function is used throughout the completion system to com‐
4491 plete filenames. It allows completion of partial paths. For
4492 example, the string `/u/i/s/sig' may be completed to `/usr/in‐
4493 clude/sys/signal.h'.
4494
4495 The options accepted by both _path_files and _files are:
4496
4497 -f Complete all filenames. This is the default.
4498
4499 -/ Specifies that only directories should be completed.
4500
4501 -g pattern
4502 Specifies that only files matching the pattern should be
4503 completed.
4504
4505 -W paths
4506 Specifies path prefixes that are to be prepended to the
4507 string from the command line to generate the filenames
4508 but that should not be inserted as completions nor shown
4509 in completion listings. Here, paths may be the name of
4510 an array parameter, a literal list of paths enclosed in
4511 parentheses or an absolute pathname.
4512
4513 -F ignored-files
4514 This behaves as for the corresponding option to the com‐
4515 padd builtin. It gives direct control over which file‐
4516 names should be ignored. If the option is not present,
4517 the ignored-patterns style is used.
4518
4519 Both _path_files and _files also accept the following options
4520 which are passed to compadd: `-J', `-V', `-1', `-2', `-n', `-X',
4521 `-M', `-P', `-S', `-q', `-r', and `-R'.
4522
4523 Finally, the _path_files function uses the styles expand, am‐
4524 biguous, special-dirs, list-suffixes and file-sort described
4525 above.
4526
4527
4528 _pick_variant [ -b builtin-label ] [ -c command ] [ -r name ]
4529 label=pattern ... label [ arg ... ]
4530 This function is used to resolve situations where a single com‐
4531 mand name requires more than one type of handling, either be‐
4532 cause it has more than one variant or because there is a name
4533 clash between two different commands.
4534
4535 The command to run is taken from the first element of the array
4536 words unless this is overridden by the option -c. This command
4537 is run and its output is compared with a series of patterns.
4538 Arguments to be passed to the command can be specified at the
4539 end after all the other arguments. The patterns to try in order
4540 are given by the arguments label=pattern; if the output of `com‐
4541 mand arg ...' contains pattern, then label is selected as the
4542 label for the command variant. If none of the patterns match,
4543 the final command label is selected and status 1 is returned.
4544
4545 If the `-b builtin-label' is given, the command is tested to see
4546 if it is provided as a shell builtin, possibly autoloaded; if
4547 so, the label builtin-label is selected as the label for the
4548 variant.
4549
4550 If the `-r name' is given, the label picked is stored in the pa‐
4551 rameter named name.
4552
4553 The results are also cached in the _cmd_variant associative ar‐
4554 ray indexed by the name of the command run.
4555
4556 _regex_arguments name spec ...
4557 This function generates a completion function name which matches
4558 the specifications specs, a set of regular expressions as de‐
4559 scribed below. After running _regex_arguments, the function
4560 name should be called as a normal completion function. The pat‐
4561 tern to be matched is given by the contents of the words array
4562 up to the current cursor position joined together with null
4563 characters; no quotation is applied.
4564
4565 The arguments are grouped as sets of alternatives separated by
4566 `|', which are tried one after the other until one matches.
4567 Each alternative consists of a one or more specifications which
4568 are tried left to right, with each pattern matched being
4569 stripped in turn from the command line being tested, until all
4570 of the group succeeds or until one fails; in the latter case,
4571 the next alternative is tried. This structure can be repeated
4572 to arbitrary depth by using parentheses; matching proceeds from
4573 inside to outside.
4574
4575 A special procedure is applied if no test succeeds but the re‐
4576 maining command line string contains no null character (implying
4577 the remaining word is the one for which completions are to be
4578 generated). The completion target is restricted to the remain‐
4579 ing word and any actions for the corresponding patterns are exe‐
4580 cuted. In this case, nothing is stripped from the command line
4581 string. The order of evaluation of the actions can be deter‐
4582 mined by the tag-order style; the various formats supported by
4583 _alternative can be used in action. The descr is used for set‐
4584 ting up the array parameter expl.
4585
4586 Specification arguments take one of following forms, in which
4587 metacharacters such as `(', `)', `#' and `|' should be quoted.
4588
4589 /pattern/ [%lookahead%] [-guard] [:tag:descr:action]
4590 This is a single primitive component. The function tests
4591 whether the combined pattern `(#b)((#B)pattern)look‐
4592 ahead*' matches the command line string. If so, `guard'
4593 is evaluated and its return status is examined to deter‐
4594 mine if the test has succeeded. The pattern string `[]'
4595 is guaranteed never to match. The lookahead is not
4596 stripped from the command line before the next pattern is
4597 examined.
4598
4599 The argument starting with : is used in the same manner
4600 as an argument to _alternative.
4601
4602 A component is used as follows: pattern is tested to see
4603 if the component already exists on the command line. If
4604 it does, any following specifications are examined to
4605 find something to complete. If a component is reached
4606 but no such pattern exists yet on the command line, the
4607 string containing the action is used to generate matches
4608 to insert at that point.
4609
4610 /pattern/+ [%lookahead%] [-guard] [:tag:descr:action]
4611 This is similar to `/pattern/ ...' but the left part of
4612 the command line string (i.e. the part already matched by
4613 previous patterns) is also considered part of the comple‐
4614 tion target.
4615
4616 /pattern/- [%lookahead%] [-guard] [:tag:descr:action]
4617 This is similar to `/pattern/ ...' but the actions of the
4618 current and previously matched patterns are ignored even
4619 if the following `pattern' matches the empty string.
4620
4621 ( spec )
4622 Parentheses may be used to groups specs; note each paren‐
4623 thesis is a single argument to _regex_arguments.
4624
4625 spec # This allows any number of repetitions of spec.
4626
4627 spec spec
4628 The two specs are to be matched one after the other as
4629 described above.
4630
4631 spec | spec
4632 Either of the two specs can be matched.
4633
4634 The function _regex_words can be used as a helper function to
4635 generate matches for a set of alternative words possibly with
4636 their own arguments as a command line argument.
4637
4638 Examples:
4639
4640 _regex_arguments _tst /$'[^\0]#\0'/ \
4641 /$'[^\0]#\0'/ :'compadd aaa'
4642
4643 This generates a function _tst that completes aaa as its only
4644 argument. The tag and description for the action have been
4645 omitted for brevity (this works but is not recommended in normal
4646 use). The first component matches the command word, which is
4647 arbitrary; the second matches any argument. As the argument is
4648 also arbitrary, any following component would not depend on aaa
4649 being present.
4650
4651 _regex_arguments _tst /$'[^\0]#\0'/ \
4652 /$'aaa\0'/ :'compadd aaa'
4653
4654 This is a more typical use; it is similar, but any following
4655 patterns would only match if aaa was present as the first argu‐
4656 ment.
4657
4658 _regex_arguments _tst /$'[^\0]#\0'/ \( \
4659 /$'aaa\0'/ :'compadd aaa' \
4660 /$'bbb\0'/ :'compadd bbb' \) \#
4661
4662 In this example, an indefinite number of command arguments may
4663 be completed. Odd arguments are completed as aaa and even argu‐
4664 ments as bbb. Completion fails unless the set of aaa and bbb
4665 arguments before the current one is matched correctly.
4666
4667 _regex_arguments _tst /$'[^\0]#\0'/ \
4668 \( /$'aaa\0'/ :'compadd aaa' \| \
4669 /$'bbb\0'/ :'compadd bbb' \) \#
4670
4671 This is similar, but either aaa or bbb may be completed for any
4672 argument. In this case _regex_words could be used to generate a
4673 suitable expression for the arguments.
4674
4675 _regex_words tag description spec ...
4676 This function can be used to generate arguments for the
4677 _regex_arguments command which may be inserted at any point
4678 where a set of rules is expected. The tag and description give
4679 a standard tag and description pertaining to the current con‐
4680 text. Each spec contains two or three arguments separated by a
4681 colon: note that there is no leading colon in this case.
4682
4683 Each spec gives one of a set of words that may be completed at
4684 this point, together with arguments. It is thus roughly equiva‐
4685 lent to the _arguments function when used in normal (non-regex)
4686 completion.
4687
4688 The part of the spec before the first colon is the word to be
4689 completed. This may contain a *; the entire word, before and
4690 after the * is completed, but only the text before the * is re‐
4691 quired for the context to be matched, so that further arguments
4692 may be completed after the abbreviated form.
4693
4694 The second part of spec is a description for the word being com‐
4695 pleted.
4696
4697 The optional third part of the spec describes how words follow‐
4698 ing the one being completed are themselves to be completed. It
4699 will be evaluated in order to avoid problems with quoting. This
4700 means that typically it contains a reference to an array con‐
4701 taining previously generated regex arguments.
4702
4703 The option -t term specifies a terminator for the word instead
4704 of the usual space. This is handled as an auto-removable suffix
4705 in the manner of the option -s sep to _values.
4706
4707 The result of the processing by _regex_words is placed in the
4708 array reply, which should be made local to the calling function.
4709 If the set of words and arguments may be matched repeatedly, a #
4710 should be appended to the generated array at that point.
4711
4712 For example:
4713
4714 local -a reply
4715 _regex_words mydb-commands 'mydb commands' \
4716 'add:add an entry to mydb:$mydb_add_cmds' \
4717 'show:show entries in mydb'
4718 _regex_arguments _mydb "$reply[@]"
4719 _mydb "$@"
4720
4721 This shows a completion function for a command mydb which takes
4722 two command arguments, add and show. show takes no arguments,
4723 while the arguments for add have already been prepared in an ar‐
4724 ray mydb_add_cmds, quite possibly by a previous call to
4725 _regex_words.
4726
4727 _requested [ -x ] [ -12VJ ] tag [ name descr [ command [ arg ... ] ]
4728 This function is called to decide whether a tag already regis‐
4729 tered by a call to _tags (see below) has been requested by the
4730 user and hence completion should be performed for it. It re‐
4731 turns status zero if the tag is requested and non-zero other‐
4732 wise. The function is typically used as part of a loop over
4733 different tags as follows:
4734
4735 _tags foo bar baz
4736 while _tags; do
4737 if _requested foo; then
4738 ... # perform completion for foo
4739 fi
4740 ... # test the tags bar and baz in the same way
4741 ... # exit loop if matches were generated
4742 done
4743
4744 Note that the test for whether matches were generated is not
4745 performed until the end of the _tags loop. This is so that the
4746 user can set the tag-order style to specify a set of tags to be
4747 completed at the same time.
4748
4749 If name and descr are given, _requested calls the _description
4750 function with these arguments together with the options passed
4751 to _requested.
4752
4753 If command is given, the _all_labels function will be called im‐
4754 mediately with the same arguments. In simple cases this makes
4755 it possible to perform the test for the tag and the matching in
4756 one go. For example:
4757
4758 local expl ret=1
4759 _tags foo bar baz
4760 while _tags; do
4761 _requested foo expl 'description' \
4762 compadd foobar foobaz && ret=0
4763 ...
4764 (( ret )) || break
4765 done
4766
4767 If the command is not compadd, it must nevertheless be prepared
4768 to handle the same options.
4769
4770 _retrieve_cache cache_identifier
4771 This function retrieves completion information from the file
4772 given by cache_identifier, stored in a directory specified by
4773 the cache-path style which defaults to ~/.zcompcache. The re‐
4774 turn status is zero if retrieval was successful. It will only
4775 attempt retrieval if the use-cache style is set, so you can call
4776 this function without worrying about whether the user wanted to
4777 use the caching layer.
4778
4779 See _store_cache below for more details.
4780
4781 _sep_parts
4782 This function is passed alternating arrays and separators as ar‐
4783 guments. The arrays specify completions for parts of strings to
4784 be separated by the separators. The arrays may be the names of
4785 array parameters or a quoted list of words in parentheses. For
4786 example, with the array `hosts=(ftp news)' the call `_sep_parts
4787 '(foo bar)' @ hosts' will complete the string `f' to `foo' and
4788 the string `b@n' to `bar@news'.
4789
4790 This function accepts the compadd options `-V', `-J', `-1',
4791 `-2', `-n', `-X', `-M', `-P', `-S', `-r', `-R', and `-q' and
4792 passes them on to the compadd builtin used to add the matches.
4793
4794 _sequence [ -s sep ] [ -n max ] [ -d ] function [ - ] ...
4795 This function is a wrapper to other functions for completing
4796 items in a separated list. The same function is used to complete
4797 each item in the list. The separator is specified with the -s
4798 option. If -s is omitted it will use `,'. Duplicate values are
4799 not matched unless -d is specified. If there is a fixed or maxi‐
4800 mum number of items in the list, this can be specified with the
4801 -n option.
4802
4803 Common compadd options are passed on to the function. It is pos‐
4804 sible to use compadd directly with _sequence, though _values may
4805 be more appropriate in this situation.
4806
4807 _setup tag [ group ]
4808 This function sets up the special parameters used by the comple‐
4809 tion system appropriately for the tag given as the first argu‐
4810 ment. It uses the styles list-colors, list-packed,
4811 list-rows-first, last-prompt, accept-exact, menu and force-list.
4812
4813 The optional group supplies the name of the group in which the
4814 matches will be placed. If it is not given, the tag is used as
4815 the group name.
4816
4817 This function is called automatically from _description and
4818 hence is not normally called explicitly.
4819
4820 _store_cache cache_identifier param ...
4821 This function, together with _retrieve_cache and _cache_invalid,
4822 implements a caching layer which can be used in any completion
4823 function. Data obtained by costly operations are stored in pa‐
4824 rameters; this function then dumps the values of those parame‐
4825 ters to a file. The data can then be retrieved quickly from
4826 that file via _retrieve_cache, even in different instances of
4827 the shell.
4828
4829 The cache_identifier specifies the file which the data should be
4830 dumped to. The file is stored in a directory specified by the
4831 cache-path style which defaults to ~/.zcompcache. The remaining
4832 params arguments are the parameters to dump to the file.
4833
4834 The return status is zero if storage was successful. The func‐
4835 tion will only attempt storage if the use-cache style is set, so
4836 you can call this function without worrying about whether the
4837 user wanted to use the caching layer.
4838
4839 The completion function may avoid calling _retrieve_cache when
4840 it already has the completion data available as parameters.
4841 However, in that case it should call _cache_invalid to check
4842 whether the data in the parameters and in the cache are still
4843 valid.
4844
4845 See the _perl_modules completion function for a simple example
4846 of the usage of the caching layer.
4847
4848 _tags [ [ -C name ] tag ... ]
4849 If called with arguments, these are taken to be the names of
4850 tags valid for completions in the current context. These tags
4851 are stored internally and sorted by using the tag-order style.
4852
4853 Next, _tags is called repeatedly without arguments from the same
4854 completion function. This successively selects the first, sec‐
4855 ond, etc. set of tags requested by the user. The return status
4856 is zero if at least one of the tags is requested and non-zero
4857 otherwise. To test if a particular tag is to be tried, the _re‐
4858 quested function should be called (see above).
4859
4860 If `-C name' is given, name is temporarily stored in the argu‐
4861 ment field (the fifth) of the context in the curcontext parame‐
4862 ter during the call to _tags; the field is restored on exit.
4863 This allows _tags to use a more specific context without having
4864 to change and reset the curcontext parameter (which has the same
4865 effect).
4866
4867 _tilde_files
4868 Like _files, but resolve leading tildes according to the rules
4869 of filename expansion, so the suggested completions don't start
4870 with a `~' even if the filename on the command-line does.
4871
4872 _values [ -O name ] [ -s sep ] [ -S sep ] [ -wC ] desc spec ...
4873 This is used to complete arbitrary keywords (values) and their
4874 arguments, or lists of such combinations.
4875
4876 If the first argument is the option `-O name', it will be used
4877 in the same way as by the _arguments function. In other words,
4878 the elements of the name array will be passed to compadd when
4879 executing an action.
4880
4881 If the first argument (or the first argument after `-O name') is
4882 `-s', the next argument is used as the character that separates
4883 multiple values. This character is automatically added after
4884 each value in an auto-removable fashion (see below); all values
4885 completed by `_values -s' appear in the same word on the command
4886 line, unlike completion using _arguments. If this option is not
4887 present, only a single value will be completed per word.
4888
4889 Normally, _values will only use the current word to determine
4890 which values are already present on the command line and hence
4891 are not to be completed again. If the -w option is given, other
4892 arguments are examined as well.
4893
4894 The first non-option argument, desc, is used as a string to
4895 print as a description before listing the values.
4896
4897 All other arguments describe the possible values and their argu‐
4898 ments in the same format used for the description of options by
4899 the _arguments function (see above). The only differences are
4900 that no minus or plus sign is required at the beginning, values
4901 can have only one argument, and the forms of action beginning
4902 with an equal sign are not supported.
4903
4904 The character separating a value from its argument can be set
4905 using the option -S (like -s, followed by the character to use
4906 as the separator in the next argument). By default the equals
4907 sign will be used as the separator between values and arguments.
4908
4909 Example:
4910
4911 _values -s , 'description' \
4912 '*foo[bar]' \
4913 '(two)*one[number]:first count:' \
4914 'two[another number]::second count:(1 2 3)'
4915
4916 This describes three possible values: `foo', `one', and `two'.
4917 The first is described as `bar', takes no argument and may ap‐
4918 pear more than once. The second is described as `number', may
4919 appear more than once, and takes one mandatory argument de‐
4920 scribed as `first count'; no action is specified, so it will not
4921 be completed. The `(two)' at the beginning says that if the
4922 value `one' is on the line, the value `two' will no longer be
4923 considered a possible completion. Finally, the last value
4924 (`two') is described as `another number' and takes an optional
4925 argument described as `second count' for which the completions
4926 (to appear after an `=') are `1', `2', and `3'. The _values
4927 function will complete lists of these values separated by com‐
4928 mas.
4929
4930 Like _arguments, this function temporarily adds another context
4931 name component to the arguments element (the fifth) of the cur‐
4932 rent context while executing the action. Here this name is just
4933 the name of the value for which the argument is completed.
4934
4935 The style verbose is used to decide if the descriptions for the
4936 values (but not those for the arguments) should be printed.
4937
4938 The associative array val_args is used to report values and
4939 their arguments; this works similarly to the opt_args associa‐
4940 tive array used by _arguments. Hence the function calling _val‐
4941 ues should declare the local parameters state, state_descr,
4942 line, context and val_args:
4943
4944 local context state state_descr line
4945 typeset -A val_args
4946
4947 when using an action of the form `->string'. With this function
4948 the context parameter will be set to the name of the value whose
4949 argument is to be completed. Note that for _values, the state
4950 and state_descr are scalars rather than arrays. Only a single
4951 matching state is returned.
4952
4953 Note also that _values normally adds the character used as the
4954 separator between values as an auto-removable suffix (similar to
4955 a `/' after a directory). However, this is not possible for a
4956 `->string' action as the matches for the argument are generated
4957 by the calling function. To get the usual behaviour, the call‐
4958 ing function can add the separator x as a suffix by passing the
4959 options `-qS x' either directly or indirectly to compadd.
4960
4961 The option -C is treated in the same way as it is by _arguments.
4962 In that case the parameter curcontext should be made local in‐
4963 stead of context (as described above).
4964
4965 _wanted [ -x ] [ -C name ] [ -12VJ ] tag name descr command [ arg ...]
4966 In many contexts, completion can only generate one particular
4967 set of matches, usually corresponding to a single tag. However,
4968 it is still necessary to decide whether the user requires
4969 matches of this type. This function is useful in such a case.
4970
4971 The arguments to _wanted are the same as those to _requested,
4972 i.e. arguments to be passed to _description. However, in this
4973 case the command is not optional; all the processing of tags,
4974 including the loop over both tags and tag labels and the genera‐
4975 tion of matches, is carried out automatically by _wanted.
4976
4977 Hence to offer only one tag and immediately add the correspond‐
4978 ing matches with the given description:
4979
4980 local expl
4981 _wanted tag expl 'description' \
4982 compadd -- match1 match2...
4983
4984 See also the use of _wanted in the example function in the sub‐
4985 section `Dynamic named directories' in zshexpn(1).
4986
4987 Note that, as for _requested, the command must be able to accept
4988 options to be passed down to compadd.
4989
4990 Like _tags this function supports the -C option to give a dif‐
4991 ferent name for the argument context field. The -x option has
4992 the same meaning as for _description.
4993
4994 _widgets [ -g pattern ]
4995 This function completes names of zle widgets (see the section
4996 `Widgets' in zshzle(1)). The pattern, if present, is matched
4997 against values of the $widgets special parameter, documented in
4998 the section `The zsh/zleparameter Module' in zshmodules(1).
4999
5001 There are some standard variables, initialised by the _main_complete
5002 function and then used from other functions.
5003
5004 The standard variables are:
5005
5006 _comp_caller_options
5007 The completion system uses setopt to set a number of options.
5008 This allows functions to be written without concern for compati‐
5009 bility with every possible combination of user options. However,
5010 sometimes completion needs to know what the user's option pref‐
5011 erences are. These are saved in the _comp_caller_options asso‐
5012 ciative array. Option names, spelled in lowercase without under‐
5013 scores, are mapped to one or other of the strings `on' and
5014 `off'.
5015
5016 _comp_priv_prefix
5017 Completion functions such as _sudo can set the _comp_priv_prefix
5018 array to a command prefix that may then be used by _call_program
5019 to match the privileges when calling programs to generate
5020 matches.
5021
5022 Two more features are offered by the _main_complete function. The ar‐
5023 rays compprefuncs and comppostfuncs may contain names of functions that
5024 are to be called immediately before or after completion has been tried.
5025 A function will only be called once unless it explicitly reinserts it‐
5026 self into the array.
5027
5029 In the source distribution, the files are contained in various subdi‐
5030 rectories of the Completion directory. They may have been installed in
5031 the same structure, or into one single function directory. The follow‐
5032 ing is a description of the files found in the original directory
5033 structure. If you wish to alter an installed file, you will need to
5034 copy it to some directory which appears earlier in your fpath than the
5035 standard directory where it appears.
5036
5037 Base The core functions and special completion widgets automatically
5038 bound to keys. You will certainly need most of these, though
5039 will probably not need to alter them. Many of these are docu‐
5040 mented above.
5041
5042 Zsh Functions for completing arguments of shell builtin commands and
5043 utility functions for this. Some of these are also used by
5044 functions from the Unix directory.
5045
5046 Unix Functions for completing arguments of external commands and
5047 suites of commands. They may need modifying for your system,
5048 although in many cases some attempt is made to decide which ver‐
5049 sion of a command is present. For example, completion for the
5050 mount command tries to determine the system it is running on,
5051 while completion for many other utilities try to decide whether
5052 the GNU version of the command is in use, and hence whether the
5053 --help option is supported.
5054
5055 X, AIX, BSD, ...
5056 Completion and utility function for commands available only on
5057 some systems. These are not arranged hierarchically, so, for
5058 example, both the Linux and Debian directories, as well as the X
5059 directory, may be useful on your system.
5060
5061
5062
5063zsh 5.9 May 14, 2022 ZSHCOMPSYS(1)