compctl [ -CDT ] options [ command ... ]
compctl [ -CDT ] options
[ -x pattern options - ... -- ] [ + options [ -x ... -- ] ... [+] ]
[ command ... ]
compctl -L [ -CDT ] [ command ... ]
compctl + command ...
Control the editor's completion behaviour 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.
Completion of the arguments of a command may be different for each command or may use the default. The behaviour when completing 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 section Options Flags.
command ...
COMPLETE_ALIASES
option is set. Commands should not be combined with the `-D',
`-C' or `-T' flags.
-D
compctl -D
command has
been issued, filenames are completed.
-C
compctl -C
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.
-T
compctl
definitions. This is only useful when combined with extended completion
(the `-x' flag. See section Extended Completion).
Using this flag you can define default behaviour which will apply
to all commands without exception, or you can alter the standard behaviour
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
no argument
compctl
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 behaviour 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.
[ -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 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 described in the following sections.
These produce completion lists made up by the shell itself:
-f
-c
-F
-B
-m
-w
-a
-R
-G
-d
-e
-o
-v
-N
-A
-I
-O
-p
-Z
-E
-n
-b
-j
-r
-z
-u
These have user supplied arguments to determine how the list of completions is to be made up:
-k array
$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 be escaped with a backslash;
in this case the argument should be quoted. For example,
`compctl -k "(cputime filesize datasize stacksize coredumpsize
resident descriptors)" limit'.
-g globstring
*(/)
instead of */
for directories. The fignore
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
(either|or
) to match alternatives.)
-K function
reply
to an array containing the completions (one completion
per element); note that reply
should not be made local to the
function. From such a function the command line can be accessed with the
`-c' and `-l' flags to the read
builtin. For example,
function whoson { reply=(`users`); }
compctl -K whoson talk
completes only logged-on users after `talk'. Note that whoson
must return an array so that just reply=`users`
is incorrect.
-H num pattern
*
). A typical
use is
compctl -D -f + -H 0 '' -X '(No file found; using history)'
which forces completion to look back in the history list for a word if no
filename matches. The explanation string is useful as it tells the user
that no file of that name exists, which is otherwise ambiguous. (See the
next section for `-X'.)
These do not directly specify types of name to be completed, but manipulate the options that do:
-Q
-P prefix
compctl -j -P "%" kill
inserts a %
after the kill
command and then completes job
names.
-S suffix
-q
AUTO_REMOVE_SLASH
option). The option is most useful for list separators (comma, colon, etc.).
-l cmd
compctl -x 'r[-exec,;]' -l '' -- find
completes arguments between -exec
and the following ;
(or the
end of the command line if there is no such string) as if they were a separate
command line.
-U
read
builtin's `-c' and `-l' flags) and use its own criteria to decide
what matches. If there is no completion, the original word is retained.
-X explanation
%n
in this string is replaced by the number of
matches.
compctl [ -CDT ] options + options [ + ... ] [ + ] command ...
The form with +
specifies alternative options. Completion is
tried with the options before the first +
. If this produces 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.
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
section Options Flags, are used to generate possible completions. If no
pattern matches, the options given before the
`-x' are used.
Note that each pattern should be supplied as a single argument and should be quoted to prevent expansion of meta-characters 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:
s[string] ...
S[string] ...
p[from,to] ...
n
'th last word on the
line.
c[offset,string] ...
C[offset,pattern] ...
w[index,string] ...
W[index,pattern] ...
n[index,string] ...
N[index,string] ...
m[min,max] ...
r[str1,str2] ...
R[str1,str2] ...
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 previous word is
-f
) or (the current word begins with -f+
)), then complete 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.
Go to the first, previous, next, last section, table of contents.