zshcompctl(1)
NAME
zshcompctl - zsh programmable completion
DESCRIPTION
compctl [ -CDT ] options [ command ... ]
- compctl [ -CDT ] options
- [ -x pattern options - ... -- ]
[ + options [ -x ... -- ] ... [+] ]
[ command ... ] - compctl -L [ -CDT ] [ command ... ]
- compctl + command ...
- Control the editor's completion behavior according to the
- supplied set of options. Various editing commands, notably
- expand-or-complete-word, usually bound to TAB, will attempt to
- complete a word typed by the user, while others, notably
- delete-char-or-list, usually bound to ^D in emacs editing mode,
- list the possibilities; compctl controls what those possibilities
- are. They may for example be filenames (the most common case,
- and hence the default), shell variables, or words from a user
- specified list.
COMMAND FLAGS
- Completion of the arguments of a command may be different
- for each command or may use the default. The behavior when com
- pleting the command word itself may also be separately specified.
- These correspond to the following flags and arguments, all of
- which (except for -L) may be combined with any combination of the
- options described subsequently in the section OPTION FLAGS:
command ...controls completion for the named commands,which must be listed last on the command line. If completion isattempted for a command with a pathname containing slashes and nocompletion definition is found, the search is retried with thelast pathname component. Note that aliases are expanded beforethe command name is determined unless the COMPLETE_ALIASES optionis set. Commands should not be combined with the -D, -C or -Tflags.- -D controls default completion behavior for the
- arguments of commands not assigned any special behavior. If no
- compctl -D command has been issued, filenames are completed. -C controls completion when the command word
- itself is being completed. If no compctl -C command has been is
- sued, the names of any executable command (whether in the path
- or specific to the shell, such as aliases or functions) are com
- pleted.
-T supplies completion flags to be used before - any other processing is done, even those given to specific com
- mands with other compctl definitions. This is only useful when
- combined with extended completion (the -x flag, see the section
EXTENDED COMPLETION
- fault behavior 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 contains too many users (so that completion after ~ is
too slow to be usable), you can use
compctl -Tx 'C[0,*/*]' -f - 's[~]' -k - friends -S/
- to complete the strings in the array friends
- after a ~. The first argument is necessary so that this form of
- ~-completion is not tried after the directory name is finished.
- -L 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 may
- be specified, otherwise all defined completions are listed. Any
- other flags supplied are ignored.
no argument - If no argument is given, compctl lists all
- defined completions in an abbreviated form; with a list of
- options, all completions with those flags set (not counting ex
- tended 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 the options specified by the -D flag.
OPTION FLAGS
[ -fcFBdeaRGovNAIOPZEnbjrzu ]
[ -k array ] [ -g globstring ] [ -s subststring ]
[ -K function ] [ -H num pattern ]
[ -Q ] [ -P prefix ] [ -S suffix ]
[ -q ] [ -X explanation ]
[ -l cmd ] [ -U ]
- The remaining options specify the type of command argu
- ments 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.
- Simple flags
- These produce completion lists made up by the shell it
- self:
-f Filenames and filesystem paths.
-c Command names, including aliases, shellfunctions, builtins and reserved words.
-F Function names.
-B Names of builtin commands.
-m Names of external commands.
-w Reserved words.
-a Alias names.
-R Names of regular (non-global) aliases.
-G Names of global aliases.
-d This can be combined with -F, -B, -w, -a, -Rand -G to get names of disabled functions, builtins, reservedwords or aliases.
-e This option (to show enabled commands) is ineffect by default, but may be combined with -d; -de in combination with -F, -B, -w, -a, -R and -G will complete names of functions, builtins, reserved words or aliases whether or not theyare disabled.
-o Names of shell options (see the zshoptionsmanual page).
-v Names of any variable defined in the shell.
-N Names of scalar (non-array) parameters.
-A Array names.
-I Names of integer variables.
-O Names of read-only variables.
-p Names of parameters used by the shell (including special parameters).
-Z Names of shell special parameters.
-E Names of environment variables.
-n Named directories.
-b Key binding names.
-j Job names: the first word of the job leader's command line. This is useful with the kill builtin.
-r Names of running jobs.
-z Names of suspended jobs.
-u User names. - Flags with arguments
These have user supplied arguments to determine how thelist of completions is to be made up:-k arrayNames taken from the elements of $array(note that the $ does not appear on the command line). Alternatively, the argument array itself may be a set of space- or comma-separated values in parentheses, in which any delimiter may beescaped with a backslash; in this case the argument should bequoted. For example,compctl -k "(cputime filesize datasizestacksize
coredumpsize resident descriptors)" limit-g globstringThe globstring is expanded using filenameglobbing; 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 fignorespecial parameter is not applied to the resulting files. Morethan one pattern may be given separated by blanks. (Note thatbrace expansion is not part of globbing. Use the syntax `(either|or)' to match alternatives.)-s subststringThe subststring is split into words andthese words are than expanded using all shell expansion mechanisms (see the zshexpn manual page). The resulting words are taken as possible completions. The fignore special parameter is notapplied to the resulting files. Note that -g is faster for filenames.-K functionCall the given function to get the completions. The function is passed two arguments: the prefix and thesuffix of the word on which completion is to be attempted, inother words those characters before the cursor position, andthose from the cursor position onwards. The function should setthe variable reply to an array containing the completions (onecompletion per element); note that reply should not be made localto the function. From such a function the command line can beaccessed with the -c and -l flags to the read builtin. For example,function whoson { reply=(`users`); }
compctl -K whoson talkcompletes only logged-on users after `talk'.Note that `whoson' must return an array so that "reply=`users`"is incorrect.-H num patternThe possible completions are taken from thelast num history lines. Only words matching pattern are taken. Ifnum is zero or negative the whole history is searched and ifpattern is the empty string all words are taken (as with `*'). Atypical use iscompctl -D -f + -H 0 ''-X '(No file found; using history)'which forces completion to look back in thehistory list for a word if no filename matches. The explanationstring is useful as it tells the user that no file of that nameexists, which is otherwise ambiguous. (See the next section for-X).Control flagsThese do not directly specify types of name to be completed, but manipulate the options that do:-Q This instructs the shell not to quote anymetacharacters in the possible completions. Normally the resultsof a completion are inserted into the command line with anymetacharacters quoted so that they are interpreted as normalcharacters. This is appropriate for filenames and ordinarystrings. However, for special effects, such as inserting a backquoted expression from a completion array (-k) so that the expression will not be evaluated until the complete line is executed, this option must be used.
-P prefixThe prefix is inserted just before the completed string; any initial part already typed will be completedand the whole prefix ignored for completion purposes. For example,compctl -j -P "%" killinserts a `%' after the kill command andthen completes job names.-S suffixWhen a completion is found the suffix is inserted after the completed string. In the case of menu completion the suffix is inserted immediately, but it is still possibleto cycle through the list of completions by repeatedly hittingthe same key.-q If used with a suffix as specified by theprevious option, this causes the suffix to be removed if the nextcharacter typed is a blank or does not insert anything (the samerule as used for the AUTO_REMOVE_SLASH option). The option ismost useful for list separators (comma, colon, etc.).
-l cmd This option cannot be combined with any other. It restricts the range of command line words that are considered to be arguments. If combined with one of the extendedcompletion patterns `p[...]', `r[...]', or `R[...]' (see thesection EXTENDED COMPLETION below) the range is restricted to therange of arguments specified in the brackets. Completion is thenperformed as if these had been given as arguments to the cmd supplied with the option. If the cmd string is empty the first wordin the range is instead taken as the command name, and commandname completion performed on the first word in the range. Forexample,compctl -x 'r[-exec,;]' -l '' -- findcompletes arguments between `-exec' and thefollowing `;' (or the end of the command line if there is no suchstring) as if they were a separate command line.-U 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 witha function (given by the -K option) which can examine the wordcomponents passed to it (or via the read builtin's -c and -lflags) and use its own criteria to decide what matches. If thereis no completion, the original word is retained.
-X explanationPrint explanation when trying completion onthe current set of options. A `%n' in this string is replaced bythe number of matches.
ALTERNATIVE COMPLETION
- compctl [ -CDT ] options + options [ + ... ] [ + ] command
- ...
- The form with `+' specifies alternative options. Comple
- tion is tried with the options before the first `+'. If this pro
- duces no matches completion 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 that point, default completion is tried.
EXTENDED COMPLETION
- compctl [ -CDT ] options -x pattern options - ... -- [
- command ... ]
- compctl [ -CDT ] options [ -x pattern options - ... -- ]
- [ + options [ -x ... -- ] ... [+] ] [ command ... ]
- The form with `-x' 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 corresponding options, as described in the
- section OPTION FLAGS above, are used to generate possible comple
- tions. If no pattern matches, the options given before the -x
- are used.
- Note that each pattern should be supplied as a single ar
- gument and should be quoted to prevent expansion of metacharac
- ters 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-pat
- terns 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:
s[string] ...Matches if the current word on the commandline starts with one of the strings given in brackets. Thestring is not removed and is not part of the completion.- S[string] ...
Like s[string] except that the string ispart of the completion.
- p[from,to] ...
Matches if the number of the current word isbetween one of the from and to pairs inclusive. The comma and toare optional; to defaults to the same value as from. The numbersmay be negative: -n refers to the n'th last word on the line.
- c[offset,string] ...
Matches if the string matches the word offset by offset from the current word position. Usually offsetwill be negative.
- C[offset,pattern] ...
Like c but using pattern matching instead.
- w[index,string] ...
Matches if the word in position index isequal to the corresponding string. Note that the word count ismade after any alias expansion.
- W[index,pattern] ...
Like w but using pattern matching instead.
- n[index,string] ...
Matches if the current word contains string.Anything up to and including the index'th occurrence of thisstring will not be considered part of the completion, but therest will. Index may be negative to count from the end: in mostcases, index will be 1 or -1.
- N[index,string] ...
Like n[index,string] except that the stringwill be taken as a character class. Anything up to and includingthe index'th occurrence of any of the characters in string willnot be considered part of the completion.
- m[min,max] ...
Matches if the total number of words liesbetween min and max inclusive.
- r[str1,str2]...
Matches if the cursor is after a word withprefix str1. If there is also a word with prefix str2 on the command line it matches only if the cursor is before this word.
- R[str1,str2]...
Like r but using pattern matching instead.
EXAMPLE
- compctl -u -x 's[+] c[-1,-f],s[-f+]' -g
- '~/Mail/*(:t)' - 's[-f],c[-1,-f]' -f -- mail
- This is to be interpreted as follows:
- If the current command is mail, then
if ((the current word begins with + and the previ- ous word is -f) or (the current word begins with -f+)), then com
- plete the non-directory part (the :t glob modifier) of files in
- the directory ~/Mail; else
- if the current word begins with -f or the previous
- word was -f, then complete any file; else
- complete user names.
- zsh version 3.0 June 26, 1996