git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Cc: "SZEDER Gábor" <szeder@ira.uka.de>
Subject: [PATCHv2 3/3] completion: match ctags symbol names in grep patterns
Date: Fri, 21 Oct 2011 13:30:21 -0400	[thread overview]
Message-ID: <20111021173021.GC24417@sigill.intra.peff.net> (raw)
In-Reply-To: <20111021172239.GA22289@sigill.intra.peff.net>

A common thing to grep for is the name of a symbol. This
patch teaches the completion for "git grep" to look in
a 'tags' file, if present, to complete a pattern. For
example, in git.git:

  $ make tags
  $ git grep get_sha1<Tab><Tab>
  get_sha1                 get_sha1_oneline
  get_sha1_1               get_sha1_with_context
  get_sha1_basic           get_sha1_with_context_1
  get_sha1_hex             get_sha1_with_mode
  get_sha1_hex_segment     get_sha1_with_mode_1
  get_sha1_mb

Signed-off-by: Jeff King <peff@peff.net>
---
This incorporates the suggestions from Gábor's review, with one
exception: it still looks only in the current directory for the "tags"
files. I think that might have some performance implications, so I'd
rather add it separately, if at all.

 contrib/completion/git-completion.bash |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 888e8e1..af283cb 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1429,6 +1429,10 @@ _git_gitk ()
 	_gitk
 }
 
+__git_match_ctag() {
+	awk "/^${1////\\/}/ { print \$1 }" "$2"
+}
+
 _git_grep ()
 {
 	__git_has_doubledash && return
@@ -1451,6 +1455,15 @@ _git_grep ()
 		;;
 	esac
 
+	case "$cword,$prev" in
+	2,*|*,-*)
+		if test -r tags; then
+			__gitcomp "$(__git_match_ctag "$cur" tags)"
+			return
+		fi
+		;;
+	esac
+
 	__gitcomp "$(__git_refs)"
 }
 
-- 
1.7.7.rc1.28.g5dd2ee

  parent reply	other threads:[~2011-10-21 17:30 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-18  4:49 [PATCH 0/3] stupid git tricks Jeff King
2011-10-18  4:52 ` [PATCH 1/3] contrib: add diff highlight script Jeff King
2011-10-18  4:54 ` [PATCH 2/3] contrib: add git-jump script Jeff King
2011-10-18  5:01 ` [PATCH 3/3] completion: match ctags symbol names in grep patterns Jeff King
2011-10-18  7:15   ` Junio C Hamano
2011-10-18  7:26     ` Jonathan Nieder
2011-10-18  7:35       ` Junio C Hamano
2011-10-18  7:41         ` Matthieu Moy
2011-10-18  7:55           ` Junio C Hamano
2011-10-18  7:55         ` Jonathan Nieder
2011-10-18 17:14           ` Junio C Hamano
2011-10-18 15:04     ` Jeff King
2011-10-21 13:25   ` SZEDER Gábor
2011-10-21 17:22     ` Jeff King
2011-10-21 17:26       ` [PATCHv2 1/3] contrib: add diff highlight script Jeff King
2011-10-21 17:28       ` [PATCH 2/3] contrib: add git-jump script Jeff King
2011-10-21 17:35         ` Jeff King
2011-10-21 17:30       ` Jeff King [this message]
2011-10-21 17:37         ` [PATCHv2 4/3] completion: use __gitcomp_nl for ctag matching Jeff King
2011-10-23 21:29         ` [PATCHv2 3/3] completion: match ctags symbol names in grep patterns SZEDER Gábor
2011-10-28  6:05           ` Jeff King
2011-10-29 12:47             ` SZEDER Gábor
2011-11-01 15:21               ` Jeff King
2011-11-01 18:14                 ` Junio C Hamano

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=20111021173021.GC24417@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=szeder@ira.uka.de \
    /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).