From f44032e1d0f137807d2246d9a79ac273acf17b75 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Thu, 26 Jul 2012 12:35:37 -0300 Subject: [PATCH] bin/gg: moved over from svn.openmoko.org/developers/werner/bin/gg --- bin/gg | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 bin/gg diff --git a/bin/gg b/bin/gg new file mode 100755 index 0000000..f2f1f0d --- /dev/null +++ b/bin/gg @@ -0,0 +1,29 @@ +#!/bin/sh +# +# git grep through a tree, list the hits, then set up vi to go through the +# files we found, searching for the expression. +# +# usage: gg [grep_options] search_expression +# + +nondash() +{ + while [ ! -z "$*" ]; do + if [ "${1#-}" = "$1" ]; then + echo "$1" + return + fi + shift + done +} + +# +# the "cat" here serves two purposes: +# 1) keep "git grep" from truncating long lines +# 2) keep "git grep" from using a pager, which would result in waiting twice +# for user input at the end, which is confusing +# +git grep "$@" | cat +echo -n '[Enter to vi] ' +read x +${GG_EDITOR:-vi} -c /"`nondash \"$@\"`" `git grep -l "$@"`