Thread (15 messages) flat view 15 messages, 2 authors, 2016-06-15

[PATCHv2 3/3] completion: match ctags symbol names in grep patterns

From: Jeff King <hidden>
Date: 2016-06-15 22:52:18
Subsystem: the rest · Maintainer: Linus Torvalds

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 <redacted>
---
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help