mailinfo: iconv does not like "latin-1" -- should spell it "latin1"
[git.git] / git-grep.sh
1 #!/bin/sh
2 #
3 # Copyright (c) Linus Torvalds, 2005
4 #
5
6 USAGE='<option>... <pattern> <path>...'
7 SUBDIRECTORY_OK='Yes'
8 . git-sh-setup
9
10 pattern=
11 flags=()
12 git_flags=()
13 while : ; 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
45 done
46 [ "$pattern" ] || {
47         usage
48 }
49 git-ls-files -z "${git_flags[@]}" "$@" |
50         xargs -0 grep "${flags[@]}" -e "$pattern"