Skip to content

Commit 883946d

Browse files
committed
fix(_comp_{load,realcommand}): handle option-like command name
1 parent 5c75fa3 commit 883946d

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

bash_completion

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,7 +2201,7 @@ _comp_realcommand()
22012201
{
22022202
REPLY=""
22032203
local file
2204-
file=$(type -P "$1") || return $?
2204+
file=$(type -P -- "$1") || return $?
22052205
if type -p realpath >/dev/null; then
22062206
REPLY=$(realpath "$file")
22072207
elif type -p greadlink >/dev/null; then
@@ -3153,7 +3153,7 @@ _comp_load()
31533153
31543154
# Resolve absolute path to $cmd
31553155
local REPLY pathcmd origcmd=$cmd
3156-
if pathcmd=$(type -P "$cmd"); then
3156+
if pathcmd=$(type -P -- "$cmd"); then
31573157
_comp_abspath "$pathcmd"
31583158
cmd=$REPLY
31593159
fi

test/t/unit/test_unit_load.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,6 @@ def test_cmd_intree_precedence(self, bash, fixture_dir):
128128
# The in-tree `sh` completion should be loaded here,
129129
# and cause no output, unlike our `$PWD/prefix1/bin/sh` canary.
130130
assert_bash_exec(bash, "_comp_load sh", want_output=False)
131+
132+
def test_option_like_cmd_name(self, bash):
133+
assert_bash_exec(bash, "! _comp_load -- --non-existent")

test/t/unit/test_unit_realcommand.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,11 @@ def test_absolute_nonexistent(self, bash, functions):
8888
want_output=False,
8989
)
9090
assert output.strip() == ""
91+
92+
def test_option_like_cmd_name(self, bash, functions):
93+
output = assert_bash_exec(
94+
bash,
95+
"! __tester --non-existent",
96+
want_output=False,
97+
)
98+
assert output.strip() == ""

0 commit comments

Comments
 (0)