Root/bin/gg

1#!/bin/sh
2#
3# git grep through a tree, list the hits, then set up vi to go through the
4# files we found, searching for the expression.
5#
6# usage: gg [grep_options] search_expression
7#
8
9nondash()
10{
11    while [ ! -z "$*" ]; do
12    if [ "${1#-}" = "$1" ]; then
13        echo "$1"
14        return
15    fi
16    shift
17    done
18}
19
20#
21# the "cat" here serves two purposes:
22# 1) keep "git grep" from truncating long lines
23# 2) keep "git grep" from using a pager, which would result in waiting twice
24# for user input at the end, which is confusing
25#
26git grep "$@" | cat
27echo -n '[Enter to vi] '
28read x
29${GG_EDITOR:-vi} -c /"`nondash \"$@\"`" `git grep -l "$@"`
30

Archive Download this file

Branches:
master



interactive