Skip to content

Commit 76f980c

Browse files
akinomyogascop
authored andcommitted
fix(export): suffix "=" only when unique and already complete
1 parent 2617d26 commit 76f980c

3 files changed

Lines changed: 49 additions & 4 deletions

File tree

.typos.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,8 @@ ser = "ser"
6767

6868
[files]
6969
extend-exclude = ["CHANGELOG.md"]
70+
71+
# test/t/test_export.py
72+
[type.test_export]
73+
extend-glob = ["test_export.py"]
74+
extend-identifiers = { BASH_VERSIO = "BASH_VERSIO" }

completions-core/export.bash

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ _comp_cmd_export()
5252
_comp_compgen -a -- -W '-p'
5353
return
5454
fi
55-
local suffix=""
55+
_comp_compgen -- -A "$action"
5656
if [[ ! $remove && $action != function ]]; then
57-
suffix="="
5857
compopt -o nospace
58+
if ((${#COMPREPLY[@]} == 1)) && [[ ${COMPREPLY[0]} == "$cur" ]]; then
59+
COMPREPLY[0]+="="
60+
fi
5961
fi
60-
_comp_compgen -- -A "$action" -S "$suffix"
6162
;;
6263
esac
6364
} &&

test/t/test_export.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,55 @@ def test_7(self, completion):
3636
def test_8(self, completion):
3737
assert completion
3838

39+
@pytest.mark.complete("export BASH_VERSIO")
40+
def test_no_equals_sign_for_variable_incomplete(self, completion):
41+
"""When the variable name is completed, we should not
42+
immediately suffix the equal sign. The equal sign will be
43+
appended on a further TAB after the word becomes a complete
44+
variable name.
45+
"""
46+
assert completion
47+
assert "=" not in "".join(completion)
48+
assert not completion.endswith(" ")
49+
50+
@pytest.mark.complete("export BASH")
51+
def test_no_equals_sign_for_variable_ambiguous(self, completion):
52+
"""When the completion is not unique, we should not suffix the
53+
equal sign.
54+
"""
55+
assert completion
56+
assert "=" not in "".join(completion)
57+
assert not completion.endswith(" ")
58+
59+
@pytest.mark.complete("export BASH_VERSION")
60+
def test_no_equals_sign_for_variable_complete(self, completion):
61+
"""Only when the current word is already complete and matches
62+
unique completion, we should suffix the equal sign.
63+
"""
64+
assert completion
65+
assert "=" in "".join(completion)
66+
3967
@pytest.fixture(scope="class")
4068
def export_f_canary(self, request, bash):
4169
assert_bash_exec(bash, "_comp__test_export_f_canary() { return; }")
4270

4371
@pytest.mark.complete("export -f _comp__test_export_f_canar")
44-
def test_no_equals_sign_for_function(self, completion, export_f_canary):
72+
def test_no_equals_sign_for_function_incomplete(
73+
self, completion, export_f_canary
74+
):
4575
assert completion
4676
assert "=" not in "".join(completion)
4777
assert completion.endswith(" ")
4878

79+
@pytest.mark.complete("export -f _comp__test_export_f_canary")
80+
def test_no_equals_sign_for_function_complete(
81+
self, completion, export_f_canary
82+
):
83+
"""We can suffix a space to a function name because there is
84+
no possibility that the equal sign is suffixed to a function
85+
name."""
86+
assert completion.output == " "
87+
4988
@pytest.mark.complete("export -f -")
5089
def test_second_option(self, completion):
5190
assert completion

0 commit comments

Comments
 (0)