Skip to content

Commit c422102

Browse files
committed
feat(_comp_compgen_help): allow plus prefix in short option argument
Allows `-f [+]ARG --foo=[+]ARG` as used by smartctl.
1 parent ecdf490 commit c422102

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

bash_completion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,7 @@ _comp_compgen_help()
16941694
for _line in "${_lines[@]}"; do
16951695
[[ $_line == *([[:blank:]])-* ]] || continue
16961696
# transform "-f FOO, --foo=FOO" to "-f , --foo=FOO" etc
1697-
while [[ $_line =~ ((^|[^-])-[A-Za-z0-9?][[:space:]]+)(\[,?)?[A-Z0-9]+([,_-]+[A-Z0-9]+)?(\.\.+)?\]* ]]; do
1697+
while [[ $_line =~ ((^|[^-])-[A-Za-z0-9?][[:space:]]+)(\[,?)?(\+\]?)?[A-Z0-9]+([,_-]+[A-Z0-9]+)?(\.\.+)?\]* ]]; do
16981698
_line=${_line/"${BASH_REMATCH[0]}"/"${BASH_REMATCH[1]}"}
16991699
done
17001700
_comp_compgen_help__parse "${_line// or /, }"

test/t/unit/test_unit_parse_help.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ def test_33(self, bash):
208208
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
209209
assert output.split() == "--foo".split()
210210

211+
def test_34(self, bash):
212+
assert_bash_exec(bash, "fn() { echo '-f [+]ARG --foo=[+]ARG'; }")
213+
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
214+
assert output.split() == "--foo".split()
215+
211216
def test_custom_helpopt1(self, bash):
212217
assert_bash_exec(bash, "fn() { [[ $1 == -h ]] && echo '-option'; }")
213218
output = assert_bash_exec(bash, "_parse_help fn -h", want_output=True)

0 commit comments

Comments
 (0)