Skip to content

Commit

Permalink
fix(_comp_{load,realcommand}): handle option-like command name
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Apr 4, 2024
1 parent 5c75fa3 commit 883946d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -2201,7 +2201,7 @@ _comp_realcommand()
{
REPLY=""
local file
file=$(type -P "$1") || return $?
file=$(type -P -- "$1") || return $?
if type -p realpath >/dev/null; then
REPLY=$(realpath "$file")
elif type -p greadlink >/dev/null; then
Expand Down Expand Up @@ -3153,7 +3153,7 @@ _comp_load()
# Resolve absolute path to $cmd
local REPLY pathcmd origcmd=$cmd
if pathcmd=$(type -P "$cmd"); then
if pathcmd=$(type -P -- "$cmd"); then
_comp_abspath "$pathcmd"
cmd=$REPLY
fi
Expand Down
3 changes: 3 additions & 0 deletions test/t/unit/test_unit_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,6 @@ def test_cmd_intree_precedence(self, bash, fixture_dir):
# The in-tree `sh` completion should be loaded here,
# and cause no output, unlike our `$PWD/prefix1/bin/sh` canary.
assert_bash_exec(bash, "_comp_load sh", want_output=False)

def test_option_like_cmd_name(self, bash):
assert_bash_exec(bash, "! _comp_load -- --non-existent")
8 changes: 8 additions & 0 deletions test/t/unit/test_unit_realcommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,11 @@ def test_absolute_nonexistent(self, bash, functions):
want_output=False,
)
assert output.strip() == ""

def test_option_like_cmd_name(self, bash, functions):
output = assert_bash_exec(
bash,
"! __tester --non-existent",
want_output=False,
)
assert output.strip() == ""

0 comments on commit 883946d

Please sign in to comment.