From 5afd2a42fd9b8d44ce8a031e827015e5baa3155b 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/4] Extract VCS folders to avoid repetition --- lib/grep.zsh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/grep.zsh b/lib/grep.zsh index 276fec382..60a105d80 100644 --- a/lib/grep.zsh +++ b/lib/grep.zsh @@ -6,17 +6,15 @@ GREP_OPTIONS="--color=auto" # avoid VCS folders (if the necessary grep flags are available) +local 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 unfunction grep-flag-available From 0e59a2c368e22f042622ec9c27a556ccdf9d3b7f 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/4] 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 60a105d80..2976ca329 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) -local VCS_folders="{.cvs,.git,.hg,.svn}" +local VCS_folders="{.bzr,.cvs,.git,.hg,.svn}" grep-flag-available() { echo | grep $1 "" >/dev/null 2>&1 From 37f88a73ff20094cafc3800383ae0349950699f6 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/4] 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 2976ca329..f7798f3dd 100644 --- a/lib/grep.zsh +++ b/lib/grep.zsh @@ -9,7 +9,7 @@ GREP_OPTIONS="--color=auto" local 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 15d529157f6685e4cc9cc28781afa17ac0e5d4e2 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/4] Delete grep variables after we use them --- lib/grep.zsh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/grep.zsh b/lib/grep.zsh index f7798f3dd..7cc20952e 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) -local VCS_folders="{.bzr,.cvs,.git,.hg,.svn}" +VCS_folders="{.bzr,.cvs,.git,.hg,.svn}" grep-flag-available() { echo | command grep $1 "" >/dev/null 2>&1 @@ -16,7 +16,11 @@ if grep-flag-available --exclude-dir=.cvs; then elif grep-flag-available --exclude=.cvs; then GREP_OPTIONS+=" --exclude=$VCS_folders" fi -unfunction grep-flag-available export GREP_OPTIONS="$GREP_OPTIONS" export GREP_COLOR='1;32' + + +# cleanup +unset VCS_folders +unfunction grep-flag-available