diff --git a/completions/update-alternatives b/completions/update-alternatives index 0d678fcc82a..b6f52830931 100644 --- a/completions/update-alternatives +++ b/completions/update-alternatives @@ -83,7 +83,12 @@ _comp_cmd_update_alternatives() _comp_cmd_update_alternatives__installed ;; *) - _comp_compgen_help + _comp_compgen_help - <<<"$(LANG=C "$1" --help 2>&1 | command sed ' + /usage:/,/^[[:space:]]*$/{ + s/^\([[:space:]]*usage:\)\{0,1\}[[:space:]]*[^[:space:]]*alternatives / / + s/^[[:space:]]*\[\(-.*\)\]/ \1/ + } + /common options:/,$s/ --/\n --/g')" ;; esac } && diff --git a/test/t/test_update_alternatives.py b/test/t/test_update_alternatives.py index 7c77730744f..16d63e295b1 100644 --- a/test/t/test_update_alternatives.py +++ b/test/t/test_update_alternatives.py @@ -6,3 +6,7 @@ class TestUpdateAlternatives: @pytest.mark.complete("update-alternatives --", require_cmd=True) def test_1(self, completion): assert completion + + @pytest.mark.complete("update-alternatives --", require_cmd=True) + def test_2(self, bash, completion): + assert all(x in completion for x in ["--list", "--remove"])