NAME
zshcompctl - zsh programmable completion
DESCRIPTION
This version of zsh has two ways of performing completion of words on the command line. New users of the shell may prefer to use the newer and more powerful system based on shell functions; this is described in zshcompsys(1), and the basic shell mechanisms which support it aredescribed in zshcompwid(1). This manual entry describes the older ccoomm-
ppccttll command.ccoommppccttll [ -CCDDTT ] options [ command ... ]
ccoommppccttll [ -CCDDTT ] options [ -xx pattern options - ... -- ] [ ++ options [
-xx ... -- ] ... [++] ] [ command ... ]
ccoommppccttll -MM match-specs ...
ccoommppccttll -LL [ -CCDDTTMM ] [ command ... ]
ccoommppccttll ++ command ... Control the editor's completion behavior according to the supplied setof options. Various editing commands, notably eexxppaanndd-oorr-ccoommpplleettee-wwoorrdd,
usually bound to tab, will attempt to complete a word typed by theuser, while others, notably ddeelleettee-cchhaarr-oorr-lliisstt, usually bound to ^D in
EMACS editing mode, list the possibilities; ccoommppccttll controls what those possibilities are. They may for example be filenames (the most common case, and hence the default), shell variables, or words from auser-specified list.
CCOOMMMMAANNDD FFLLAAGGSSCompletion of the arguments of a command may be different for each com-
mand or may use the default. The behavior when completing the command word itself may also be separately specified. These correspond to thefollowing flags and arguments, all of which (except for -LL) may be com-
bined with any combination of the options described subsequently in the section `Option Flags': command ... controls completion for the named commands, which must be listedlast on the command line. If completion is attempted for a com-
mand with a pathname containing slashes and no completion defi-
nition is found, the search is retried with the last pathname component. If the command starts with a ==, completion is tried with the pathname of the command. Any of the command strings may be patterns of the form normallyused for filename generation. These should be be quoted to pro-
tect them from immediate expansion; for example the commandstring ''ffoooo**'' arranges for completion of the words of any com-
mand beginning with ffoooo. When completion is attempted, all pat-
tern completions are tried in the reverse order of their defini-
tion until one matches. By default, completion then proceeds as normal, i.e. the shell will try to generate more matches for the specific command on the command line; this can be overridden byincluding -ttnn in the flags for the pattern completion.
Note that aliases are expanded before the command name is deter-
mined unless the CCOOMMPPLLEETTEEAALLIIAASSEESS option is set. Commands maynot be combined with the -CC, -DD or -TT flags.
-CC controls completion when the command word itself is being com-
pleted. If no ccoommppccttll -CC command has been issued, the names of
any executable command (whether in the path or specific to the shell, such as aliases or functions) are completed.-DD controls default completion behavior for the arguments of com-
mands not assigned any special behavior. If no ccoommppccttll -DD com-
mand has been issued, filenames are completed.-TT supplies completion flags to be used before any other processing
is done, even before processing for ccoommppccttlls defined for spe-
cific commands. This is especially useful when combined withextended completion (the -xx flag, see the section `Extended Com-
pletion' below). Using this flag you can define default behav-
ior which will apply to all commands without exception, or you can alter the standard behavior for all commands. For example,if your access to the user database is too slow and/or it con-
tains too many users (so that completion after `~~' is too slow to be usable), you can useccoommppccttll -TT -xx ''ss[[~~]] CC[[00,,[[^^//]]##]]'' -kk ffrriieennddss -SS// -ttnn
to complete the strings in the array ffrriieennddss after a `~~'. TheCC[[......]] argument is necessary so that this form of ~-completion
is not tried after the directory name is finished.-LL lists the existing completion behavior in a manner suitable for
putting into a start-up script; the existing behavior is not
changed. Any combination of the above forms, or the -MM flag
(which must follow the -LL flag), may be specified, otherwise all
defined completions are listed. Any other flags supplied are ignored. no argument If no argument is given, ccoommppccttll lists all defined completions in an abbreviated form; with a list of options, all completions with those flags set (not counting extended completion) are listed. If the ++ flag is alone and followed immediately by the command list, the completion behavior for all the commands in the list is reset to the default. In other words, completion will subsequently use theoptions specified by the -DD flag.
The form with -MM as the first and only option defines global matching
specifications (see zshcompwid). The match specifications given will be used for every completion attempt (only when using ccoommppccttll, not with the new completion system) and are tried in the order in which they are defined until one generates at least one match. E.g.:ccoommppccttll -MM '''' ''mm::{{aa-zzAA-ZZ}}=={{AA-ZZaa-zz}}''
This will first try completion without any global match specifications (the empty string) and, if that generates no matches, will try case insensitive completion. OOPPTTIIOONN FFLLAAGGSS[ -ffccFFBBddeeaaRRGGoovvNNAAIIOOPPZZEEnnbbjjrrzzuu//1122 ]
[ -kk array ] [ -gg globstring ] [ -ss subststring ]
[ -KK function ]
[ -QQ ] [ -PP prefix ] [ -SS suffix ]
[ -WW file-prefix ] [ -HH num pattern ]
[ -qq ] [ -XX explanation ] [ -YY explanation ]
[ -yy func-or-var ] [ -ll cmd ] [ -hh cmd ] [ -UU ]
[ -tt continue ] [ -JJ name ] [ -VV name ]
[ -MM match-spec ]
The remaining options specify the type of command arguments to look for during completion. Any combination of these flags may be specified; the result is a sorted list of all the possibilities. The options are as follows. SSiimmppllee FFllaaggss These produce completion lists made up by the shell itself:-ff Filenames and filesystem paths.
-// Just filesystem paths.
-cc Command names, including aliases, shell functions, builtins and
reserved words.-FF Function names.
-BB Names of builtin commands.
-mm Names of external commands.
-ww Reserved words.
-aa Alias names.
-RR Names of regular (non-global) aliases.
-GG Names of global aliases.
-dd This can be combined with -FF, -BB, -ww, -aa, -RR and -GG to get names
of disabled functions, builtins, reserved words or aliases.-ee This option (to show enabled commands) is in effect by default,
but may be combined with -dd; -ddee in combination with -FF, -BB, -ww,
-aa, -RR and -GG will complete names of functions, builtins,
reserved words or aliases whether or not they are disabled.-oo Names of shell options (see zshoptions(1)).
-vv Names of any variable defined in the shell.
-NN Names of scalar (non-array) parameters.
-AA Array names.
-II Names of integer variables.
-OO Names of read-only variables.
-pp Names of parameters used by the shell (including special parame-
ters).-ZZ Names of shell special parameters.
-EE Names of environment variables.
-nn Named directories.
-bb Key binding names.
-jj Job names: the first word of the job leader's command line.
This is useful with the kkiillll builtin.-rr Names of running jobs.
-zz Names of suspended jobs.
-uu User names.
FFllaaggss wwiitthh AArrgguummeennttssThese have user supplied arguments to determine how the list of comple-
tions is to be made up:-kk array
Names taken from the elements of $$array (note that the `$$' does
not appear on the command line). Alternatively, the argumentarray itself may be a set of space- or comma-separated values in
parentheses, in which any delimiter may be escaped with a back-
slash; in this case the argument should be quoted. For example,ccoommppccttll -kk ""((ccppuuttiimmee ffiilleessiizzee ddaattaassiizzee ssttaacckkssiizzee
ccoorreedduummppssiizzee rreessiiddeenntt ddeessccrriippttoorrss))"" lliimmiitt-gg globstring
The globstring is expanded using filename globbing; it should be quoted to protect it from immediate expansion. The resulting filenames are taken as the possible completions. Use `**((//))' instead of `**//' for directories. The ffiiggnnoorree special parameter is not applied to the resulting files. More than one pattern may be given separated by blanks. (Note that brace expansion is not part of globbing. Use the syntax `((eeiitthheerr||oorr))' to match alternatives.)-ss subststring
The subststring is split into words and these words are than expanded using all shell expansion mechanisms (see zshexpn(1)).The resulting words are taken as possible completions. The ffiigg-
nnoorree special parameter is not applied to the resulting files.Note that -gg is faster for filenames.
-KK function
Call the given function to get the completions. Unless the name starts with an underscore, the function is passed two arguments: the prefix and the suffix of the word on which completion is to be attempted, in other words those characters before the cursor position, and those from the cursor position onwards. The wholecommand line can be accessed with the -cc and -ll flags of the
rreeaadd builtin. The function should set the variable rreeppllyy to an array containing the completions (one completion per element); note that rreeppllyy should not be made local to the function. Fromsuch a function the command line can be accessed with the -cc and
-ll flags to the rreeaadd builtin. For example,
ffuunnccttiioonn wwhhoossoonn {{ rreeppllyy==((``uusseerrss``));; }}ccoommppccttll -KK wwhhoossoonn ttaallkk
completes only logged-on users after `ttaallkk'. Note that `wwhhoossoonn'
must return an array, so `rreeppllyy==``uusseerrss``' would be incorrect.-HH num pattern
The possible completions are taken from the last num history lines. Only words matching pattern are taken. If num is zero or negative the whole history is searched and if pattern is the empty string all words are taken (as with `**'). A typical use isccoommppccttll -DD -ff ++ -HH 00 ''''
which forces completion to look back in the history list for a word if no filename matches. CCoonnttrrooll FFllaaggssThese do not directly specify types of name to be completed, but manip-
ulate the options that do:-QQ This instructs the shell not to quote any metacharacters in the
possible completions. Normally the results of a completion are inserted into the command line with any metacharacters quoted sothat they are interpreted as normal characters. This is appro-
priate for filenames and ordinary strings. However, for specialeffects, such as inserting a backquoted expression from a com-
pletion array (-kk) so that the expression will not be evaluated
until the complete line is executed, this option must be used.-PP prefix
The prefix is inserted just before the completed string; anyinitial part already typed will be completed and the whole pre-
fix ignored for completion purposes. For example,ccoommppccttll -jj -PP ""%%"" kkiillll
inserts a `%' after the kill command and then completes job
names.-SS suffix
When a completion is found the suffix is inserted after the com-
pleted string. In the case of menu completion the suffix is inserted immediately, but it is still possible to cycle through the list of completions by repeatedly hitting the same key.-WW file-prefix
With directory file-prefix: for command, file, directory and
globbing completion (options -cc, -ff, -//, -gg), the file prefix is
implicitly added in front of the completion. For example,ccoommppccttll -// -WW ~~//MMaaiill mmaaiillddiirrss
completes any subdirectories to any depth beneath the directory ~~//MMaaiill, although that prefix does not appear on the commandline. The file-prefix may also be of the form accepted by the
-kk flag, i.e. the name of an array or a literal list in paren-
thesis. In this case all the directories in the list will be searched for possible completions.-qq If used with a suffix as specified by the -SS option, this causes
the suffix to be removed if the next character typed is a blank or does not insert anything or if the suffix consists of onlyone character and the next character typed is the same charac-
ter; this the same rule used for the AAUUTTOORREEMMOOVVEESSLLAASSHH option. The option is most useful for list separators (comma, colon, etc.).-ll cmd This option restricts the range of command line words that are
considered to be arguments. If combined with one of the extended completion patterns `pp[[...]]', `rr[[...]]', or `RR[[...]]' (see the section `Extended Completion' below) the range is restricted to the range of arguments specified in the brackets.Completion is then performed as if these had been given as argu-
ments to the cmd supplied with the option. If the cmd string isempty the first word in the range is instead taken as the com-
mand name, and command name completion performed on the first word in the range. For example,ccoommppccttll -xx ''rr[[-eexxeecc,,;;]]'' -ll '''' -- ffiinndd
completes arguments between `-eexxeecc' and the following `;;' (or
the end of the command line if there is no such string) as if they were a separate command line.-hh cmd Normally zsh completes quoted strings as a whole. With this
option, completion can be done separately on different parts ofsuch strings. It works like the -ll option but makes the comple-
tion code work on the parts of the current word that are sepa-
rated by spaces. These parts are completed as if they were argu-
ments to the given cmd. If cmd is the empty string, the firstpart is completed as a command name, as with -ll.
-UU Use the whole list of possible completions, whether or not they
actually match the word on the command line. The word typed so far will be deleted. This is most useful with a function (givenby the -KK option) which can examine the word components passed
to it (or via the rreeaadd builtin's -cc and -ll flags) and use its
own criteria to decide what matches. If there is no completion,the original word is retained. Since the produced possible com-
pletions seldom have interesting common prefixes and suffixes, menu completion is started immediately if AAUUTTOOMMEENNUU is set and this flag is used.-yy func-or-var
The list provided by func-or-var is displayed instead of the
list of completions whenever a listing is required; the actual completions to be inserted are not affected. It can be providedin two ways. Firstly, if func-or-var begins with a $$ it defines
a variable, or if it begins with a left parenthesis a literal array, which contains the list. A variable may have been set bya call to a function using the -KK option. Otherwise it contains
the name of a function which will be executed to create the list. The function will be passed as an argument list all matching completions, including prefixes and suffixes expanded in full, and should set the array rreeppllyy to the result. In both cases, the display list will only be retrieved after a complete list of matches has been created. Note that the returned list does not have to correspond, even in length, to the original set of matches, and may be passed as a scalar instead of an array. No special formatting of characters is performed on the output in this case; in particular, newlines are printed literally and if they appear output in columns is suppressed.-XX explanation
Print explanation when trying completion on the current set ofoptions. A `%%nn' in this string is replaced by the number of
matches that were added for this explanation string. The expla-
nation only appears if completion was tried and there was no unique match, or when listing completions. Explanation strings will be listed together with the matches of the group specifiedtogether with the -XX option (using the -JJ or -VV option). If the
same explanation string is given to multiple -XX options, the
string appears only once (for each group) and the number ofmatches shown for the `%%nn' is the total number of all matches
for each of these uses. In any case, the explanation string will only be shown if there was at least one match added for the explanation string.The sequences %%BB, %%bb, %%SS, %%ss, %%UU, and %%uu specify output
attributes (bold, standout, and underline) and %%{{......%%}} can be
used to include literal escape sequences as in prompts.-YY explanation
Identical to -XX, except that the explanation first undergoes
expansion following the usual rules for strings in double quotes. The expansion will be carried out after any functionsare called for the -KK or -yy options, allowing them to set vari-
ables.-tt continue
The continue-string contains a character that specifies which
set of completion flags should be used next. It is useful:(i) With -TT, or when trying a list of pattern completions, when
ccoommppccttll would usually continue with ordinary processing afterfinding matches; this can be suppressed with `-ttnn'.
(ii) With a list of alternatives separated by ++, when ccoommppccttll would normally stop when one of the alternatives generatesmatches. It can be forced to consider the next set of comple-
tions by adding `-tt++' to the flags of the alternative before the
`++'. (iii) In an extended completion list (see below), when ccoommppccttll would normally continue until a set of conditions succeeded,then use only the immediately following flags. With `-tt-', ccoomm-
ppccttll will continue trying extended completions after the next`-'; with `-ttxx' it will attempt completion with the default
flags, in other words those before the `-xx'.
-JJ name
This gives the name of the group the matches should be placedin. Groups are listed and sorted separately; likewise, menu com-
pletion will offer the matches in the groups in the order in which the groups were defined. If no group name is explicitly given, the matches are stored in a group named default. The first time a group name is encountered, a group with that name is created. After that all matches with the same group name are stored in that group.This can be useful with non-exclusive alternative completions.
For example, inccoommppccttll -ff -JJ ffiilleess -tt++ ++ -vv -JJ vvaarriiaabblleess ffoooo
both files and variables are possible completions, as the -tt++
forces both sets of alternatives before and after the ++ to beconsidered at once. Because of the -JJ options, however, all
files are listed before all variables.-VV name
Like -JJ, but matches within the group will not be sorted in
listings nor in menu completion. These unsorted groups are in a different name space from the sorted ones, so groups defined as-JJ ffiilleess and -VV ffiilleess are distinct.
-11 If given together with the -VV option, makes only consecutive
duplicates in the group be removed. Note that groups with and without this flag are in different name spaces.-22 If given together with the -JJ or -VV option, makes all duplicates
be kept. Again, groups with and without this flag are in differ-
ent name spaces.-MM match-spec
This defines additional matching control specifications that should be used only when testing words for the list of flagsthis flag appears in. The format of the match-spec string is
described in zshcompwid. AALLTTEERRNNAATTIIVVEE CCOOMMPPLLEETTIIOONNccoommppccttll [ -CCDDTT ] options ++ options [ ++ ... ] [ ++ ] command ...
The form with `++' specifies alternative options. Completion is triedwith the options before the first `++'. If this produces no matches com-
pletion is tried with the flags after the `++' and so on. If there are no flags after the last `++' and a match has not been found up to thatpoint, default completion is tried. If the list of flags contains a -tt
with a ++ character, the next list of flags is used even if the current list produced matches. EEXXTTEENNDDEEDD CCOOMMPPLLEETTIIOONNccoommppccttll [ -CCDDTT ] options -xx pattern options - ... --
[ command ... ]ccoommppccttll [ -CCDDTT ] options [ -xx pattern options - ... -- ]
[ ++ options [ -xx ... -- ] ... [++] ] [ command ... ]
The form with `-xx' specifies extended completion for the commands
given; as shown, it may be combined with alternative completion using`++'. Each pattern is examined in turn; when a match is found, the cor-
responding options, as described in the section `Option Flags' above, are used to generate possible completions. If no pattern matches, theoptions given before the -xx are used.
Note that each pattern should be supplied as a single argument and should be quoted to prevent expansion of metacharacters by the shell.A pattern is built of sub-patterns separated by commas; it matches if
at least one of these sub-patterns matches (they are `or'ed). These
sub-patterns are in turn composed of other sub-patterns separated by
white spaces which match if all of the sub-patterns match (they are
`and'ed). An element of the sub-patterns is of the form `c[[...]][[...]]',
where the pairs of brackets may be repeated as often as necessary, and matches if any of the sets of brackets match (an `or'). The example below makes this clearer. The elements may be any of the following: ss[[string]]... Matches if the current word on the command line starts with one of the strings given in brackets. The string is not removed and is not part of the completion. SS[[string]]... Like ss[[string]] except that the string is part of the completion. pp[[from,,to]]... Matches if the number of the current word is between one of the from and to pairs inclusive. The comma and to are optional; todefaults to the same value as from. The numbers may be nega-
tive: -n refers to the n'th last word on the line.
cc[[offset,,string]]... Matches if the string matches the word offset by offset from the current word position. Usually offset will be negative. CC[[offset,,pattern]]... Like cc but using pattern matching instead. ww[[index,,string]]...Matches if the word in position index is equal to the corre-
sponding string. Note that the word count is made after any alias expansion. WW[[index,,pattern]]... Like ww but using pattern matching instead. nn[[index,,string]]... Matches if the current word contains string. Anything up to andincluding the indexth occurrence of this string will not be con-
sidered part of the completion, but the rest will. index may be negative to count from the end: in most cases, index will be 1or -1. For example,
ccoommppccttll -ss ''``uusseerrss``'' -xx ''nn[[11,,@@]]'' -kk hhoossttss -- ttaallkk
will usually complete usernames, but if you insert an @@ afterthe name, names from the array hosts (assumed to contain host-
names, though you must make the array yourself) will be com-
pleted. Other commands such as rrccpp can be handled similarly. NN[[index,,string]]... Like nn except that the string will be taken as a character class. Anything up to and including the indexth occurrence of any of the characters in string will not be considered part of the completion. mm[[min,,max]]... Matches if the total number of words lies between min and max inclusive. rr[[str1,,str2]]... Matches if the cursor is after a word with prefix str1. If there is also a word with prefix str2 on the command line after the one matched by str1 it matches only if the cursor is before this word. If the comma and str2 are omitted, it matches if the cursor is after a word with prefix str1. RR[[str1,,str2]]... Like rr but using pattern matching instead. qq[[str]]... Matches the word currently being completed is in single quotes and the str begins with the letter `s', or if completion is donein double quotes and str starts with the letter `d', or if com-
pletion is done in backticks and str starts with a `b'. EEXXAAMMPPLLEEccoommppccttll -uu -xx ''ss[[++]] cc[[-11,,-ff]],,ss[[-ff++]]'' \\
-gg ''~~//MMaaiill//**((::tt))'' - ''ss[[-ff]],,cc[[-11,,-ff]]'' -ff -- mmaaiill
This is to be interpreted as follows: If the current command is mmaaiill, thenif ((the current word begins with ++ and the previous word is -ff)
or (the current word begins with -ff++)), then complete the
non-directory part (the `::tt' glob modifier) of files in the directory
~~//MMaaiill; elseif the current word begins with -ff or the previous word was -ff, then
complete any file; else complete user names. zsh 4.2.3 January 13, 2005 ZSHCOMPCTL(1)