Skip to content

Commit dafd338

Browse files
committed
fix(bash_completion,conftest): use complete -p -- for arbitrary cmds
1 parent 3c1d9bc commit dafd338

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

bash_completion

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2765,18 +2765,18 @@ _comp_command_offset()
27652765
else
27662766
_comp_dequote "${COMP_WORDS[0]}" || REPLY=${COMP_WORDS[0]}
27672767
local cmd=$REPLY compcmd=$REPLY
2768-
local cspec=$(complete -p "$cmd" 2>/dev/null)
2768+
local cspec=$(complete -p -- "$cmd" 2>/dev/null)
27692769

27702770
# If we have no completion for $cmd yet, see if we have for basename
27712771
if [[ ! $cspec && $cmd == */* ]]; then
2772-
cspec=$(complete -p "${cmd##*/}" 2>/dev/null)
2772+
cspec=$(complete -p -- "${cmd##*/}" 2>/dev/null)
27732773
[[ $cspec ]] && compcmd=${cmd##*/}
27742774
fi
27752775
# If still nothing, just load it for the basename
27762776
if [[ ! $cspec ]]; then
27772777
compcmd=${cmd##*/}
27782778
_comp_load -D -- "$compcmd"
2779-
cspec=$(complete -p "$compcmd" 2>/dev/null)
2779+
cspec=$(complete -p -- "$compcmd" 2>/dev/null)
27802780
fi
27812781

27822782
local retry_count=0
@@ -2809,7 +2809,7 @@ _comp_command_offset()
28092809
# state of COMPREPLY is discarded.
28102810
COMPREPLY=()
28112811

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

28142814
# Note: When completion spec is removed after 124, we
28152815
# do not generate any completions including the default
@@ -3147,7 +3147,7 @@ _comp_load()
31473147
if [[ $cmd == \\* ]]; then
31483148
cmd=${cmd:1}
31493149
# If we already have a completion for the "real" command, use it
3150-
$(complete -p "$cmd" 2>/dev/null || echo false) "\\$cmd" && return 0
3150+
$(complete -p -- "$cmd" 2>/dev/null || echo false) "\\$cmd" && return 0
31513151
backslash=\\
31523152
fi
31533153
@@ -3222,18 +3222,18 @@ _comp_load()
32223222
elif [[ -e $compfile ]] && . "$compfile" "$cmd" "$@"; then
32233223
# At least $cmd is expected to have a completion set when
32243224
# we return successfully; see if it already does
3225-
if compspec=$(complete -p "$cmd" 2>/dev/null); then
3225+
if compspec=$(complete -p -- "$cmd" 2>/dev/null); then
32263226
# $cmd is the case in which we do backslash processing
32273227
[[ $backslash ]] && eval "$compspec \"\$backslash\$cmd\""
32283228
# If invoked without path, that one should be set, too
32293229
# ...but let's not overwrite an existing one, if any
32303230
[[ $origcmd != */* ]] &&
3231-
! complete -p "$origcmd" &>/dev/null &&
3231+
! complete -p -- "$origcmd" &>/dev/null &&
32323232
eval "$compspec \"\$origcmd\""
32333233
return 0
32343234
fi
32353235
# If not, see if we got one for $cmdname
3236-
if [[ $cmdname != "$cmd" ]] && compspec=$(complete -p "$cmdname" 2>/dev/null); then
3236+
if [[ $cmdname != "$cmd" ]] && compspec=$(complete -p -- "$cmdname" 2>/dev/null); then
32373237
# Use that for $cmd too, if we have a full path to it
32383238
[[ $cmd == /* ]] && eval "$compspec \"\$cmd\""
32393239
return 0

test/t/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def load_completion_for(bash: pexpect.spawn, cmd: str) -> bool:
382382
# Allow _comp_load to fail so we can test completions
383383
# that are directly loaded in bash_completion without a separate file.
384384
assert_bash_exec(bash, "_comp_load -- %s || :" % cmd)
385-
assert_bash_exec(bash, "complete -p %s &>/dev/null" % cmd)
385+
assert_bash_exec(bash, "complete -p -- %s &>/dev/null" % cmd)
386386
except AssertionError:
387387
return False
388388
return True

0 commit comments

Comments
 (0)