From dafd3382e019cf90156cc6abc4266a82ab4ebe5f Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Fri, 5 Apr 2024 08:16:08 +0900 Subject: [PATCH] fix(bash_completion,conftest): use `complete -p --` for arbitrary cmds --- bash_completion | 16 ++++++++-------- test/t/conftest.py | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/bash_completion b/bash_completion index 2cf440505b6..e117d4a40d1 100644 --- a/bash_completion +++ b/bash_completion @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/test/t/conftest.py b/test/t/conftest.py index 425b0505bbe..2ca0f9a0e2d 100644 --- a/test/t/conftest.py +++ b/test/t/conftest.py @@ -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