diff --git a/bash_completion b/bash_completion index c39580c4bf8..117ebbb9d6c 100644 --- a/bash_completion +++ b/bash_completion @@ -1694,7 +1694,7 @@ _comp_compgen_help() for _line in "${_lines[@]}"; do [[ $_line == *([[:blank:]])-* ]] || continue # transform "-f FOO, --foo=FOO" to "-f , --foo=FOO" etc - while [[ $_line =~ ((^|[^-])-[A-Za-z0-9?][[:space:]]+)\[?[A-Z0-9]+([,_-]+[A-Z0-9]+)?(\.\.+)?\]? ]]; do + while [[ $_line =~ ((^|[^-])-[A-Za-z0-9?][[:space:]]+)(\[,?)?[A-Z0-9+]+([,_-]+[A-Z0-9]+)?(\.\.+)?\]* ]]; do _line=${_line/"${BASH_REMATCH[0]}"/"${BASH_REMATCH[1]}"} done _comp_compgen_help__parse "${_line// or /, }" diff --git a/test/t/unit/test_unit_parse_help.py b/test/t/unit/test_unit_parse_help.py index 1a46f3f71aa..d8fd9ed85fe 100644 --- a/test/t/unit/test_unit_parse_help.py +++ b/test/t/unit/test_unit_parse_help.py @@ -203,6 +203,20 @@ def test_32(self, bash): output = assert_bash_exec(bash, "_parse_help fn", want_output=True) assert output.split() == "--exclude=".split() + def test_33(self, bash): + """Pattern found in the output of 'smartctl --help'.""" + assert_bash_exec( + bash, "fn() { echo '-f A1[,A2[,A3]] --foo=A1[,A2[,A3]]'; }" + ) + output = assert_bash_exec(bash, "_parse_help fn", want_output=True) + assert output.split() == "--foo=".split() + + def test_34(self, bash): + """Pattern found in the output of 'smartctl --help'.""" + assert_bash_exec(bash, "fn() { echo '-f [+]ARG --foo=[+]ARG'; }") + output = assert_bash_exec(bash, "_parse_help fn", want_output=True) + assert output.split() == "--foo=".split() + def test_custom_helpopt1(self, bash): assert_bash_exec(bash, "fn() { [[ $1 == -h ]] && echo '-option'; }") output = assert_bash_exec(bash, "_parse_help fn -h", want_output=True)