/
libfind
38 lines (32 loc) · 1.14 KB
/
libfind
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
COLOR='magenta'
while getopts :c:d:p: name
do
case $name in
c) CAT="$OPTARG" ;;
d) DIR="$OPTARG" ;;
p) PATTERN="$OPTARG" ;;
*) usage ;; # display usage and return
esac
done
result_grep="$(ggrep --binary-file=without-match --line-number -i --no-messages --recursive --exclude-dir=css --exclude-dir=fonts --exclude-dir=www --exclude-dir='.*' --exclude-dir=lib --exclude-dir='*plugin*' --exclude-dir=vendor --exclude-dir='*js*' --exclude-dir=platforms --exclude-dir=frameworks --exclude-dir=tools --exclude-dir='*bootstrap*' --exclude='*min*' --word-regexp $PATTERN $DIR)"
results=("${(f)result_grep}")
if [ -n "$results" ]
then
for result in $results
do
color_words $result $PATTERN $COLOR
done
fi
result_find=$(find . -type d -name lib -name fonts -name www -name '*plugin*' -name vendor -name '*js*' -name platforms -name frameworks -name tools -name '*bootstrap*' -prune -o -type f -name "*$PATTERN*")
results=("${(f)result_find}")
for result in $results
do
if [[ "$CAT" == "" ]]
then
color_words $result $PATTERN $COLOR
else
# If CAT not null
eval "$COLOR $result"
color_words "$(cat $result)" $PATTERN $COLOR
fi
done