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

13
14
# ignore these folders (if the necessary grep flags are available)
EXC_FOLDERS="{.bzr,CVS,.git,.hg,.svn,.idea}"
15

16
if grep-flag-available --exclude-dir=.cvs; then
17
    GREP_OPTIONS+=" --exclude-dir=$EXC_FOLDERS"
18
elif grep-flag-available --exclude=.cvs; then
19
    GREP_OPTIONS+=" --exclude=$EXC_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
27
unset EXC_FOLDERS
Marc Cornellà's avatar
Marc Cornellà committed
28
unfunction grep-flag-available