completion: match ctags symbol names in grep patterns

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>

Jeff King committed Oct 21, 2011 at 13:30 UTC 29eec71f21853f2428cdae83d6b04d4ae1084b7d
1 file changed +13
contrib/completion/git-completion.bash
+13
@@ -1429,6 +1429,10 @@ _git_gitk ()
1429 _gitk
1430 }
1431
1432 +__git_match_ctag() {
1433 + awk "/^${1////\\/}/ { print \$1 }" "$2"
1434 +}
1435 +
1436 _git_grep ()
1437 {
1438 __git_has_doubledash && return
@@ -1451,6 +1455,15 @@ _git_grep ()
1455 ;;
1456 esac
1457
1458 + case "$cword,$prev" in
1459 + 2,*|*,-*)
1460 + if test -r tags; then
1461 + __gitcomp "$(__git_match_ctag "$cur" tags)"
1462 + return
1463 + fi
1464 + ;;
1465 + esac
1466 +
1467 __gitcomp "$(__git_refs)"
1468 }
1469