diff options
author | Guido Günther <agx@sigxcpu.org> | 2017-09-14 18:24:10 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2017-09-14 18:32:34 +0200 |
commit | 0c6cbfaf56088e1199ad61706469d3c47ec59a65 (patch) | |
tree | c9b75f4368f54b4e2f02ee7721e4411d8cbbc2f2 /debian | |
parent | 01ee02783d51ffc6cd94820cb66c49812f9eeec9 (diff) |
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"
Diffstat (limited to 'debian')
-rw-r--r-- | debian/gbp.completion | 68 |
1 files changed, 35 insertions, 33 deletions
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 |