@@ -22,15 +22,17 @@ __math_cursor_index_in_current_word() {
22
22
#
23
23
# required variables:
24
24
#
25
- # - flags: the flags that the current (sub)command can accept
26
- # - options: the options that the current (sub)command can accept
25
+ # - repeating_flags: the repeating flags that the current (sub)command can accept
26
+ # - non_repeating_flags: the non-repeating flags that the current (sub)command can accept
27
+ # - repeating_options: the repeating options that the current (sub)command can accept
28
+ # - non_repeating_options: the non-repeating options that the current (sub)command can accept
27
29
# - positional_number: value ignored
28
30
# - unparsed_words: unparsed words from the current command line
29
31
#
30
32
# modified variables:
31
33
#
32
- # - flags : remove flags for this (sub)command that are already on the command line
33
- # - options : remove options for this (sub)command that are already on the command line
34
+ # - non_repeating_flags : remove flags for this (sub)command that are already on the command line
35
+ # - non_repeating_options : remove options for this (sub)command that are already on the command line
34
36
# - positional_number: set to the current positional number
35
37
# - unparsed_words: remove all flags, options, and option values for this (sub)command
36
38
__math_offer_flags_options () {
@@ -67,26 +69,26 @@ __math_offer_flags_options() {
67
69
# ${word} is a flag or an option
68
70
# If ${word} is an option, mark that the next word to be parsed is an option value
69
71
local option
70
- for option in " ${options [@]} " ; do
72
+ for option in " ${repeating_options[@]} " " ${non_repeating_options [@]}" ; do
71
73
[[ " ${word} " = " ${option} " ]] && is_parsing_option_value=true && break
72
74
done
73
75
74
- # Remove ${word} from ${flags } or ${options } so it isn't offered again
76
+ # Remove ${word} from ${non_repeating_flags } or ${non_repeating_options } so it isn't offered again
75
77
local not_found=true
76
78
local -i index
77
- for index in " ${! flags [@]} " ; do
78
- if [[ " ${flags [${index}]} " = " ${word} " ]]; then
79
- unset " flags [${index} ]"
80
- flags =(" ${flags [@]} " )
79
+ for index in " ${! non_repeating_flags [@]} " ; do
80
+ if [[ " ${non_repeating_flags [${index}]} " = " ${word} " ]]; then
81
+ unset " non_repeating_flags [${index} ]"
82
+ non_repeating_flags =(" ${non_repeating_flags [@]} " )
81
83
not_found=false
82
84
break
83
85
fi
84
86
done
85
87
if " ${not_found} " ; then
86
- for index in " ${! options [@]} " ; do
87
- if [[ " ${options [${index}]} " = " ${word} " ]]; then
88
- unset " options [${index} ]"
89
- options =(" ${options [@]} " )
88
+ for index in " ${! non_repeating_flags [@]} " ; do
89
+ if [[ " ${non_repeating_flags [${index}]} " = " ${word} " ]]; then
90
+ unset " non_repeating_flags [${index} ]"
91
+ non_repeating_flags =(" ${non_repeating_flags [@]} " )
90
92
break
91
93
fi
92
94
done
@@ -121,7 +123,7 @@ __math_offer_flags_options() {
121
123
&& ! " ${is_parsing_option_value} " \
122
124
&& [[ (" ${cur} " = -* && " ${positional_number} " -ge 0) || " ${positional_number} " -eq -1 ]]
123
125
then
124
- COMPREPLY+=($( compgen -W " ${flags [*]} ${options [*]} " -- " ${cur} " ) )
126
+ COMPREPLY+=($( compgen -W " ${repeating_flags [*]} ${non_repeating_flags[*]} ${repeating_options[*]} ${non_repeating_options [*]}" -- " ${cur} " ) )
125
127
fi
126
128
}
127
129
@@ -158,8 +160,10 @@ _math() {
158
160
local -i positional_number
159
161
local -a unparsed_words=(" ${COMP_WORDS[@]: 1: ${COMP_CWORD} } " )
160
162
161
- local -a flags=(--version -h --help)
162
- local -a options=()
163
+ local -a repeating_flags=()
164
+ local -a non_repeating_flags=(--version -h --help)
165
+ local -a repeating_options=()
166
+ local -a non_repeating_options=()
163
167
__math_offer_flags_options 0
164
168
165
169
# Offer subcommand / subcommand argument completions
@@ -179,20 +183,26 @@ _math() {
179
183
}
180
184
181
185
_math_add () {
182
- flags=(--hex-output -x --version -h --help)
183
- options=()
186
+ repeating_flags=()
187
+ non_repeating_flags=(--hex-output -x --version -h --help)
188
+ repeating_options=()
189
+ non_repeating_options=()
184
190
__math_offer_flags_options 9223372036854775807
185
191
}
186
192
187
193
_math_multiply () {
188
- flags=(--hex-output -x --version -h --help)
189
- options=()
194
+ repeating_flags=()
195
+ non_repeating_flags=(--hex-output -x --version -h --help)
196
+ repeating_options=()
197
+ non_repeating_options=()
190
198
__math_offer_flags_options 9223372036854775807
191
199
}
192
200
193
201
_math_stats () {
194
- flags=(--version -h --help)
195
- options=()
202
+ repeating_flags=()
203
+ non_repeating_flags=(--version -h --help)
204
+ repeating_options=()
205
+ non_repeating_options=()
196
206
__math_offer_flags_options 0
197
207
198
208
# Offer subcommand / subcommand argument completions
@@ -212,8 +222,10 @@ _math_stats() {
212
222
}
213
223
214
224
_math_stats_average () {
215
- flags=(--version -h --help)
216
- options=(--kind)
225
+ repeating_flags=()
226
+ non_repeating_flags=(--version -h --help)
227
+ repeating_options=()
228
+ non_repeating_options=(--kind)
217
229
__math_offer_flags_options 9223372036854775807
218
230
219
231
# Offer option value completions
@@ -226,14 +238,18 @@ _math_stats_average() {
226
238
}
227
239
228
240
_math_stats_stdev () {
229
- flags=(--version -h --help)
230
- options=()
241
+ repeating_flags=()
242
+ non_repeating_flags=(--version -h --help)
243
+ repeating_options=()
244
+ non_repeating_options=()
231
245
__math_offer_flags_options 9223372036854775807
232
246
}
233
247
234
248
_math_stats_quantiles () {
235
- flags=(--version -h --help)
236
- options=(--file --directory --shell --custom --custom-deprecated)
249
+ repeating_flags=()
250
+ non_repeating_flags=(--version -h --help)
251
+ repeating_options=()
252
+ non_repeating_options=(--file --directory --shell --custom --custom-deprecated)
237
253
__math_offer_flags_options 9223372036854775807
238
254
239
255
# Offer option value completions
@@ -278,8 +294,10 @@ _math_stats_quantiles() {
278
294
}
279
295
280
296
_math_help () {
281
- flags=(--version)
282
- options=()
297
+ repeating_flags=()
298
+ non_repeating_flags=(--version)
299
+ repeating_options=()
300
+ non_repeating_options=()
283
301
__math_offer_flags_options 9223372036854775807
284
302
}
285
303
0 commit comments