-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathGrepQuick
executable file
·69 lines (58 loc) · 2.06 KB
/
GrepQuick
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
#!/bin/bash
### Options ###################################################################
source ScriptFunctions
Import OptionParser
Import String
scriptDescription="Shorthand for 'grep'."
scriptCredits="Copyright (C) 2001-2002 Hisham Muhammad. Released under the GNU GPL."
helpOnNoArguments=yes
scriptUsage="<pattern> [<files...>]"
Add_Option_Boolean "r" "recursive" "Recursive."
Add_Option_Boolean "w" "whole-word" "Match whole words only."
Add_Option_Boolean "C" "no-color" "Avoid coloring (for grep's that don't support it)."
Add_Option_Boolean "b" "binaries" "Also search binary files."
scriptNotes="
Search is case sensitive only if there is at least one uppercase character
in the pattern.
Binary files are not searched unless --binaries is given.
Error messages are not displayed.
Line numbers are displayed.
If no files are specified, all files are selected (except in \"source\" mode, where
*.[CcHh]* is selected instead).
"
Parse_Options "$@"
### Flags #####################################################################
Boolean "whole-word" && export whole="-w"
Boolean "recursive" && export recursive='-r'
color="--color=always"
Boolean "no-color" && export color=
function all() {
{
pwd=${PWD#/}
if [ -L share -a "${pwd%%/*}" = "${goboPrograms#/}" ]
then ls -d -- * .[A-Za-z0-9]* 2> /dev/null | grep -E -v "^(\.svn|\.git)$" | grep -v "^share$"
else ls -d -- * .[A-Za-z0-9]* 2> /dev/null | grep -E -v "^(\.svn|\.git)$"
fi
} | sed 's/.*/"\0"/'
}
esc=`echo -e '\033'`
function highlight() {
sed 's/^\([^:]*\):\([^:]*:\)/'$esc[1m'\1 \2'$esc[0m'/'
}
nobins=-I
Boolean "binaries" && nobins=
pattern="$(Arg 1)"
Has_Uppercase "$pattern" || insensitive=-i
if [ `Number_Of_Arguments` -gt 1 ]
then
eval `Args_To_Array files 2`
hits=`grep $insensitive $whole $recursive $color $nobins -snH -- "$pattern" "${files[@]}"`
result=$?
else
cmd='grep $insensitive $whole $recursive $color $nobins -snH -- "$pattern" '`all`
hits=$(eval $cmd)
result=$?
hits=`echo "$hits" | grep -v ".svn/"`
fi
[ ! -z "$hits" ] && echo "$hits" | highlight
exit $result