{"thread":{"id":"5595","subject":"[PATCH] Contributed bash completion support for core Git tools.","startedAt":"2006-09-18T00:48:31Z","lastAt":"2006-09-28T16:28:10Z","messageCount":11,"participants":["Shawn Pearce","Junio C Hamano","Johannes Schindelin","Sebastian Harl"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"27102","messageId":"20060918004831.GA19851@spearce.org","threadId":"5595","inReplyTo":null,"subject":"[PATCH] Contributed bash completion support for core Git tools.","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-09-18T00:48:31Z","receivedAt":"2006-09-18T00:48:31Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"This is a set of bash completion routines for many of the\npopular core Git tools.  I wrote these routines from scratch\nafter reading the git-compl and git-compl-lib routines available\nfrom the gitcompletion package at http://gitweb.hawaga.org.uk/\nand found those to be lacking in functionality for some commands.\nConsequently there may be some similarities but many differences.\n\nSince these are completion routines only for tools shipped with\ncore Git and since bash is a popular shell on many of the native\ncore Git platforms (Linux, Mac OS X, Solaris, BSD) including these\nroutines as part of the stock package would probably be convienent\nfor many users.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n I put this together rather quickly today so although I find it\n to work well for me and be useful, others might not.  User be\n warned.\n\n In particular I have found the completion of remote refs and\n paths within 'ref:foo/path' style arguments to be very useful,\n even if there is some (mild) latency involved.\n\n contrib/bash-git-completion.sh |  330 ++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 330 insertions(+), 0 deletions(-)\n\ndiff --git a/contrib/bash-git-completion.sh b/contrib/bash-git-completion.sh\nnew file mode 100644\nindex 0000000..4800185\n--- /dev/null\n+++ b/contrib/bash-git-completion.sh\n@@ -0,0 +1,330 @@\n+#\n+# bash completion support for core Git.\n+#\n+# Copyright (C) 2006 Shawn Pearce\n+# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).\n+#\n+# The contained completion routines provide support for completing:\n+#\n+#    *) local and remote branch names\n+#    *) local and remote tag names\n+#    *) .git/remotes file names\n+#    *) git 'subcommands'\n+#    *) tree paths within 'ref:path/to/file' expressions\n+# \n+# To use these routines:\n+#\n+#    1) Copy this file to somewhere (e.g. ~/.git-completion.sh).\n+#    2) Added the following line to your .bashrc:\n+#        source ~/.git-completion.sh\n+#\n+\n+__git_refs ()\n+{\n+\tlocal cmd i is_hash=y\n+\tif [ -d \"$1\" ]; then\n+\t\tcmd=git-peek-remote\n+\telse\n+\t\tcmd=git-ls-remote\n+\tfi\n+\tfor i in $($cmd \"$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,refs/heads/*) is_hash=y; echo \"${i#refs/heads/}\" ;;\n+\t\tn,*) is_hash=y; echo \"$i\" ;;\n+\t\tesac\n+\tdone\n+}\n+\n+__git_refs2 ()\n+{\n+\tlocal cmd i is_hash=y\n+\tif [ -d \"$1\" ]; then\n+\t\tcmd=git-peek-remote\n+\telse\n+\t\tcmd=git-ls-remote\n+\tfi\n+\tfor i in $($cmd \"$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/}:${i#refs/tags/}\" ;;\n+\t\tn,refs/heads/*) is_hash=y; echo \"${i#refs/heads/}:${i#refs/heads/}\" ;;\n+\t\tn,*) is_hash=y; echo \"$i:$i\" ;;\n+\t\tesac\n+\tdone\n+}\n+\n+__git_remotes ()\n+{\n+\tlocal i REVERTGLOB=$(shopt -p nullglob)\n+\tshopt -s nullglob\n+\tfor i in .git/remotes/*; do\n+\t\techo ${i#.git/remotes/}\n+\tdone\n+\t$REVERTGLOB\n+}\n+\n+__git_complete_file ()\n+{\n+\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n+\tcase \"$cur\" in\n+\t?*:*)\n+\t\tlocal pfx ls ref=\"$(echo \"$cur\" | sed 's,:.*$,,')\"\n+\t\tcur=\"$(echo \"$cur\" | sed 's,^.*:,,')\"\n+\t\tcase \"$cur\" in\n+\t\t?*/*)\n+\t\t\tpfx=\"$(echo \"$cur\" | sed 's,/[^/]*$,,')\"\n+\t\t\tcur=\"$(echo \"$cur\" | sed 's,^.*/,,')\"\n+\t\t\tls=\"$ref:$pfx\"\n+\t\t\tpfx=\"$pfx/\"\n+\t\t\t;;\n+\t\t*)\n+\t\t\tls=\"$ref\"\n+\t\t\t;;\n+\t    esac\t    \n+\t\tCOMPREPLY=($(compgen -P \"$pfx\" \\\n+\t\t\t-W \"$(git-ls-tree \"$ls\" \\\n+\t\t\t\t| sed '/^100... blob /s,^.*\t,,\n+\t\t\t\t       /^040000 tree /{\n+\t\t\t\t           s,^.*\t,,\n+\t\t\t\t           s,$,/,\n+\t\t\t\t       }\n+\t\t\t\t       s/^.*\t//')\" \\\n+\t\t\t-- \"$cur\"))\n+\t\t;;\n+\t*)\n+\t\tCOMPREPLY=($(compgen -W \"$(__git_refs .)\" -- \"$cur\"))\n+\t\t;;\n+\tesac\n+}\n+\n+_git_branch ()\n+{\n+\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n+\tCOMPREPLY=($(compgen -W \"-l -f -d -D $(__git_refs .)\" -- \"$cur\"))\n+}\n+\n+_git_cat_file ()\n+{\n+\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n+\tcase \"${COMP_WORDS[0]},$COMP_CWORD\" in\n+\tgit-cat-file*,1)\n+\t\tCOMPREPLY=($(compgen -W \"-p -t blob tree commit tag\" -- \"$cur\"))\n+\t\t;;\n+\tgit,2)\n+\t\tCOMPREPLY=($(compgen -W \"-p -t blob tree commit tag\" -- \"$cur\"))\n+\t\t;;\n+\t*)\n+\t\t__git_complete_file\n+\t\t;;\n+\tesac\n+}\n+\n+_git_checkout ()\n+{\n+\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n+\tCOMPREPLY=($(compgen -W \"-l -b $(__git_refs .)\" -- \"$cur\"))\n+}\n+\n+_git_diff ()\n+{\n+\t__git_complete_file\n+}\n+\n+_git_diff_tree ()\n+{\n+\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n+\tCOMPREPLY=($(compgen -W \"-r -p -M $(__git_refs .)\" -- \"$cur\"))\n+}\n+\n+_git_fetch ()\n+{\n+\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n+\n+\tcase \"${COMP_WORDS[0]},$COMP_CWORD\" in\n+\tgit-fetch*,1)\n+\t\tCOMPREPLY=($(compgen -W \"$(__git_remotes)\" -- \"$cur\"))\n+\t\t;;\n+\tgit,2)\n+\t\tCOMPREPLY=($(compgen -W \"$(__git_remotes)\" -- \"$cur\"))\n+\t\t;;\n+\t*)\n+\t\tcase \"$cur\" in\n+\t\t*:*)\n+\t        cur=$(echo \"$cur\" | sed 's/^.*://')\n+\t\t\tCOMPREPLY=($(compgen -W \"$(__git_refs .)\" -- \"$cur\"))\n+\t\t\t;;\n+\t\t*)\n+\t\t\tlocal remote\n+\t\t\tcase \"${COMP_WORDS[0]}\" in\n+\t\t\tgit-fetch) remote=\"${COMP_WORDS[1]}\" ;;\n+\t\t\tgit)       remote=\"${COMP_WORDS[2]}\" ;;\n+\t\t\tesac\n+\t\t\tCOMPREPLY=($(compgen -W \"$(__git_refs2 \"$remote\")\" -- \"$cur\"))\n+\t\t\t;;\n+\t\tesac\n+\t\t;;\n+\tesac\n+}\n+\n+_git_ls_remote ()\n+{\n+\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n+\tCOMPREPLY=($(compgen -W \"$(__git_remotes)\" -- \"$cur\"))\n+}\n+\n+_git_ls_tree ()\n+{\n+\t__git_complete_file\n+}\n+\n+_git_log ()\n+{\n+\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n+\tcase \"$cur\" in\n+\t*..*)\n+\t\tlocal pfx=$(echo \"$cur\" | sed 's/\\.\\..*$/../')\n+\t\tcur=$(echo \"$cur\" | sed 's/^.*\\.\\.//')\n+\t\tCOMPREPLY=($(compgen -P \"$pfx\" -W \"$(__git_refs .)\" -- \"$cur\"))\n+\t\t;;\n+\t*)\n+\t\tCOMPREPLY=($(compgen -W \"$(__git_refs .)\" -- \"$cur\"))\n+\t\t;;\n+\tesac\n+}\n+\n+_git_merge_base ()\n+{\n+\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n+\tCOMPREPLY=($(compgen -W \"$(__git_refs .)\" -- \"$cur\"))\n+}\n+\n+_git_pull ()\n+{\n+\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n+\n+\tcase \"${COMP_WORDS[0]},$COMP_CWORD\" in\n+\tgit-pull*,1)\n+\t\tCOMPREPLY=($(compgen -W \"$(__git_remotes)\" -- \"$cur\"))\n+\t\t;;\n+\tgit,2)\n+\t\tCOMPREPLY=($(compgen -W \"$(__git_remotes)\" -- \"$cur\"))\n+\t\t;;\n+\t*)\n+\t\tlocal remote\n+\t\tcase \"${COMP_WORDS[0]}\" in\n+\t\tgit-pull)  remote=\"${COMP_WORDS[1]}\" ;;\n+\t\tgit)       remote=\"${COMP_WORDS[2]}\" ;;\n+\t\tesac\n+\t\tCOMPREPLY=($(compgen -W \"$(__git_refs \"$remote\")\" -- \"$cur\"))\n+\t\t;;\n+\tesac\n+}\n+\n+_git_push ()\n+{\n+\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n+\n+\tcase \"${COMP_WORDS[0]},$COMP_CWORD\" in\n+\tgit-push*,1)\n+\t\tCOMPREPLY=($(compgen -W \"$(__git_remotes)\" -- \"$cur\"))\n+\t\t;;\n+\tgit,2)\n+\t\tCOMPREPLY=($(compgen -W \"$(__git_remotes)\" -- \"$cur\"))\n+\t\t;;\n+\t*)\n+\t\tcase \"$cur\" in\n+\t\t*:*)\n+\t\t\tlocal remote\n+\t\t\tcase \"${COMP_WORDS[0]}\" in\n+\t\t\tgit-push)  remote=\"${COMP_WORDS[1]}\" ;;\n+\t\t\tgit)       remote=\"${COMP_WORDS[2]}\" ;;\n+\t\t\tesac\n+\t        cur=$(echo \"$cur\" | sed 's/^.*://')\n+\t\t\tCOMPREPLY=($(compgen -W \"$(__git_refs \"$remote\")\" -- \"$cur\"))\n+\t\t\t;;\n+\t\t*)\n+\t\t\tCOMPREPLY=($(compgen -W \"$(__git_refs2 .)\" -- \"$cur\"))\n+\t\t\t;;\n+\t\tesac\n+\t\t;;\n+\tesac\n+}\n+\n+_git_whatchanged ()\n+{\n+\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n+\tcase \"$cur\" in\n+\t*..*)\n+\t\tlocal pfx=$(echo \"$cur\" | sed 's/\\.\\..*$/../')\n+\t\tcur=$(echo \"$cur\" | sed 's/^.*\\.\\.//')\n+\t\tCOMPREPLY=($(compgen -P \"$pfx\" -W \"$(__git_refs .)\" -- \"$cur\"))\n+\t\t;;\n+\t*)\n+\t\tCOMPREPLY=($(compgen -W \"$(__git_refs .)\" -- \"$cur\"))\n+\t\t;;\n+\tesac\n+}\n+\n+_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-- \"${COMP_WORDS[COMP_CWORD]}\"))\n+\telse\n+\t\tcase \"${COMP_WORDS[1]}\" in\n+\t\tbranch)      _git_branch ;;\n+\t\tcat-file)    _git_cat_file ;;\n+\t\tcheckout)    _git_checkout ;;\n+\t\tdiff)        _git_diff ;;\n+\t\tdiff-tree)   _git_diff_tree ;;\n+\t\tfetch)       _git_fetch ;;\n+\t\tlog)         _git_log ;;\n+\t\tls-remote)   _git_ls_remote ;;\n+\t\tls-tree)     _git_ls_tree ;;\n+\t\tpull)        _git_pull ;;\n+\t\tpush)        _git_push ;;\n+\t\twhatchanged) _git_whatchanged ;;\n+\t\t*)           COMPREPLY=() ;;\n+\t\tesac\n+\tfi\n+}\n+\n+_gitk ()\n+{\n+\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n+\tCOMPREPLY=($(compgen -W \"--all $(__git_refs .)\" -- \"$cur\"))\n+}\n+\n+complete -o default -o nospace -F _git git\n+complete -o default            -F _gitk gitk\n+complete -o default            -F _git_branch git-branch\n+complete -o default -o nospace -F _git_cat_file git-cat-file\n+complete -o default            -F _git_checkout git-checkout\n+complete -o default -o nospace -F _git_diff git-diff\n+complete -o default            -F _git_diff_tree git-diff-tree\n+complete -o default -o nospace -F _git_fetch git-fetch\n+complete -o default -o nospace -F _git_log git-log\n+complete -o default            -F _git_ls_remote git-ls-remote\n+complete -o default -o nospace -F _git_ls_tree git-ls-tree\n+complete -o default            -F _git_merge_base git-merge-base\n+complete -o default -o nospace -F _git_pull git-pull\n+complete -o default -o nospace -F _git_push git-push\n+complete -o default -o nospace -F _git_whatchanged git-whatchanged\n+\n+# The following are necessary only for Cygwin, and only are needed\n+# when the user has tab-completed the executable name and consequently\n+# included the '.exe' suffix.\n+#\n+complete -o default -o nospace -F _git_cat_file git-cat-file.exe\n+complete -o default -o nospace -F _git_diff git-diff.exe\n+complete -o default -o nospace -F _git_diff_tree git-diff-tree.exe\n+complete -o default -o nospace -F _git_log git-log.exe\n+complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe\n+complete -o default            -F _git_merge_base git-merge-base.exe\n+complete -o default -o nospace -F _git_push git-push.exe\n+complete -o default -o nospace -F _git_whatchanged git-whatchanged.exe\n-- \n1.4.2.1.ga817\n"},{"id":"27103","messageId":"7vodtex9xm.fsf@assigned-by-dhcp.cox.net","threadId":"5595","inReplyTo":"20060918004831.GA19851@spearce.org","subject":"Re: [PATCH] Contributed bash completion support for core Git tools.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-09-18T01:03:49Z","receivedAt":"2006-09-18T01:03:49Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Shawn Pearce <spearce@spearce.org> writes:\n\n> Since these are completion routines only for tools shipped with\n> core Git and since bash is a popular shell on many of the native\n> core Git platforms (Linux, Mac OS X, Solaris, BSD) including these\n> routines as part of the stock package would probably be convienent\n> for many users.\n>\n> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>\n>\n>  contrib/bash-git-completion.sh |  330 +++++++++++++++...\n>  1 files changed, 330 insertions(+), 0 deletions(-)\n\nHmph.  I tried this and found that I like \"git pull .\"\ncompletion quite a bit.  Having said that:\n\n * If many people like it (like me), this may deserve to be\n   outside contrib/\n\n * Otherwise, it would probably be better to place it in either\n   contrib/bash/git-completion.sh (with potentially other\n   bash-related things not just completion, but I do not know\n   offhand what other kind of hooks would be useful) or\n   contrib/completion/git-completion.bash (possibly with\n   completion for other shells).\n"},{"id":"27104","messageId":"20060918011855.GA19955@spearce.org","threadId":"5595","inReplyTo":"7vodtex9xm.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Contributed bash completion support for core Git tools.","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-09-18T01:18:55Z","receivedAt":"2006-09-18T01:18:55Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> Shawn Pearce <spearce@spearce.org> writes:\n> \n> > Since these are completion routines only for tools shipped with\n> > core Git and since bash is a popular shell on many of the native\n> > core Git platforms (Linux, Mac OS X, Solaris, BSD) including these\n> > routines as part of the stock package would probably be convienent\n> > for many users.\n> >\n> > Signed-off-by: Shawn O. Pearce <spearce@spearce.org>\n> >\n> >  contrib/bash-git-completion.sh |  330 +++++++++++++++...\n> >  1 files changed, 330 insertions(+), 0 deletions(-)\n> \n> Hmph.  I tried this and found that I like \"git pull .\"\n> completion quite a bit.  Having said that:\n\nI got hooked very fast on the completion for git pull, git checkout\nand git fetch, especially on my local network where setting up\nthe SSH connection for a remote git-ls-remote isn't that much\nof a performance hit.  Trying to use ref completion on the Git\nrepository itself on kernel.org was quite horrible.  But it does\n(sort of) beat doing an ls-remote first.\n \n>  * If many people like it (like me), this may deserve to be\n>    outside contrib/\n> \n>  * Otherwise, it would probably be better to place it in either\n>    contrib/bash/git-completion.sh (with potentially other\n>    bash-related things not just completion, but I do not know\n>    offhand what other kind of hooks would be useful) or\n>    contrib/completion/git-completion.bash (possibly with\n>    completion for other shells).\n\nI'm not sure there are too many other things to hook into bash in\naddition to completion so contrib/completion/git-completion.bash may\nbe the better location, assuming it doesn't graduate out of contrib/.\n\n-- \nShawn.\n"},{"id":"27125","messageId":"Pine.LNX.4.63.0609181012180.19042@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"5595","inReplyTo":"20060918004831.GA19851@spearce.org","subject":"Re: [PATCH] Contributed bash completion support for core Git tools.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-09-18T08:17:35Z","receivedAt":"2006-09-18T08:17:35Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nthe only gripe I have with it: whenever some options are added, or \nremoved, or renamed, you have to adapt the completion script. That is why \nI started (ages ago) to auto-generate the completion script from the \ndocumentation (of course, this means that the options have to be described \nconsistently in the documentation, which is good in its own).\n\nUnfortunately, I never got around to finish it, but a preliminary version \nis in the mailing list archives.\n\nHowever, since your script works well, and I do not have a working script, \nyou clearly won! So, unless some kind soul actually implements my \nproposal, I am happy with your script.\n\nCiao,\nDscho\n"},{"id":"27127","messageId":"7virjlr3am.fsf@assigned-by-dhcp.cox.net","threadId":"5595","inReplyTo":"20060918004831.GA19851@spearce.org","subject":"Re: [PATCH] Contributed bash completion support for core Git tools.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-09-18T08:23:45Z","receivedAt":"2006-09-18T08:23:45Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Shawn Pearce <spearce@spearce.org> writes:\n\n> +_git_log ()\n> +{\n> +...\n> +}\n> +...\n> +_git_whatchanged ()\n> +{\n> +...\n> +}\n\nThese two look the same.  Probably not very easy to maintain in\nthe long run.\n\nIt would be nice to have git-show as well but it usually does\nnot take ranges unlike these two. It is more like \"git branch\"\nfrom completion purposes.\n"},{"id":"27128","messageId":"20060918083114.GQ20913@albany.tokkee.org","threadId":"5595","inReplyTo":"20060918004831.GA19851@spearce.org","subject":"Re: [PATCH] Contributed bash completion support for core Git tools.","fromName":"Sebastian Harl","fromEmail":"sh@tokkee.org","sentAt":"2006-09-18T08:31:16Z","receivedAt":"2006-09-18T08:31:16Z","isPatch":true,"sender":{"key":"sh@tokkee.org","avatar":"https://gravatar.com/avatar/c19b9c37bd63e5d1dabe8d222904921fb807d53d1d8d41af758a16c066eeb59c?d=mp&s=160"},"body":"Hi,\n\n> This is a set of bash completion routines for many of the\n> popular core Git tools.  I wrote these routines from scratch\n> after reading the git-compl and git-compl-lib routines available\n> from the gitcompletion package at http://gitweb.hawaga.org.uk/\n> and found those to be lacking in functionality for some commands.\n\nDid you talk to Ben Clifford (the maintainer of these scripts) before? His\nscripts seem to be in pretty wide-spread use already, so it might make sense\nto join efforts and improve his scripts (and get them into git-core).\n\n> Consequently there may be some similarities but many differences.\n\nDo you know of any (incompatible) differences?\n\nCheers,\nSebastian\n\n-- \nSebastian \"tokkee\" Harl\nGnuPG-ID: 0x8501C7FC\nhttp://tokkee.org/\n\n"},{"id":"27136","messageId":"20060918172958.GB31140@spearce.org","threadId":"5595","inReplyTo":"Pine.LNX.4.63.0609181012180.19042@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] Contributed bash completion support for core Git tools.","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-09-18T17:29:58Z","receivedAt":"2006-09-18T17:29:58Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> the only gripe I have with it: whenever some options are added, or \n> removed, or renamed, you have to adapt the completion script. That is why \n> I started (ages ago) to auto-generate the completion script from the \n> documentation (of course, this means that the options have to be described \n> consistently in the documentation, which is good in its own).\n> \n> Unfortunately, I never got around to finish it, but a preliminary version \n> is in the mailing list archives.\n\nI was torn about putting options into the completion list.  Right now\n\"-l -b -f\" are available for 'git checkout' but I think that was\na bad idea.  There's little point in offering completion for an\noption which is a single character.  But that's my opinion and I'm\nsure someone else might actually find it useful.\n\nLonger options however such as \"--since\" or \"--pretty=\" with its\nassociated format options, or the merge strategy argument to \"-s\"\nwould all be nice to have completion support for.  However I did\nnot implement these.\n \n> However, since your script works well, and I do not have a working script, \n> you clearly won! So, unless some kind soul actually implements my \n> proposal, I am happy with your script.\n\nI was mainly getting tired of copying and pasting or retyping\nbranch names and remote names.  So that's what I implemented.\n(And remote names aren't quite right as they don't tab complete\nthe ones available in .git/config.)\n\n-- \nShawn.\n"},{"id":"27137","messageId":"20060918174225.GC31140@spearce.org","threadId":"5595","inReplyTo":"7virjlr3am.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Contributed bash completion support for core Git tools.","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-09-18T17:42:25Z","receivedAt":"2006-09-18T17:42:25Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> Shawn Pearce <spearce@spearce.org> writes:\n> \n> > +_git_log ()\n> > +{\n> > +...\n> > +}\n> > +...\n> > +_git_whatchanged ()\n> > +{\n> > +...\n> > +}\n> \n> These two look the same.  Probably not very easy to maintain in\n> the long run.\n\nThey are the same.\n \n> It would be nice to have git-show as well but it usually does\n> not take ranges unlike these two. It is more like \"git branch\"\n> from completion purposes.\n\nLike this?  :-)\n\n-- >8 --\nConsolidated git_log and git_whatchanged; added git_show.\n\nMinor requests from Junio: Consolidate the identical implementations of\ngit_log and git_whatchanged, especially since these two commands take\npretty much identical arguments.  This should make the completion package\na little easier to maintain.\n\nAlso added branch name completion for git-show.  I tried to implement\n--pretty=oneline (etc.) but am apparently missing something as bash did\nnot want to complete it through the registered completion routine, so that's\nstill unsupported.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n contrib/bash-git-completion.sh |   21 +++++++--------------\n 1 files changed, 7 insertions(+), 14 deletions(-)\n\ndiff --git a/contrib/bash-git-completion.sh b/contrib/bash-git-completion.sh\nindex 4800185..e8cf6bb 100644\n--- a/contrib/bash-git-completion.sh\n+++ b/contrib/bash-git-completion.sh\n@@ -254,19 +254,10 @@ _git_push ()\n \tesac\n }\n \n-_git_whatchanged ()\n+_git_show ()\n {\n \tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n-\tcase \"$cur\" in\n-\t*..*)\n-\t\tlocal pfx=$(echo \"$cur\" | sed 's/\\.\\..*$/../')\n-\t\tcur=$(echo \"$cur\" | sed 's/^.*\\.\\.//')\n-\t\tCOMPREPLY=($(compgen -P \"$pfx\" -W \"$(__git_refs .)\" -- \"$cur\"))\n-\t\t;;\n-\t*)\n-\t\tCOMPREPLY=($(compgen -W \"$(__git_refs .)\" -- \"$cur\"))\n-\t\t;;\n-\tesac\n+\tCOMPREPLY=($(compgen -W \"$(__git_refs .)\" -- \"$cur\"))\n }\n \n _git ()\n@@ -288,7 +279,8 @@ _git ()\n \t\tls-tree)     _git_ls_tree ;;\n \t\tpull)        _git_pull ;;\n \t\tpush)        _git_push ;;\n-\t\twhatchanged) _git_whatchanged ;;\n+\t\tshow)        _git_show ;;\n+\t\twhatchanged) _git_log ;;\n \t\t*)           COMPREPLY=() ;;\n \t\tesac\n \tfi\n@@ -314,7 +306,8 @@ complete -o default -o nospace -F _git_l\n complete -o default            -F _git_merge_base git-merge-base\n complete -o default -o nospace -F _git_pull git-pull\n complete -o default -o nospace -F _git_push git-push\n-complete -o default -o nospace -F _git_whatchanged git-whatchanged\n+complete -o default            -F _git_show git-show\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 # when the user has tab-completed the executable name and consequently\n@@ -327,4 +320,4 @@ complete -o default -o nospace -F _git_l\n complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe\n complete -o default            -F _git_merge_base git-merge-base.exe\n complete -o default -o nospace -F _git_push git-push.exe\n-complete -o default -o nospace -F _git_whatchanged git-whatchanged.exe\n+complete -o default -o nospace -F _git_log git-whatchanged.exe\n-- \n1.4.2.1.ga817\n"},{"id":"27138","messageId":"20060918175509.GD31140@spearce.org","threadId":"5595","inReplyTo":"20060918083114.GQ20913@albany.tokkee.org","subject":"Re: [PATCH] Contributed bash completion support for core Git tools.","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-09-18T17:55:09Z","receivedAt":"2006-09-18T17:55:09Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Sebastian Harl <sh@tokkee.org> wrote:\n> Hi,\n> \n> > This is a set of bash completion routines for many of the\n> > popular core Git tools.  I wrote these routines from scratch\n> > after reading the git-compl and git-compl-lib routines available\n> > from the gitcompletion package at http://gitweb.hawaga.org.uk/\n> > and found those to be lacking in functionality for some commands.\n> \n> Did you talk to Ben Clifford (the maintainer of these scripts) before?\n\nNo.  I found his scripts yesterday, played around with them for\nabout 15 minutes and found them to be missing some features.\nIn particular they don't actually list all branch names as they\nonly list only those contained directly in refs/heads.  This is\ncertainly very annoying when your topic branch policy uses \"sp/\",\n\"jh/\", \"lt/\" as branch name prefixes.  It also won't work with Linus'\nnew packed ref format...\n\nBen's scripts also don't always complete tags at points where Git\naccepts a tag, nor can they complete through a path with git diff\nor git cat-file to yank a file out of another branch which doesn't\nexist in the current working directory.  They also can't complete\nbranch names in a remote repository when you are fetching or pushing.\n\nSo I set out to write my own, finished it in less than an hour,\nused it for 4 hours while doing some merging, and sent an email to\nput the script into contrib.  :-)\n\n> His scripts seem to be in pretty wide-spread use already, so it might\n> make sense to join efforts and improve his scripts (and get them\n> into git-core).\n\nAgreed.  There may be a few things my script is lacking but I\nthink the one I sent yesterday is already more powerful than Ben's.\nBut I'd like to see it be smarter about completion context and do\neven more.  But right now I'm happy as it can complete my topic\nbranch names and tag names.\n\nI'd like to see core Git at least carry the completion for core Git.\nI know Ben has support for StGit and Cogito as well; two packages\nthat my script doesn't support.  In my humble opnion the completion\nscripts should migrate into the packages they support.  I don't\nthink its unreasonable to expect bash completion support to be part\nof a popular package which is heavily dependent on the shell for\nits user interface[*1*].\n\n> > Consequently there may be some similarities but many differences.\n> \n> Do you know of any (incompatible) differences?\n\nNone that I can think of.  I believe that my script will complete\nanything Ben's does with the exception of a stray single character\noption here or there.\n\nYou can't load both into your shell at the same time as bash will\nonly accept one completion function for any given command and both\npackages use the same function names to implement the completion\nlogic.\n\n\n[*1*] So long as there is someone to maintain it anyway.  :-)\n\n-- \nShawn.\n"},{"id":"27899","messageId":"7v64f8vueh.fsf@assigned-by-dhcp.cox.net","threadId":"5595","inReplyTo":"20060918011855.GA19955@spearce.org","subject":"Re: [PATCH] Contributed bash completion support for core Git tools.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-09-28T16:16:22Z","receivedAt":"2006-09-28T16:16:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Shawn Pearce <spearce@spearce.org> writes:\n\n> I'm not sure there are too many other things to hook into bash in\n> addition to completion so contrib/completion/git-completion.bash may\n> be the better location, assuming it doesn't graduate out of contrib/.\n\nJust so that we do not forget, I applied this (and your\nfollow-up patch).\n"},{"id":"27901","messageId":"20060928162810.GA3201@spearce.org","threadId":"5595","inReplyTo":"7v64f8vueh.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Contributed bash completion support for core Git tools.","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-09-28T16:28:10Z","receivedAt":"2006-09-28T16:28:10Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> Shawn Pearce <spearce@spearce.org> writes:\n> \n> > I'm not sure there are too many other things to hook into bash in\n> > addition to completion so contrib/completion/git-completion.bash may\n> > be the better location, assuming it doesn't graduate out of contrib/.\n> \n> Just so that we do not forget, I applied this (and your\n> follow-up patch).\n\nThanks.  I was starting to wonder about that patch set and was\nprobably going to send a reminder next week.  Now I don't have to.\n:-)\n\n-- \nShawn.\n"}]}