grep.zsh 737 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
# ignore these folders (if the necessary grep flags are available)
Shi Yan's avatar
Shi Yan committed
14
EXC_FOLDERS="{.bzr,CVS,.git,.hg,.svn,.idea,.tox}"
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

22
# export grep, egrep and fgrep settings
23
alias grep="grep $GREP_OPTIONS"
24
25
alias egrep="egrep $GREP_OPTIONS"
alias fgrep="fgrep $GREP_OPTIONS"
Marc Cornellà's avatar
Marc Cornellà committed
26
27

# clean up
Shi Yan's avatar
Shi Yan committed
28
unset GREP_OPTIONS EXC_FOLDERS
Marc Cornellà's avatar
Marc Cornellà committed
29
unfunction grep-flag-available