git-grep.shon commit GIT 0.99.9n aka 1.0rc6 (1ed9193)
   1#!/bin/sh
   2#
   3# Copyright (c) Linus Torvalds, 2005
   4#
   5
   6USAGE='<option>... <pattern> <path>...'
   7SUBDIRECTORY_OK='Yes'
   8. git-sh-setup
   9
  10pattern=
  11flags=()
  12git_flags=()
  13while : ; do
  14        case "$1" in
  15        --cached|--deleted|--others|--killed|\
  16        --ignored|--exclude=*|\
  17        --exclude-from=*|\--exclude-per-directory=*)
  18                git_flags=("${git_flags[@]}" "$1")
  19                ;;
  20        -e)
  21                pattern="$2"
  22                shift
  23                ;;
  24        -A|-B|-C|-D|-d|-f|-m)
  25                flags=("${flags[@]}" "$1" "$2")
  26                shift
  27                ;;
  28        --)
  29                # The rest are git-ls-files paths (or flags)
  30                shift
  31                break
  32                ;;
  33        -*)
  34                flags=("${flags[@]}" "$1")
  35                ;;
  36        *)
  37                if [ -z "$pattern" ]; then
  38                        pattern="$1"
  39                        shift
  40                fi
  41                break
  42                ;;
  43        esac
  44        shift
  45done
  46[ "$pattern" ] || {
  47        usage
  48}
  49git-ls-files -z "${git_flags[@]}" "$@" |
  50        xargs -0 grep "${flags[@]}" -e "$pattern"