git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Teemu Matilainen <teemu.matilainen@iki.fi>
To: git@vger.kernel.org
Cc: "Shawn O. Pearce" <spearce@spearce.org>,
	Teemu Matilainen <teemu.matilainen@iki.fi>
Subject: [PATCH 1/2] bash: Enable completion for external subcommands
Date: Tue, 23 Feb 2010 16:43:12 +0200	[thread overview]
Message-ID: <1266936193-10644-1-git-send-email-teemu.matilainen@iki.fi> (raw)

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

             reply	other threads:[~2010-02-23 14:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-23 14:43 Teemu Matilainen [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1266936193-10644-1-git-send-email-teemu.matilainen@iki.fi \
    --to=teemu.matilainen@iki.fi \
    --cc=git@vger.kernel.org \
    --cc=spearce@spearce.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).