|
2 | 2 | # Use of this source code is governed by a BSD-style |
3 | 3 | # license that can be found in the LICENSE file. |
4 | 4 |
|
5 | | - |
6 | | -# COMPREPLY: array holds the completion results that gets displayed after |
7 | | -# pressing [TAB][TAB] |
8 | | -# |
9 | | -# COMP_WORDS: array of words that is typed on the command line |
10 | | -# |
11 | | -# COMP_CWORD: index for the COMP_WORDS array and using this different position |
12 | | -# words on command line can be accessed. |
13 | | -# |
14 | | -# compgen : -W holds the possible completions and the respective argument get |
15 | | -# chosen based on the $current_arg. |
16 | | -# |
17 | | -# By convention, the function name starts with an underscore. |
18 | | -# .bash_completion |
19 | | -# source ./lib/completion.bash |
20 | | - |
21 | | - |
22 | 5 | # |
23 | 6 | # dev completion |
| 7 | +# By convention, the function name starts with an underscore. |
24 | 8 | # |
25 | 9 | _dev_init_completion() { |
26 | 10 | # Pointer to current completion word. |
27 | 11 | # By convention, it's named "cur" but this isn't strictly necessary. |
28 | | - local arr cur prev opts |
| 12 | + local arr cur opts |
29 | 13 |
|
| 14 | + # COMPREPLY: array holds the completion results that gets displayed after |
| 15 | + # pressing [TAB][TAB] |
30 | 16 | COMPREPLY=() # Array variable storing the possible completions. |
| 17 | + |
| 18 | + # COMP_WORDS: array of words that is typed on the command line |
| 19 | + # |
| 20 | + # COMP_CWORD: index for the COMP_WORDS array and using this different position |
| 21 | + # words on command line can be accessed. |
31 | 22 | cur=${COMP_WORDS[COMP_CWORD]} |
32 | | - prev=${COMP_WORDS[COMP_CWORD-1]} |
33 | 23 |
|
34 | 24 | if [ "${cur:0:1}" == "-" ]; then |
35 | 25 | opts=$(dev ":options" 2>/dev/null) # |
36 | 26 | else |
37 | | - arr=(${COMP_WORDS[@]}) |
38 | | - unset arr[COMP_CWORD] |
| 27 | + arr=(${COMP_WORDS[@]}) && unset arr[COMP_CWORD] |
39 | 28 | [ "${arr[0]}" == "dev" ] && unset arr[0] |
40 | | - # echo "cur:$cur" >&2 |
41 | | - # echo "arr:${arr[@]:1}" >&2 |
42 | | - opts=$(dev ":completion" ":$cur" "${arr[@]}" 2>/dev/null) # |
| 29 | + opts=$(dev ":completion" ":$cur" "${arr[@]}" 2>/dev/null) |
43 | 30 | fi |
44 | 31 |
|
| 32 | + # compgen : -W holds the possible completions and the respective argument get |
| 33 | + # chosen based on the $current_arg. |
45 | 34 | COMPREPLY=( $(compgen -W "$opts" -- "$cur" ) ); |
46 | 35 | } |
47 | 36 |
|
|
0 commit comments