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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <spearce@xxxxxxxxxxx>
---
 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

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]