Skip to content

Commit 7d799ed

Browse files
committed
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 df8cdda commit 7d799ed

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

bash_completion

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,8 @@ _comp_delimited()
833833
COMPREPLY=($(compgen "$@" -- "${cur##*"$delimiter"}"))
834834
fi
835835

836-
((${#COMPREPLY[@]} == 1)) && COMPREPLY=(${COMPREPLY/#/$prefix})
836+
COMPREPLY=("${COMPREPLY[@]/#/"$prefix"}")
837+
837838
[[ $delimiter != : ]] || __ltrim_colon_completions "$cur"
838839
}
839840

test/t/unit/test_unit_delimited.py

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

0 commit comments

Comments
 (0)