Skip to content

Commit 89ff88f

Browse files
committed
fix(_comp_delimited): append space by default
1 parent c13ff8a commit 89ff88f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

bash_completion

+3
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,9 @@ _comp_delimited()
706706
local -a existing
707707
local x i ifs=$IFS IFS=$delimiter
708708
existing=($cur)
709+
# Do not remove the last from existing if it's not followed by the
710+
# delimiter so we get space appended.
711+
[[ $cur == *"$delimiter" ]] || unset "existing[${#existing[@]}-1]"
709712
IFS=$ifs
710713
for x in ${existing+"${existing[@]}"}; do
711714
for i in "${!COMPREPLY[@]}"; do

test/t/test_man.py

+23
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,26 @@ def test_10(self, bash, colonpath, completion):
113113
@pytest.mark.complete("man -", require_cmd=True)
114114
def test_11(self, completion):
115115
assert completion
116+
117+
@pytest.mark.complete("man -S 1", require_cmd=True)
118+
def test_delimited_first(self, completion):
119+
# just appends space
120+
assert not completion
121+
assert completion.endswith(" ")
122+
123+
@pytest.mark.complete("man -S 1:", require_cmd=True)
124+
def test_delimited_after_delimiter(self, completion):
125+
assert completion
126+
assert "1" not in completion
127+
128+
@pytest.mark.complete("man -S 1:2", require_cmd=True)
129+
def test_delimited_later(self, completion):
130+
# just appends space
131+
assert not completion
132+
assert completion.endswith(" ")
133+
134+
@pytest.mark.complete("man -S 1:1", require_cmd=True)
135+
def test_delimited_deduplication(self, completion):
136+
# no completion, no space appended
137+
assert not completion
138+
assert not completion.endswith(" ")

0 commit comments

Comments
 (0)