{"thread":{"id":"43532","subject":"[PATCH] Bash completion support for aliases","startedAt":"2006-10-28T12:12:20Z","lastAt":"2006-10-28T20:37:50Z","messageCount":2,"participants":["Dennis Stosberg","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"295311","messageId":"20061028121220.G3421aba@leonov.stosberg.net","threadId":"43532","inReplyTo":null,"subject":"[PATCH] Bash completion support for aliases","fromName":"Dennis Stosberg","fromEmail":"dennis@stosberg.net","sentAt":"2006-10-28T12:12:20Z","receivedAt":"2006-10-28T12:12:20Z","isPatch":true,"sender":{"key":"dennis@stosberg.net","avatar":null},"body":" - Add aliases to the list of available git commands.\n - Make completion work for aliased commands.\n\nSigned-off-by: Dennis Stosberg <dennis@stosberg.net>\n---\n contrib/completion/git-completion.bash |   29 +++++++++++++++++++++++++++--\n 1 files changed, 27 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex d9cb17d..b074f4f 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -101,6 +101,23 @@ __git_complete_file ()\n \tesac\n }\n \n+__git_aliases ()\n+{\n+\tgit repo-config --list | grep '^alias\\.' \\\n+\t\t| sed -e 's/^alias\\.//' -e 's/=.*$//'\n+}\n+\n+__git_aliased_command ()\n+{\n+\tlocal cmdline=$(git repo-config alias.$1)\n+\tfor word in $cmdline; do\n+\t\tif [ \"${word##-*}\" ]; then\n+\t\t\techo $word\n+\t\t\treturn\n+\t\tfi\n+\tdone\n+}\n+\n _git_branch ()\n {\n \tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n@@ -264,10 +281,18 @@ _git ()\n {\n \tif [ $COMP_CWORD = 1 ]; then\n \t\tCOMPREPLY=($(compgen \\\n-\t\t\t-W \"--version $(git help -a|egrep '^ ')\" \\\n+\t\t\t-W \"--version $(git help -a|egrep '^ ') \\\n+\t\t\t    $(__git_aliases)\" \\\n \t\t\t-- \"${COMP_WORDS[COMP_CWORD]}\"))\n \telse\n-\t\tcase \"${COMP_WORDS[1]}\" in\n+\t\tlocal command=\"${COMP_WORDS[1]}\"\n+\t\tlocal expansion=$(__git_aliased_command \"$command\")\n+\n+\t\tif [ \"$expansion\" ]; then\n+\t\t\tcommand=\"$expansion\"\n+\t\tfi\n+\n+\t\tcase \"$command\" in\n \t\tbranch)      _git_branch ;;\n \t\tcat-file)    _git_cat_file ;;\n \t\tcheckout)    _git_checkout ;;\n-- \n"},{"id":"298481","messageId":"7vlkn06ush.fsf@assigned-by-dhcp.cox.net","threadId":"43532","inReplyTo":"20061028121220.G3421aba@leonov.stosberg.net","subject":"Re: [PATCH] Bash completion support for aliases","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-10-28T20:37:50Z","receivedAt":"2006-10-28T20:37:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Dennis Stosberg <dennis@stosberg.net> writes:\n\n>  - Add aliases to the list of available git commands.\n>  - Make completion work for aliased commands.\n\nYou are my hero.\n\nI started to get annoyed that \"git co\" does not complete my\nbranch names and I needed to say \"git checkout\".  This fixes it\nnicely.\n\n"}]}