\section complete complete - edit command specific tab-completions.
\subsection complete-synopsis Synopsis
complete (-c|--command|-p|--path) COMMAND [(-s|--short-option) SHORT_OPTION] [(-l|--long-option|-o|--old-option) LONG_OPTION [(-a||--arguments) OPTION_ARGUMENTS] [(-d|--description) DESCRIPTION]
\subsection complete-description Description
- COMMAND is the name of the command for which to add a completion
- SHORT_OPTION is a one character option for the command
- LONG_OPTION is a multi character option for the command
- OPTION_ARGUMENTS is parameter containing a space-separated list of possible option-arguments, which may contain subshells
- DESCRIPTION is a description of what the option and/or option arguments do
- -e or --erase implies that the specified completion should be deleted
- -f or --no-files specifies that the option specified by this completion may not be followed by a filename
- -n or --condition specides a shell command that must return 0 if the completion is to be used. This makes it possible to specify completions that should only be used in some cases.
- -o or --old-option implies that the command uses old long style options with only one dash
- -p or --path implies that the string COMMAND is the full path of the command
- -r or --require-parameter specifies that the option specified by this completion always must have an option argument, i.e. may not be followed by another option
- -u or --unauthorative implies that there may be more options than the ones specified, and that fish should not assume that options not listed are spelling errors
- -x or --exclusive implies both -r and -f
Command specific tab-completions in \c fish are based on the notion
of options and arguments. An option is a parameter which begins with a
hyphen, such as '-h', '-help' or '--help'. Arguments are parameters
that do not begin with a hyphen. Fish recognizes three styles of
options, the same styles as the GNU version of the getopt
library. These styles are:
- Short options, like '-a'. Short options are a single character long, are preceeded by a single hyphen and may ge grouped together (like '-la', which is equivalent to '-l -a'). Option arguments may be specified in the following parameter ('-w 32') or by appending the option with the value ('-w32').
- Old style long options, like '-Wall'. Old style long options are more than one character long, are preceeded by a single hyphen and may not be grouped together. Option arguments are specified in the following parameter ('-ao null').
- GNU style long options, like '--colors'. GNU style long options are more than one character long, are preceeded by two hyphens, and may not be grouped together. Option arguments may be specified in the following parameter ('--quoting-style shell') or by appending the option with a '=' and the value ('--quoting-style=shell'). GNU style long options may be abbrevated so long as the abbrevation is unique ('--h' is equivalent to '--help' if help is the only long option beginning with an 'h').
\c complete only allows one of old style long options and GNU style
long options to be used on a specific command, but short options can
always be specified.
When erasing completions, it is possible to either erase all
completions for a specific command by specifying complete -e -c
COMMAND, or by specifying a specific completion option to delete
by specifying either a long, short or old style option.
\subsection complete-example Example
The short style option -o for the \c gcc command requires
that a file follows it. This can be done using writing complete
-c gcc -s o -r.
The short style option -d for the \c grep command requires
that one of the strings 'read', 'skip' or 'recurse' is used. This can
be specified writing complete -c grep -s d -x -a "read skip
recurse".
The \c su command takes any username as an argument. Usernames are
given as the first colon-separated field in the file /etc/passwd. This
can be specified as: complete -x -c su -d "Username" -a "(cat
/etc/passwd|cut -d : -f 1)" .
The \c rpm command has several different modes. If the \c -e or \c
--erase flag has been specified, \c rpm should delete one or more
packages, in which case several switches related to deleting packages
are valid, like the \c nodeps switch.
This can be written as:
complete -c rpm -n "__fish_contains_opt -s e erase" -l nodeps -d 'Dont check dependencies'
where \c __fish_contains_opt is a function that checks the commandline buffer for the presense of a specified set of options.