Skip to content

Commit ee42474

Browse files
committed
perf(_comp_count_args): skip reinitializing cword and words
In most of the contexts calling `_comp_count_args` in the current codebase, `cword` and `words` are already initialized with the same set of exclude chars (-n chars) by _comp_initialize, so there seems to be no need to again reassemble `cword` and `words`. This patch removes the redundant initialization of `cword` and `words`. * When `_comp_initialize` is called without `-s` or `-n chars` and `_comp_count_args` is called with an empty $1, they are compatible so `cword` and `words` outside can be directly used. * `7z` and `nslookup` specify the same set of exclude chars as `_comp_initialize`, so existing `cword` and `words` are compatible. Nevertheless, we need to reinitialize `cword` and `words` when the specified exclude chars are different from those specified to _comp_initialize. * The `ssh` completion calls `_comp_count_args` with excluding `=` while it calls `_comp_initialize` with `-n :`. * The `chown` completion calls `_comp_count_args` with excluding `:` while it calls `_comp_initialize` with `-sn :`. * The `nc` completions calls `_comp_count_args` without exclude chars while it calls `_comp_initialize` with `-n :`. * The completions for `chmod`, `cryptsetup`, `hcitool`, `mkinitrd`, `patch`, `quota`, and `zopflipng` does not specify exclude chars to `_comp_count_args` while they specify `-s` to `_comp_initialize`. It is not clear whether these discrepancies are intended ones are not, but this patch tries to keep the current behavior by explicitly specifying the original exclude chars.
1 parent 22a8e03 commit ee42474

File tree

12 files changed

+40
-29
lines changed

12 files changed

+40
-29
lines changed

bash_completion

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,8 +2216,10 @@ _comp_count_args()
22162216
done
22172217
shift "$((OPTIND - 1))"
22182218

2219-
local cword words
2220-
_comp__reassemble_words "$exclude<>&" words cword
2219+
if [[ $has_exclude ]]; then
2220+
local cword words
2221+
_comp__reassemble_words "$exclude<>&" words cword
2222+
fi
22212223

22222224
local i
22232225
ret=1

completions/7z

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ _comp_cmd_7z()
8585
fi
8686

8787
local ret
88-
_comp_count_args -n "="
88+
_comp_count_args
8989
if ((ret == 2)); then
9090
_filedir_xspec unzip "${@:2}"
9191
# TODO: parsing 7z i output?

completions/chmod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ _comp_cmd_chmod()
2828
fi
2929

3030
local ret
31-
_comp_count_args -i "$modearg"
31+
_comp_count_args -n "" -i "$modearg"
3232

3333
case $ret in
3434
1) ;; # mode

completions/cryptsetup

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ _comp_cmd_cryptsetup()
3737
local ret
3838
if _comp_get_first_arg; then
3939
local arg=$ret
40-
_comp_count_args -a "-${noargopts}[chslSbopitTdM]"
40+
_comp_count_args -n "" -a "-${noargopts}[chslSbopitTdM]"
4141
local args=$ret
4242
case $arg in
4343
open | create | luksOpen | loopaesOpen | tcryptOpen)

completions/hcitool

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ _comp_cmd_hcitool()
4949
if _comp_get_first_arg; then
5050
case $ret in
5151
name | info | dc | rssi | lq | afh | auth | key | clkoff | lst)
52-
_comp_count_args
52+
_comp_count_args -n ""
5353
if ((ret == 2)); then
5454
_comp_cmd_hcitool__bluetooth_addresses
5555
fi
@@ -58,30 +58,30 @@ _comp_cmd_hcitool()
5858
if [[ $cur == -* ]]; then
5959
_comp_compgen -- -W '--role --pkt-type'
6060
else
61-
_comp_count_args
61+
_comp_count_args -n ""
6262
if ((ret == 2)); then
6363
_comp_cmd_hcitool__bluetooth_addresses
6464
fi
6565
fi
6666
;;
6767
sr)
68-
_comp_count_args
68+
_comp_count_args -n ""
6969
if ((ret == 2)); then
7070
_comp_cmd_hcitool__bluetooth_addresses
7171
else
7272
_comp_compgen -- -W 'master slave'
7373
fi
7474
;;
7575
cpt)
76-
_comp_count_args
76+
_comp_count_args -n ""
7777
if ((ret == 2)); then
7878
_comp_cmd_hcitool__bluetooth_addresses
7979
else
8080
_comp_cmd_hcitool__bluetooth_packet_types
8181
fi
8282
;;
8383
tpl | enc | clock)
84-
_comp_count_args
84+
_comp_count_args -n ""
8585
if ((ret == 2)); then
8686
_comp_cmd_hcitool__bluetooth_addresses
8787
else

completions/mkinitrd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ _comp_cmd_mkinitrd()
3131
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
3232
else
3333
local ret
34-
_comp_count_args
34+
_comp_count_args -n ""
3535

3636
case $ret in
3737
1)

completions/nc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ _comp_cmd_nc()
3939

4040
# Complete 1st non-option arg only
4141
local ret
42-
_comp_count_args -a "-*[IiMmOPpqsTVWwXx]"
42+
_comp_count_args -n "" -a "-*[IiMmOPpqsTVWwXx]"
4343
((ret == 1)) || return
4444

4545
_known_hosts_real -- "$cur"

completions/nslookup

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ _comp_cmd_nslookup()
5353
fi
5454

5555
local ret
56-
_comp_count_args -n "="
56+
_comp_count_args
5757
if ((ret <= 2)); then
5858
_known_hosts_real -- "$cur"
5959
[[ $ret -eq 1 && $cur == @(|-) ]] && COMPREPLY+=(-)

completions/patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ _comp_cmd_patch()
5656
fi
5757

5858
local ret
59-
_comp_count_args
59+
_comp_count_args -n ""
6060
case $ret in
6161
1)
6262
_comp_compgen_filedir

completions/quota

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ _comp_cmd_setquota()
8484
_comp_cmd_quota__parse_help "$1"
8585
else
8686
local ret
87-
_comp_count_args
87+
_comp_count_args -n ""
8888

8989
case $ret in
9090
1)

0 commit comments

Comments
 (0)