-
Notifications
You must be signed in to change notification settings - Fork 0
/
srcfind
executable file
·91 lines (72 loc) · 1.6 KB
/
srcfind
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
#!/usr/bin/env bash
set -e
helpstr="\
NAME
srcfind - recursively find files, ignoring common VCS and tmp files
SYNOPSIS
srcfind [-d DIRECTORY] PATTERN
DESCRIPTION
PATTERN is automatically surrounded by \'*' characters and passed to find's
-iname argument (and is therefore case insenstive). Directories such as
.git, .svn, CVS, etc. are ignored. Files such as *.pyc, *.swp, etc. are
ignored.
By default, the current
OPTIONS
-d, --directory DIRECTORY
The parent directory in which to search. Can be used multiple times.
-0
Use find's -print0 instead of -print.
-h, --help
Print this help.
REQUIREMENTS
n/a
AUTHOR
John Brunelle
"
directories=()
printopt='-print'
args=$(getopt -l directory:,help -o d:0h -- "$@")
if [ $? -ne 0 ]; then
exit 65 #(getopt will have written the error message)
fi
eval set -- "$args"
while [ ! -z "$1" ]; do
case "$1" in
-d | --directory)
directories[${#directories[@]}]="$2"
shift
;;
-0)
printopt='-print0'
;;
-h | --help)
echo -n "$helpstr"
exit 0
;;
--)
shift
break
;;
esac
shift
done
pattern="$@"
if [ -z "$pattern" ]; then
pattern='*'
else
pattern='*'"$pattern"'*'
fi
if [ ${#directories[@]} -eq 0 ]; then
directories=(.)
fi
set -u
#---
#(not_mine is a hack that is not generally applicable)
for d in "${directories[@]}"; do
find "$d" \
\( -name .git -o -name .svn -o -name CVS \) -prune -o \
\( -name '*.pyc' -o -name '*.swp' \) -prune -o \
\( -name _attic \) -prune -o \
\( -name not_mine \) -prune -o \
-iname "$pattern" $printopt
done