Subject: [PATCH 9/10] Allow completion of --committer and --author arguments to git log.

From: "Shawn O. Pearce" <[email-masked]>
Date: Mon, 27 Nov 2006 03:42:28 -0500

This is just a cute hack, but we can (easily) complete the parameter
to --author or --committer in bash by asking for all possible authors
or committers in this project from git log and offering them up as
valid choices.

We replace spaces with dots as this prevents names with spaces from
appearing as two parameters rather than one, yet it still matches the
space in the field.

Currently my Mac OS X system takes ~5 seconds to compute the completions
for --author on git.git and ~4 seconds to compute the completions for
--committer on same.  I imagine it would take longer on more active
projects, but its a good way to see if the name you are entering is
going to be unique or not.

Signed-off-by: Shawn O. Pearce <[email-masked]>
---
 contrib/completion/git-completion.bash |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 8acfb09..b456a3b 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -360,6 +360,26 @@ _git_log ()
 {
 	local cur="${COMP_WORDS[COMP_CWORD]}"
 	case "$cur" in
+	--committer=*)
+		COMPREPLY=($(compgen -W "$(git log --pretty=raw --all \
+			| sed -n -e "/^committer /{
+				s/^committer //
+				s/ <.*//
+				s/ /./g
+				p
+			}")" -- "${cur##--committer=}"))
+		return
+		;;
+	--author=*)
+		COMPREPLY=($(compgen -W "$(git log --pretty=raw --all \
+			| sed -n -e "/^author /{
+				s/^author //
+				s/ <.*//
+				s/ /./g
+				p
+			}")" -- "${cur##--author=}"))
+		return
+		;;
 	--pretty=*)
 		COMPREPLY=($(compgen -W "
 			oneline short medium full fuller email raw
-- 
1.4.4.1.ge3fb