grep.zsh 645 Bytes
Newer Older
Marc Cornellà's avatar
Marc Cornellà committed
1
2
3
4
# is x grep argument available?
grep-flag-available() {
    echo | grep $1 "" >/dev/null 2>&1
}
nXqd's avatar
nXqd committed
5

6
7
GREP_OPTIONS=""

Marc Cornellà's avatar
Marc Cornellà committed
8
# color grep results
9
10
11
if grep-flag-available --color=auto; then
    GREP_OPTIONS+=" --color=auto"
fi
12

Marc Cornellà's avatar
Marc Cornellà committed
13
# ignore VCS folders (if the necessary grep flags are available)
shawn's avatar
shawn committed
14
VCS_FOLDERS="{.bzr,CVS,.git,.hg,.svn}"
15

16
if grep-flag-available --exclude-dir=.cvs; then
17
    GREP_OPTIONS+=" --exclude-dir=$VCS_FOLDERS"
18
elif grep-flag-available --exclude=.cvs; then
19
    GREP_OPTIONS+=" --exclude=$VCS_FOLDERS"
20
21
fi

Marc Cornellà's avatar
Marc Cornellà committed
22
# export grep settings
23
alias grep="grep $GREP_OPTIONS"
Marc Cornellà's avatar
Marc Cornellà committed
24
25

# clean up
26
unset GREP_OPTIONS
Marc Cornellà's avatar
Marc Cornellà committed
27
28
unset VCS_FOLDERS
unfunction grep-flag-available