diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/bash/programmable-completion-builtins.html | |
new repository
Diffstat (limited to 'devdocs/bash/programmable-completion-builtins.html')
| -rw-r--r-- | devdocs/bash/programmable-completion-builtins.html | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/devdocs/bash/programmable-completion-builtins.html b/devdocs/bash/programmable-completion-builtins.html new file mode 100644 index 00000000..8cdc5eda --- /dev/null +++ b/devdocs/bash/programmable-completion-builtins.html @@ -0,0 +1,57 @@ +<h1 class="section">Programmable Completion Builtins</h1> <p>Three builtin commands are available to manipulate the programmable completion facilities: one to specify how the arguments to a particular command are to be completed, and two to modify the completion as it is happening. </p> <dl compact> <dt id="index-compgen"><span><code>compgen</code></span></dt> <dd> +<div class="example"> <pre class="example">compgen [option] [word] +</pre> +</div> <p>Generate possible completion matches for <var>word</var> according to the <var>option</var>s, which may be any option accepted by the <code>complete</code> builtin with the exception of <samp>-p</samp> and <samp>-r</samp>, and write the matches to the standard output. When using the <samp>-F</samp> or <samp>-C</samp> options, the various shell variables set by the programmable completion facilities, while available, will not have useful values. </p> <p>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 <var>word</var> is specified, only those completions matching <var>word</var> will be displayed. </p> <p>The return value is true unless an invalid option is supplied, or no matches were generated. </p> </dd> <dt id="index-complete"><span><code>complete</code></span></dt> <dd> +<div class="example"> <pre class="example">complete [-abcdefgjksuv] [-o comp-option] [-DEI] [-A action] [-G globpat] +[-W wordlist] [-F function] [-C command] [-X filterpat] +[-P prefix] [-S suffix] name [name …] +complete -pr [-DEI] [name …] +</pre> +</div> <p>Specify how arguments to each <var>name</var> should be completed. If the <samp>-p</samp> option 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 <samp>-r</samp> option removes a completion specification for each <var>name</var>, or, if no <var>name</var>s are supplied, all completion specifications. The <samp>-D</samp> option indicates that other supplied options and actions should apply to the “default” command completion; that is, completion attempted on a command for which no completion has previously been defined. The <samp>-E</samp> option indicates that other supplied options and actions should apply to “empty” command completion; that is, completion attempted on a blank line. The <samp>-I</samp> option indicates that other supplied options and actions should apply to completion on the initial non-assignment word on the line, or after a command delimiter such as ‘<samp>;</samp>’ or ‘<samp>|</samp>’, which is usually command name completion. If multiple options are supplied, the <samp>-D</samp> option takes precedence over <samp>-E</samp>, and both take precedence over <samp>-I</samp>. If any of <samp>-D</samp>, <samp>-E</samp>, or <samp>-I</samp> are supplied, any other <var>name</var> arguments are ignored; these completions only apply to the case specified by the option. </p> <p>The process of applying these completion specifications when word completion is attempted is described above (see <a href="programmable-completion">Programmable Completion</a>). </p> <p>Other options, if specified, have the following meanings. The arguments to the <samp>-G</samp>, <samp>-W</samp>, and <samp>-X</samp> options (and, if necessary, the <samp>-P</samp> and <samp>-S</samp> options) should be quoted to protect them from expansion before the <code>complete</code> builtin is invoked. </p> <dl compact> <dt><span><code>-o <var>comp-option</var></code></span></dt> <dd> +<p>The <var>comp-option</var> controls several aspects of the compspec’s behavior beyond the simple generation of completions. <var>comp-option</var> may be one of: </p> <dl compact> <dt><span><code>bashdefault</code></span></dt> <dd> +<p>Perform the rest of the default Bash completions if the compspec generates no matches. </p> </dd> <dt><span><code>default</code></span></dt> <dd> +<p>Use Readline’s default filename completion if the compspec generates no matches. </p> </dd> <dt><span><code>dirnames</code></span></dt> <dd> +<p>Perform directory name completion if the compspec generates no matches. </p> </dd> <dt><span><code>filenames</code></span></dt> <dd> +<p>Tell Readline that the compspec generates filenames, so it can perform any filename-specific processing (like adding a slash to directory names, quoting special characters, or suppressing trailing spaces). This option is intended to be used with shell functions specified with <samp>-F</samp>. </p> </dd> <dt><span><code>noquote</code></span></dt> <dd> +<p>Tell Readline not to quote the completed words if they are filenames (quoting filenames is the default). </p> </dd> <dt><span><code>nosort</code></span></dt> <dd> +<p>Tell Readline not to sort the list of possible completions alphabetically. </p> </dd> <dt><span><code>nospace</code></span></dt> <dd> +<p>Tell Readline not to append a space (the default) to words completed at the end of the line. </p> </dd> <dt><span><code>plusdirs</code></span></dt> <dd> +<p>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. </p> </dd> </dl> </dd> <dt><span><code>-A <var>action</var></code></span></dt> <dd> +<p>The <var>action</var> may be one of the following to generate a list of possible completions: </p> <dl compact> <dt><span><code>alias</code></span></dt> <dd> +<p>Alias names. May also be specified as <samp>-a</samp>. </p> </dd> <dt><span><code>arrayvar</code></span></dt> <dd> +<p>Array variable names. </p> </dd> <dt><span><code>binding</code></span></dt> <dd> +<p>Readline key binding names (see <a href="bindable-readline-commands">Bindable Readline Commands</a>). </p> </dd> <dt><span><code>builtin</code></span></dt> <dd> +<p>Names of shell builtin commands. May also be specified as <samp>-b</samp>. </p> </dd> <dt><span><code>command</code></span></dt> <dd> +<p>Command names. May also be specified as <samp>-c</samp>. </p> </dd> <dt><span><code>directory</code></span></dt> <dd> +<p>Directory names. May also be specified as <samp>-d</samp>. </p> </dd> <dt><span><code>disabled</code></span></dt> <dd> +<p>Names of disabled shell builtins. </p> </dd> <dt><span><code>enabled</code></span></dt> <dd> +<p>Names of enabled shell builtins. </p> </dd> <dt><span><code>export</code></span></dt> <dd> +<p>Names of exported shell variables. May also be specified as <samp>-e</samp>. </p> </dd> <dt><span><code>file</code></span></dt> <dd> +<p>File names. May also be specified as <samp>-f</samp>. </p> </dd> <dt><span><code>function</code></span></dt> <dd> +<p>Names of shell functions. </p> </dd> <dt><span><code>group</code></span></dt> <dd> +<p>Group names. May also be specified as <samp>-g</samp>. </p> </dd> <dt><span><code>helptopic</code></span></dt> <dd> +<p>Help topics as accepted by the <code>help</code> builtin (see <a href="bash-builtins">Bash Builtin Commands</a>). </p> </dd> <dt><span><code>hostname</code></span></dt> <dd> +<p>Hostnames, as taken from the file specified by the <code>HOSTFILE</code> shell variable (see <a href="bash-variables">Bash Variables</a>). </p> </dd> <dt><span><code>job</code></span></dt> <dd> +<p>Job names, if job control is active. May also be specified as <samp>-j</samp>. </p> </dd> <dt><span><code>keyword</code></span></dt> <dd> +<p>Shell reserved words. May also be specified as <samp>-k</samp>. </p> </dd> <dt><span><code>running</code></span></dt> <dd> +<p>Names of running jobs, if job control is active. </p> </dd> <dt><span><code>service</code></span></dt> <dd> +<p>Service names. May also be specified as <samp>-s</samp>. </p> </dd> <dt><span><code>setopt</code></span></dt> <dd> +<p>Valid arguments for the <samp>-o</samp> option to the <code>set</code> builtin (see <a href="the-set-builtin">The Set Builtin</a>). </p> </dd> <dt><span><code>shopt</code></span></dt> <dd> +<p>Shell option names as accepted by the <code>shopt</code> builtin (see <a href="bash-builtins">Bash Builtin Commands</a>). </p> </dd> <dt><span><code>signal</code></span></dt> <dd> +<p>Signal names. </p> </dd> <dt><span><code>stopped</code></span></dt> <dd> +<p>Names of stopped jobs, if job control is active. </p> </dd> <dt><span><code>user</code></span></dt> <dd> +<p>User names. May also be specified as <samp>-u</samp>. </p> </dd> <dt><span><code>variable</code></span></dt> <dd><p>Names of all shell variables. May also be specified as <samp>-v</samp>. </p></dd> </dl> </dd> <dt><span><code>-C <var>command</var></code></span></dt> <dd> +<p><var>command</var> is executed in a subshell environment, and its output is used as the possible completions. Arguments are passed as with the <samp>-F</samp> option. </p> </dd> <dt><span><code>-F <var>function</var></code></span></dt> <dd> +<p>The shell function <var>function</var> is executed in the current shell environment. When it is executed, $1 is the name of the command whose arguments are being completed, $2 is the word being completed, and $3 is the word preceding the word being completed, as described above (see <a href="programmable-completion">Programmable Completion</a>). When it finishes, the possible completions are retrieved from the value of the <code>COMPREPLY</code> array variable. </p> </dd> <dt><span><code>-G <var>globpat</var></code></span></dt> <dd> +<p>The filename expansion pattern <var>globpat</var> is expanded to generate the possible completions. </p> </dd> <dt><span><code>-P <var>prefix</var></code></span></dt> <dd> +<p><var>prefix</var> is added at the beginning of each possible completion after all other options have been applied. </p> </dd> <dt><span><code>-S <var>suffix</var></code></span></dt> <dd> +<p><var>suffix</var> is appended to each possible completion after all other options have been applied. </p> </dd> <dt><span><code>-W <var>wordlist</var></code></span></dt> <dd> +<p>The <var>wordlist</var> is split using the characters in the <code>IFS</code> 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. </p> </dd> <dt><span><code>-X <var>filterpat</var></code></span></dt> <dd><p><var>filterpat</var> 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 <var>filterpat</var> is removed from the list. A leading ‘<samp>!</samp>’ in <var>filterpat</var> negates the pattern; in this case, any completion not matching <var>filterpat</var> is removed. </p></dd> </dl> <p>The return value is true unless an invalid option is supplied, an option other than <samp>-p</samp> or <samp>-r</samp> is supplied without a <var>name</var> argument, an attempt is made to remove a completion specification for a <var>name</var> for which no specification exists, or an error occurs adding a completion specification. </p> </dd> <dt id="index-compopt"><span><code>compopt</code></span></dt> <dd> +<div class="example"> <pre class="example">compopt [-o option] [-DEI] [+o option] [name] +</pre> +</div> <p>Modify completion options for each <var>name</var> according to the <var>option</var>s, or for the currently-executing completion if no <var>name</var>s are supplied. If no <var>option</var>s are given, display the completion options for each <var>name</var> or the current completion. The possible values of <var>option</var> are those valid for the <code>complete</code> builtin described above. The <samp>-D</samp> option indicates that other supplied options should apply to the “default” command completion; that is, completion attempted on a command for which no completion has previously been defined. The <samp>-E</samp> option indicates that other supplied options should apply to “empty” command completion; that is, completion attempted on a blank line. The <samp>-I</samp> option indicates that other supplied options should apply to completion on the initial non-assignment word on the line, or after a command delimiter such as ‘<samp>;</samp>’ or ‘<samp>|</samp>’, which is usually command name completion. </p> <p>If multiple options are supplied, the <samp>-D</samp> option takes precedence over <samp>-E</samp>, and both take precedence over <samp>-I</samp> </p> <p>The return value is true unless an invalid option is supplied, an attempt is made to modify the options for a <var>name</var> for which no completion specification exists, or an output error occurs. </p> </dd> </dl><div class="_attribution"> + <p class="_attribution-p"> + Copyright © 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.<br>Licensed under the GNU Free Documentation License.<br> + <a href="https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html" class="_attribution-link">https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html</a> + </p> +</div> |
