Skip to content

Commit 71b7fb2

Browse files
committed
feat(env): treat -* as the command name after assignments
1 parent 883946d commit 71b7fb2

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

completions/env

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ _comp_cmd_env()
77

88
local i noargopts='!(-*|*[uCS]*)'
99
for ((i = 1; i <= cword; i++)); do
10-
if [[ ${words[i]} != -* && ${words[i]} != *=* ]]; then
11-
_comp_command_offset $i
12-
return
10+
if [[ ${words[i]} != -* ]]; then
11+
for (( ; i <= cword; i++)); do
12+
if [[ ${words[i]} != *=* ]]; then
13+
_comp_command_offset "$i"
14+
return
15+
fi
16+
done
17+
break
1318
fi
19+
1420
# shellcheck disable=SC2254
1521
[[ ${words[i]} == @(--@(unset|chdir|split-string)|-${noargopts}[uCS]) ]] &&
1622
((i++))

test/t/test_env.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ def test_lang_envvar(self, completion):
2222
"",
2323
"foo=bar",
2424
"--debug",
25-
"foo=bar --debug",
2625
"--debug foo=bar",
2726
],
2827
)
2928
def test_command(self, bash, opts):
3029
completion = assert_complete(bash, "env %s s" % opts)
3130
assert completion == "h" or "sh" in completion
31+
32+
@pytest.mark.complete("env foo=bar --debug s")
33+
def test_option_like_command_after_assignment(self, completion):
34+
assert not (completion == "h" or "sh" in completion)

0 commit comments

Comments
 (0)