Skip to content

Commit

Permalink
fix(bash_completion,conftest): use complete -p -- for arbitrary cmds
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Apr 4, 2024
1 parent 3c1d9bc commit dafd338
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -2765,18 +2765,18 @@ _comp_command_offset()
else
_comp_dequote "${COMP_WORDS[0]}" || REPLY=${COMP_WORDS[0]}
local cmd=$REPLY compcmd=$REPLY
local cspec=$(complete -p "$cmd" 2>/dev/null)
local cspec=$(complete -p -- "$cmd" 2>/dev/null)

# If we have no completion for $cmd yet, see if we have for basename
if [[ ! $cspec && $cmd == */* ]]; then
cspec=$(complete -p "${cmd##*/}" 2>/dev/null)
cspec=$(complete -p -- "${cmd##*/}" 2>/dev/null)
[[ $cspec ]] && compcmd=${cmd##*/}
fi
# If still nothing, just load it for the basename
if [[ ! $cspec ]]; then
compcmd=${cmd##*/}
_comp_load -D -- "$compcmd"
cspec=$(complete -p "$compcmd" 2>/dev/null)
cspec=$(complete -p -- "$compcmd" 2>/dev/null)
fi

local retry_count=0
Expand Down Expand Up @@ -2809,7 +2809,7 @@ _comp_command_offset()
# state of COMPREPLY is discarded.
COMPREPLY=()

cspec=$(complete -p "$compcmd" 2>/dev/null)
cspec=$(complete -p -- "$compcmd" 2>/dev/null)

# Note: When completion spec is removed after 124, we
# do not generate any completions including the default
Expand Down Expand Up @@ -3147,7 +3147,7 @@ _comp_load()
if [[ $cmd == \\* ]]; then
cmd=${cmd:1}
# If we already have a completion for the "real" command, use it
$(complete -p "$cmd" 2>/dev/null || echo false) "\\$cmd" && return 0
$(complete -p -- "$cmd" 2>/dev/null || echo false) "\\$cmd" && return 0
backslash=\\
fi
Expand Down Expand Up @@ -3222,18 +3222,18 @@ _comp_load()
elif [[ -e $compfile ]] && . "$compfile" "$cmd" "$@"; then
# At least $cmd is expected to have a completion set when
# we return successfully; see if it already does
if compspec=$(complete -p "$cmd" 2>/dev/null); then
if compspec=$(complete -p -- "$cmd" 2>/dev/null); then
# $cmd is the case in which we do backslash processing
[[ $backslash ]] && eval "$compspec \"\$backslash\$cmd\""
# If invoked without path, that one should be set, too
# ...but let's not overwrite an existing one, if any
[[ $origcmd != */* ]] &&
! complete -p "$origcmd" &>/dev/null &&
! complete -p -- "$origcmd" &>/dev/null &&
eval "$compspec \"\$origcmd\""
return 0
fi
# If not, see if we got one for $cmdname
if [[ $cmdname != "$cmd" ]] && compspec=$(complete -p "$cmdname" 2>/dev/null); then
if [[ $cmdname != "$cmd" ]] && compspec=$(complete -p -- "$cmdname" 2>/dev/null); then
# Use that for $cmd too, if we have a full path to it
[[ $cmd == /* ]] && eval "$compspec \"\$cmd\""
return 0
Expand Down
2 changes: 1 addition & 1 deletion test/t/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def load_completion_for(bash: pexpect.spawn, cmd: str) -> bool:
# Allow _comp_load to fail so we can test completions
# that are directly loaded in bash_completion without a separate file.
assert_bash_exec(bash, "_comp_load -- %s || :" % cmd)
assert_bash_exec(bash, "complete -p %s &>/dev/null" % cmd)
assert_bash_exec(bash, "complete -p -- %s &>/dev/null" % cmd)
except AssertionError:
return False
return True
Expand Down

0 comments on commit dafd338

Please sign in to comment.