Debian Codegraph @

invoke/completion/zsh.completion

raw
1 # Invoke tab-completion script to be sourced with the Z shell.
2 # Known to work on zsh 5.0.x, probably works on later 4.x releases as well (as
3 # it uses the older compctl completion system).
4
5 _complete_{binary}() {{
6 # `words` contains the entire command string up til now (including
7 # program name).
8 #
9 # We hand it to Invoke so it can figure out the current context: spit back
10 # core options, task names, the current task's options, or some combo.
11 #
12 # Before doing so, we attempt to tease out any collection flag+arg so we
13 # can ensure it is applied correctly.
14 collection_arg=''
15 if [[ "${{words}}" =~ "(-c|--collection) [^ ]+" ]]; then
16 collection_arg=$MATCH
17 fi
18 # `reply` is the array of valid completions handed back to `compctl`.
19 # Use ${{=...}} to force whitespace splitting in expansion of
20 # $collection_arg
21 reply=( $({binary} ${{=collection_arg}} --complete -- ${{words}}) )
22 }}
23
24
25 # Tell shell builtin to use the above for completing our given binary name(s).
26 # * -K: use given function name to generate completions.
27 # * +: specifies 'alternative' completion, where options after the '+' are only
28 # used if the completion from the options before the '+' result in no matches.
29 # * -f: when function generates no results, use filenames.
30 # * positional args: program names to complete for.
31 compctl -K _complete_{binary} + -f {spaced_names}
32
33 # vim: set ft=sh :