zsh: Command Flags

Next: Option Flags, Up: Completion Using compctl [Contents][Index]

### 21.3 Command Flags

Completion of the arguments of a command may be different for each command or may use the default. The behavior when completing the command word itself may also be separately specified. These correspond to the following flags and arguments, all of which (except for `-L`) may be combined with any combination of the options described subsequently in Option Flags:

command ...

  controls completion for the named commands, which must be listed last on the command line. If completion is attempted for a command with a pathname containing slashes and no completion definition is found, the search is retried with the last pathname component. If the command starts with a `=`, completion is tried with the pathname of the command.

  Any of the command strings may be patterns of the form normally used for filename generation. These should be quoted to protect them from immediate expansion; for example the command string `'foo*'` arranges for completion of the words of any command beginning with `foo`. When completion is attempted, all pattern completions are tried in the reverse order of their definition until one matches. By default, completion then proceeds as normal, i.e. the shell will try to generate more matches for the specific command on the command line; this can be overridden by including `-tn` in the flags for the pattern completion.

  Note that aliases are expanded before the command name is determined unless the `COMPLETE_ALIASES` option is set. Commands may not be combined with the `-C`, `-D` or `-T` flags.

`-C`

  controls completion when the command word itself is being completed. If no `compctl -C` command has been issued, the names of any executable command (whether in the path or specific to the shell, such as aliases or functions) are completed.

`-D`

  controls default completion behavior for the arguments of commands not assigned any special behavior. If no `compctl -D` command has been issued, filenames are completed.

`-T`

  supplies completion flags to be used before any other processing is done, even before processing for `compctl`s defined for specific commands. This is especially useful when combined with extended completion (the `-x` flag, see Extended Completion below). Using this flag you can define default behavior which will apply to all commands without exception, or you can alter the standard behavior for all commands. For example, if your access to the user database is too slow and/or it contains too many users (so that completion after ‘`~`’ is too slow to be usable), you can use

      compctl -T -x 's[~] C[0,[^/]#]' -k friends -S/ -tn

  to complete the strings in the array `friends` after a ‘`~`’. The `C[`...`]` argument is necessary so that this form of `~`-completion is not tried after the directory name is finished.

`-L`

  lists the existing completion behavior in a manner suitable for putting into a start-up script; the existing behavior is not changed. Any combination of the above forms, or the `-M` flag (which must follow the `-L` flag), may be specified, otherwise all defined completions are listed. Any other flags supplied are ignored.

no argument

  If no argument is given, `compctl` lists all defined completions in an abbreviated form; with a list of options, all completions with those flags set (not counting extended completion) are listed.

If the `+` flag is alone and followed immediately by the command list, the completion behavior for all the commands in the list is reset to the default. In other words, completion will subsequently use the options specified by the `-D` flag.

The form with `-M` as the first and only option defines global matching specifications (see Completion Matching Control). The match specifications given will be used for every completion attempt (only when using `compctl`, not with the new completion system) and are tried in the order in which they are defined until one generates at least one match. E.g.:

    compctl -M {No value for `dsq'} 'm:{a-zA-Z}={A-Za-z}'

This will first try completion without any global match specifications (the empty string) and, if that generates no matches, will try case insensitive completion.

Next: Option Flags, Up: Completion Using compctl [Contents][Index]