diff --git a/lib/grep.zsh b/lib/grep.zsh index 348ebe623..9a2c6f5a3 100644 --- a/lib/grep.zsh +++ b/lib/grep.zsh @@ -1,24 +1,25 @@ -# is x grep argument available? -grep-flag-available() { - echo | grep $1 "" >/dev/null 2>&1 -} - -# color grep results -GREP_OPTIONS="--color=auto" - -# ignore 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}" -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 +_setup_grep_alias() { + # Is grep argument $1 available? + grep-flag-available() { + echo | grep $1 "" >/dev/null 2>&1 + } -# export grep settings -alias grep="grep $GREP_OPTIONS" + # Color grep results. + local GREP_OPTIONS="--color=auto" -# clean up -unset GREP_OPTIONS -unset VCS_FOLDERS -unfunction grep-flag-available + 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 + + # Re-define alias. + alias grep="grep $GREP_OPTIONS" + + # Clean up. + unfunction grep-flag-available +} +alias grep=_setup_grep_alias