From 0bd3c9996fa58494fbefaad483abbe60ed332889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sat, 13 Dec 2014 19:13:27 +0100 Subject: [PATCH 1/5] Extract VCS folders definition to avoid repetition --- lib/grep.zsh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/grep.zsh b/lib/grep.zsh index 276fec38..ad38ec6f 100644 --- a/lib/grep.zsh +++ b/lib/grep.zsh @@ -6,18 +6,17 @@ GREP_OPTIONS="--color=auto" # avoid VCS folders (if the necessary grep flags are available) +VCS_FOLDERS="{.cvs,.git,.hg,.svn}" + grep-flag-available() { echo | grep $1 "" >/dev/null 2>&1 } if grep-flag-available --exclude-dir=.cvs; then - for PATTERN in .cvs .git .hg .svn; do - GREP_OPTIONS+=" --exclude-dir=$PATTERN" - done + GREP_OPTIONS+=" --exclude-dir=$VCS_FOLDERS" elif grep-flag-available --exclude=.cvs; then - for PATTERN in .cvs .git .hg .svn; do - GREP_OPTIONS+=" --exclude=$PATTERN" - done + GREP_OPTIONS+=" --exclude=$VCS_FOLDERS" fi +unset VCS_FOLDERS unfunction grep-flag-available export GREP_OPTIONS="$GREP_OPTIONS" From cf586b54b8aacd7fad7afc74d4f395da56e828b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sat, 13 Dec 2014 19:14:23 +0100 Subject: [PATCH 2/5] Ignore .bzr folders in grep too --- lib/grep.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/grep.zsh b/lib/grep.zsh index ad38ec6f..4a44113e 100644 --- a/lib/grep.zsh +++ b/lib/grep.zsh @@ -6,7 +6,7 @@ GREP_OPTIONS="--color=auto" # avoid VCS folders (if the necessary grep flags are available) -VCS_FOLDERS="{.cvs,.git,.hg,.svn}" +VCS_FOLDERS="{.bzr,.cvs,.git,.hg,.svn}" grep-flag-available() { echo | grep $1 "" >/dev/null 2>&1 From 0190eb084bfb39bfa5920f85c2fc33730236217c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sat, 13 Dec 2014 19:18:11 +0100 Subject: [PATCH 3/5] Use unaliased grep in flag check --- lib/grep.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/grep.zsh b/lib/grep.zsh index 4a44113e..06751db1 100644 --- a/lib/grep.zsh +++ b/lib/grep.zsh @@ -9,7 +9,7 @@ GREP_OPTIONS="--color=auto" VCS_FOLDERS="{.bzr,.cvs,.git,.hg,.svn}" grep-flag-available() { - echo | grep $1 "" >/dev/null 2>&1 + echo | command grep $1 "" >/dev/null 2>&1 } if grep-flag-available --exclude-dir=.cvs; then GREP_OPTIONS+=" --exclude-dir=$VCS_FOLDERS" From 711843153d6e53a89d37931217f59c4f6a3a35db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sat, 13 Dec 2014 19:36:57 +0100 Subject: [PATCH 4/5] Tidy up the grep.zsh library --- lib/grep.zsh | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/grep.zsh b/lib/grep.zsh index 06751db1..4e55464c 100644 --- a/lib/grep.zsh +++ b/lib/grep.zsh @@ -1,23 +1,24 @@ -# -# Color grep results -# Examples: http://rubyurl.com/ZXv -# +# is x grep argument available? +grep-flag-available() { + echo | grep $1 "" >/dev/null 2>&1 +} +# color grep results GREP_OPTIONS="--color=auto" -# avoid VCS folders (if the necessary grep flags are available) +# ignore VCS folders (if the necessary grep flags are available) VCS_FOLDERS="{.bzr,.cvs,.git,.hg,.svn}" -grep-flag-available() { - echo | command grep $1 "" >/dev/null 2>&1 -} 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 -unset VCS_FOLDERS -unfunction grep-flag-available +# export grep settings export GREP_OPTIONS="$GREP_OPTIONS" export GREP_COLOR='1;32' + +# clean up +unset VCS_FOLDERS +unfunction grep-flag-available From dd270878053a73600382de1c3592c04d985e5e08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20S=C3=BAkup?= Date: Mon, 24 Nov 2014 13:08:39 +0100 Subject: [PATCH 5/5] Change to alias and remove deprecated GREP_COLOR --- lib/grep.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/grep.zsh b/lib/grep.zsh index 4e55464c..348ebe62 100644 --- a/lib/grep.zsh +++ b/lib/grep.zsh @@ -16,9 +16,9 @@ elif grep-flag-available --exclude=.cvs; then fi # export grep settings -export GREP_OPTIONS="$GREP_OPTIONS" -export GREP_COLOR='1;32' +alias grep="grep $GREP_OPTIONS" # clean up +unset GREP_OPTIONS unset VCS_FOLDERS unfunction grep-flag-available