@@ -22,15 +22,17 @@ __math_cursor_index_in_current_word() {
2222#
2323# required variables:
2424#
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
2729# - positional_number: value ignored
2830# - unparsed_words: unparsed words from the current command line
2931#
3032# modified variables:
3133#
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
3436# - positional_number: set to the current positional number
3537# - unparsed_words: remove all flags, options, and option values for this (sub)command
3638__math_offer_flags_options () {
@@ -67,26 +69,26 @@ __math_offer_flags_options() {
6769 # ${word} is a flag or an option
6870 # If ${word} is an option, mark that the next word to be parsed is an option value
6971 local option
70- for option in " ${options [@]} " ; do
72+ for option in " ${repeating_options[@]} " " ${non_repeating_options [@]}" ; do
7173 [[ " ${word} " = " ${option} " ]] && is_parsing_option_value=true && break
7274 done
7375
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
7577 local not_found=true
7678 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 [@]} " )
8183 not_found=false
8284 break
8385 fi
8486 done
8587 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 [@]} " )
9092 break
9193 fi
9294 done
@@ -121,7 +123,7 @@ __math_offer_flags_options() {
121123 && ! " ${is_parsing_option_value} " \
122124 && [[ (" ${cur} " = -* && " ${positional_number} " -ge 0) || " ${positional_number} " -eq -1 ]]
123125 then
124- COMPREPLY+=($( compgen -W " ${flags [*]} ${options [*]} " -- " ${cur} " ) )
126+ COMPREPLY+=($( compgen -W " ${repeating_flags [*]} ${non_repeating_flags[*]} ${repeating_options[*]} ${non_repeating_options [*]}" -- " ${cur} " ) )
125127 fi
126128}
127129
@@ -158,8 +160,10 @@ _math() {
158160 local -i positional_number
159161 local -a unparsed_words=(" ${COMP_WORDS[@]: 1: ${COMP_CWORD} } " )
160162
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=()
163167 __math_offer_flags_options 0
164168
165169 # Offer subcommand / subcommand argument completions
@@ -179,20 +183,26 @@ _math() {
179183}
180184
181185_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=()
184190 __math_offer_flags_options 9223372036854775807
185191}
186192
187193_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=()
190198 __math_offer_flags_options 9223372036854775807
191199}
192200
193201_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=()
196206 __math_offer_flags_options 0
197207
198208 # Offer subcommand / subcommand argument completions
@@ -212,8 +222,10 @@ _math_stats() {
212222}
213223
214224_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)
217229 __math_offer_flags_options 9223372036854775807
218230
219231 # Offer option value completions
@@ -226,14 +238,18 @@ _math_stats_average() {
226238}
227239
228240_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=()
231245 __math_offer_flags_options 9223372036854775807
232246}
233247
234248_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)
237253 __math_offer_flags_options 9223372036854775807
238254
239255 # Offer option value completions
@@ -278,8 +294,10 @@ _math_stats_quantiles() {
278294}
279295
280296_math_help () {
281- flags=(--version)
282- options=()
297+ repeating_flags=()
298+ non_repeating_flags=(--version)
299+ repeating_options=()
300+ non_repeating_options=()
283301 __math_offer_flags_options 9223372036854775807
284302}
285303
0 commit comments