From 7374d00b74c60a2d7574216711c4b835d8711b5a Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Mon, 3 Jan 2011 22:47:30 +0100 Subject: bash completion: also complete on tags --- debian/git-buildpackage.bash-completion | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'debian') diff --git a/debian/git-buildpackage.bash-completion b/debian/git-buildpackage.bash-completion index ff71753..653c412 100644 --- a/debian/git-buildpackage.bash-completion +++ b/debian/git-buildpackage.bash-completion @@ -14,6 +14,13 @@ _gbp_branches () } +_gbp_tags () +{ + [ -d .git ] || return 0 + git for-each-ref --format="%(refname:short)" refs/tags +} + + _gbp_options () { $1 --help | sed -ne 's/^ \+\(\(\-[a-z]\), \)\?\(\-\-[a-z\-]\+\=\?\).*/\2 \3/p' @@ -26,6 +33,7 @@ _gbp_comp () local prev="${COMP_WORDS[COMP_CWORD - 1]}" local options=$1 local branch_opts=$2 + local tag_opts=$3 # COMPREPLY considers '=' as a word. For $prev we prefer the word before the actual "=" if [[ "$prev" == "=" ]] @@ -42,6 +50,12 @@ _gbp_comp () return 0 fi + if [[ "${tag_opts}" == *$prev* ]]; then + local refs=$(_gbp_tags) + COMPREPLY=( $(compgen -W "$refs" -- $cur ) ) + return 0 + fi + COMPREPLY=($(compgen -W "$options" -- $cur)) } @@ -51,8 +65,9 @@ _git_buildpackage() { local options=$(_gbp_options git-buildpackage) local branch_opts="--git-debian-branch\= --git-upstream-branch\=" + local tag_opts="--git-debian-tag\= --git-upstream-tag\=" - _gbp_comp "$options" "$branch_opts" + _gbp_comp "$options" "$branch_opts" "$tag_opts" } [ "${have:-}" ] && complete -F _git_buildpackage -o default git-buildpackage @@ -62,8 +77,9 @@ _git_dch () { local options=$(_gbp_options git-dch) local branch_opts="--debian-branch\=" + local tag_opts="--debian-tag\= --upstream-tag\=" - _gbp_comp "$options" "$branch_opts" + _gbp_comp "$options" "$branch_opts" "$tag_opts" } [ "${have:-}" ] && complete -F _git_dch -o default git-dch @@ -73,8 +89,9 @@ _git_import_orig () { local options=$(_gbp_options git-import-orig) local branch_opts="--debian-branch\= --upstream-branch\=" + local tag_opts="--debian-tag\= --upstream-tag\=" - _gbp_comp "$options" "$branch_opts" + _gbp_comp "$options" "$branch_opts" "$tag_opts" } [ "${have:-}" ] && complete -F _git_import_orig -o default git-import-orig @@ -84,8 +101,9 @@ _git_import_dsc () { local options=$(_gbp_options git-import-dsc) local branch_opts="--debian-branch\= --upstream-branch\=" + local tag_opts="--debian-tag\= --upstream-tag\=" - _gbp_comp "$options" "$branch_opts" + _gbp_comp "$options" "$branch_opts" "$tag_opts" } [ "${have:-}" ] && complete -F _git_import_dsc -o default git-import-dsc -- cgit v1.2.3