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