{"thread":{"id":"9733","subject":"[PATCH] Teach bash about completing arguments for git-tag","startedAt":"2007-09-01T03:49:05Z","lastAt":"2007-09-01T03:49:05Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"52120","messageId":"20070901034905.GA22893@spearce.org","threadId":"9733","inReplyTo":null,"subject":"[PATCH] Teach bash about completing arguments for git-tag","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-09-01T03:49:05Z","receivedAt":"2007-09-01T03:49:05Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Please pull from:\n\n   repo.or.cz:/srv/git/git/fastimport.git master\n\n-->8--\nLately I have been doing a lot of calls to `git tag -d` and also to\n`git tag -v`.  In both such cases being able to complete the names\nof existing tags saves the fingers some typing effort.  We now look\nfor the -d or -v option to git-tag in the bash completion support\nand offer up existing tag names as possible choices for these.\n\nWhen creating a new tag we now also offer bash completion support\nfor the second argument to git-tag (the object to be tagged) as this\ncan often be a specific existing branch name and is not necessarily\nthe current HEAD.\n\nIf the -f option is being used to recreate an existing tag we now\nalso offer completion support on the existing tag names for the\nfirst argument of git-tag, helping to the user to reselect the\nprior tag name that they are trying to replace.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n contrib/completion/git-completion.bash |   58 ++++++++++++++++++++++++++++++++\n 1 files changed, 58 insertions(+), 0 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 5ed1821..cad842a 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -114,6 +114,27 @@ __git_heads ()\n \tdone\n }\n \n+__git_tags ()\n+{\n+\tlocal cmd i is_hash=y dir=\"$(__gitdir \"$1\")\"\n+\tif [ -d \"$dir\" ]; then\n+\t\tfor i in $(git --git-dir=\"$dir\" \\\n+\t\t\tfor-each-ref --format='%(refname)' \\\n+\t\t\trefs/tags ); do\n+\t\t\techo \"${i#refs/tags/}\"\n+\t\tdone\n+\t\treturn\n+\tfi\n+\tfor i in $(git-ls-remote \"$1\" 2>/dev/null); do\n+\t\tcase \"$is_hash,$i\" in\n+\t\ty,*) is_hash=n ;;\n+\t\tn,*^{}) is_hash=y ;;\n+\t\tn,refs/tags/*) is_hash=y; echo \"${i#refs/tags/}\" ;;\n+\t\tn,*) is_hash=y; echo \"$i\" ;;\n+\t\tesac\n+\tdone\n+}\n+\n __git_refs ()\n {\n \tlocal cmd i is_hash=y dir=\"$(__gitdir \"$1\")\"\n@@ -1050,6 +1071,40 @@ _git_submodule ()\n \tfi\n }\n \n+_git_tag ()\n+{\n+\tlocal i c=1 f=0\n+\twhile [ $c -lt $COMP_CWORD ]; do\n+\t\ti=\"${COMP_WORDS[c]}\"\n+\t\tcase \"$i\" in\n+\t\t-d|-v)\n+\t\t\t__gitcomp \"$(__git_tags)\"\n+\t\t\treturn\n+\t\t\t;;\n+\t\t-f)\n+\t\t\tf=1\n+\t\t\t;;\n+\t\tesac\n+\t\tc=$((++c))\n+\tdone\n+\n+\tcase \"${COMP_WORDS[COMP_CWORD-1]}\" in\n+\t-m|-F)\n+\t\tCOMPREPLY=()\n+\t\t;;\n+\t-*|tag|git-tag)\n+\t\tif [ $f = 1 ]; then\n+\t\t\t__gitcomp \"$(__git_tags)\"\n+\t\telse\n+\t\t\tCOMPREPLY=()\n+\t\tfi\n+\t\t;;\n+\t*)\n+\t\t__gitcomp \"$(__git_refs)\"\n+\t\t;;\n+\tesac\n+}\n+\n _git ()\n {\n \tlocal i c=1 command __git_dir\n@@ -1117,6 +1172,7 @@ _git ()\n \tshow-branch) _git_log ;;\n \tstash)       _git_stash ;;\n \tsubmodule)   _git_submodule ;;\n+\ttag)         _git_tag ;;\n \twhatchanged) _git_log ;;\n \t*)           COMPREPLY=() ;;\n \tesac\n@@ -1167,6 +1223,7 @@ complete -o default -o nospace -F _git_show git-show\n complete -o default -o nospace -F _git_stash git-stash\n complete -o default -o nospace -F _git_submodule git-submodule\n complete -o default -o nospace -F _git_log git-show-branch\n+complete -o default -o nospace -F _git_tag git-tag\n complete -o default -o nospace -F _git_log git-whatchanged\n \n # The following are necessary only for Cygwin, and only are needed\n@@ -1192,5 +1249,6 @@ complete -o default -o nospace -F _git_config git-config\n complete -o default -o nospace -F _git_shortlog git-shortlog.exe\n complete -o default -o nospace -F _git_show git-show.exe\n complete -o default -o nospace -F _git_log git-show-branch.exe\n+complete -o default -o nospace -F _git_tag git-tag.exe\n complete -o default -o nospace -F _git_log git-whatchanged.exe\n fi\n-- \n1.5.3.rc7.16.ge340d\n"}]}