|
4 | 4 | # completely (https://github.com/bashly-framework/completely) |
5 | 5 | # Modifying it manually is not recommended |
6 | 6 |
|
7 | | -_bashly_completions_flag_expects_value() { |
8 | | - case "$1" in |
9 | | - --env|-e) return 0 ;; |
10 | | - --wrap|-r) return 0 ;; |
11 | | - --source|-s) return 0 ;; |
12 | | - --show|-s) return 0 ;; |
| 7 | +_bashly_completions_route_flag_expects_value() { |
| 8 | + case "$1:$2" in |
| 9 | + 4:--env|4:-e) return 0 ;; |
| 10 | + 4:--wrap|4:-r) return 0 ;; |
| 11 | + 5:--source|5:-s) return 0 ;; |
| 12 | + 8:--show|8:-s) return 0 ;; |
13 | 13 | esac |
14 | 14 |
|
15 | 15 | return 1 |
16 | 16 | } |
17 | 17 |
|
18 | | -_bashly_completions() { |
19 | | - local cur=${COMP_WORDS[COMP_CWORD]} |
20 | | - local prev= |
21 | | - if ((COMP_CWORD > 0)); then |
22 | | - prev=${COMP_WORDS[$((COMP_CWORD - 1))]} |
23 | | - fi |
24 | | - |
25 | | - local completed=() |
26 | | - if ((COMP_CWORD > 1)); then |
27 | | - completed=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}") |
28 | | - fi |
29 | | - |
30 | | - local non_options=() |
31 | | - local completed_options=() |
32 | | - local skip_next=0 |
33 | | - for word in "${completed[@]}"; do |
34 | | - if ((skip_next)); then |
35 | | - skip_next=0 |
36 | | - continue |
37 | | - fi |
38 | | - |
39 | | - if [[ "${word:0:1}" == "-" ]]; then |
40 | | - completed_options+=("$word") |
41 | | - if _bashly_completions_flag_expects_value "$word"; then |
42 | | - skip_next=1 |
43 | | - fi |
44 | | - continue |
45 | | - fi |
46 | | - |
47 | | - non_options+=("$word") |
48 | | - done |
49 | | - |
50 | | - local route_id= |
51 | | - local route_word_count=-1 |
52 | | - local route_has_positionals=0 |
53 | | - local positional_index=0 |
| 18 | +_bashly_completions_resolve_route() { |
| 19 | + route_id= |
| 20 | + route_word_count=-1 |
| 21 | + route_has_positionals=0 |
| 22 | + positional_index=0 |
54 | 23 | if (( ${#non_options[@]} >= 0 )) && |
55 | 24 | (( 0 > route_word_count )) |
56 | 25 | then |
@@ -150,6 +119,47 @@ _bashly_completions() { |
150 | 119 | positional_index=$((${#non_options[@]} - 1)) |
151 | 120 | fi |
152 | 121 |
|
| 122 | +} |
| 123 | + |
| 124 | +_bashly_completions() { |
| 125 | + local cur=${COMP_WORDS[COMP_CWORD]} |
| 126 | + local prev= |
| 127 | + if ((COMP_CWORD > 0)); then |
| 128 | + prev=${COMP_WORDS[$((COMP_CWORD - 1))]} |
| 129 | + fi |
| 130 | + |
| 131 | + local completed=() |
| 132 | + if ((COMP_CWORD > 1)); then |
| 133 | + completed=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}") |
| 134 | + fi |
| 135 | + |
| 136 | + local non_options=() |
| 137 | + local completed_options=() |
| 138 | + local route_id= |
| 139 | + local route_word_count=-1 |
| 140 | + local route_has_positionals=0 |
| 141 | + local positional_index=0 |
| 142 | + _bashly_completions_resolve_route |
| 143 | + |
| 144 | + local skip_next=0 |
| 145 | + for word in "${completed[@]}"; do |
| 146 | + if ((skip_next)); then |
| 147 | + skip_next=0 |
| 148 | + continue |
| 149 | + fi |
| 150 | + |
| 151 | + if [[ "${word:0:1}" == "-" ]]; then |
| 152 | + completed_options+=("$word") |
| 153 | + if _bashly_completions_route_flag_expects_value "$route_id" "$word"; then |
| 154 | + skip_next=1 |
| 155 | + fi |
| 156 | + continue |
| 157 | + fi |
| 158 | + |
| 159 | + non_options+=("$word") |
| 160 | + _bashly_completions_resolve_route |
| 161 | + done |
| 162 | + |
153 | 163 | COMPREPLY=() |
154 | 164 |
|
155 | 165 | if [[ -z "$route_id" ]] || { (( route_word_count == 0 )) && (( !route_has_positionals )) && [[ "${cur:0:1}" != "-" ]]; }; then |
|
0 commit comments