Debian Codegraph @

invoke/completion/bash.completion

raw
1 # Invoke tab-completion script to be sourced with Bash shell.
2 # Known to work on Bash 3.x, untested on 4.x.
3
4 _complete_{binary}() {{
5 local candidates
6
7 # COMP_WORDS contains the entire command string up til now (including
8 # program name).
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 candidates=`{binary} --complete -- ${{COMP_WORDS[*]}}`
12
13 # `compgen -W` takes list of valid options & a partial word & spits back
14 # possible matches. Necessary for any partial word completions (vs
15 # completions performed when no partial words are present).
16 #
17 # $2 is the current word or token being tabbed on, either empty string or a
18 # partial word, and thus wants to be compgen'd to arrive at some subset of
19 # our candidate list which actually matches.
20 #
21 # COMPREPLY is the list of valid completions handed back to `complete`.
22 COMPREPLY=( $(compgen -W "${{candidates}}" -- $2) )
23 }}
24
25
26 # Tell shell builtin to use the above for completing our invocations.
27 # * -F: use given function name to generate completions.
28 # * -o default: when function generates no results, use filenames.
29 # * positional args: program names to complete for.
30 complete -F _complete_{binary} -o default {spaced_names}
31
32 # vim: set ft=sh :