Skip to content

Commit a5fe7d2

Browse files
authored
Merge pull request #1034 from akinomyoga/refactor-api-3
refactor: rename variable `{ => _comp_}root_command` plus misc small fixes
2 parents 8a76f3d + 67f1189 commit a5fe7d2

File tree

10 files changed

+25
-24
lines changed

10 files changed

+25
-24
lines changed

bash_completion

+6-5
Original file line numberDiff line numberDiff line change
@@ -1751,10 +1751,11 @@ _expand()
17511751
;;
17521752
~*)
17531753
_comp_compgen -v COMPREPLY tilde &&
1754-
eval "COMPREPLY[0]=$(printf ~%q "${COMPREPLY[0]#\~}")"
1755-
return ${#COMPREPLY[@]}
1754+
eval "COMPREPLY[0]=$(printf ~%q "${COMPREPLY[0]#\~}")" &&
1755+
return 1
17561756
;;
17571757
esac
1758+
return 0
17581759
}
17591760

17601761
# Process ID related functions.
@@ -2722,7 +2723,7 @@ complete -F _comp_command aoss command "do" else eval exec ltrace nice nohup pad
27222723
_comp_root_command()
27232724
{
27242725
local PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
2725-
local root_command=$1
2726+
local _comp_root_command=$1
27262727
_comp_command
27272728
}
27282729
complete -F _comp_root_command fakeroot gksu gksudo kdesudo really
@@ -2732,7 +2733,7 @@ complete -F _comp_root_command fakeroot gksu gksudo kdesudo really
27322733
# @since 2.12
27332734
_comp_as_root()
27342735
{
2735-
[[ $EUID -eq 0 || ${root_command-} ]]
2736+
[[ $EUID -eq 0 || ${_comp_root_command-} ]]
27362737
}
27372738

27382739
# Complete on available commands, subject to `no_empty_cmd_completion`.
@@ -2821,7 +2822,7 @@ _filedir_xspec()
28212822
_comp_quote_compgen "$cur"
28222823
local quoted=$ret
28232824
2824-
local xspec=${_xspecs[${1##*/}]} tmp
2825+
local xspec=${_xspecs[${1##*/}]}
28252826
local -a toks
28262827
_comp_compgen -v toks -c "$quoted" -- -d
28272828

completions/_slackpkg

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ _comp_cmd_slackpkg()
5151
. "$config"
5252

5353
local i action
54-
for ((i = 1; i < ${#words[@]}; i++)); do
54+
for ((i = 1; i < cword; i++)); do
5555
if [[ ${words[i]} != -* ]]; then
5656
action="${words[i]}"
5757
break

completions/getent

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ _comp_cmd_getent()
66
_comp_initialize -s -- "$@" || return
77

88
local noargopts='!(-*|*[s]*)'
9-
local i db has_db=""
9+
local i db="" has_db=""
1010
for ((i = 1; i < cword; i++)); do
1111
# shellcheck disable=SC2254
1212
case ${words[i]} in
@@ -27,7 +27,7 @@ _comp_cmd_getent()
2727
esac
2828
done
2929

30-
case ${db-} in
30+
case $db in
3131
passwd)
3232
_comp_compgen -- -u
3333
return
@@ -57,8 +57,9 @@ _comp_cmd_getent()
5757
;;
5858
esac
5959

60+
# shellcheck disable=SC2254
6061
case $prev in
61-
-s | --service)
62+
-${noargopts}s | --service)
6263
return
6364
;;
6465
esac

completions/sbopkg

+5-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ _comp_cmd_sbopkg()
3636

3737
local i config
3838
config="/etc/sbopkg/sbopkg.conf"
39-
for ((i = ${#words[@]} - 1; i > 0; i--)); do
39+
for ((i = ${#words[@]} - 2; i > 0; i--)); do
4040
if [[ ${words[i]} == -f ]]; then
4141
config="${words[i + 1]}"
4242
__expand_tilde_by_ref config
@@ -47,7 +47,7 @@ _comp_cmd_sbopkg()
4747
[[ -r $config ]] || return
4848
. "$config"
4949

50-
for ((i = 1; i < ${#words[@]}; i++)); do
50+
for ((i = 1; i < ${#words[@]} - 1; i++)); do
5151
case "${words[i]}" in
5252
-V)
5353
REPO_NAME="${words[i + 1]%%/*}"
@@ -58,11 +58,12 @@ _comp_cmd_sbopkg()
5858
;;
5959
esac
6060
done
61-
[[ -r $REPO_ROOT/$REPO_NAME/$REPO_BRANCH/SLACKBUILDS.TXT ]] || return
61+
local file=${REPO_ROOT-}/${REPO_NAME-}/${REPO_BRANCH-}/SLACKBUILDS.TXT
62+
[[ -r $file ]] || return
6263

6364
COMPREPLY=($(
6465
command sed -ne "/^SLACKBUILD NAME: $cur/{s/^SLACKBUILD NAME: //;p}" \
65-
"$REPO_ROOT/$REPO_NAME/$REPO_BRANCH/SLACKBUILDS.TXT"
66+
"$file"
6667
))
6768
_comp_compgen -aC "$QUEUEDIR" -- -f -X "!*.sqf"
6869
} &&

completions/ssh

+1-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ _comp_cmd_ssh()
378378
_count_args "=" "-*[BbcDeLpRWEFSIiJlmOoQw]"
379379
if ((args > 1)); then
380380
compopt -o filenames
381-
_comp_compgen -a commands
381+
_comp_compgen_commands
382382
else
383383
_known_hosts_real ${ipvx-} -a ${configfile:+-F "$configfile"} \
384384
-- "$cur"

completions/sudo

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ _comp_cmd_sudo()
1313
for ((i = 1; i <= cword; i++)); do
1414
if [[ ${words[i]} != -* ]]; then
1515
local PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
16-
local root_command=${words[i]}
16+
local _comp_root_command=$1
1717
_comp_command_offset $i
1818
return
1919
fi

completions/svcadm

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ _comp_cmd_svcadm()
108108
for ((i = 1; i < cword; i++)); do
109109
if [[ ${words[i]} == @(enable|disable|restart|refresh|clear|mark|milestone) ]]; then
110110
command=${words[i]}
111+
break
111112
fi
112113
done
113114

completions/timeout

+4-7
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22

33
_comp_cmd_timeout()
44
{
5-
local cur prev words cword was_split comp_args i found=""
5+
local cur prev words cword was_split comp_args i
66
_comp_initialize -s -- "$@" || return
77

88
local noargopts='!(-*|*[ks]*)'
9-
for ((i = 1; i <= cword; i++)); do
9+
for ((i = 1; i < cword; i++)); do
1010
if [[ ${words[i]} != -* ]]; then
11-
if [[ $found ]]; then
12-
_comp_command_offset $i
13-
return
14-
fi
15-
found=set
11+
_comp_command_offset "$((i + 1))"
12+
return
1613
fi
1714
# shellcheck disable=SC2254
1815
[[ ${words[i]} == -@(-kill-after|-signal|${noargopts}[ks]) ]] && ((i++))

completions/update-alternatives

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ _comp_cmd_update_alternatives()
3131
;;
3232
esac
3333

34-
local mode args i
34+
local mode="" args i
3535

3636
# find which mode to use and how many real args used so far
3737
for ((i = 1; i < cword; i++)); do

test/t/test_chown.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
@pytest.mark.bashcomp(
99
pre_cmds=(
1010
# Fake root command to get all users/groups completed at least for now
11-
"root_command=sudo",
11+
"_comp_root_command=sudo",
1212
)
1313
)
1414
class TestChown:

0 commit comments

Comments
 (0)