Skip to content

refactor: rename variable { => _comp_}root_command plus misc small fixes #1034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Aug 14, 2023
Merged
11 changes: 6 additions & 5 deletions bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -1751,10 +1751,11 @@ _expand()
;;
~*)
_comp_compgen -v COMPREPLY tilde &&
eval "COMPREPLY[0]=$(printf ~%q "${COMPREPLY[0]#\~}")"
return ${#COMPREPLY[@]}
eval "COMPREPLY[0]=$(printf ~%q "${COMPREPLY[0]#\~}")" &&
return 1
;;
esac
return 0
}

# Process ID related functions.
Expand Down Expand Up @@ -2722,7 +2723,7 @@ complete -F _comp_command aoss command "do" else eval exec ltrace nice nohup pad
_comp_root_command()
{
local PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
local root_command=$1
local _comp_root_command=$1
_comp_command
}
complete -F _comp_root_command fakeroot gksu gksudo kdesudo really
Expand All @@ -2732,7 +2733,7 @@ complete -F _comp_root_command fakeroot gksu gksudo kdesudo really
# @since 2.12
_comp_as_root()
{
[[ $EUID -eq 0 || ${root_command-} ]]
[[ $EUID -eq 0 || ${_comp_root_command-} ]]
}

# Complete on available commands, subject to `no_empty_cmd_completion`.
Expand Down Expand Up @@ -2821,7 +2822,7 @@ _filedir_xspec()
_comp_quote_compgen "$cur"
local quoted=$ret

local xspec=${_xspecs[${1##*/}]} tmp
local xspec=${_xspecs[${1##*/}]}
local -a toks
_comp_compgen -v toks -c "$quoted" -- -d

Expand Down
2 changes: 1 addition & 1 deletion completions/_slackpkg
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ _comp_cmd_slackpkg()
. "$config"

local i action
for ((i = 1; i < ${#words[@]}; i++)); do
for ((i = 1; i < cword; i++)); do
if [[ ${words[i]} != -* ]]; then
action="${words[i]}"
break
Expand Down
7 changes: 4 additions & 3 deletions completions/getent
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ _comp_cmd_getent()
_comp_initialize -s -- "$@" || return

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

case ${db-} in
case $db in
passwd)
_comp_compgen -- -u
return
Expand Down Expand Up @@ -57,8 +57,9 @@ _comp_cmd_getent()
;;
esac

# shellcheck disable=SC2254
case $prev in
-s | --service)
-${noargopts}s | --service)
return
;;
esac
Expand Down
9 changes: 5 additions & 4 deletions completions/sbopkg
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ _comp_cmd_sbopkg()

local i config
config="/etc/sbopkg/sbopkg.conf"
for ((i = ${#words[@]} - 1; i > 0; i--)); do
for ((i = ${#words[@]} - 2; i > 0; i--)); do
if [[ ${words[i]} == -f ]]; then
config="${words[i + 1]}"
__expand_tilde_by_ref config
Expand All @@ -47,7 +47,7 @@ _comp_cmd_sbopkg()
[[ -r $config ]] || return
. "$config"

for ((i = 1; i < ${#words[@]}; i++)); do
for ((i = 1; i < ${#words[@]} - 1; i++)); do
case "${words[i]}" in
-V)
REPO_NAME="${words[i + 1]%%/*}"
Expand All @@ -58,11 +58,12 @@ _comp_cmd_sbopkg()
;;
esac
done
[[ -r $REPO_ROOT/$REPO_NAME/$REPO_BRANCH/SLACKBUILDS.TXT ]] || return
local file=${REPO_ROOT-}/${REPO_NAME-}/${REPO_BRANCH-}/SLACKBUILDS.TXT
[[ -r $file ]] || return

COMPREPLY=($(
command sed -ne "/^SLACKBUILD NAME: $cur/{s/^SLACKBUILD NAME: //;p}" \
"$REPO_ROOT/$REPO_NAME/$REPO_BRANCH/SLACKBUILDS.TXT"
"$file"
))
_comp_compgen -aC "$QUEUEDIR" -- -f -X "!*.sqf"
} &&
Expand Down
2 changes: 1 addition & 1 deletion completions/ssh
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ _comp_cmd_ssh()
_count_args "=" "-*[BbcDeLpRWEFSIiJlmOoQw]"
if ((args > 1)); then
compopt -o filenames
_comp_compgen -a commands
_comp_compgen_commands
else
_known_hosts_real ${ipvx-} -a ${configfile:+-F "$configfile"} \
-- "$cur"
Expand Down
2 changes: 1 addition & 1 deletion completions/sudo
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ _comp_cmd_sudo()
for ((i = 1; i <= cword; i++)); do
if [[ ${words[i]} != -* ]]; then
local PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
local root_command=${words[i]}
local _comp_root_command=$1
_comp_command_offset $i
return
fi
Expand Down
1 change: 1 addition & 0 deletions completions/svcadm
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ _comp_cmd_svcadm()
for ((i = 1; i < cword; i++)); do
if [[ ${words[i]} == @(enable|disable|restart|refresh|clear|mark|milestone) ]]; then
command=${words[i]}
break
fi
done

Expand Down
11 changes: 4 additions & 7 deletions completions/timeout
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

_comp_cmd_timeout()
{
local cur prev words cword was_split comp_args i found=""
local cur prev words cword was_split comp_args i
_comp_initialize -s -- "$@" || return

local noargopts='!(-*|*[ks]*)'
for ((i = 1; i <= cword; i++)); do
for ((i = 1; i < cword; i++)); do
if [[ ${words[i]} != -* ]]; then
if [[ $found ]]; then
_comp_command_offset $i
return
fi
found=set
_comp_command_offset "$((i + 1))"
return
fi
# shellcheck disable=SC2254
[[ ${words[i]} == -@(-kill-after|-signal|${noargopts}[ks]) ]] && ((i++))
Expand Down
2 changes: 1 addition & 1 deletion completions/update-alternatives
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ _comp_cmd_update_alternatives()
;;
esac

local mode args i
local mode="" args i

# find which mode to use and how many real args used so far
for ((i = 1; i < cword; i++)); do
Expand Down
2 changes: 1 addition & 1 deletion test/t/test_chown.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@pytest.mark.bashcomp(
pre_cmds=(
# Fake root command to get all users/groups completed at least for now
"root_command=sudo",
"_comp_root_command=sudo",
)
)
class TestChown:
Expand Down