git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Add "git grep" helper
@ 2005-09-12 19:06 Linus Torvalds
  2005-09-12 20:57 ` Morten Welinder
  2005-09-12 21:45 ` Junio C Hamano
  0 siblings, 2 replies; 17+ messages in thread
From: Linus Torvalds @ 2005-09-12 19:06 UTC (permalink / raw)
  To: Git Mailing List, Junio C Hamano


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>
---

diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -76,7 +76,7 @@ SCRIPT_SH = \
 	git-tag.sh git-verify-tag.sh git-whatchanged.sh git.sh \
 	git-applymbox.sh git-applypatch.sh \
 	git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \
-	git-merge-resolve.sh
+	git-merge-resolve.sh git-grep.sh
 
 SCRIPT_PERL = \
 	git-archimport.perl git-cvsimport.perl git-relink.perl \
diff --git a/git-grep.sh b/git-grep.sh
new file mode 100755
--- /dev/null
+++ b/git-grep.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+flags=
+while :; do
+  pattern="$1"
+  case "$pattern" in
+  -i|-I|-a|-E|-H|-h|-l)
+    flags="$flags $pattern"
+    shift
+    ;;
+  -*)
+    echo "unknown flag $pattern" >&2
+    exit 1
+    ;;
+  *)
+    break
+    ;;
+  esac
+done
+shift
+git-ls-files -z "$@" | xargs -0 grep $flags "$pattern"

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2005-09-13 19:09 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-09-12 19:06 Add "git grep" helper Linus Torvalds
2005-09-12 20:57 ` Morten Welinder
2005-09-12 21:37   ` Linus Torvalds
2005-09-12 21:45 ` Junio C Hamano
2005-09-12 22:12   ` Linus Torvalds
2005-09-12 22:22     ` Improve "git grep" flags handling Linus Torvalds
2005-09-12 22:37       ` Junio C Hamano
2005-09-12 22:43         ` Linus Torvalds
2005-09-12 23:26           ` Junio C Hamano
2005-09-12 23:46             ` Linus Torvalds
2005-09-12 23:55               ` Junio C Hamano
2005-09-13  0:51               ` [PATCH] " Junio C Hamano
2005-09-13 17:39                 ` Horst von Brand
2005-09-13 17:51                   ` Linus Torvalds
2005-09-13 18:53                   ` Junio C Hamano
2005-09-13 19:09                     ` Linus Torvalds
2005-09-12 22:31     ` Add "git grep" helper Junio C Hamano

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).