git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: [PATCH 2/4] Teach bash about git-commit's options.
Date: Mon, 27 Nov 2006 15:11:10 -0500	[thread overview]
Message-ID: <20061127201110.GB7308@spearce.org> (raw)
In-Reply-To: <139669072795537547ec26b69115509100dcd7ec.1164658223.git.spearce@spearce.org>

Not only can we complete the long options for git-commit, but now we
can also complete author strings by looking up all prior author names
in all branches and offering them up as possible completions.  This
is similiar to the support used by the --author= option to git-log.

Unfortunately this changes names which use ' within their string.
It seems to be bash's fault here, the ' is being passed out by sed
but is getting removed during the completion generation.  Fortunately
' appears in only one name in git.git so the damage is likely to be
rather low.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 contrib/completion/git-completion.bash |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index e53f040..d4eb138 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -332,6 +332,32 @@ _git_cherry_pick ()
 	esac
 }
 
+_git_commit ()
+{
+	local cur="${COMP_WORDS[COMP_CWORD]}"
+	case "$cur" in
+	--author=*)
+		local IFS=$'\n'
+		cur="${cur##--author=}"
+		COMPREPLY=($(compgen -P \' -S \' \
+			-W "$(git log --pretty=raw --all \
+			| sed -n -e "/^author /{
+				s/^author //
+				s/>.*/>/
+				p
+			}")" -- "${cur##\'}"))
+		return
+		;;
+	--*)
+		COMPREPLY=($(compgen -W "
+			--all --author=\' --signoff --verify --no-verify
+			--edit --amend --include --only
+			" -- "$cur"))
+		return
+	esac
+	COMPREPLY=()
+}
+
 _git_diff ()
 {
 	__git_complete_file
@@ -720,6 +746,7 @@ _git ()
 	cat-file)    _git_cat_file ;;
 	checkout)    _git_checkout ;;
 	cherry-pick) _git_cherry_pick ;;
+	commit)      _git_commit ;;
 	diff)        _git_diff ;;
 	diff-tree)   _git_diff_tree ;;
 	fetch)       _git_fetch ;;
@@ -754,6 +781,7 @@ complete -o default            -F _git_branch git-branch
 complete -o default -o nospace -F _git_cat_file git-cat-file
 complete -o default            -F _git_checkout git-checkout
 complete -o default            -F _git_cherry_pick git-cherry-pick
+complete -o default            -F _git_commit git-commit
 complete -o default -o nospace -F _git_diff git-diff
 complete -o default            -F _git_diff_tree git-diff-tree
 complete -o default -o nospace -F _git_fetch git-fetch
-- 
1.4.4.1.ge3fb

       reply	other threads:[~2006-11-27 20:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <139669072795537547ec26b69115509100dcd7ec.1164658223.git.spearce@spearce.org>
2006-11-27 20:11 ` Shawn O. Pearce [this message]
2006-11-27 20:11 ` [PATCH 3/4] Cache the list of merge strategies and available commands during load Shawn O. Pearce
2006-11-27 20:12 ` [PATCH 4/4] Teach bash about git-am/git-apply and their whitespace options Shawn O. Pearce

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=20061127201110.GB7308@spearce.org \
    --to=spearce@spearce.org \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /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).