Skip to content

refactor(_command_offset): rename { => _comp}{_command_offset,_command,_root_command} #799

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 2 commits into from
Sep 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 27 additions & 24 deletions bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -2192,30 +2192,11 @@ else
complete -F _cd -o nospace cd pushd
fi

# A _command_offset wrapper function for use when the offset is unknown.
# Only intended to be used as a completion function directly associated
# with a command, not to be invoked from within other completion functions.
#
_command()
{
local offset i

# find actual offset, as position of the first non-option
offset=1
for ((i = 1; i <= COMP_CWORD; i++)); do
if [[ ${COMP_WORDS[i]} != -* ]]; then
offset=$i
break
fi
done
_command_offset $offset
}

# A meta-command completion function for commands like sudo(8), which need to
# first complete on a command, then complete according to that command's own
# completion definition.
#
_command_offset()
_comp_command_offset()
{
# rewrite current completion context before invoking
# actual command completion
Expand Down Expand Up @@ -2321,16 +2302,38 @@ _command_offset()
done
fi
}
complete -F _command aoss command "do" else eval exec ltrace nice nohup padsp \
_comp_deprecate_func _command_offset _comp_command_offset

# A _comp_command_offset wrapper function for use when the offset is unknown.
# Only intended to be used as a completion function directly associated
# with a command, not to be invoked from within other completion functions.
#
_comp_command()
{
local offset i

# find actual offset, as position of the first non-option
offset=1
for ((i = 1; i <= COMP_CWORD; i++)); do
if [[ ${COMP_WORDS[i]} != -* ]]; then
offset=$i
break
fi
done
_comp_command_offset $offset
}
_comp_deprecate_func _command _comp_command
complete -F _comp_command aoss command "do" else eval exec ltrace nice nohup padsp \
"then" time tsocks vsound xargs

_root_command()
_comp_root_command()
{
local PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
local root_command=$1
_command
_comp_command
}
complete -F _root_command fakeroot gksu gksudo kdesudo really
_comp_deprecate_func _root_command _comp_root_command
complete -F _comp_root_command fakeroot gksu gksudo kdesudo really

# Return true if the completion should be treated as running as root
_complete_as_root()
Expand Down
2 changes: 1 addition & 1 deletion completions/_ionice
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ _ionice()
done

if ((offset > 0)); then
_command_offset $offset
_comp_command_offset $offset
return
fi

Expand Down
2 changes: 1 addition & 1 deletion completions/ccache
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ _ccache()
local i
for ((i = 1; i <= COMP_CWORD; i++)); do
if [[ ${COMP_WORDS[i]} != -* ]]; then
_command_offset $i
_comp_command_offset $i
return
fi
[[ ${COMP_WORDS[i]} == -*[oFM] ]] && ((i++))
Expand Down
2 changes: 1 addition & 1 deletion completions/find
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ _find()
for i in ${!words[*]}; do
if [[ ${words[i]} == -@(exec|ok)?(dir) ]]; then
((cword > i)) || break
_command_offset $((i + 1))
_comp_command_offset $((i + 1))
return
fi
done
Expand Down
2 changes: 1 addition & 1 deletion completions/gdb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ _gdb()
# gdb [options] --args executable-file [inferior-arguments ...]
for ((i = 1; i < cword; i++)); do
if [[ ${words[i]} == --args ]]; then
_command_offset $((i + 1))
_comp_command_offset $((i + 1))
return $?
fi
done
Expand Down
2 changes: 1 addition & 1 deletion completions/screen
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ _screen_sessions()
;;
esac

_command_offset $i
_comp_command_offset $i
return
done

Expand Down
2 changes: 1 addition & 1 deletion completions/strace
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ _strace()
done

if ((offset > 0)); then
_command_offset $offset
_comp_command_offset $offset
else

case $prev in
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 @@ _sudo()
if [[ ${words[i]} != -* ]]; then
local PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
local root_command=${words[i]}
_command_offset $i
_comp_command_offset $i
return
fi
if [[ ${words[i]} == -@(!(-*)e*|-edit) ]]; then
Expand Down
2 changes: 1 addition & 1 deletion completions/timeout
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ _timeout()
for ((i = 1; i <= COMP_CWORD; i++)); do
if [[ ${COMP_WORDS[i]} != -* && ${COMP_WORDS[i - 1]} != = ]]; then
if $found; then
_command_offset $i
_comp_command_offset $i
return
fi
found=true
Expand Down
4 changes: 2 additions & 2 deletions completions/valgrind
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ _valgrind()
local i
# Note: intentionally using COMP_WORDS and COMP_CWORD instead of
# words and cword here due to splitting on = causing index differences
# (_command_offset assumes the former).
# (_comp_command_offset assumes the former).
for ((i = 1; i <= COMP_CWORD; i++)); do
if [[ ${COMP_WORDS[i]} != @([-=])* && ${COMP_WORDS[i - 1]} != = ]]; then
_command_offset $i
_comp_command_offset $i
return
fi
done
Expand Down
2 changes: 1 addition & 1 deletion completions/watch
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ _watch()
done

if ((offset > 0)); then
_command_offset $offset
_comp_command_offset $offset
return
fi

Expand Down
2 changes: 1 addition & 1 deletion completions/xvfb-run
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ _xvfb_run()
local i
for ((i = 1; i <= COMP_CWORD; i++)); do
if [[ ${COMP_WORDS[i]} != -* ]]; then
_command_offset $i
_comp_command_offset $i
return
fi
[[ ${COMP_WORDS[i]} == -!(-*)[npsef] ]] && ((i++))
Expand Down
4 changes: 2 additions & 2 deletions test/t/unit/test_unit_command_offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class TestUnitCommandOffset:
def functions(self, bash):
assert_bash_exec(
bash,
"_cmd1() { _command_offset 1; }; complete -F _cmd1 cmd1; "
"complete -F _command meta; "
"_cmd1() { _comp_command_offset 1; }; complete -F _cmd1 cmd1; "
"complete -F _comp_command meta; "
"_compfunc() { COMPREPLY=(%s); }" % join(self.wordlist),
)
completions = [
Expand Down