aboutsummaryrefslogtreecommitdiff
path: root/.oh-my-zsh/lib/grep.zsh
diff options
context:
space:
mode:
authorMarvin Borner2019-03-05 01:09:01 +0100
committerMarvin Borner2019-03-05 01:09:01 +0100
commit55457187d18221e76bd12f0fb2cfab65c49b92fb (patch)
tree8db042d2d80710d54100c2709ad4332153ac848a /.oh-my-zsh/lib/grep.zsh
Initial commit
Diffstat (limited to '.oh-my-zsh/lib/grep.zsh')
-rw-r--r--.oh-my-zsh/lib/grep.zsh28
1 files changed, 28 insertions, 0 deletions
diff --git a/.oh-my-zsh/lib/grep.zsh b/.oh-my-zsh/lib/grep.zsh
new file mode 100644
index 0000000..abc1650
--- /dev/null
+++ b/.oh-my-zsh/lib/grep.zsh
@@ -0,0 +1,28 @@
+# is x grep argument available?
+grep-flag-available() {
+ echo | grep $1 "" >/dev/null 2>&1
+}
+
+GREP_OPTIONS=""
+
+# color grep results
+if grep-flag-available --color=auto; then
+ GREP_OPTIONS+=" --color=auto"
+fi
+
+# ignore VCS folders (if the necessary grep flags are available)
+VCS_FOLDERS="{.bzr,CVS,.git,.hg,.svn}"
+
+if grep-flag-available --exclude-dir=.cvs; then
+ GREP_OPTIONS+=" --exclude-dir=$VCS_FOLDERS"
+elif grep-flag-available --exclude=.cvs; then
+ GREP_OPTIONS+=" --exclude=$VCS_FOLDERS"
+fi
+
+# export grep settings
+alias grep="grep $GREP_OPTIONS"
+
+# clean up
+unset GREP_OPTIONS
+unset VCS_FOLDERS
+unfunction grep-flag-available