9385b3ee0a8425ae8a2b5c16084d4fab1ebc3764

Author
Dmitriy <me@kemko.ru>
Committer
kemko <me@kemko.ru>
Date

Message

set exclude-dir or exclude grep flags only if available

Diff

 1diff --git a/lib/grep.zsh b/lib/grep.zsh
 2index 977435ee4041424f24efa25d3531697f4a706adf..276fec382ffbb056fc4f77ef01c0f0a94f22ef94 100644
 3--- a/lib/grep.zsh
 4+++ b/lib/grep.zsh
 5@@ -3,11 +3,22 @@
 6 # Examples: http://rubyurl.com/ZXv
 7 #
 8 
 9-# avoid VCS folders
10-GREP_OPTIONS=
11-for PATTERN in .cvs .git .hg .svn; do
12-    GREP_OPTIONS+="--exclude-dir=$PATTERN "
13-done
14-GREP_OPTIONS+="--color=auto"
15+GREP_OPTIONS="--color=auto"
16+
17+# avoid VCS folders (if the necessary grep flags are available)
18+grep-flag-available() {
19+    echo | grep $1 "" >/dev/null 2>&1
20+}
21+if grep-flag-available --exclude-dir=.cvs; then
22+    for PATTERN in .cvs .git .hg .svn; do
23+        GREP_OPTIONS+=" --exclude-dir=$PATTERN"
24+    done
25+elif grep-flag-available --exclude=.cvs; then
26+    for PATTERN in .cvs .git .hg .svn; do
27+        GREP_OPTIONS+=" --exclude=$PATTERN"
28+    done
29+fi
30+unfunction grep-flag-available
31+
32 export GREP_OPTIONS="$GREP_OPTIONS"
33 export GREP_COLOR='1;32'