Debian Codegraph @

examples/generated/bash/example

raw
1 # This script was generated by crazy-complete.
2 # crazy-complete: A tool that creates robust and reliable autocompletion scripts for Bash, Fish and Zsh.
3 # For more information, visit: https://github.com/crazy-complete/crazy-complete
4
5 _example__parse_commandline() {
6 POSITIONALS=()
7 END_OF_OPTIONS=0
8
9 local cmd="root" argi arg i char trailing_chars VAR ARGS
10
11 __find_option() {
12 case "$1" in root:view-log*)
13 case "$2" in
14 --pager) VAR=OPT_pager; ARGS='?'; return;;
15 esac
16 esac
17 case "$1" in root:start*)
18 case "$2" in
19 -v|--verbose) VAR=OPT_verbose; ARGS=0; return;;
20 --deprecated-option) VAR=OPT_deprecated_option; ARGS=0; return;;
21 --preserve-env) VAR=OPT_preserve_env; ARGS=1; return;;
22 --priority) VAR=OPT_priority; ARGS=1; return;;
23 --foreground) VAR=OPT_foreground; ARGS=0; return;;
24 --background) VAR=OPT_background; ARGS=0; return;;
25 --pid-file) VAR=OPT_pid_file; ARGS=1; return;;
26 -o|--options) VAR=OPT_options; ARGS=1; return;;
27 esac
28 esac
29 case "$1" in root*)
30 case "$2" in
31 -h|--help) VAR=OPT_help; ARGS=0; return;;
32 esac
33 esac
34 return 1
35 }
36
37 __append_to_array() {
38 local -n arr=$1
39 arr+=("$2")
40 }
41
42 for ((argi=1; argi < cword; ++argi)); do
43 arg="${words[argi]}"
44
45 case "$arg" in
46 --)
47 END_OF_OPTIONS=1
48 POSITIONALS+=("${words[@]:$((++argi))}")
49 return;;
50 --*=*)
51 if __find_option "$cmd" "${arg%%=*}"
52 then __append_to_array "$VAR" "${arg#*=}"
53 fi;;
54 --*)
55 if __find_option "$cmd" "$arg"; then
56 if [[ "$ARGS" == 1 ]]
57 then __append_to_array "$VAR" "${words[++argi]}"
58 else __append_to_array "$VAR" "_OPT_ISSET_"
59 fi
60 fi;;
61 -?*) # ignore '-'
62
63 for ((i=1; i < ${#arg}; ++i)); do
64 char="${arg:$i:1}"
65 trailing_chars="${arg:$((i + 1))}"
66
67 if __find_option "$cmd" "-$char"; then
68 if [[ "$ARGS" == 1 ]]; then
69 if [[ -n "$trailing_chars" ]]
70 then __append_to_array "$VAR" "$trailing_chars"
71 else __append_to_array "$VAR" "${words[++argi]}"
72 fi
73 break;
74 else
75 __append_to_array "$VAR" "_OPT_ISSET_"
76 fi
77 fi
78 done
79 ;;
80 *)
81 POSITIONALS+=("$arg")
82 case "$cmd|${#POSITIONALS[@]}" in
83 'root|1')
84 case "$arg" in
85 launch) cmd+=":start";;
86 *) cmd+=":$arg";;
87 esac;;
88 esac
89 ;;
90 esac
91 done
92
93 for ((; argi <= cword; ++argi)); do
94 case "${words[argi]}" in
95 -?*);;
96 *) POSITIONALS+=("${words[argi]}");;
97 esac
98 done
99 }
100
101 _example__value_list() {
102 local duplicates=0
103 [[ "$1" == '-d' ]] && { duplicates=1; shift; }
104 local separator="$1"; shift
105
106 compopt -o nospace
107
108 local cur_unquoted break_pos in_quotes
109 _example__dequote "$cur" cur_unquoted break_pos in_quotes
110
111 if [[ -z "$cur_unquoted" ]]; then
112 COMPREPLY=("$@")
113 return
114 fi
115
116 local value having_value having_values=() remaining_values=()
117
118 IFS="$separator" read -r -a having_values <<< "$cur_unquoted"
119
120 if (( duplicates )); then
121 remaining_values=("$@")
122 else
123 for value; do
124 if ! _example__array_contains "$value" "${having_values[@]}"; then
125 remaining_values+=("$value")
126 fi
127 done
128 fi
129
130 COMPREPLY=()
131
132 local cur_stripped="$cur_unquoted"
133 if (( break_pos > -1 )); then
134 cur_stripped="${cur_stripped:break_pos}"
135 fi
136
137 if [[ "${cur_unquoted: -1}" == "$separator" ]]; then
138 for value in "${remaining_values[@]}"; do
139 COMPREPLY+=("$cur_stripped$value")
140 done
141 elif (( ${#remaining_values[@]} )); then
142 if _example__array_contains "${having_values[-1]}" "$@"; then
143 COMPREPLY+=("$cur_stripped$separator")
144 elif (( ${#having_values[@]} )); then
145 local cur_last_value=${having_values[-1]}
146 cur_stripped="${cur_stripped%"$cur_last_value"}"
147
148 for value in "${remaining_values[@]}"; do
149 if [[ "$value" == "$cur_last_value"* ]]; then
150 COMPREPLY+=("$cur_stripped$value")
151 fi
152 done
153 fi
154 fi
155 }
156
157 _example__dequote() {
158 local in="$1" len=${#1} i=0 result='' ___break_pos=-1 ___in_quotes=0
159
160 for ((; i < len; ++i)); do
161 case "${in:i:1}" in
162 "'")
163 ___in_quotes=1
164 for ((++i; i < len; ++i)); do
165 [[ "${in:i:1}" == "'" ]] && { ___in_quotes=0; break; }
166 result+="${in:i:1}"
167 done;;
168 '"')
169 ___in_quotes=1
170 for ((++i; i < len; ++i)); do
171 [[ "${in:i:1}" == '"' ]] && { ___in_quotes=0; break; }
172
173 if [[ "${in:i:1}" == '\' ]]; then
174 result+="${in:$((++i)):1}"
175 else
176 result+="${in:i:1}"
177 fi
178 done;;
179 '\')
180 result+="${in:$((++i)):1}";;
181 [$COMP_WORDBREAKS])
182 result+="${in:i:1}"
183 ___break_pos=${#result};;
184 *)
185 result+="${in:i:1}";;
186 esac
187 done
188
189 local -n ___RESULT=$2
190 local -n ___BREAK_POS=$3
191 local -n ___IN_QUOTES=$4
192 ___RESULT="$result"
193 ___BREAK_POS=$___break_pos
194 ___IN_QUOTES=$___in_quotes
195 }
196
197 _example__array_contains() {
198 local w='' search="$1"; shift;
199 for w; do [[ "$search" == "$w" ]] && return 0; done
200 return 1
201 }
202
203 _example__locales() {
204 COMPREPLY=($(compgen -W "$(command locale -a)" -- "$cur"))
205 }
206
207 _example__key_value_list() {
208 local sep1="$1"; shift
209 local sep2="$1"; shift
210 local -A keys=()
211 local i
212
213 for ((i=1; i <= $#; i += 2)); do
214 keys["${@:i:1}"]="${@:i + 1:1}"
215 done
216
217 local strip_chars=''
218 [[ "$COMP_WORDBREAKS" == *"$sep1"* ]] && strip_chars+="$sep1"
219 [[ "$COMP_WORDBREAKS" == *"$sep2"* ]] && strip_chars+="$sep2"
220 [[ "${cur:0:1}" == '"' ]] && strip_chars=''
221 [[ "${cur:0:1}" == "'" ]] && strip_chars=''
222 local cur="$cur" break_pos in_quotes
223 _example__dequote "$cur" cur break_pos in_quotes
224
225 if [[ -z "$cur" ]]; then
226 COMPREPLY=("${!keys[@]}")
227 return
228 fi
229
230 local pair key value found_key cur_stripped="$cur"
231 local -a having_pairs having_keys remaining_keys
232
233 IFS="$sep1" read -r -a having_pairs <<< "$cur"
234
235 for pair in "${having_pairs[@]}"; do
236 having_keys+=("${pair%%"$sep2"*}")
237 done
238
239 for key in "${!keys[@]}"; do
240 found_key=0
241
242 for having_key in "${having_keys[@]}"; do
243 if [[ "$key" == "$having_key" ]]; then
244 found_key=1
245 break
246 fi
247 done
248
249 if (( ! found_key )); then
250 remaining_keys+=("$key")
251 fi
252 done
253
254 COMPREPLY=()
255
256 if [[ "${cur: -1}" == "$sep1" ]]; then
257 [[ -n "$strip_chars" ]] && cur_stripped="${cur_stripped##*[$strip_chars]}"
258
259 for key in "${remaining_keys[@]}"; do
260 COMPREPLY+=("$cur_stripped$key")
261 done
262 else
263 pair="${cur##*"$sep1"}"
264 if [[ "$pair" == *"$sep2"* ]]; then
265 key="${pair%%"$sep2"*}"
266 value="${pair##*"$sep2"}"
267 cur="$value"
268 ${keys[$key]}
269
270 cur_stripped="${cur_stripped:0:$(( ${#cur_stripped} - ${#value} ))}"
271 if [[ -n "$strip_chars" ]]; then
272 cur_stripped="${cur_stripped##*[$strip_chars]}"
273 fi
274
275 for i in "${!COMPREPLY[@]}"; do
276 COMPREPLY[i]="$cur_stripped${COMPREPLY[i]}"
277 done
278 else
279 [[ -n "$strip_chars" ]] && cur_stripped="${cur_stripped##*[$strip_chars]}"
280 cur_stripped="${cur_stripped%"$pair"}"
281
282 for key in "${remaining_keys[@]}"; do
283 if [[ "$key" == "$pair"* ]]; then
284 COMPREPLY+=("$cur_stripped$key")
285 fi
286 done
287 fi
288 fi
289 }
290
291 _example__prefix_compreply() {
292 [[ "$cur" == *[$COMP_WORDBREAKS]* ]] && return
293
294 local i prefix="$1"
295 for ((i=0; i < ${#COMPREPLY[@]}; ++i)); do
296 COMPREPLY[i]="$prefix${COMPREPLY[i]}"
297 done
298 }
299
300 _example_start__-o() {
301 COMPREPLY=($(compgen -A user -- "$cur"))
302 }
303
304 _example_start__-o0() {
305 COMPREPLY=($(compgen -A group -- "$cur"))
306 }
307
308 _example() {
309 local cur prev words cword split
310 _init_completion -n =: || return
311
312 local END_OF_OPTIONS POSITIONALS
313 local -a OPT_help OPT_verbose OPT_deprecated_option OPT_preserve_env OPT_priority OPT_foreground OPT_background OPT_pid_file OPT_options OPT_pager
314
315 _example__parse_commandline
316
317 if (( 0 < ${#POSITIONALS[@]} )); then
318 case "${POSITIONALS[0]}" in
319 start|launch) _example_start && return 0;;
320 view-log) _example_view_log && return 0;;
321 esac
322 fi
323
324 if (( ! END_OF_OPTIONS )) && [[ "$cur" = -* ]]; then
325 local -a opts
326 if (( ! ${#OPT_help[@]} )); then
327 opts+=(-h --help)
328 fi
329 COMPREPLY+=($(compgen -W "${opts[*]}" -- "$cur"))
330 [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
331 return 1
332 fi
333
334 (( ${#POSITIONALS[@]} == 1 )) && {
335 COMPREPLY=($(compgen -W 'start launch view-log' -- "$cur"))
336 return 0;
337 }
338
339 return 1
340 }
341
342 _example_start() {
343 if (( ${#POSITIONALS[@]} >= 3 )); then
344 local realpos
345 for realpos in "${!COMP_WORDS[@]}"; do
346 [[ "${COMP_WORDS[realpos]}" == "${POSITIONALS[1]}" ]] && {
347 _command_offset $realpos
348 return 0;
349 }
350 done
351 fi
352
353 __complete_option() {
354 local opt="$1" cur="$2"
355
356 case "$opt" in --pid-file)
357 if (( ${#OPT_background[@]} )); then
358 _filedir
359 return 0
360 fi;;
361 esac
362
363 case "$opt" in
364 --preserve-env)
365 local cur_old="$cur"
366 cur="${cur##*,}"
367 COMPREPLY=($(compgen -A export -- "$cur"))
368 cur="$cur_old"
369 _example__value_list , "${COMPREPLY[@]}"
370 return 0;;
371 --priority)
372 COMPREPLY=($(compgen -W 'low normal high realtime' -- "$cur"))
373 compopt -o nosort
374 return 0;;
375 --options|-o)
376 _example__key_value_list , = \
377 lang _example__locales \
378 user _example_start__-o \
379 group _example_start__-o0
380 return 0;;
381 esac
382
383 return 1
384 }
385
386 case "$prev" in
387 --*) __complete_option "$prev" "$cur" && return 0;;
388 -*([vh])[o])
389 __complete_option "-${prev: -1}" "$cur" && return 0;;
390 esac
391
392 case "$cur" in
393 --*=*)
394 __complete_option "${cur%%=*}" "${cur#*=}" && return 0;;
395 --*);;
396 -*([vh])[o]*)
397 local i
398 for ((i=2; i <= ${#cur}; ++i)); do
399 local pre="${cur:0:$i}" value="${cur:$i}"
400 __complete_option "-${pre: -1}" "$value" && {
401 _example__prefix_compreply "$pre"
402 return 0
403 }
404 done;;
405 esac
406
407 if (( ! END_OF_OPTIONS )) && [[ "$cur" = -* ]]; then
408 local -a opts
409 if (( ! ${#OPT_help[@]} )); then
410 opts+=(-v --verbose)
411 (( ! ${#OPT_preserve_env[@]} )) && opts+=(--preserve-env=)
412 (( ! ${#OPT_priority[@]} )) && opts+=(--priority=)
413 (( ! ${#OPT_background[@]} && ! ${#OPT_foreground[@]} )) && opts+=(--foreground --background)
414 (( ! ${#OPT_pid_file[@]} )) && (( ${#OPT_background[@]} )) && opts+=(--pid-file=)
415 (( ! ${#OPT_options[@]} )) && opts+=(-o --options=)
416 fi
417 COMPREPLY+=($(compgen -W "${opts[*]}" -- "$cur"))
418 [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
419 return 1
420 fi
421
422 (( ${#POSITIONALS[@]} == 2 )) && {
423 COMPREPLY=($(compgen -A command -- "$cur"))
424 return 0;
425 }
426
427 return 1
428 }
429
430 _example_view_log() {
431 __complete_option() {
432 local opt="$1" cur="$2" mode="$3" ret=0
433
434 (( ! ret )) && return 0
435 [[ "$mode" == WITH_OPTIONAL ]] || return 1
436 ret=0
437
438 case "$opt" in
439 --pager)
440 COMPREPLY=($(compgen -A command -- "$cur"));;
441 *) ret=1;;
442 esac
443
444 return $ret
445 }
446
447 case "$cur" in
448 --*=*)
449 __complete_option "${cur%%=*}" "${cur#*=}" WITH_OPTIONAL && return 0;;
450 esac
451
452 if (( ! END_OF_OPTIONS )) && [[ "$cur" = -* ]]; then
453 local -a opts
454 if (( ! ${#OPT_help[@]} )); then
455 (( ! ${#OPT_pager[@]} )) && opts+=(--pager=)
456 fi
457 COMPREPLY+=($(compgen -W "${opts[*]}" -- "$cur"))
458 [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
459 return 1
460 fi
461
462 return 1
463 }
464
465 complete -F _example example
466
467 # vim: ft=sh ts=2 sts=2 sw=2 et