-
Notifications
You must be signed in to change notification settings - Fork 0
/
grepall
97 lines (92 loc) · 2.36 KB
/
grepall
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
# A script by (https://github.com/mgedmin) to make recursive greps easier.
#
# Examples:
#
# grepall foo
#
# locates 'foo' in all files in the directory tree, recursively starting
# from the current directory (but ignoring .svn/.bzr subdirs).
#
# grepall -name '*.txt' -- foo
#
# locates 'foo' in all files named '*.txt' in the directory tree.
#
# Usage: grepall [[dir] [find-args ...] --] [grep-options] pattern
#
# find-args is spliced into the middle of a complicated find expression, so
# it might not do what you want if you attempt something more complicated
# than a bunch of and-ed tests.
findargs=()
grepargs=()
for arg in "$@"; do
if [ "$arg" = -- ]; then
findargs=("${grepargs[@]}")
grepargs=()
else
grepargs+=("$arg")
fi
done
paths=()
set -- "${findargs[@]}"
while true; do
case "$1" in
-*|!|"")
break
;;
*)
paths+=("$1")
shift
;;
esac
done
if [ $# -ne 0 ]; then
findargs=("(" "$@" ")")
else
findargs=()
fi
find "${paths[@]}" \
'(' -name '.svn' -o \
-name '.bzr' -o \
-name '.git' -o \
-name '.hg' -o \
-name '.tox' -o \
-name '.eggs' -o \
-name '.env' -o \
-name '.venv' -o \
-name 'junk' -o \
-name 'build' -o \
-name 'ftest-coverage' -o \
-name 'htmlcov' -o \
-name 'dist' ')' -prune -o \
'(' -type f \
'!' -name '*.min.js' \
'!' -name '*.py[co]' \
'!' -name '*.fs' \
'!' -name 'Data.fs.*' \
'!' -name '*.index' \
'!' -name '*.lock' \
'!' -name '*.tmp' \
'!' -name '*.png' \
'!' -name '*.jpg' \
'!' -name '*.jpeg' \
'!' -name '*.gif' \
'!' -name '*.bmp' \
'!' -name '*.ico' \
'!' -name '*.psd' \
'!' -name '*.ps' \
'!' -name '*.pdf' \
'!' -name '*.pickle' \
'!' -name '*.zip' \
'!' -name '*.gz' \
'!' -name '*.so' \
'!' -name '*.mo' \
'!' -name '*.[od]' \
'!' -name '*.sw[a-p]' \
'!' -name '.#*' \
'!' -name '*~' \
'!' -name '.installed.cfg' \
'!' -name 'ID' \
'!' -iname 'tags' \
"${findargs[@]}" ')' \
-exec grep --color=auto -nH "${grepargs[@]}" {} +