The shell’s programmable completion mechanism can be manipulated in two
ways; here the low-level features supporting the newer, function-based
mechanism are defined. A complete set of shell functions based on these
features is described in
the next chapter, Completion System,
and users with no interest in adding to that system (or, potentially,
writing their own — see dictionary entry for ‘hubris’) should skip
the current section. The older system based on the compctl
builtin
command is described in
Completion Using compctl.
Completion widgets are defined by the -C
option to the zle
builtin command provided by the zsh/zle
module (see
The zsh/zle Module). For example,
zle -C complete expand-or-complete completer
defines a widget named ‘complete
’. The second argument is the name
of any of the builtin widgets that handle completions:
complete-word
, expand-or-complete
,
expand-or-complete-prefix
, menu-complete
,
menu-expand-or-complete
, reverse-menu-complete
,
list-choices
, or delete-char-or-list
. Note that this will still
work even if the widget in question has been re-bound.
When this newly defined widget is bound to a key
using the bindkey
builtin command defined in the zsh/zle
module
(Zsh Line Editor), typing that key will call the shell function ‘completer
’. This
function is responsible for generating completion matches using the
builtins described below. As with other ZLE widgets, the function is
called with its standard input closed.
Once the function returns, the completion code takes over control again
and treats the matches in the same manner as the specified builtin
widget, in this case expand-or-complete
.