From 0c6cbfaf56088e1199ad61706469d3c47ec59a65 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Thu, 14 Sep 2017 18:24:10 +0200 Subject: bash completion: don't accidentaly match subcommands as options We match on option first so we need to make sure we don't accidentaly match on subcommands. This unbreaks command completion for e.g. "gbp tag" --- debian/gbp.completion | 68 ++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 33 deletions(-) (limited to 'debian') diff --git a/debian/gbp.completion b/debian/gbp.completion index 7aa3424d..7366fc22 100644 --- a/debian/gbp.completion +++ b/debian/gbp.completion @@ -67,39 +67,41 @@ _gbp_comp () cur="" fi - if [[ "${branch_opts}" == *$prev* ]]; then - local refs=$(_gbp_branches) - COMPREPLY=( $(compgen -W "$refs" -- $cur ) ) - return 0 - fi - - if [[ "${tag_opts}" == *$prev* ]]; then - local refs=$(_gbp_tags) - COMPREPLY=( $(compgen -W "$refs" -- $cur ) ) - return 0 - fi - - if [[ "${tristate_opts}" == *$prev* ]]; then - COMPREPLY=( $(compgen -W 'on off auto' -- $cur ) ) - return 0 - fi - - if [[ "${cbdist_opts}" == *$prev* ]]; then - local BASE="/var/cache/pbuilder/base-" - COMPREPLY=( $( compgen -o dirnames -G "${BASE}${cur}*.cow" \ - | sed -e "s,${BASE}\(.*\)\.cow,\1,g" ) ) - return 0 - fi - - if [[ "${remote_config_opts}" == *$prev* ]]; then - local remote_configs=$(_gbp_remote_configs) - COMPREPLY=( $(compgen -W "$remote_configs" -- $cur ) ) - return 0 - fi - - if [[ "${file_opts}" == *$prev* ]]; then - COMPREPLY=( $(compgen -f -- $cur ) ) - return 0 + if [[ ${prev} == --* ]]; then + if [[ "${branch_opts}" == *$prev* && "${prev}" == --* ]]; then + local refs=$(_gbp_branches) + COMPREPLY=( $(compgen -W "$refs" -- $cur ) ) + return 0 + fi + + if [[ "${tag_opts}" == *$prev* && "${prev}" == --* ]]; then + local refs=$(_gbp_tags) + COMPREPLY=( $(compgen -W "$refs" -- $cur ) ) + return 0 + fi + + if [[ "${tristate_opts}" == *$prev* ]]; then + COMPREPLY=( $(compgen -W 'on off auto' -- $cur ) ) + return 0 + fi + + if [[ "${cbdist_opts}" == *$prev* ]]; then + local BASE="/var/cache/pbuilder/base-" + COMPREPLY=( $( compgen -o dirnames -G "${BASE}${cur}*.cow" \ + | sed -e "s,${BASE}\(.*\)\.cow,\1,g" ) ) + return 0 + fi + + if [[ "${remote_config_opts}" == *$prev* ]]; then + local remote_configs=$(_gbp_remote_configs) + COMPREPLY=( $(compgen -W "$remote_configs" -- $cur ) ) + return 0 + fi + + if [[ "${file_opts}" == *$prev* ]]; then + COMPREPLY=( $(compgen -f -- $cur ) ) + return 0 + fi fi # separate opts by tab so we can append a space to all options not ending -- cgit v1.2.3