Skip to content

Commit 7e56c99

Browse files
committed
refactor(_comp_get_first_arg): return result via ret
1 parent 32ab3e3 commit 7e56c99

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

bash_completion

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,19 +2136,19 @@ _comp_realcommand()
21362136
}
21372137

21382138
# This function returns the first argument, excluding options
2139-
# @var[out] arg First argument if any, or otherwise an empty string
2139+
# @var[out] ret First argument if any, or otherwise an empty string
21402140
# @since 2.12
21412141
_comp_get_first_arg()
21422142
{
21432143
local i
21442144

2145-
arg=
2145+
ret=
21462146
for ((i = 1; i < cword; i++)); do
21472147
if [[ ${words[i]} != -?* ]]; then
2148-
arg=${words[i]}
2148+
ret=${words[i]}
21492149
break
21502150
elif [[ ${words[i]} == -- ]]; then
2151-
((i + 1 < cword)) && arg=${words[i + 1]}
2151+
((i + 1 < cword)) && ret=${words[i + 1]}
21522152
break
21532153
fi
21542154
done

bash_completion.d/000_bash_completion_compat.bash

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ _fstypes()
402402
# @deprecated 2.12 Use `_comp_get_first_arg`. Note that the new function
403403
# `_comp_get_first_arg` operates on `words` and `cword` instead of `COMP_WORDS`
404404
# and `COMP_CWORD`. The new function considers a command-line argument after
405-
# `--` as an argument.
405+
# `--` as an argument. The new function returns the result in variable `ret`
406+
# instead of `arg`.
406407
_get_first_arg()
407408
{
408409
local i

completions/cryptsetup

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ _comp_cmd_cryptsetup()
3434

3535
[[ $was_split ]] && return
3636

37-
local arg
37+
local ret
3838
_comp_get_first_arg
39+
local arg=$ret
3940
if [[ ! $arg ]]; then
4041
if [[ $cur == -* ]]; then
4142
_comp_compgen_help
@@ -47,7 +48,6 @@ _comp_cmd_cryptsetup()
4748
luksResume luksHeaderBackup luksHeaderRestore'
4849
fi
4950
else
50-
local ret
5151
_comp_count_args "" "-${noargopts}[chslSbopitTdM]"
5252
local args=$ret
5353
case $arg in

completions/hcitool

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,17 @@ _comp_cmd_hcitool()
4545

4646
[[ $was_split ]] && return
4747

48-
local arg
48+
local ret
4949
_comp_get_first_arg
50-
if [[ ! $arg ]]; then
50+
if [[ ! $ret ]]; then
5151
if [[ $cur == -* ]]; then
5252
_comp_compgen_help
5353
else
5454
_comp_compgen -- -W 'dev inq scan name info spinq epinq cmd con cc
5555
dc sr cpt rssi lq tpl afh lst auth enc key clkoff clock'
5656
fi
5757
else
58-
local ret
59-
case $arg in
58+
case $ret in
6059
name | info | dc | rssi | lq | afh | auth | key | clkoff | lst)
6160
_comp_count_args
6261
if ((ret == 2)); then
@@ -116,17 +115,17 @@ _comp_cmd_sdptool()
116115

117116
[[ $was_split ]] && return
118117

119-
local arg
118+
local ret
120119
_comp_get_first_arg
121-
if [[ ! $arg ]]; then
120+
if [[ ! $ret ]]; then
122121
if [[ $cur == -* ]]; then
123122
_comp_compgen_help
124123
else
125124
_comp_compgen -- -W 'search browse records add del get setattr
126125
setseq'
127126
fi
128127
else
129-
case $arg in
128+
case $ret in
130129
search)
131130
if [[ $cur == -* ]]; then
132131
_comp_compgen -- -W '--bdaddr --tree --raw --xml'
@@ -198,16 +197,16 @@ _comp_cmd_rfcomm()
198197
;;
199198
esac
200199

201-
local arg
200+
local ret
202201
_comp_get_first_arg
202+
local arg=$ret
203203
if [[ ! $arg ]]; then
204204
if [[ $cur == -* ]]; then
205205
_comp_compgen_help
206206
else
207207
_comp_compgen -- -W 'show connect listen watch bind release'
208208
fi
209209
else
210-
local ret
211210
_comp_count_args
212211
local args=$ret
213212
if ((args == 2)); then
@@ -238,16 +237,16 @@ _comp_cmd_ciptool()
238237
;;
239238
esac
240239

241-
local arg
240+
local ret
242241
_comp_get_first_arg
243-
if [[ ! $arg ]]; then
242+
if [[ ! $ret ]]; then
244243
if [[ $cur == -* ]]; then
245244
_comp_compgen_help
246245
else
247246
_comp_compgen -- -W 'show search connect release loopback'
248247
fi
249248
else
250-
case $arg in
249+
case $ret in
251250
connect | release | loopback)
252251
local ret
253252
_comp_count_args
@@ -294,9 +293,9 @@ _comp_cmd_hciconfig()
294293
local cur prev words cword comp_args
295294
_comp_initialize -- "$@" || return
296295

297-
local arg
296+
local ret
298297
_comp_get_first_arg
299-
if [[ ! $arg ]]; then
298+
if [[ ! $ret ]]; then
300299
if [[ $cur == -* ]]; then
301300
_comp_compgen -- -W '--help --all'
302301
else
@@ -307,8 +306,7 @@ _comp_cmd_hciconfig()
307306
version revision lm'
308307
fi
309308
else
310-
local ret
311-
case $arg in
309+
case $ret in
312310
putkey | delkey)
313311
_comp_count_args
314312
if ((ret == 2)); then

0 commit comments

Comments
 (0)