complete ( -c | --command | -p | --path ) COMMAND [( -c | --command | -p | --path ) COMMAND]... [( -e | --erase )] [( -s | --short-option ) SHORT_OPTION]... [( -l | --long-option | -o | --old-option ) LONG_OPTION]... [( -a | --arguments ) OPTION_ARGUMENTS] [( -k | --keep-order )] [( -f | --no-files )] [( -F | --force-files )] [( -r | --require-parameter )] [( -x | --exclusive )] [( -w | --wraps ) WRAPPED_COMMAND]... [( -n | --condition ) CONDITION] [( -d | --description ) DESCRIPTION] complete ( -C [STRING] | --do-complete[=STRING] )
For an introduction to specifying completions, see Writing your own completions in the fish manual.
COMMANDis the name of the command for which to add a completion.
SHORT_OPTIONis a one character option for the command.
LONG_OPTIONis a multi character option for the command.
OPTION_ARGUMENTSis parameter containing a space-separated list of possible option-arguments, which may contain command substitutions.
DESCRIPTIONis a description of what the option and/or option arguments do.
--command COMMANDspecifies that
COMMANDis the name of the command.
--path COMMANDspecifies that
COMMANDis the absolute path of the program (optionally containing wildcards).
--erasedeletes the specified completion.
--short-option=SHORT_OPTIONadds a short option to the completions list.
--long-option=LONG_OPTIONadds a GNU style long option to the completions list.
--old-option=LONG_OPTIONadds an old style long option to the completions list (See below for details).
--arguments=OPTION_ARGUMENTSadds the specified option arguments to the completions list.
--keep-orderpreserves the order of the
--argumentsinstead of sorting alphabetically. Multiple
-kresult in arguments of the later ones displayed first.
--no-filessays that the options specified by this completion may not be followed by a filename.
--force-filessays that the options specified by this completion may be followed by a filename, even if another applicable
--require-parametersays that the options specified by this completion must have an option argument, i.e. may not be followed by another option.
--wraps=WRAPPED_COMMANDcauses the specified command to inherit completions from the wrapped command (See below for details).
--conditionspecifies 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.
--do-complete=STRINGmakes complete try to find all possible completions for the specified string.
--do-completewith no argument makes complete try to find all possible completions for the current command line buffer. If the shell is not in interactive mode, an error is returned.
--authoritativeno longer do anything and are silently ignored.
--unauthoritativeno longer do anything and are silently ignored.
Command specific tab-completions in
fish are based on the notion of options and arguments. An option is a parameter which begins with a hyphen, such as '
-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:
-a'. Short options are a single character long, are preceded by a single hyphen and may be 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 ('
-Wall'. Old style long options can be more than one character long, are preceded by a single hyphen and may not be grouped together. Option arguments are specified in the following parameter ('
--colors'. GNU style long options can be more than one character long, are preceded 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 abbreviated so long as the abbreviation is unique ('
--h') is equivalent to '
--help' if help is the only long option beginning with an 'h').
The options for specifying command name and command path may be used multiple times to define the same completions for multiple commands.
The options for specifying command switches and wrapped commands may be used multiple times to define multiple completions for the command(s) in a single call.
complete multiple times for the same command adds the new definitions on top of any existing completions defined for the command.
--arguments is specified in conjunction with long, short, or old style options, the specified arguments are only used as completions when attempting to complete an argument for any of the specified options. If
--arguments is specified without any long, short, or old style options, the specified arguments are used when completing any argument to the command (except when completing an option argument that was specified with
Command substitutions found in
OPTION_ARGUMENTS are not expected to return a space-separated list of arguments. Instead they must return a newline-separated list of arguments, and each argument may optionally have a tab character followed by the argument description. Any description provided in this way overrides a description given with
--wraps options causes the specified command to inherit completions from another command. The inheriting command is said to "wrap" the inherited command. The wrapping command may have its own completions in addition to inherited ones. A command may wrap multiple commands, and wrapping is transitive: if A wraps B, and B wraps C, then A automatically inherits all of C's completions. Wrapping can be removed using the
--erase options. Note that wrapping only works for completions specified with
--command and are ignored when specifying completions with
When erasing completions, it is possible to either erase all completions for a specific command by specifying
complete -c COMMAND -e, or by specifying a specific completion option to delete by specifying either a long, short or old style option.
The short style option
-o for the
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
grep command requires that one of the strings '
skip' or '
recurse' is used. This can be specified writing:
complete -c grep -s d -x -a "read skip recurse"
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)"
rpm command has several different modes. If the
--erase flag has been specified,
rpm should delete one or more packages, in which case several switches related to deleting packages are valid, like the
This can be written as:
complete -c rpm -n "__fish_contains_opt -s e erase" -l nodeps -d "Don't check dependencies"
__fish_contains_opt is a function that checks the command line buffer for the presence of a specified set of options.
To implement an alias, use the
complete -c hub -w git
Now hub inherits all of the completions from git. Note this can also be specified in a function declaration.
© 2019 fish-shell developers
Licensed under the GNU General Public License, version 2.