Debian Codegraph @

examples/generated/zsh/example.sourceable

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__query() {
6
7 __zsh_query_contains() {
8 local arg='' key="$1"; shift
9 for arg; do [[ "$key" == "$arg" ]] && return 0; done
10 return 1
11 }
12
13 local cmd="$1"; shift
14
15 case "$cmd" in
16 get_positional)
17 printf "%s" "${POSITIONALS[$1]}"
18 return 0;;
19 has_option)
20 local option='' with_incomplete=0
21 [[ "$1" == 'WITH_INCOMPLETE' ]] && { with_incomplete=1; shift; }
22
23 for option in "${HAVING_OPTIONS[@]}"; do
24 __zsh_query_contains "$option" "$@" && return 0
25 done
26
27 (( with_incomplete )) && \
28 __zsh_query_contains "$INCOMPLETE_OPTION" "$@" && return 0
29
30 return 1;;
31 init)
32 local IFS=','
33 local -a options=(${=1})
34 unset IFS
35 shift;;
36 *)
37 echo "_example__query: argv[1]: invalid command" >&2
38 return 1;;
39 esac
40
41
42 local long_opts_with_arg=() long_opts_with_optional_arg=() long_opts_without_arg=()
43 local short_opts_with_arg=() short_opts_with_optional_arg=() short_opts_without_arg=()
44
45 local option=''
46 for option in "${options[@]}"; do
47 case "$option" in
48 --?*=) long_opts_with_arg+=("${option%=}");;
49 --?*=\?) long_opts_with_optional_arg+=("${option%=?}");;
50 --?*) long_opts_without_arg+=("$option");;
51 -?=) short_opts_with_arg+=("${option%=}");;
52 -?=\?) short_opts_with_optional_arg+=("${option%=?}");;
53 -?) short_opts_without_arg+=("$option");;
54 esac
55 done
56
57 POSITIONALS=()
58 HAVING_OPTIONS=()
59 OPTION_VALUES=()
60 INCOMPLETE_OPTION=''
61
62 local argi=2 # argi[1] is program name
63 for ((; argi <= $#; ++argi)); do
64 local arg="${@[$argi]}"
65 local have_trailing_arg=$(test $argi -lt $# && echo true || echo false)
66
67 case "$arg" in
68 --)
69 POSITIONALS+=("${@:$((argi + 1))}")
70 break;;
71 --*=*)
72 HAVING_OPTIONS+=("${arg%%=*}")
73 OPTION_VALUES+=("${arg#*=}");;
74 --*)
75 if __zsh_query_contains "$arg" "${long_opts_with_arg[@]}"; then
76 if $have_trailing_arg; then
77 HAVING_OPTIONS+=("$arg")
78 OPTION_VALUES+=("${@[$((++argi))]}")
79 else
80 INCOMPLETE_OPTION="$arg"
81 fi
82 else
83 HAVING_OPTIONS+=("$arg")
84 OPTION_VALUES+=("")
85 fi
86 ;;
87 -?*) # ignore '-'
88
89 local i=1 arg_length=${#arg}
90 for ((; i < arg_length; ++i)); do
91 local option="-${arg:$i:1}"
92 local trailing_chars="${arg:$((i+1))}"
93
94 if __zsh_query_contains "$option" "${short_opts_without_arg[@]}"; then
95 HAVING_OPTIONS+=("$option")
96 OPTION_VALUES+=("")
97 elif __zsh_query_contains "$option" "${short_opts_with_arg[@]}"; then
98 if [[ -n "$trailing_chars" ]]; then
99 HAVING_OPTIONS+=("$option")
100 OPTION_VALUES+=("$trailing_chars")
101 elif $have_trailing_arg; then
102 HAVING_OPTIONS+=("$option")
103 OPTION_VALUES+=("${@[$((++argi))]}")
104 else
105 INCOMPLETE_OPTION="$option"
106 fi
107
108 continue 2
109 elif __zsh_query_contains "$option" "${short_opts_with_optional_arg[@]}"; then
110 HAVING_OPTIONS+=("$option")
111 OPTION_VALUES+=("$trailing_chars") # may be empty
112 continue 2
113 fi
114 done
115 ;;
116 *)
117 POSITIONALS+=("$arg");;
118 esac
119 done
120 }
121
122 _example_start__--preserve-env() {
123 _parameters -g '*export*'
124 }
125
126 _example_start__--priority() {
127 local items=(
128 low:'Run with lowest priority, background tasks only'
129 normal:'Standard scheduling priority for regular tasks'
130 high:'Higher priority for time-sensitive operations'
131 realtime:'Real-time scheduling, may affect system responsiveness'
132 )
133
134 _describe -- '' items
135 }
136
137 _example_start__-o() {
138 _values -s , -S = '' \
139 lang'[set language]':::_locales \
140 user'[set user]':::_users \
141 group'[set group]':::_groups
142 }
143
144 _example() {
145 local opts=-h,--help
146 local HAVING_OPTIONS=() OPTION_VALUES=() POSITIONALS=() INCOMPLETE_OPTION=''
147 _example__query init "$opts" "${words[@]}"
148
149 case "$(_example__query get_positional 1)" in
150 start|launch) _example_start; return $?;;
151 view-log) _example_view_log; return $?;;
152 esac
153
154 local -a args=(
155 '(- *)'{-h,--help}
156 1:command1:'((start launch view-log))'
157 )
158 _arguments -S -s -w "${args[@]}"
159 }
160
161 _example_start() {
162 local opts=-v,--verbose,--deprecated-option,--preserve-env=,--priority=,--foreground,--background,--pid-file=,-o=,--options=,-h,--help
163 local HAVING_OPTIONS=() OPTION_VALUES=() POSITIONALS=() INCOMPLETE_OPTION=''
164 _example__query init "$opts" "${words[@]}"
165
166 local -a args=(
167 '*'{-v,--verbose}
168 '(--preserve-env)'--preserve-env=:' ':'_sequence _example_start__--preserve-env'
169 '(--priority)'--priority=:' ':_example_start__--priority
170 '(--background --foreground)'--foreground
171 '(--foreground --background)'--background
172 '(--options -o)'{-o+,--options=}:' ':'{_example_start__-o}'
173 '(- *)'{-h,--help}
174 1:command1:'((start launch view-log))'
175 2:command:_command_names
176 '*'::argument:_normal
177 )
178 _example__query has_option WITH_INCOMPLETE --deprecated-option &&\
179 args+=('(--deprecated-option)'--deprecated-option)
180 _example__query has_option --background &&\
181 args+=('(--pid-file)'--pid-file=:' ':_files)
182 _arguments -S -s -w "${args[@]}"
183 }
184
185 _example_view_log() {
186 local -a args=(
187 '(--pager)'--pager=-:command:_command_names
188 '(- *)'{-h,--help}
189 1:command1:'((start launch view-log))'
190 )
191 _arguments -S -s -w "${args[@]}"
192 }
193
194 zstyle ':completion:*:*:example:option--priority-*' sort false
195
196 compdef _example example
197
198 # vim: ft=zsh ts=2 sts=2 sw=2 et