-
Notifications
You must be signed in to change notification settings - Fork 0
/
myfind
executable file
·78 lines (64 loc) · 1.75 KB
/
myfind
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
#! /bin/bash
# Redundant since I discovered ack
print_usage () {
echo "
Usage: $0 [OPTIONS] grep_arg
Wrapper for running finds with a grep, e.g:
$ find OXi/oxixmlserver -name \"*tcl\" -exec grep --colour -i txsysxfer {} +
More generally, the places can be set as follows:
$ find <find_loc> ?-name \"*<find_type>\"? -exec grep --colour ?-i? ?-w? <grep_arg> {} +
The -f flag will search for filenames instead of grepping files, and is
analogous to the following (grep is simply for highlighting):
$ find <find_loc> ?-name \"*<find_type>\"? -name <grep_arg> | grep --colour <grep_arg>
OPTIONS:
-a grep with color=always, to persist colourings
-f search for filename instead of grepping file
-i grep case insensitive
-l find_loc location to use as root of search
-n grep with line numbers
-o just output find statement, don't execute
-t find_type file extension to search for
-w grep for whole words, i.e. grep -w
"
}
#find_loc=.
find_loc=$(ls | grep -v log)
find_type=
grep_insensitive=
grep_numbers=
grep_whole_word=
execute=true
filename=false
color="--color"
while getopts l:t:hifowan o
do
case $o in
a) color="--color=always";;
f) filename=true;;
h) print_usage; exit;;
i) grep_insensitive="-i";;
l) find_loc=$OPTARG;;
n) grep_numbers="-n";;
o) execute=false;;
t) find_type="-name \"*.$OPTARG\"";;
w) grep_whole_word="-w"
esac
done
shift $(($OPTIND - 1))
if [ $# -eq 0 ]
then
echo $*
print_usage
exit
fi
if $filename
then
cmd="find $find_loc $find_type -name \"*$1*\" | grep $color $1"
else
cmd="find $find_loc $find_type -exec grep $color $grep_insensitive $grep_numbers $grep_whole_word \"$1\" {} +"
fi
echo $cmd
if $execute
then
eval $cmd
fi