Skip to content

Commit dba3181

Browse files
authored
Merge pull request #770 from akinomyoga/redirection-glob
fix(_init_completion): update redirection pattern
2 parents b835a5a + 3bc4376 commit dba3181

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

bash_completion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ _init_completion()
10031003
done
10041004

10051005
COMPREPLY=()
1006-
local redir="@(?([0-9])<|?([0-9&])>?(>)|>&)"
1006+
local redir='@(?(+([0-9])|{[a-zA-Z_]*([a-zA-Z_0-9])})@(>?([>|&])|<?([>&])|<<?([-<]))|&>?(>))'
10071007
_get_comp_words_by_ref -n "$exclude<>&" cur prev words cword
10081008

10091009
# Complete variable names.

test/t/unit/test_unit_init_completion.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@pytest.mark.bashcomp(
77
cmd=None,
88
ignore_env=r"^[+-](COMP(_(WORDS|CWORD|LINE|POINT)|REPLY)|"
9-
r"cur|cword|words)=",
9+
r"cur|cword|words)=|^\+declare -f _cmd1$",
1010
)
1111
class TestUnitInitCompletion(TestUnitBase):
1212
def test_1(self, bash):
@@ -32,3 +32,28 @@ def test_redirect(self, bash, redirect):
3232
bash, "%s " % redirect, cwd="shared/default"
3333
)
3434
assert all(x in completion for x in "foo bar".split())
35+
36+
@pytest.fixture(scope="class")
37+
def cmd1_empty_completion_setup(self, bash):
38+
assert_bash_exec(
39+
bash,
40+
"_cmd1() { local cur prev words cword; _init_completion; } && "
41+
"complete -F _cmd1 cmd1",
42+
)
43+
44+
@pytest.mark.parametrize("redirect", "> >> 2> {fd1}> < &> &>> >|".split())
45+
def test_redirect_2(self, bash, cmd1_empty_completion_setup, redirect):
46+
# Note: Bash 4.3 and below cannot properly extract the redirection ">|"
47+
if redirect == ">|":
48+
skipif = "((BASH_VERSINFO[0] * 100 + BASH_VERSINFO[1] < 404))"
49+
try:
50+
assert_bash_exec(bash, skipif, want_output=None)
51+
except AssertionError:
52+
pass
53+
else:
54+
pytest.skip(skipif)
55+
56+
completion = assert_complete(
57+
bash, "cmd1 %s f" % redirect, cwd="shared/default"
58+
)
59+
assert "foo" in completion

0 commit comments

Comments
 (0)