Werner's Miscellanea
Sign in or create your account | Project List | Help
Werner's Miscellanea Git Source Tree
Root/
| 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 | |
| 9 | nondash() |
| 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 | # |
| 26 | git grep "$@" | cat |
| 27 | echo -n '[Enter to vi] ' |
| 28 | read x |
| 29 | ${GG_EDITOR:-vi} -c /"`nondash \"$@\"`" `git grep -l "$@"` |
| 30 |
Branches:
master
