grep.zsh 578 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
alias grep="grep $GREP_OPTIONS"
Marc Cornellà's avatar
Marc Cornellà committed
20
21

# clean up
22
unset GREP_OPTIONS
Marc Cornellà's avatar
Marc Cornellà committed
23
24
unset VCS_FOLDERS
unfunction grep-flag-available