Table of Contents

Bash - Complete (Builtin command) - Completion

About

The programmable completion feature in Bash permits typing a partial command, then pressing the [Tab] key to auto-complete the command sequence

The process of applying these completion specifications when word completion is attempted is described above under Programmable Completion.

Syntax

complete [-abcdefgjksuv] [-o comp-option] [-A action] [-G globpat]  [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] name [name ...]
complete -pr [name ...]

Specify how arguments to each name should be completed.

Other options, if specified, have the following meanings.

The arguments to the -G, -W, and -X options (and, if necessary, the -P and -S options) should be quoted to protect them from expansion before the complete builtin is invoked.

-o comp-option

The comp-option controls several aspects of the compspec’s behavior beyond the simple generation of completions. comp-option may be one of:

-A action

The action may be one of the following to generate a list of possible completions:

-G globpat

The filename expansion pattern globpat is expanded to generate the possible completions.

-W wordlist

The wordlist is split using the characters in the IFS special variable as delimiters, and each resultant word is expanded. The possible completions are the members

of  the  resultant  list which match the word being completed.

-C command

command is executed in a subshell environment, and its output is used as the possible completions.

-F function

The shell function function is executed in the current shell environment. When it finishes, the possible completions are retrieved from the value of the COMPREPLY array variable.

-X filterpat

filterpat is a pattern as used for filename expansion. It is applied to the list of possible completions generated by the preceding options and arguments, and each completion matching filterpat is removed from the list.

A leading ! in filterpat negates the pattern; in this case, any completion not matching filterpat is removed.

-P prefix

prefix is added at the beginning of each possible completion after all other options have been applied.

-S suffix

suffix is appended to each possible completion after all other options have been applied.

Return value

The return value is true unless an invalid option is supplied, an option other than -p or -r is supplied without a name argument, an attempt is made to remove a completion specification for a name for which no specification exists, or an error occurs adding a completion specification.

Example

Auto-completion of script option

http://www.tldp.org/LDP/abs/html/tabexpansion.html