Skip to content

Commit 0eea357

Browse files
Rogachscop
authored andcommitted
fix(_comp_delimited): prepend prefix to all compreply args
Fixes #552. Previously prefix was only prepended if COMPREPLY only contained one argument - this commit fixes it so prefix is prepended to all arguments.
1 parent e9bf32c commit 0eea357

File tree

7 files changed

+47
-6
lines changed

7 files changed

+47
-6
lines changed

bash_completion

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,8 @@ _comp_delimited()
895895
_comp_compgen COMPREPLY "$@" -- "${cur##*"$delimiter"}"
896896
fi
897897

898-
((${#COMPREPLY[@]} == 1)) && COMPREPLY=("$prefix$COMPREPLY")
898+
((${#COMPREPLY[@]})) && COMPREPLY=("${COMPREPLY[@]/#/"$prefix"}")
899+
899900
[[ $delimiter != : ]] || __ltrim_colon_completions "$cur"
900901
}
901902

test/t/test_pgrep.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,3 @@ def test_nslist(self, completion):
3131
)
3232
def test_nslist_after_comma(self, completion):
3333
assert completion
34-
assert not any("," in x for x in completion)

test/t/test_ssh_keygen.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ def test_filedir_pub_at_end_of_s(self, completion):
2727
@pytest.mark.complete("ssh-keygen -s foo_key -n foo,")
2828
def test_usernames_for_n(self, completion):
2929
assert completion
30-
assert not any("," in x for x in completion)
3130
# TODO check that these are usernames
3231

3332
@pytest.mark.complete("ssh-keygen -s foo_key -h -n foo,")
3433
def test_host_for_h_n(self, completion):
3534
assert completion
36-
assert not any("," in x for x in completion)
3735
# TODO check that these are hostnames
3836

3937
@pytest.mark.complete("ssh-keygen -Y foo -n ")

test/t/test_tox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def test_2(self, completion):
1212

1313
@pytest.mark.complete("tox -e foo,", cwd="tox")
1414
def test_3(self, completion):
15-
assert all(x in completion for x in "py37 ALL".split())
15+
assert all("foo," + x in completion for x in "py37 ALL".split())
1616

1717
@pytest.mark.complete("tox -e foo -- ", cwd="tox")
1818
def test_default_after_dashdash(self, completion):

test/t/test_tshark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_2(self, completion):
1414
@pytest.mark.complete("tshark -O foo,htt", require_cmd=True)
1515
def test_3(self, completion):
1616
# p: one completion only; http: e.g. http and http2
17-
assert completion == "p" or "http" in completion
17+
assert completion == "p" or "foo,http" in completion
1818

1919
@pytest.mark.complete("tshark -o tcp", require_cmd=True)
2020
def test_4(self, completion):

test/t/unit/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ EXTRA_DIST = \
22
test_unit_command_offset.py \
33
test_unit_compgen.py \
44
test_unit_count_args.py \
5+
test_unit_delimited.py \
56
test_unit_deprecate_func.py \
67
test_unit_dequote.py \
78
test_unit_expand.py \

test/t/unit/test_unit_delimited.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import pytest
2+
3+
from conftest import assert_bash_exec
4+
5+
6+
@pytest.mark.bashcomp(cmd=None)
7+
class TestUnitDelimited:
8+
@pytest.fixture(scope="class")
9+
def functions(self, request, bash):
10+
assert_bash_exec(
11+
bash,
12+
"_comp_cmd_test_delim() {"
13+
" local cur prev words cword comp_args;"
14+
" _comp_get_words cur;"
15+
" _comp_delimited , -W 'alpha beta bravo';"
16+
"};"
17+
"complete -F _comp_cmd_test_delim test_delim",
18+
)
19+
20+
@pytest.mark.complete("test_delim --opt=a")
21+
def test_1(self, functions, completion):
22+
assert completion == ["lpha"]
23+
24+
@pytest.mark.complete("test_delim --opt=b")
25+
def test_2(self, functions, completion):
26+
assert completion == ["beta", "bravo"]
27+
28+
@pytest.mark.complete("test_delim --opt=alpha,b")
29+
def test_3(self, functions, completion):
30+
assert completion == ["alpha,beta", "alpha,bravo"]
31+
32+
@pytest.mark.complete("test_delim --opt=alpha,be")
33+
def test_4(self, functions, completion):
34+
assert completion == ["ta"]
35+
36+
@pytest.mark.complete("test_delim --opt=beta,a")
37+
def test_5(self, functions, completion):
38+
assert completion == ["lpha"]
39+
40+
@pytest.mark.complete("test_delim --opt=c")
41+
def test_6(self, functions, completion):
42+
assert not completion

0 commit comments

Comments
 (0)