Skip to content

Commit

Permalink
completion: match ctags symbol names in grep patterns
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Oct 21, 2011
1 parent 21e4631 commit 29eec71
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions contrib/completion/git-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,10 @@ _git_gitk ()
_gitk
}

__git_match_ctag() {
awk "/^${1////\\/}/ { print \$1 }" "$2"
}

_git_grep ()
{
__git_has_doubledash && return
Expand All @@ -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)"
}

Expand Down

0 comments on commit 29eec71

Please sign in to comment.