1ZSHCOMPWID(1)               General Commands Manual              ZSHCOMPWID(1)
2
3
4

NAME

6       zshcompwid - zsh completion widgets
7

DESCRIPTION

9       The shell's programmable completion mechanism can be manipulated in two
10       ways; here the low-level features supporting the newer,  function-based
11       mechanism  are  defined.   A  complete  set of shell functions based on
12       these features is described in zshcompsys(1), and users with no  inter‐
13       est  in  adding  to that system (or, potentially, writing their own ---
14       see dictionary entry for `hubris') should skip this section.  The older
15       system  based  on  the  compctl builtin command is described in zshcom‐
16       pctl(1).
17
18       Completion widgets are defined by the -C option to the zle builtin com‐
19       mand provided by the zsh/zle module (see zshzle(1)). For example,
20
21              zle -C complete expand-or-complete completer
22
23       defines  a widget named `complete'.  The second argument is the name of
24       any of the builtin  widgets  that  handle  completions:  complete-word,
25       expand-or-complete,      expand-or-complete-prefix,      menu-complete,
26       menu-expand-or-complete,   reverse-menu-complete,   list-choices,    or
27       delete-char-or-list.  Note that this will still work even if the widget
28       in question has been re-bound.
29
30       When this newly defined widget is bound to  a  key  using  the  bindkey
31       builtin  command  defined in the zsh/zle module (see zshzle(1)), typing
32       that key will call the shell function  `completer'.  This  function  is
33       responsible  for  generating  the  possible  matches using the builtins
34       described below.  As with other ZLE widgets,  the  function  is  called
35       with its standard input closed.
36
37       Once the function returns, the completion code takes over control again
38       and treats the matches in the same manner as the specified builtin wid‐
39       get, in this case expand-or-complete.
40

SPECIAL PARAMETERS

42       Inside  completion  widgets,  and  any functions called from them, some
43       parameters have special meaning; outside these functions they  are  not
44       special  to  the  shell  in any way.  These parameters are used to pass
45       information between the completion code and the completion widget. Some
46       of  the builtin commands and the condition codes use or change the cur‐
47       rent values of these parameters.  Any existing values  will  be  hidden
48       during  execution  of  completion  widgets;  except  for compstate, the
49       parameters are reset on each function exit (including  nested  function
50       calls  from  within  the completion widget) to the values they had when
51       the function was entered.
52
53       CURRENT
54              This is the number of the current word, i.e. the word the cursor
55              is  currently  on  in  the words array.  Note that this value is
56              only correct if the ksharrays option is not set.
57
58       IPREFIX
59              Initially this will be set to the empty string.  This  parameter
60              functions  like  PREFIX; it contains a string which precedes the
61              one in PREFIX and is not considered part of the list of matches.
62              Typically,  a string is transferred from the beginning of PREFIX
63              to the end of IPREFIX, for example:
64
65                     IPREFIX=${PREFIX%%\=*}=
66                     PREFIX=${PREFIX#*=}
67
68              causes the part of the prefix up  to  and  including  the  first
69              equal  sign not to be treated as part of a matched string.  This
70              can be done automatically by the compset builtin, see below.
71
72       ISUFFIX
73              As IPREFIX, but for a suffix that should not be considered  part
74              of  the matches; note that the ISUFFIX string follows the SUFFIX
75              string.
76
77       PREFIX Initially this will be set to the part of the current word  from
78              the  beginning  of the word up to the position of the cursor; it
79              may be altered to give a common prefix for all matches.
80
81       QIPREFIX
82              This parameter is read-only and contains the quoted string up to
83              the  word  being  completed.  E.g.  when completing `"foo', this
84              parameter contains the double quote. If the -q option of compset
85              is used (see below), and the original string was `"foo bar' with
86              the cursor on the `bar', this parameter contains `"foo '.
87
88       QISUFFIX
89              Like QIPREFIX, but containing the suffix.
90
91       SUFFIX Initially this will be set to the part of the current word  from
92              the cursor position to the end; it may be altered to give a com‐
93              mon suffix for all matches.  It is most useful when  the  option
94              COMPLETE_IN_WORD is set, as otherwise the whole word on the com‐
95              mand line is treated as a prefix.
96
97       compstate
98              This is an associative array with various keys and  values  that
99              the  completion  code uses to exchange information with the com‐
100              pletion widget.  The keys are:
101
102              all_quotes
103                     The -q option of the compset builtin command (see  below)
104                     allows  a quoted string to be broken into separate words;
105                     if the cursor is on one of those words, that word will be
106                     completed,  possibly  invoking  `compset -q' recursively.
107                     With this key it is possible to test the types of  quoted
108                     strings  which  are  currently  broken into parts in this
109                     fashion.  Its value contains one character for each quot‐
110                     ing level.  The characters are a single quote or a double
111                     quote for strings quoted  with  these  characters  and  a
112                     backslash  for  strings not starting with a quote charac‐
113                     ter.  The first character in the value always corresponds
114                     to the innermost quoting level.
115
116              context
117                     This  will  be  set by the completion code to the overall
118                     context in which completion is attempted. Possible values
119                     are:
120
121                     array_value
122                            when  completing  inside  the  value  of  an array
123                            parameter assignment; in this case the words array
124                            contains the words inside the parentheses.
125
126                     brace_parameter
127                            when  completing  the  name  of  a  parameter in a
128                            parameter expansion beginning with ${.
129
130                     assign_parameter
131                            when completing the  name  of  a  parameter  in  a
132                            parameter assignment.
133
134                     command
135                            when  completing  for  a normal command (either in
136                            command position or for an argument  of  the  com‐
137                            mand).
138
139                     condition
140                            when  completing  inside  a  `[[...]]' conditional
141                            expression; in this case the words array  contains
142                            only the words inside the conditional expression.
143
144                     math   when completing in a mathematical environment such
145                            as a `((...))' construct.
146
147                     parameter
148                            when completing the  name  of  a  parameter  in  a
149                            parameter expansion beginning with $ but not ${.
150
151                     redirect
152                            when completing after a redirection operator.
153
154                     subscript
155                            when completing inside a parameter subscript.
156
157                     value  when  completing  the value of a parameter assign‐
158                            ment.
159
160              exact  Controls the behaviour when the REC_EXACT option is  set.
161                     It  will  be  set  to  accept  if an exact match would be
162                     accepted, and will be unset otherwise.
163
164                     If it was set when at least one match equal to the string
165                     on the line was generated, the match is accepted.
166
167              exact_string
168                     The  string of an exact match if one was found, otherwise
169                     unset.
170
171              ignored
172                     The number  of  words  that  were  ignored  because  they
173                     matched  one  of the patterns given with the -F option to
174                     the compadd builtin command.
175
176              insert This controls the manner in which  a  match  is  inserted
177                     into  the command line.  On entry to the widget function,
178                     if it is unset the command line is not to be changed;  if
179                     set  to  unambiguous, any prefix common to all matches is
180                     to be inserted; if set to automenu-unambiguous, the  com‐
181                     mon  prefix  is to be inserted and the next invocation of
182                     the completion code may start menu completion (due to the
183                     AUTO_MENU  option  being set); if set to menu or automenu
184                     menu completion will be started for the matches currently
185                     generated  (in  the  latter case this will happen because
186                     the AUTO_MENU is set). The value  may  also  contain  the
187                     string  `tab' when the completion code would normally not
188                     really do completion, but only insert the TAB character.
189
190                     On exit it may be set to any of the values  above  (where
191                     setting  it  to the empty string is the same as unsetting
192                     it), or to a number, in which case the match whose number
193                     is  given  will be inserted into the command line.  Nega‐
194                     tive numbers count backward from  the  last  match  (with
195                     `-1'  selecting  the  last match) and out-of-range values
196                     are wrapped around, so that a value of zero  selects  the
197                     last  match and a value one more than the maximum selects
198                     the first. Unless the value of this key ends in a  space,
199                     the match is inserted as in a menu completion, i.e. with‐
200                     out automatically appending a space.
201
202                     Both menu and automenu may also specify the the number of
203                     the  match  to insert, given after a colon.  For example,
204                     `menu:2' says to start menu  completion,  beginning  with
205                     the second match.
206
207                     Note  that  a  value containing the substring `tab' makes
208                     the matches generated be ignored  and  only  the  TAB  be
209                     inserted.
210
211                     Finally,  it  may  also  be  set  to all, which makes all
212                     matches generated be inserted into the line.
213
214              insert_positions
215                     When the completion system inserts an unambiguous  string
216                     into the line, there may be multiple places where charac‐
217                     ters are missing or where the character inserted  differs
218                     from  at least one match.  The value of this key contains
219                     a colon separated list of all these positions, as indexes
220                     into the command line.
221
222              last_prompt
223                     If  this  is  set  to  a non-empty string for every match
224                     added, the completion code will move the cursor  back  to
225                     the  previous  prompt  after  the list of completions has
226                     been displayed.  Initially this is set or unset according
227                     to the ALWAYS_LAST_PROMPT option.
228
229              list   This  controls whether or how the list of matches will be
230                     displayed.  If it is unset or empty they  will  never  be
231                     listed;  if  its value begins with list, they will always
232                     be listed; if it begins with autolist or ambiguous,  they
233                     will  be  listed  when  the  AUTO_LIST  or LIST_AMBIGUOUS
234                     options respectively would normally cause them to be.
235
236                     If the substring force appears in the value,  this  makes
237                     the  list  be shown even if there is only one match. Nor‐
238                     mally, the list would be shown only if there are at least
239                     two matches.
240
241                     The   value   contains   the   substring  packed  if  the
242                     LIST_PACKED option is set. If this substring is given for
243                     all  matches  added  to a group, this group will show the
244                     LIST_PACKED  behavior.  The  same   is   done   for   the
245                     LIST_ROWS_FIRST option with the substring rows.
246
247                     Finally,  if  the value contains the string explanations,
248                     only the explanation strings, if any, will be listed  and
249                     if  it  contains  messages, only the messages (added with
250                     the -x option of compadd) will be listed.  If it contains
251                     both  explanations and messages both kinds of explanation
252                     strings will be listed.  It will be set appropriately  on
253                     entry to a completion widget and may be changed there.
254
255              list_lines
256                     This gives the number of lines that are needed to display
257                     the full list of completions.  Note that to calculate the
258                     total number of lines to display you need to add the num‐
259                     ber of lines needed for the command line to  this  value,
260                     this is available as the value of the BUFFERLINES special
261                     parameter.
262
263              list_max
264                     Initially this is set to the value of the LISTMAX parame‐
265                     ter.   It  may be set to any other value; when the widget
266                     exits this value will be used in  the  same  way  as  the
267                     value of LISTMAX.
268
269              nmatches
270                     The  number of matches generated and accepted by the com‐
271                     pletion code so far.
272
273              old_insert
274                     On entry to the widget this will be set to the number  of
275                     the match of an old list of completions that is currently
276                     inserted into the command line.  If  no  match  has  been
277                     inserted, this is unset.
278
279                     As with old_list, the value of this key will only be used
280                     if it is the string keep. If it was set to this value  by
281                     the  widget  and there was an old match inserted into the
282                     command line, this match will be kept and if the value of
283                     the  insert  key  specifies  that another match should be
284                     inserted, this will be inserted after the old one.
285
286              old_list
287                     This is set to yes if there is still a valid list of com‐
288                     pletions  from a previous completion at the time the wid‐
289                     get is invoked.  This will usually be  the  case  if  and
290                     only  if  the previous editing operation was a completion
291                     widget or one of the builtin  completion  functions.   If
292                     there  is  a valid list and it is also currently shown on
293                     the screen, the value of this key is shown.
294
295                     After the widget has exited the value of this key is only
296                     used  if it was set to keep.  In this case the completion
297                     code will continue to use this old list.  If  the  widget
298                     generated new matches, they will not be used.
299
300              parameter
301                     The  name of the parameter when completing in a subscript
302                     or in the value of a parameter assignment.
303
304              pattern_insert
305                     Normally this is set to menu, which specifies  that  menu
306                     completion  will  be  used  whenever a set of matches was
307                     generated using pattern matching.  If it is  set  to  any
308                     other non-empty string by the user and menu completion is
309                     not selected by other  option  settings,  the  code  will
310                     instead  insert  any  common  prefix  for  the  generated
311                     matches as with normal completion.
312
313              pattern_match
314                     Locally controls the behaviour given by the GLOB_COMPLETE
315                     option.   Initially  it  is set to `*' if and only if the
316                     option is set.  The completion widget may set it to  this
317                     value,  to  an empty string (which has the same effect as
318                     unsetting it), or to any other non-empty string.   If  it
319                     is non-empty, unquoted metacharacters on the command line
320                     will be treated as patterns; if it is `*', then addition‐
321                     ally a wildcard `*' is assumed at the cursor position; if
322                     it is empty or unset, metacharacters will be treated lit‐
323                     erally.
324
325                     Note that the matcher specifications given to the compadd
326                     builtin command  are  not  used  if  this  is  set  to  a
327                     non-empty string.
328
329              quote  When  completing  inside quotes, this contains the quota‐
330                     tion character (i.e. either  a  single  quote,  a  double
331                     quote, or a backtick).  Otherwise it is unset.
332
333              quoting
334                     When  completing inside single quotes, this is set to the
335                     string single; inside double quotes, the  string  double;
336                     inside  backticks,  the string backtick.  Otherwise it is
337                     unset.
338
339              redirect
340                     The redirection operator when completing in a redirection
341                     position, i.e. one of <, >, etc.
342
343              restore
344                     This  is  set to auto before a function is entered, which
345                     forces the special  parameters  mentioned  above  (words,
346                     CURRENT,  PREFIX,  IPREFIX,  SUFFIX,  and  ISUFFIX) to be
347                     restored to  their  previous  values  when  the  function
348                     exits.    If a function unsets it or sets it to any other
349                     string, they will not be restored.
350
351              to_end Specifies the occasions on which the cursor is  moved  to
352                     the  end  of a string when a match is inserted.  On entry
353                     to a widget function, it may be single if this will  hap‐
354                     pen when a single unambiguous match was inserted or match
355                     if it will happen any time a match is inserted (for exam‐
356                     ple,  by menu completion; this is likely to be the effect
357                     of the ALWAYS_TO_END option).
358
359                     On exit, it may be set to single as above.  It  may  also
360                     be  set  to  always,  or to the empty string or unset; in
361                     those cases the cursor will be moved to the  end  of  the
362                     string always or never respectively.  Any other string is
363                     treated as match.
364
365              unambiguous
366                     This key is read-only and will always be set to the  com‐
367                     mon  (unambiguous)  prefix the completion code has gener‐
368                     ated for all matches added so far.
369
370              unambiguous_cursor
371                     This gives the position the cursor would be placed at  if
372                     the  common  prefix in the unambiguous key were inserted,
373                     relative to the value of that key. The  cursor  would  be
374                     placed  before the character whose index is given by this
375                     key.
376
377              unambiguous_positions
378                     This contains all positions where characters in the unam‐
379                     biguous   string  are  missing  or  where  the  character
380                     inserted differs from at least one of the  matches.   The
381                     positions  are  given as indexes into the string given by
382                     the value of the unambiguous key.
383
384              vared  If completion is called while editing a  line  using  the
385                     vared  builtin,  the value of this key is set to the name
386                     of the parameter given as an argument to vared.  This key
387                     is only set while a vared command is active.
388
389       words  This  array  contains the words present on the command line cur‐
390              rently being edited.
391

BUILTIN COMMANDS

393       compadd [ -akqQfenUl12C ] [ -F array ]
394       [ -P prefix ] [ -S suffix ]
395       [ -p hidden-prefix ] [ -s hidden-suffix ]
396       [ -i ignored-prefix ] [ -I ignored-suffix ]
397       [ -W file-prefix ] [ -d array ]
398       [ -J name ] [ -V name ] [ -X explanation ] [ -x message ]
399       [ -r remove-chars ] [ -R remove-func ]
400       [ -D array ] [ -O array ] [ -A array ]
401       [ -E number ]
402       [ -M match-spec ] [ -- ] [ words ... ]
403
404              This builtin command can be used to  add  matches  directly  and
405              control all the information the completion code stores with each
406              possible match. The return value is zero if at least  one  match
407              was added and non-zero if no matches were added.
408
409              The  completion  code  breaks  the string to complete into seven
410              fields in the order:
411
412                     <ipre><apre><hpre><word><hsuf><asuf><isuf>
413
414              The first field is an ignored  prefix  taken  from  the  command
415              line,  the  contents  of  the  IPREFIX parameter plus the string
416              given with the -i option. With the -U option,  only  the  string
417              from the -i option is used. The field <apre> is an optional pre‐
418              fix string given with the -P option.   The  <hpre>  field  is  a
419              string  that is considered part of the match but that should not
420              be shown when listing completions, given with the -p option; for
421              example,  functions  that do filename generation might specify a
422              common path prefix this way.  <word> is the part  of  the  match
423              that  should  appear in the list of completions, i.e. one of the
424              words given at the end of the compadd command line. The suffixes
425              <hsuf>,  <asuf>  and  <isuf>  correspond to the prefixes <hpre>,
426              <apre> and <ipre> and are given by the options -s,  -S  and  -I,
427              respectively.
428
429              The supported flags are:
430
431              -P prefix
432                     This  gives  a  string  to  be  inserted before the given
433                     words.  The string given is not considered as part of the
434                     match  and  any  shell  metacharacters  in it will not be
435                     quoted when the string is inserted.
436
437              -S suffix
438                     Like -P, but gives a string  to  be  inserted  after  the
439                     match.
440
441              -p hidden-prefix
442                     This gives a string that should be inserted into the com‐
443                     mand line before the match but that should not appear  in
444                     the  list of matches. Unless the -U option is given, this
445                     string must be matched as part of the string on the  com‐
446                     mand line.
447
448              -s hidden-suffix
449                     Like `-p', but gives a string to insert after the match.
450
451              -i ignored-prefix
452                     This  gives a string to insert into the command line just
453                     before any string given with the  `-P'  option.   Without
454                     `-P'  the string is inserted before the string given with
455                     `-p' or directly before the match.
456
457              -I ignored-suffix
458                     Like -i, but gives an ignored suffix.
459
460              -a     With this flag the words are taken as names of arrays and
461                     the possible matches are their values.  If only some ele‐
462                     ments of the arrays are needed, the words may  also  con‐
463                     tain subscripts, as in `foo[2,-1]'.
464
465              -k     With  this  flag the words are taken as names of associa‐
466                     tive arrays and the possible matches are their keys.   As
467                     for  -a,  the  words  may  also contain subscripts, as in
468                     `foo[(R)*bar*]'.
469
470              -d array
471                     This adds per-match display  strings.  The  array  should
472                     contain  one  element per word given. The completion code
473                     will then display the first element instead of the  first
474                     word, and so on. The array may be given as the name of an
475                     array parameter or directly as a space-separated list  of
476                     words in parentheses.
477
478                     If  there are fewer display strings than words, the left‐
479                     over words will be displayed unchanged and if  there  are
480                     more  display  strings  than  words, the leftover display
481                     strings will be silently ignored.
482
483              -l     This option only has an effect if used together with  the
484                     -d option. If it is given, the display strings are listed
485                     one per line, not arrayed in columns.
486
487              -J name
488                     Gives the name of the group of matches the  words  should
489                     be stored in.
490
491              -V name
492                     Like  -J but naming a unsorted group. These are in a dif‐
493                     ferent name space than groups created with the -J flag.
494
495              -1     If given together with the -V option, makes only consecu‐
496                     tive duplicates in the group be removed. If combined with
497                     the -J option, this has  no  visible  effect.  Note  that
498                     groups  with  and without this flag are in different name
499                     spaces.
500
501              -2     If given together with the -J or  -V  option,  makes  all
502                     duplicates  be  kept. Again, groups with and without this
503                     flag are in different name spaces.
504
505              -X explanation
506                     The explanation string will be printed with the  list  of
507                     matches, above the group currently selected.
508
509              -x message
510                     Like  -X,  but  the message will be printed even if there
511                     are no matches in the group.
512
513              -q     The suffix given with -S will be automatically removed if
514                     the  next  character  typed is a blank or does not insert
515                     anything, or if the suffix consists of only one character
516                     and the next character typed is the same character.
517
518              -r remove-chars
519                     This is a more versatile form of the -q option.  The suf‐
520                     fix given with -S or the slash automatically added  after
521                     completing  directories  will be automatically removed if
522                     the next character typed inserts one  of  the  characters
523                     given  in  the  remove-chars.  This string is parsed as a
524                     characters class and understands the backslash  sequences
525                     used  by  the  print  command.  For example, `-r "a-z\t"'
526                     removes the suffix if the next character typed inserts  a
527                     lowercase character or a TAB, and `-r "^0-9"' removes the
528                     suffix if the next character typed inserts anything but a
529                     digit. One extra backslash sequence is understood in this
530                     string: `\-' stands for all characters that insert  noth‐
531                     ing.  Thus  `-S  "="  -q'  is  the  same as `-S "=" -r "=
532                     \t\n\-"'.
533
534                     This option may also be used without the -S option;  then
535                     any automatically added space will be removed when one of
536                     the characters in the list is typed.
537
538              -R remove-func
539                     This is another form of the -r option. When a suffix  has
540                     been  inserted  and the completion accepted, the function
541                     remove-func will  be  called  after  the  next  character
542                     typed.  It is passed the length of the suffix as an argu‐
543                     ment and can use  the  special  parameters  available  in
544                     ordinary  (non-completion) zle widgets (see zshzle(1)) to
545                     analyse and modify the command line.
546
547              -f     If this flag is given, all  of  the  matches  built  from
548                     words  are  marked as being the names of files.  They are
549                     not required to be actual filenames, but if they are, and
550                     the  option  LIST_TYPES is set, the characters describing
551                     the types of the files in the completion  lists  will  be
552                     shown. This also forces a slash to be added when the name
553                     of a directory is completed.
554
555              -e     This flag can be used to tell the  completion  code  that
556                     the  matches  added  are  parameter names for a parameter
557                     expansion.  This  will  make  the  AUTO_PARAM_SLASH   and
558                     AUTO_PARAM_KEYS options be used for the matches.
559
560              -W file-prefix
561                     This  string is a pathname that will be prepended to each
562                     of the matches formed by the given  words  together  with
563                     any  prefix specified by the -p option to form a complete
564                     filename for testing.  Hence it is only  useful  if  com‐
565                     bined  with  the -f flag, as the tests will not otherwise
566                     be performed.
567
568              -F array
569                     Specifies an array containing  patterns.  Words  matching
570                     one of these patterns are ignored, i.e. not considered to
571                     be possible matches.
572
573                     The array may be the name of an array parameter or a list
574                     of  literal  patterns enclosed in parentheses and quoted,
575                     as in `-F "(*?.o *?.h)"'. If the  name  of  an  array  is
576                     given,  the  elements  of the array are taken as the pat‐
577                     terns.
578
579              -Q     This flag instructs the completion code not to quote  any
580                     metacharacters  in the words when inserting them into the
581                     command line.
582
583              -M match-spec
584                     This gives local match specifications as described  below
585                     in  the  section  `Matching  Control'. This option may be
586                     given more than once. In this case all match-specs  given
587                     are  concatenated  with  spaces  between them to form the
588                     specification string to use.  Note that they will only be
589                     used if the -U option is not given.
590
591              -n     Specifies that the words added are to be used as possible
592                     matches, but are not to appear in the completion listing.
593
594              -U     If this flag is given, all words given will  be  accepted
595                     and no matching will be done by the completion code. Nor‐
596                     mally this is used in  functions  that  do  the  matching
597                     themselves.
598
599              -O array
600                     If  this  option is given, the words are not added to the
601                     set of possible completions.  Instead, matching  is  done
602                     as  usual  and  all  of the words given as arguments that
603                     match the string on the command line will  be  stored  in
604                     the array parameter whose name is given as array.
605
606              -A array
607                     As  the  -O  option,  except that instead of those of the
608                     words which match being stored in array, the strings gen‐
609                     erated  internally by the completion code are stored. For
610                     example, with a matching specification of `-M  "L:|no="',
611                     the string `nof' on the command line and the string `foo'
612                     as one of  the  words,  this  option  stores  the  string
613                     `nofoo'  in  the  array, whereas the -O option stores the
614                     `foo' originally given.
615
616              -D array
617                     As with -O, the words are not added to the set of  possi‐
618                     ble  completions.   Instead,  the  completion  code tests
619                     whether each word in turn matches what is  on  the  line.
620                     If  the n'th word does not match, the n'th element of the
621                     array is removed.  Elements for which  the  corresponding
622                     word is matched are retained.
623
624              -C     This  option  adds  a  special match which expands to all
625                     other matches when inserted into  the  line,  even  those
626                     that  are added after this option is used.  Together with
627                     the -d option it is possible to  specify  a  string  that
628                     should  be  displayed in the list for this special match.
629                     If no string is given, it will be shown as a string  con‐
630                     taining  the strings that would be inserted for the other
631                     matches, truncated to the width of the screen.
632
633              -E     This option adds number empty  matches  after  the  words
634                     have  been  added.  An empty match takes up space in com‐
635                     pletion listings but will never be inserted in  the  line
636                     and can't be selected with menu completion or menu selec‐
637                     tion.  This makes empty matches  only  useful  to  format
638                     completion  lists and to make explanatory string be shown
639                     in completion lists (since empty  matches  can  be  given
640                     display strings with the -d option).  And because all but
641                     one empty string would otherwise be removed, this  option
642                     implies  the  -V  and  -2 options (even if an explicit -J
643                     option is given).
644
645              -
646              --     This flag ends the list of flags and options.  All  argu‐
647                     ments  after  it  will  be  taken  as the words to use as
648                     matches even if they begin with hyphens.
649
650              Except for the -M flag, if any of these flags is given more than
651              once, the first one (and its argument) will be used.
652
653       compset -p number
654       compset -P [ number ] pattern
655       compset -s number
656       compset -S [ number ] pattern
657       compset -n begin [ end ]
658       compset -N beg-pat [ end-pat ]
659       compset -q
660              This  command simplifies modification of the special parameters,
661              while its return value allows tests on them to be carried out.
662
663              The options are:
664
665              -p number
666                     If the contents of the PREFIX parameter  is  longer  than
667                     number   characters,  the  first  number  characters  are
668                     removed from it and  appended  to  the  contents  of  the
669                     IPREFIX parameter.
670
671              -P [ number ] pattern
672                     If the value of the PREFIX parameter begins with anything
673                     that matches the pattern, the matched portion is  removed
674                     from PREFIX and appended to IPREFIX.
675
676                     Without  the optional number, the longest match is taken,
677                     but if number is given,  anything  up  to  the  number'th
678                     match is moved.  If the number is negative, the number'th
679                     longest match is moved. For example, if  PREFIX  contains
680                     the  string  `a=b=c', then compset -P '*\=' will move the
681                     string `a=b=' into the IPREFIX parameter, but compset  -P
682                     1 '*\=' will move only the string `a='.
683
684              -s number
685                     As  -p,  but transfer the last number characters from the
686                     value of SUFFIX to the front of the value of ISUFFIX.
687
688              -S [ number ] pattern
689                     As -P, but match the last portion of SUFFIX and  transfer
690                     the matched portion to the front of the value of ISUFFIX.
691
692              -n begin [ end ]
693                     If  the current word position as specified by the parame‐
694                     ter CURRENT is greater than or equal to  begin,  anything
695                     up  to  the begin'th word is removed from the words array
696                     and the value of the parameter CURRENT is decremented  by
697                     begin.
698
699                     If  the  optional  end is given, the modification is done
700                     only if the current word position is also  less  than  or
701                     equal  to  end. In this case, the words from position end
702                     onwards are also removed from the words array.
703
704                     Both begin and end may be  negative  to  count  backwards
705                     from the last element of the words array.
706
707              -N beg-pat [ end-pat ]
708                     If  one of the elements of the words array before the one
709                     at the index given by the value of the parameter  CURRENT
710                     matches  the  pattern  beg-pat,  all  elements  up to and
711                     including the matching one are  removed  from  the  words
712                     array and the value of CURRENT is changed to point to the
713                     same word in the changed array.
714
715                     If the optional pattern end-pat is also given, and  there
716                     is  an  element in the words array matching this pattern,
717                     the parameters are modified only if  the  index  of  this
718                     word  is higher than the one given by the CURRENT parame‐
719                     ter (so that the matching word has to be after  the  cur‐
720                     sor).  In  this  case,  the  words  starting with the one
721                     matching end-pat are also removed from the  words  array.
722                     If  words  contains no word matching end-pat, the testing
723                     and modification is performed as if it were not given.
724
725              -q     The word currently being completed  is  split  on  spaces
726                     into  separate  words, respecting the usual shell quoting
727                     conventions.  The resulting words are stored in the words
728                     array,  and CURRENT, PREFIX, SUFFIX, QIPREFIX, and QISUF‐
729                     FIX are modified to reflect the word part  that  is  com‐
730                     pleted.
731
732              In all the above cases the return value is zero if the test suc‐
733              ceeded and the parameters were modified and non-zero  otherwise.
734              This allows one to use this builtin in tests such as:
735
736                     if compset -P '*\='; then ...
737
738              This  forces anything up to and including the last equal sign to
739              be ignored by the completion code.
740
741       compcall [ -TD ]
742              This allows the use of  completions  defined  with  the  compctl
743              builtin  from  within  completion  widgets.  The list of matches
744              will be generated as if one of the non-widget  completion  func‐
745              tion  (complete-word,  etc.)   had been called, except that only
746              compctls given for specific commands are used. To force the code
747              to  try completions defined with the -T option of compctl and/or
748              the default completion (whether defined by  compctl  -D  or  the
749              builtin  default)  in  the  appropriate places, the -T and/or -D
750              flags can be passed to compcall.
751
752              The return value can be used to test if a matching compctl defi‐
753              nition was found. It is non-zero if a compctl was found and zero
754              otherwise.
755
756              Note that this builtin is defined by the zsh/compctl module.
757

CONDITION CODES

759       The following additional condition codes for use within the [[  ...  ]]
760       construct  are available in completion widgets.  These work on the spe‐
761       cial parameters.  All of these tests  can  also  be  performed  by  the
762       compset builtin, but in the case of the condition codes the contents of
763       the special parameters are not modified.
764
765       -prefix [ number ] pattern
766              true if the test for the -P option of compset would succeed.
767
768       -suffix [ number ] pattern
769              true if the test for the -S option of compset would succeed.
770
771       -after beg-pat
772              true if the test of the -N option with only  the  beg-pat  given
773              would succeed.
774
775       -between beg-pat end-pat
776              true if the test for the -N option with both patterns would suc‐
777              ceed.
778

MATCHING CONTROL

780       It is possible by use of the -M option of the compadd  builtin  command
781       to  specify  how the characters in the string to be completed (referred
782       to here as the command line) map onto the characters  in  the  list  of
783       matches  produced by the completion code (referred to here as the trial
784       completions). Note that this is not used if the command line contains a
785       glob  pattern  and the GLOB_COMPLETE option is set or the pattern_match
786       of the compstate special association is set to a non-empty string.
787
788       The match-spec given as the argument to the  -M  option  (see  `Builtin
789       Commands'  above)  consists  of one or more matching descriptions sepa‐
790       rated by whitespace.  Each description consists of a letter followed by
791       a  colon  and then the patterns describing which character sequences on
792       the line match which character sequences in the trial completion.   Any
793       sequence  of characters not handled in this fashion must match exactly,
794       as usual.
795
796       The forms of match-spec understood are as follows. In  each  case,  the
797       form  with  an  uppercase  initial character retains the string already
798       typed on the command line as the final result of completion, while with
799       a lowercase initial character the string on the command line is changed
800       into the corresponding part of the trial completion.
801
802       m:lpat=tpat
803       M:lpat=tpat
804              Here, lpat is a pattern that matches on the command line, corre‐
805              sponding to tpat which matches in the trial completion.
806
807       l:lanchor|lpat=tpat
808       L:lanchor|lpat=tpat
809       l:lanchor||ranchor=tpat
810       L:lanchor||ranchor=tpat
811       b:lpat=tpat
812       B:lpat=tpat
813              These letters are for patterns that are anchored by another pat‐
814              tern on the left side. Matching for lpat and tpat is  as  for  m
815              and  M, but the pattern lpat matched on the command line must be
816              preceded by the pattern lanchor.  The lanchor can  be  blank  to
817              anchor the match to the start of the command line string; other‐
818              wise the anchor can occur anywhere, but must match in  both  the
819              command line and trial completion strings.
820
821              If  no  lpat  is  given  but  a ranchor is, this matches the gap
822              between substrings matched by lanchor and ranchor.  Unlike  lan‐
823              chor,  the  ranchor  only  needs  to  match the trial completion
824              string.
825
826              The b and B forms are similar to l and L with an  empty  anchor,
827              but  need to match only the beginning of the trial completion or
828              the word on the command line, respectively.
829
830       r:lpat|ranchor=tpat
831       R:lpat|ranchor=tpat
832       r:lanchor||ranchor=tpat
833       R:lanchor||ranchor=tpat
834       e:lpat=tpat
835       E:lpat=tpat
836              As l, L, b and B, with the difference that the command line  and
837              trial  completion patterns are anchored on the right side.  Here
838              an empty ranchor and the e and E forms force the  match  to  the
839              end of the trial completion or command line string.
840
841       Each  lpat,  tpat  or anchor is either an empty string or consists of a
842       sequence of literal characters (which may be quoted with a  backslash),
843       question marks, character classes, and correspondence classes; ordinary
844       shell patterns are not used.  Literal characters match only themselves,
845       question marks match any character, and character classes are formed as
846       for globbing and match any character in the given set.
847
848       Correspondence classes are defined like character classes, but with two
849       differences:  they  are  delimited  by  a  pair  of braces, and negated
850       classes are not allowed, so the characters !  and  ^  have  no  special
851       meaning  directly  after the opening brace.  They indicate that a range
852       of characters on the line match a range of characters in the trial com‐
853       pletion,  but  (unlike  ordinary character classes) paired according to
854       the corresponding position in the sequence. For example,  to  make  any
855       lowercase  letter  on the line match the corresponding uppercase letter
856       in the trial completion, you can use `m:{a-z}={A-Z}'.   More  than  one
857       pair  of  classes can occur, in which case the first class before the =
858       corresponds to the first after it, and so on.  If  one  side  has  more
859       such  classes  than the other side, the superfluous classes behave like
860       normal character classes.  In anchor  patterns  correspondence  classes
861       also behave like normal character classes.
862
863       The  pattern tpat may also be one or two stars, `*' or `**'. This means
864       that the pattern on the command line can match any number of characters
865       in  the trial completion. In this case the pattern must be anchored (on
866       either side); in the case of a single star, the anchor then  determines
867       how much of the trial completion is to be included --- only the charac‐
868       ters up to the next appearance of the anchor will be matched. With  two
869       stars, substrings matched by the anchor can be matched, too.
870
871       Examples:
872
873       The keys of the options association defined by the parameter module are
874       the option names in all-lowercase form, without underscores, and  with‐
875       out  the  optional  no at the beginning even though the builtins setopt
876       and unsetopt understand option names  with  uppercase  letters,  under‐
877       scores,  and  the optional no.  The following alters the matching rules
878       so that the prefix no and any underscore are  ignored  when  trying  to
879       match the trial completions generated and uppercase letters on the line
880       match the corresponding lowercase letters in the words:
881
882              compadd -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' - \
883                ${(k)options}
884
885       The first part says that the pattern `[nN][oO]' at the  beginning  (the
886       empty  anchor before the pipe symbol) of the string on the line matches
887       the empty string in the list of words generated by  completion,  so  it
888       will be ignored if present. The second part does the same for an under‐
889       score anywhere in the command line string, and the third part uses cor‐
890       respondence  classes  so  that any uppercase letter on the line matches
891       the corresponding lowercase letter in the word. The use of  the  upper‐
892       case  forms  of  the specification characters (L and M) guarantees that
893       what has already been typed on the command line (in particular the pre‐
894       fix no) will not be deleted.
895
896       Note  that  the  use  of L in the first part means that it matches only
897       when at the beginning of both the command line  string  and  the  trial
898       completion.  I.e.,  the  string  `_NO_f'  would  not  be  completed  to
899       `_NO_foo', nor would `NONO_f' be completed to `NONO_foo' because of the
900       leading  underscore or the second `NO' on the line which makes the pat‐
901       tern fail even though they are otherwise  ignored.  To  fix  this,  one
902       would  use `B:[nN][oO]=' instead of the first part. As described above,
903       this matches at the beginning of the trial completion,  independent  of
904       other  characters  or  substrings  at the beginning of the command line
905       word which are ignored by the same or other match-specs.
906
907       The second example makes completion case insensitive.  This is just the
908       same  as in the option example, except here we wish to retain the char‐
909       acters in the list of completions:
910
911              compadd -M 'm:{a-z}={A-Z}' ...
912
913       This makes lowercase letters match their  uppercase  counterparts.   To
914       make uppercase letters match the lowercase forms as well:
915
916              compadd -M 'm:{a-zA-Z}={A-Za-z}' ...
917
918       A  nice  example  for the use of * patterns is partial word completion.
919       Sometimes you would like to  make  strings  like  `c.s.u'  complete  to
920       strings like `comp.source.unix', i.e. the word on the command line con‐
921       sists of multiple parts, separated by a dot in this example, where each
922       part  should  be  completed separately --- note, however, that the case
923       where each part of the word, i.e. `comp', `source' and `unix'  in  this
924       example,  is to be completed from separate sets of matches is a differ‐
925       ent problem to be solved by the implementation of the  completion  wid‐
926       get.  The example can be handled by:
927
928              compadd -M 'r:|.=* r:|=*' \
929                - comp.sources.unix comp.sources.misc ...
930
931       The  first  specification  says  that  lpat  is the empty string, while
932       anchor is a dot; tpat is *, so this can match anything except  for  the
933       `.'  from  the anchor in the trial completion word.  So in `c.s.u', the
934       matcher sees `c', followed by the empty string, followed by the  anchor
935       `.',  and  likewise  for the second dot, and replaces the empty strings
936       before the anchors, giving `c[omp].s[ources].u[nix]',  where  the  last
937       part of the completion is just as normal.
938
939       With  the  pattern shown above, the string `c.u' could not be completed
940       to `comp.sources.unix' because  the  single  star  means  that  no  dot
941       (matched  by  the  anchor)  can  be  skipped.  By using two stars as in
942       `r:|.=**', however, `c.u' could be  completed  to  `comp.sources.unix'.
943       This  also shows that in some cases, especially if the anchor is a real
944       pattern, like a character class, the form with two stars may result  in
945       more matches than one would like.
946
947       The second specification is needed to make this work when the cursor is
948       in the middle of the string on the command line  and  the  option  COM‐
949       PLETE_IN_WORD  is  set. In this case the completion code would normally
950       try to match trial completions that end with the  string  as  typed  so
951       far,  i.e.  it  will  only insert new characters at the cursor position
952       rather then at the end.  However in our example we would like the  code
953       to recognise matches which contain extra characters after the string on
954       the line (the `nix' in the example).   Hence  we  say  that  the  empty
955       string  at  the end of the string on the line matches any characters at
956       the end of the trial completion.
957
958       More generally, the specification
959
960              compadd -M 'r:|[.,_-]=* r:|=*' ...
961
962       allows one to complete words with abbreviations before any of the char‐
963       acters  in the square brackets.  For example, to complete veryverylong‐
964       file.c rather than veryverylongheader.h with the above in  effect,  you
965       can just type very.c before attempting completion.
966
967       The  specifications  with  both a left and a right anchor are useful to
968       complete partial words whose parts are not separated  by  some  special
969       character.  For  example,  in  some places strings have to be completed
970       that are formed `LikeThis' (i.e. the separate parts are determined by a
971       leading  uppercase  letter)  or  maybe one has to complete strings with
972       trailing numbers. Here one could use the  simple  form  with  only  one
973       anchor as in:
974
975              compadd -M 'r:|[A-Z0-9]=* r:|=*' LikeTHIS FooHoo 5foo123 5bar234
976
977       But with this, the string `H' would neither complete to `FooHoo' nor to
978       `LikeTHIS' because in each case there is an uppercase letter before the
979       `H'  and  that  is  matched by the anchor. Likewise, a `2' would not be
980       completed.  In  both   cases   this   could   be   changed   by   using
981       `r:|[A-Z0-9]=**',  but  then  `H'  completes  to  both  `LikeTHIS'  and
982       `FooHoo' and a `2' matches the other strings because characters can  be
983       inserted  before  every  uppercase  letter and digit. To avoid this one
984       would use:
985
986              compadd -M 'r:[^A-Z0-9]||[A-Z0-9]=** r:|=*' \
987                  LikeTHIS FooHoo foo123 bar234
988
989       By using these two anchors, a `H' matches only uppercase `H's that  are
990       immediately preceded by something matching the left anchor `[^A-Z0-9]'.
991       The effect is, of course, that `H' matches only the string `FooHoo',  a
992       `2' matches only `bar234' and so on.
993
994       When  using the completion system (see zshcompsys(1)), users can define
995       match specifications that are to be used for specific contexts by using
996       the  matcher and matcher-list styles. The values for the latter will be
997       used everywhere.
998

COMPLETION WIDGET EXAMPLE

1000       The first step is to define the widget:
1001
1002              zle -C complete complete-word complete-files
1003
1004       Then the widget can be bound to a key using the  bindkey  builtin  com‐
1005       mand:
1006
1007              bindkey '^X\t' complete
1008
1009       After that the shell function complete-files will be invoked after typ‐
1010       ing control-X and TAB. The function should then generate  the  matches,
1011       e.g.:
1012
1013              complete-files () { compadd - * }
1014
1015       This function will complete files in the current directory matching the
1016       current word.
1017
1018
1019
1020zsh 4.2.6                      November 28, 2005                 ZSHCOMPWID(1)
Impressum