git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] bash: Enable completion for external subcommands
@ 2010-02-23 14:43 Teemu Matilainen
  2010-02-23 14:43 ` [PATCH 2/2] bash: Use dynamic binding for subcommand completion functions Teemu Matilainen
  2010-02-23 15:50 ` [PATCH 1/2] bash: Enable completion for external subcommands SZEDER Gábor
  0 siblings, 2 replies; 4+ messages in thread
From: Teemu Matilainen @ 2010-02-23 14:43 UTC (permalink / raw)
  To: git; +Cc: Shawn O. Pearce, Teemu Matilainen

Now the parameter completion is only available for subcommands
delivered with git.  Providers of external subcommands do not have
a way to supply bash completion for their commands (other than
instructing users to hack their git-completion.bash file).

This makes it possible to have completion also for external git
subcommands.  It can be provided by specifying a function (or a
command in PATH) '_git_<subcommand>' that sets the environment
variable COMPREPLY.

All dashes (-) in the subcommand name are replaced with underscores
(_).  E.g. completion for command 'git foo-bar' can be provided by
'_git_foo_bar'.

Signed-off-by: Teemu Matilainen <teemu.matilainen@iki.fi>
---
 contrib/completion/git-completion.bash |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index fe93747..c7ac727 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -14,6 +14,9 @@
 #    *) git 'subcommands'
 #    *) tree paths within 'ref:path/to/file' expressions
 #    *) common --long-options
+#    *) completion for external 'git <sub-command>' can be provided by
+#       specifying function (or command in PATH) '_git_<sub_command>'
+#       that sets COMPREPLY
 #
 # To use these routines:
 #
@@ -2257,7 +2260,10 @@ _git ()
 	svn)         _git_svn ;;
 	tag)         _git_tag ;;
 	whatchanged) _git_log ;;
-	*)           COMPREPLY=() ;;
+	*)
+		local f="_git_${command//-/_}"
+		type -t "$f" >/dev/null && "$f" || COMPREPLY=()
+		;;
 	esac
 }
 
-- 
1.7.0.83.g241b9

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] bash: Use dynamic binding for subcommand completion functions
  2010-02-23 14:43 [PATCH 1/2] bash: Enable completion for external subcommands Teemu Matilainen
@ 2010-02-23 14:43 ` Teemu Matilainen
  2010-02-23 15:50 ` [PATCH 1/2] bash: Enable completion for external subcommands SZEDER Gábor
  1 sibling, 0 replies; 4+ messages in thread
From: Teemu Matilainen @ 2010-02-23 14:43 UTC (permalink / raw)
  To: git; +Cc: Shawn O. Pearce, Teemu Matilainen

Call git subcommand completion functions dynamically using the same
logic as with external commands.  I.e. call '_git_<subcommand>' if it
exists.

The only exceptions now are:
  - stage -> _git_add
  - whatchanged -> _git_log

This only changes how the functions are called.  The functionality remains
exactly the same.

Signed-off-by: Teemu Matilainen <teemu.matilainen@iki.fi>
---
 contrib/completion/git-completion.bash |   61 +++-----------------------------
 1 files changed, 5 insertions(+), 56 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index c7ac727..1d71e87 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2208,63 +2208,12 @@ _git ()
 	[ "$expansion" ] && command="$expansion"
 
 	case "$command" in
-	am)          _git_am ;;
-	add)         _git_add ;;
-	apply)       _git_apply ;;
-	archive)     _git_archive ;;
-	bisect)      _git_bisect ;;
-	bundle)      _git_bundle ;;
-	branch)      _git_branch ;;
-	checkout)    _git_checkout ;;
-	cherry)      _git_cherry ;;
-	cherry-pick) _git_cherry_pick ;;
-	clean)       _git_clean ;;
-	clone)       _git_clone ;;
-	commit)      _git_commit ;;
-	config)      _git_config ;;
-	describe)    _git_describe ;;
-	diff)        _git_diff ;;
-	difftool)    _git_difftool ;;
-	fetch)       _git_fetch ;;
-	format-patch) _git_format_patch ;;
-	fsck)        _git_fsck ;;
-	gc)          _git_gc ;;
-	grep)        _git_grep ;;
-	help)        _git_help ;;
-	init)        _git_init ;;
-	log)         _git_log ;;
-	ls-files)    _git_ls_files ;;
-	ls-remote)   _git_ls_remote ;;
-	ls-tree)     _git_ls_tree ;;
-	merge)       _git_merge;;
-	mergetool)   _git_mergetool;;
-	merge-base)  _git_merge_base ;;
-	mv)          _git_mv ;;
-	name-rev)    _git_name_rev ;;
-	notes)       _git_notes ;;
-	pull)        _git_pull ;;
-	push)        _git_push ;;
-	rebase)      _git_rebase ;;
-	remote)      _git_remote ;;
-	replace)     _git_replace ;;
-	reset)       _git_reset ;;
-	revert)      _git_revert ;;
-	rm)          _git_rm ;;
-	send-email)  _git_send_email ;;
-	shortlog)    _git_shortlog ;;
-	show)        _git_show ;;
-	show-branch) _git_show_branch ;;
-	stash)       _git_stash ;;
-	stage)       _git_add ;;
-	submodule)   _git_submodule ;;
-	svn)         _git_svn ;;
-	tag)         _git_tag ;;
-	whatchanged) _git_log ;;
-	*)
-		local f="_git_${command//-/_}"
-		type -t "$f" >/dev/null && "$f" || COMPREPLY=()
-		;;
+	stage)       command="add" ;;
+	whatchanged) command="log" ;;
 	esac
+
+	local f="_git_${command//-/_}"
+	type -t "$f" >/dev/null && "$f" || COMPREPLY=()
 }
 
 _gitk ()
-- 
1.7.0.83.g241b9

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] bash: Enable completion for external subcommands
  2010-02-23 14:43 [PATCH 1/2] bash: Enable completion for external subcommands Teemu Matilainen
  2010-02-23 14:43 ` [PATCH 2/2] bash: Use dynamic binding for subcommand completion functions Teemu Matilainen
@ 2010-02-23 15:50 ` SZEDER Gábor
  2010-02-23 16:02   ` Teemu Matilainen
  1 sibling, 1 reply; 4+ messages in thread
From: SZEDER Gábor @ 2010-02-23 15:50 UTC (permalink / raw)
  To: Teemu Matilainen; +Cc: git, Shawn O. Pearce

Hi,


On Tue, Feb 23, 2010 at 04:43:12PM +0200, Teemu Matilainen wrote:
> Now the parameter completion is only available for subcommands
> delivered with git.  Providers of external subcommands do not have
> a way to supply bash completion for their commands (other than
> instructing users to hack their git-completion.bash file).
>
> This makes it possible to have completion also for external git
> subcommands.  It can be provided by specifying a function (or a
> command in PATH) '_git_<subcommand>' that sets the environment
> variable COMPREPLY.
>
> All dashes (-) in the subcommand name are replaced with underscores
> (_).  E.g. completion for command 'git foo-bar' can be provided by
> '_git_foo_bar'.
>
> Signed-off-by: Teemu Matilainen <teemu.matilainen@iki.fi>

this issue was raised a few weeks ago, and the discussion led to a
similar patch back then.  However, Junio mentioned a few concerns
regarding this approach, and, since it was v1.7.0-rc time and this was
clearly a post v1.7.0 change, I didn't pursue the discussion and
didn't send updated patches, and then forgot it completely.  I will
try to find some time in the evening to get the commit messages in
shape send out the updates.  In the meantime please have a look at
Junio's concerns about this approach:
http://thread.gmane.org/gmane.comp.version-control.git/138316/focus=138348


Best,
Gábor

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] bash: Enable completion for external subcommands
  2010-02-23 15:50 ` [PATCH 1/2] bash: Enable completion for external subcommands SZEDER Gábor
@ 2010-02-23 16:02   ` Teemu Matilainen
  0 siblings, 0 replies; 4+ messages in thread
From: Teemu Matilainen @ 2010-02-23 16:02 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: git, Shawn O. Pearce

On Tue, 23 Feb 2010, SZEDER Gábor wrote:

> On Tue, Feb 23, 2010 at 04:43:12PM +0200, Teemu Matilainen wrote:
> > This makes it possible to have completion also for external git
> > subcommands.
> 
> this issue was raised a few weeks ago, and the discussion led to a
> similar patch back then.  However, Junio mentioned a few concerns
> regarding this approach, and, since it was v1.7.0-rc time and this was
> clearly a post v1.7.0 change, I didn't pursue the discussion and
> didn't send updated patches, and then forgot it completely.  I will
> try to find some time in the evening to get the commit messages in
> shape send out the updates.  In the meantime please have a look at
> Junio's concerns about this approach:
> http://thread.gmane.org/gmane.comp.version-control.git/138316/focus=138348

Ugh.  I *tried* to search the mailing list, but apparently failed...
Funny that anyway we got almost identical solution.

Thanks for the pointer.  I'll be waiting for the new patch.

-- 
	- Teemu

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-02-23 16:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-23 14:43 [PATCH 1/2] bash: Enable completion for external subcommands Teemu Matilainen
2010-02-23 14:43 ` [PATCH 2/2] bash: Use dynamic binding for subcommand completion functions Teemu Matilainen
2010-02-23 15:50 ` [PATCH 1/2] bash: Enable completion for external subcommands SZEDER Gábor
2010-02-23 16:02   ` Teemu Matilainen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).