[PATCH] Add "git grep" helper
Very convenient shorthand for git-ls-files [file-patterns] | xargs grep <pattern> which I tend to do all the time. Yes, it's trivial, but it's really nice. I can do git grep '\<some_variable\>' arch/i386 include/asm-i386 and it does exactly what you'd think it does. And since it just uses the normal git-ls-files file patterns, you can do things like git grep something 'include/*.h' and it will search all header files under the include/ subdirectory. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Linus Torvalds committed
Sep 12, 2005 at 12:06 UTC
f22cc3fcbfe7755154a3a151215abd39162e2e85
2 files changed
+21
-1
Makefile
+1
-1
@@ -76,7 +76,7 @@ SCRIPT_SH = \
76
git-tag.sh git-verify-tag.sh git-whatchanged.sh git.sh \
77
git-applymbox.sh git-applypatch.sh \
78
git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \
79
- git-merge-resolve.sh
79
+ git-merge-resolve.sh git-grep.sh
80
81
SCRIPT_PERL = \
82
git-archimport.perl git-cvsimport.perl git-relink.perl \
git-grep.sh
new
+20
@@ -0,0 +1,20 @@
1
+#!/bin/sh
2
+flags=
3
+while :; do
4
+ pattern="$1"
5
+ case "$pattern" in
6
+ -i|-I|-a|-E|-H|-h|-l)
7
+ flags="$flags $pattern"
8
+ shift
9
+ ;;
10
+ -*)
11
+ echo "unknown flag $pattern" >&2
12
+ exit 1
13
+ ;;
14
+ *)
15
+ break
16
+ ;;
17
+ esac
18
+done
19
+shift
20
+git-ls-files -z "$@" | xargs -0 grep $flags "$pattern"