Skip to content

Commit

Permalink
feat(env): treat -* as the command name after assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Apr 4, 2024
1 parent 883946d commit 71b7fb2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 9 additions & 3 deletions completions/env
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ _comp_cmd_env()

local i noargopts='!(-*|*[uCS]*)'
for ((i = 1; i <= cword; i++)); do
if [[ ${words[i]} != -* && ${words[i]} != *=* ]]; then
_comp_command_offset $i
return
if [[ ${words[i]} != -* ]]; then
for (( ; i <= cword; i++)); do
if [[ ${words[i]} != *=* ]]; then
_comp_command_offset "$i"
return
fi
done
break
fi

# shellcheck disable=SC2254
[[ ${words[i]} == @(--@(unset|chdir|split-string)|-${noargopts}[uCS]) ]] &&
((i++))
Expand Down
5 changes: 4 additions & 1 deletion test/t/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ def test_lang_envvar(self, completion):
"",
"foo=bar",
"--debug",
"foo=bar --debug",
"--debug foo=bar",
],
)
def test_command(self, bash, opts):
completion = assert_complete(bash, "env %s s" % opts)
assert completion == "h" or "sh" in completion

@pytest.mark.complete("env foo=bar --debug s")
def test_option_like_command_after_assignment(self, completion):
assert not (completion == "h" or "sh" in completion)

0 comments on commit 71b7fb2

Please sign in to comment.