zsh
Completion
Zsh uses widgets to provide completions. Define a completion widget named 'complete':
zle -C complete expand-or-complete completer
The second argument to the zle command 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
- delete-char-or-list
The third argument is the name of the function that will provide completions.
Enable a completion widget:
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.zsh/cache
The first argument to zstyle is called a context and is defined as follows:
:completion:<function-name>:<completer>:<command>:<argument>:<tag>
Where
function-namecompleter- name of the currently active completer functioncommand- name of the current command for which completion is performed, e.g.git-addargument- name of the command line or option argument being completedtagzstyle ':completion:' matcher-list 'm:{a-zA-Z}={A-Za-z}' '+r:|[._-]=* r:|=**'
matcher-list is set to a list of match specifications. completion system will try them one after another for each completer selected.
_complete completer
Command line and trial completion patterns are anchored on the left side:
l:lanchor|lpat=tpat
On the right side:
r:lpat|ranchor=tpat
- lpat is a pattern that matches on the command line
- tpat is a pattern that matches in the trial completion