complete [command [word/pattern/list[:select]/[[suffix]/] …]]
complete, without arguments, lists all completions. With command, complete lists completions for command. With command and word etc., complete defines completions.
> complete cd 'p/1/d/'
completes
only the first word following cd (p/1)
with a directory. > co[‸D]
complete compress
> complete -co* 'p/0/(compress)/'
> co[‸D]
> compress
This completion completes commands
(words in position 0, p/0) which begin with co (thus
matching co*) to compress (the only word in the list).
The leading - indicates that this completion is to be used only with
ambiguous commands.> complete find 'n/-user/u/'
> complete cc 'c/-I/d/'
> complete alias 'p/1/a/'
> complete man 'p/*/c/'
> complete set 'p/1/s/'
> complete true 'p/1/x:Truth has no options./'
These
complete words following alias with aliases, man with
commands, and set with shell variables. true doesn't
have any options, so x does nothing when completion is attempted
and prints 'Truth has no options.' when completion choices are listed. The man example, and several other examples that follow, could just as well have used c/* or n/* as p/*.
> complete ftp 'p/1/$hostnames/'
> set hostnames = (rtfm.mit.edu tesla.ee.cornell.edu)
> ftp [‸D]
rtfm.mit.edu tesla.ee.cornell.edu
> ftp [‸C]
> set hostnames = (rtfm.mit.edu tesla.ee.cornell.edu uunet.uu.net)
> ftp [‸D]
rtfm.mit.edu tesla.ee.cornell.edu uunet.uu.net
or
from a command run at completion time: > complete kill 'p/*/'ps | awk \{print\ \$1\}'/'
> kill -9 [‸D]
23113 23377 23380 23406 23429 23529 23530 PID
The complete command
does not itself quote its arguments, so the braces, space and $ in
{print $1} must be quoted explicitly. > complete dbx 'p/2/(core)/' 'p/*/c/'
This
example completes the second argument to dbx with
the word core and all other arguments with commands. The positional
completion is specified before the next-word completion. Since completions
are evaluated from left to right, if the next-word completion
were specified first it would always match and the positional completion
would never be executed. This is a common mistake when defining a
completion. > complete cc 'p/*/f:*.[cao]/'
completes cc arguments
only to files ending in .c, .a, or .o. select can
also exclude files, using negation of a glob-pattern as described
under File name substitution. > complete rm 'p/*/f:‸*.{c,h,cc,C,tex,1,man,l,y}/'
to
exclude precious source code from rm completion.
Of course, one could still type excluded names manually or override
the completion mechanism using the complete-word-raw or list-choices-raw editor
command. > complete elm c@=@F:$HOME/Mail/@
to
complete elm -f = as if it were elm -f ~/Mail/. We used
@ instead of / to avoid confusion with the select argument, and we
used $HOME instead of ~ because home directory substitution only works
at the beginning of a word. > complete finger 'c/*@/$hostnames/' 'p/1/u/@'
completes
arguments to finger from the list of users, appends an @, and
then completes after the @ from the hostnames variable. Note
the order in which the completions are specified. complete find \
'n/-name/f/' 'n/-newer/f/' 'n/-{,n}cpio/f/' \
'n/-exec/c/' 'n/-ok/c/' 'n/-user/u/' \
'n/-group/g/' 'n/-fstype/(nfs 4.2)/' \
'n/-type/(b c d f l p s)/' \
'c/-/(name newer cpio ncpio exec ok user \
group fstype type atime ctime depth inum \
ls mtime nogroup nouser perm print prune \
size xdev)/' \
'p/*/d/'
This completes words following -name,
-newer, -cpio or ncpio (note the pattern which matches both) to files,
words following -exec or -ok to commands, words following user and
group to users and groups respectively and words following -fstype
or -type to members of the given lists. It also completes the switches
themselves from the given list (note the use of c-type completion)
and completes anything not otherwise completed to a directory. Programmed completions are ignored if the word being completed is a tilde substitution (beginning with ~) or a variable (beginning with $). complete is an experimental feature, and the syntax might change in future versions of the shell. See also the uncomplete built-in command.
tcsh, uncomplete