-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfn
executable file
·105 lines (86 loc) · 1.58 KB
/
fn
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
98
99
100
101
102
103
104
#!/bin/bash
# Build the list of patterns
#
typeset extentions=
typeset typelist
typeset grepargs
typeset findargs
typeset findLinks
typeset edit=false
typeset editor=emacs
typeset canedit=true
typeset listLong=false
function DieUsage
{
print "Usage: $0 [-x ext1 -x ext2] [-ilvw] words to search for"
print ""
print "\tExample: $0 -i -x sdl -x soc interface"
print "\twill perform a 'grep -i' on all files below the current"
print "\tdirectory that end in the pattern sdl or soc"
exit 1
}
if [ $# -eq 0 ]
then
DieUsage
fi
while getopts "aefilmvwx:" option
do
case $option in
a)
findLinks="-o -type l"
;;
e)
edit=true
;;
m)
edit=true
editor=mate
;;
i|l|v|w)
if [ $option = "l" ]
then
canedit=true
listLong=true
fi
grepargs="$grepargs -${option}"
;;
x)
extentions="$extentions .$OPTARG$"
esac
done
shift $((${OPTIND} - 1))
extentions="$extentions $*"
for pattern in $extentions
do
if [ -n "$typelist" ]
then
typelist="$typelist -o "
fi
typelist="${typelist}-name \"*${pattern}*\""
done
findargs="\( -type f $findLinks \)"
if [ -n "$typelist" ]
then
findargs="$findargs -a \( $typelist \)"
fi
# Don't want to expand the *'s, in case there are matching file names in this
# dir
#
set -o noglob
function doFind
{
find . -path 'CVS' -prune \
-or -path '.svn' -prune \
-or -path 'ossm' -prune \
-or $(eval echo $findargs) |egrep -v "/CVS/|/.svn/|.class$"
}
if [ $edit = "true" -a $canedit = "true" ]
then
$editor $(doFind "$*")
elif [ "$listLong" = "true" ]
then
/bin/ls -lF $(doFind "$*")
else
doFind $*
fi
exit 0