grep.zsh 588 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

Marc Cornellà's avatar
Marc Cornellà committed
6
# color grep results
7
8
GREP_OPTIONS="--color=auto"

Marc Cornellà's avatar
Marc Cornellà committed
9
# ignore VCS folders (if the necessary grep flags are available)
10
VCS_FOLDERS="{.bzr,.cvs,.git,.hg,.svn}"
11

12
if grep-flag-available --exclude-dir=.cvs; then
13
    GREP_OPTIONS+=" --exclude-dir=$VCS_FOLDERS"
14
elif grep-flag-available --exclude=.cvs; then
15
    GREP_OPTIONS+=" --exclude=$VCS_FOLDERS"
16
17
fi

Marc Cornellà's avatar
Marc Cornellà committed
18
# export grep settings
19
20
export GREP_OPTIONS="$GREP_OPTIONS"
export GREP_COLOR='1;32'
Marc Cornellà's avatar
Marc Cornellà committed
21
22
23
24

# clean up
unset VCS_FOLDERS
unfunction grep-flag-available