{"thread":{"id":"22767","subject":"[PATCH 1/2] bash: Enable completion for external subcommands","startedAt":"2010-02-23T14:43:12Z","lastAt":"2010-02-23T16:02:30Z","messageCount":4,"participants":["Teemu Matilainen","SZEDER Gábor"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"135431","messageId":"1266936193-10644-1-git-send-email-teemu.matilainen@iki.fi","threadId":"22767","inReplyTo":null,"subject":"[PATCH 1/2] bash: Enable completion for external subcommands","fromName":"Teemu Matilainen","fromEmail":"teemu.matilainen@iki.fi","sentAt":"2010-02-23T14:43:12Z","receivedAt":"2010-02-23T14:43:12Z","isPatch":true,"sender":{"key":"teemu.matilainen@iki.fi","avatar":"https://avatars.githubusercontent.com/u/79116?v=4"},"body":"Now the parameter completion is only available for subcommands\ndelivered with git.  Providers of external subcommands do not have\na way to supply bash completion for their commands (other than\ninstructing users to hack their git-completion.bash file).\n\nThis makes it possible to have completion also for external git\nsubcommands.  It can be provided by specifying a function (or a\ncommand in PATH) '_git_<subcommand>' that sets the environment\nvariable COMPREPLY.\n\nAll dashes (-) in the subcommand name are replaced with underscores\n(_).  E.g. completion for command 'git foo-bar' can be provided by\n'_git_foo_bar'.\n\nSigned-off-by: Teemu Matilainen <teemu.matilainen@iki.fi>\n---\n contrib/completion/git-completion.bash |    8 +++++++-\n 1 files changed, 7 insertions(+), 1 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex fe93747..c7ac727 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -14,6 +14,9 @@\n #    *) git 'subcommands'\n #    *) tree paths within 'ref:path/to/file' expressions\n #    *) common --long-options\n+#    *) completion for external 'git <sub-command>' can be provided by\n+#       specifying function (or command in PATH) '_git_<sub_command>'\n+#       that sets COMPREPLY\n #\n # To use these routines:\n #\n@@ -2257,7 +2260,10 @@ _git ()\n \tsvn)         _git_svn ;;\n \ttag)         _git_tag ;;\n \twhatchanged) _git_log ;;\n-\t*)           COMPREPLY=() ;;\n+\t*)\n+\t\tlocal f=\"_git_${command//-/_}\"\n+\t\ttype -t \"$f\" >/dev/null && \"$f\" || COMPREPLY=()\n+\t\t;;\n \tesac\n }\n \n-- \n1.7.0.83.g241b9\n"},{"id":"135432","messageId":"1266936193-10644-2-git-send-email-teemu.matilainen@iki.fi","threadId":"22767","inReplyTo":"1266936193-10644-1-git-send-email-teemu.matilainen@iki.fi","subject":"[PATCH 2/2] bash: Use dynamic binding for subcommand completion functions","fromName":"Teemu Matilainen","fromEmail":"teemu.matilainen@iki.fi","sentAt":"2010-02-23T14:43:13Z","receivedAt":"2010-02-23T14:43:13Z","isPatch":true,"sender":{"key":"teemu.matilainen@iki.fi","avatar":"https://avatars.githubusercontent.com/u/79116?v=4"},"body":"Call git subcommand completion functions dynamically using the same\nlogic as with external commands.  I.e. call '_git_<subcommand>' if it\nexists.\n\nThe only exceptions now are:\n  - stage -> _git_add\n  - whatchanged -> _git_log\n\nThis only changes how the functions are called.  The functionality remains\nexactly the same.\n\nSigned-off-by: Teemu Matilainen <teemu.matilainen@iki.fi>\n---\n contrib/completion/git-completion.bash |   61 +++-----------------------------\n 1 files changed, 5 insertions(+), 56 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex c7ac727..1d71e87 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -2208,63 +2208,12 @@ _git ()\n \t[ \"$expansion\" ] && command=\"$expansion\"\n \n \tcase \"$command\" in\n-\tam)          _git_am ;;\n-\tadd)         _git_add ;;\n-\tapply)       _git_apply ;;\n-\tarchive)     _git_archive ;;\n-\tbisect)      _git_bisect ;;\n-\tbundle)      _git_bundle ;;\n-\tbranch)      _git_branch ;;\n-\tcheckout)    _git_checkout ;;\n-\tcherry)      _git_cherry ;;\n-\tcherry-pick) _git_cherry_pick ;;\n-\tclean)       _git_clean ;;\n-\tclone)       _git_clone ;;\n-\tcommit)      _git_commit ;;\n-\tconfig)      _git_config ;;\n-\tdescribe)    _git_describe ;;\n-\tdiff)        _git_diff ;;\n-\tdifftool)    _git_difftool ;;\n-\tfetch)       _git_fetch ;;\n-\tformat-patch) _git_format_patch ;;\n-\tfsck)        _git_fsck ;;\n-\tgc)          _git_gc ;;\n-\tgrep)        _git_grep ;;\n-\thelp)        _git_help ;;\n-\tinit)        _git_init ;;\n-\tlog)         _git_log ;;\n-\tls-files)    _git_ls_files ;;\n-\tls-remote)   _git_ls_remote ;;\n-\tls-tree)     _git_ls_tree ;;\n-\tmerge)       _git_merge;;\n-\tmergetool)   _git_mergetool;;\n-\tmerge-base)  _git_merge_base ;;\n-\tmv)          _git_mv ;;\n-\tname-rev)    _git_name_rev ;;\n-\tnotes)       _git_notes ;;\n-\tpull)        _git_pull ;;\n-\tpush)        _git_push ;;\n-\trebase)      _git_rebase ;;\n-\tremote)      _git_remote ;;\n-\treplace)     _git_replace ;;\n-\treset)       _git_reset ;;\n-\trevert)      _git_revert ;;\n-\trm)          _git_rm ;;\n-\tsend-email)  _git_send_email ;;\n-\tshortlog)    _git_shortlog ;;\n-\tshow)        _git_show ;;\n-\tshow-branch) _git_show_branch ;;\n-\tstash)       _git_stash ;;\n-\tstage)       _git_add ;;\n-\tsubmodule)   _git_submodule ;;\n-\tsvn)         _git_svn ;;\n-\ttag)         _git_tag ;;\n-\twhatchanged) _git_log ;;\n-\t*)\n-\t\tlocal f=\"_git_${command//-/_}\"\n-\t\ttype -t \"$f\" >/dev/null && \"$f\" || COMPREPLY=()\n-\t\t;;\n+\tstage)       command=\"add\" ;;\n+\twhatchanged) command=\"log\" ;;\n \tesac\n+\n+\tlocal f=\"_git_${command//-/_}\"\n+\ttype -t \"$f\" >/dev/null && \"$f\" || COMPREPLY=()\n }\n \n _gitk ()\n-- \n1.7.0.83.g241b9\n"},{"id":"135433","messageId":"20100223155007.GB10772@neumann","threadId":"22767","inReplyTo":"1266936193-10644-1-git-send-email-teemu.matilainen@iki.fi","subject":"Re: [PATCH 1/2] bash: Enable completion for external subcommands","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2010-02-23T15:50:07Z","receivedAt":"2010-02-23T15:50:07Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Hi,\n\n\nOn Tue, Feb 23, 2010 at 04:43:12PM +0200, Teemu Matilainen wrote:\n> Now the parameter completion is only available for subcommands\n> delivered with git.  Providers of external subcommands do not have\n> a way to supply bash completion for their commands (other than\n> instructing users to hack their git-completion.bash file).\n>\n> This makes it possible to have completion also for external git\n> subcommands.  It can be provided by specifying a function (or a\n> command in PATH) '_git_<subcommand>' that sets the environment\n> variable COMPREPLY.\n>\n> All dashes (-) in the subcommand name are replaced with underscores\n> (_).  E.g. completion for command 'git foo-bar' can be provided by\n> '_git_foo_bar'.\n>\n> Signed-off-by: Teemu Matilainen <teemu.matilainen@iki.fi>\n\nthis issue was raised a few weeks ago, and the discussion led to a\nsimilar patch back then.  However, Junio mentioned a few concerns\nregarding this approach, and, since it was v1.7.0-rc time and this was\nclearly a post v1.7.0 change, I didn't pursue the discussion and\ndidn't send updated patches, and then forgot it completely.  I will\ntry to find some time in the evening to get the commit messages in\nshape send out the updates.  In the meantime please have a look at\nJunio's concerns about this approach:\nhttp://thread.gmane.org/gmane.comp.version-control.git/138316/focus=138348\n\n\nBest,\nGábor\n"},{"id":"135434","messageId":"20100223160230.GB837@reaktor.fi","threadId":"22767","inReplyTo":"20100223155007.GB10772@neumann","subject":"Re: [PATCH 1/2] bash: Enable completion for external subcommands","fromName":"Teemu Matilainen","fromEmail":"teemu.matilainen@iki.fi","sentAt":"2010-02-23T16:02:30Z","receivedAt":"2010-02-23T16:02:30Z","isPatch":true,"sender":{"key":"teemu.matilainen@iki.fi","avatar":"https://avatars.githubusercontent.com/u/79116?v=4"},"body":"On Tue, 23 Feb 2010, SZEDER Gábor wrote:\n\n> On Tue, Feb 23, 2010 at 04:43:12PM +0200, Teemu Matilainen wrote:\n> > This makes it possible to have completion also for external git\n> > subcommands.\n> \n> this issue was raised a few weeks ago, and the discussion led to a\n> similar patch back then.  However, Junio mentioned a few concerns\n> regarding this approach, and, since it was v1.7.0-rc time and this was\n> clearly a post v1.7.0 change, I didn't pursue the discussion and\n> didn't send updated patches, and then forgot it completely.  I will\n> try to find some time in the evening to get the commit messages in\n> shape send out the updates.  In the meantime please have a look at\n> Junio's concerns about this approach:\n> http://thread.gmane.org/gmane.comp.version-control.git/138316/focus=138348\n\nUgh.  I *tried* to search the mailing list, but apparently failed...\nFunny that anyway we got almost identical solution.\n\nThanks for the pointer.  I'll be waiting for the new patch.\n\n-- \n\t- Teemu\n"}]}