Skip to content

Commit 0cd2883

Browse files
committed
feat(env): treat -* as the command name after - and --
1 parent 71b7fb2 commit 0cd2883

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

completions/env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ _comp_cmd_env()
77

88
local i noargopts='!(-*|*[uCS]*)'
99
for ((i = 1; i <= cword; i++)); do
10-
if [[ ${words[i]} != -* ]]; then
10+
if [[ ${words[i]} != -* || ${words[i]} == -?(-) && i -lt cword ]]; then
11+
[[ ${words[i]} == -?(-) ]] && ((i++))
1112
for (( ; i <= cword; i++)); do
1213
if [[ ${words[i]} != *=* ]]; then
1314
_comp_command_offset "$i"

test/t/test_env.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,22 @@ def test_lang_envvar(self, completion):
2323
"foo=bar",
2424
"--debug",
2525
"--debug foo=bar",
26+
"-",
27+
"- foo=bar",
2628
],
2729
)
2830
def test_command(self, bash, opts):
2931
completion = assert_complete(bash, "env %s s" % opts)
3032
assert completion == "h" or "sh" in completion
3133

32-
@pytest.mark.complete("env foo=bar --debug s")
33-
def test_option_like_command_after_assignment(self, completion):
34+
@pytest.mark.parametrize(
35+
"opts",
36+
[
37+
"foo=bar --non-existent",
38+
"- --non-existent",
39+
"-- --non-existent",
40+
],
41+
)
42+
def test_option_like_command(self, bash, opts):
43+
completion = assert_complete(bash, "env %s s" % opts)
3444
assert not (completion == "h" or "sh" in completion)

0 commit comments

Comments
 (0)