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.
Completion of the arguments of a command may be different for each
command or may use the default. The behavior 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 Option Flags:
COMPLETE_ALIASES
option is set. Commands should not be combined
with the -C
, -D
or -T
flags.
-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.
-D
compctl -D
command has
been issued, filenames are completed.
-T
-x
flag, see section Extended Completion below).
Using this flag you can define default 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
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 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.
-fcFBdeaRGovNAIOPZEnbjrzu/
]
-k
array ] [ -g
globstring ] [ -s
subststring ]
-K
function ] [ -H
num pattern ]
-Q
] [ -P
prefix ] [ -S
suffix ]
-W
file-prefix ]
-q
] [ -X
explanation ] [ -Y
explanation ]
-y
func-or-var ] [ -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 as follows.
These produce completion lists made up by the shell itself:
-f
-/
-c
-F
-B
-m
-w
-a
-R
-G
-d
-F
, -B
, -w
,
-a
, -R
and -G
to get names of disabled
functions, builtins, reserved words or aliases.
-e
-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 they are disabled.
-o
-v
-N
-A
-I
-O
-p
-Z
-E
-n
-b
-j
kill
builtin.
-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.)
-s
subststring
fignore
special parameter is not applied to the
resulting files. Note that -g
is faster for filenames.
-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 `reply=`users`
' would be incorrect.
-H
num pattern
*
'). A typical
use is
compctl -D -f + -H 0 ''
which forces completion to look back in the history list for a word if
no filename matches.
These do not directly specify types of name to be completed, but manipulate the options that do:
-Q
-k
) so that
the expression will not be evaluated until the complete line is
executed, this option must be used.
-P
prefix
compctl -j -P "%" kill
inserts a `%' after the kill command and then completes job names.
-S
suffix
-W
file-prefix
-c
, -f
, -/
, -g
), the file
prefix is implicitly added in front of the completion. For example,
compctl -/ -W ~/Mail maildirs
completes any subdirectories to any depth beneath the directory
~/Mail
, although that prefix does not appear on the command line.
-q
AUTO_REMOVE_SLASH
option). The option is most useful for list
separators (comma, colon, etc.).
-l
cmd
p[
...]
',
`r[
...]
', or `R[
...]
' (see 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 arguments to the cmd supplied with the
option. If the cmd string is empty the first word in the range
is instead taken as the command name, and command name completion
performed on the first word in the range. For example,
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
-K
option) which can examine the word components passed to it
(or via the 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.
-y
func-or-var
$
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 by a
call to a function using the -K
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 reply 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.
-X
explanation
%n
' in this string is replaced by the number of matches.
The explanation only appears if completion was tried and there was
no unique match, or when listing completions.
-Y
explanation
-X
, except that the explanation first undergoes
expansion following the usual rules for strings in double quotes.
The expansion will be carried out after any functions are called for
the -K
or -y
options, allowing them to set variables.
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 Option Flags above, 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 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:
s[
string]
...
S[
string]
...
s[
string]
except that the string is part of the
completion.
p[
from,
to]
...
-
n refers to the n'th last word
on the line.
c[
offset,
string]
...
C[
offset,
pattern]
...
c
but using pattern matching instead.
w[
index,
string]
...
W[
index,
pattern]
...
w
but using pattern matching instead.
n[
index,
string]
...
N[
index,
string]
...
n
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.
m[
min,
max]
...
r[
str1,
str2]
...
R[
str1,
str2]
...
r
but using pattern matching instead.
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.