|GNU Bash Reference Manual|
by Chet Ramey and Brian Fox
Paperback (6"x9"), 180 pages
RRP £19.95 ($29.95)
"An essential resource .... the most detailed coverage available for all aspects of Bash" --- Linux User and Developer Magazine (Issue 37, Mar 2004) Get a printed copy>>>
8.7 Programmable Completion Builtins
Two builtin commands are available to manipulate the programmable completion facilities.
compgen [option] [word]
completebuiltin with the exception of
-r, and write the matches to the standard output. When using the
-Coptions, the various shell variables set by the programmable completion facilities, while available, will not have useful values. The matches will be generated in the same way as if the programmable completion code had generated them directly from a completion specification with the same flags. If word is specified, only those completions matching word will be displayed. The return value is true unless an invalid option is supplied, or no matches were generated.
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 ...]
-poption is supplied, or if no options are supplied, existing completion specifications are printed in a way that allows them to be reused as input. The
-roption removes a completion specification for each name, or, if no names are supplied, all completion specifications. The process of applying these completion specifications when word completion is attempted is described above (see section 8.6 Programmable Completion). Other options, if specified, have the following meanings. The arguments to the
-Xoptions (and, if necessary, the
-Soptions) should be quoted to protect them from expansion before the
completebuiltin is invoked.
The comp-option controls several aspects of the compspec's behavior
beyond the simple generation of completions.
comp-option may be one of:
- Perform the rest of the default Bash completions if the compspec generates no matches.
- Use Readline's default filename completion if the compspec generates no matches.
- Perform directory name completion if the compspec generates no matches.
Tell Readline that the compspec generates filenames, so it can perform any
filename-specific processing (like adding a slash to directory names or
suppressing trailing spaces). This option is intended to be used with
shell functions specified with
- Tell Readline not to append a space (the default) to words completed at the end of the line.
- After any matches defined by the compspec are generated, directory name completion is attempted and any matches are added to the results of the other actions.
The action may be one of the following to generate a list of possible
Alias names. May also be specified as
- Array variable names.
- Readline key binding names (see section 8.4 Bindable Readline Commands).
Names of shell builtin commands. May also be specified as
Command names. May also be specified as
Directory names. May also be specified as
- Names of disabled shell builtins.
- Names of enabled shell builtins.
Names of exported shell variables. May also be specified as
File names. May also be specified as
- Names of shell functions.
Group names. May also be specified as
Help topics as accepted by the
helpbuiltin (see section 4.2 Bash Builtin Commands).
Hostnames, as taken from the file specified by the
HOSTFILEshell variable (see section 5.2 Bash Variables).
Job names, if job control is active. May also be specified as
Shell reserved words. May also be specified as
- Names of running jobs, if job control is active.
Service names. May also be specified as
Valid arguments for the
-ooption to the
setbuiltin (see section 4.3 The Set Builtin).
Shell option names as accepted by the
shoptbuiltin (see section 4.2 Bash Builtin Commands).
- Signal names.
- Names of stopped jobs, if job control is active.
User names. May also be specified as
Names of all shell variables. May also be specified as
- The filename expansion pattern globpat is expanded to generate the possible completions.
The wordlist is split using the characters in the
IFSspecial 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.
- command is executed in a subshell environment, and its output is used as the possible completions.
The shell function function is executed in the current shell
When it finishes, the possible completions are retrieved from the value
- 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.
- prefix is added at the beginning of each possible completion after all other options have been applied.
- suffix is appended to each possible completion after all other options have been applied.
-ris 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.
|ISBN 0954161777||GNU Bash Reference Manual||See the print edition|