This commit is contained in:
Daniel Hahler 2015-02-22 09:43:18 +00:00
commit 411b6a3813

View file

@ -1,24 +1,37 @@
# is x grep argument available? # Ignore VCS folders (if the necessary grep flags are 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)
VCS_FOLDERS="{.bzr,.cvs,.git,.hg,.svn}" VCS_FOLDERS="{.bzr,.cvs,.git,.hg,.svn}"
if grep-flag-available --exclude-dir=.cvs; then _setup_grep_alias() {
GREP_OPTIONS+=" --exclude-dir=$VCS_FOLDERS" local GREP_OPTIONS
elif grep-flag-available --exclude=.cvs; then # Color grep results.
GREP_OPTIONS+=" --exclude=$VCS_FOLDERS" GREP_OPTIONS=(--color=auto)
fi
# export grep settings # Is grep argument $1 available?
alias grep="grep $GREP_OPTIONS" grep-flag-available() {
echo | 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
# Clean up.
unfunction grep-flag-available
# clean up # Remove alias and setup function.
unset GREP_OPTIONS unalias grep
unset VCS_FOLDERS setopt localoptions norcexpandparam
unfunction grep-flag-available eval "grep() {
local options
options=(${(@)GREP_OPTIONS})
# Add '-r' if grepping a dir.
if [[ -d \$@[\$#] ]]; then
options+=(-r)
fi
command grep \$options \"\$@\"
}"
# Run it on first invocation.
grep $GREP_OPTIONS "$@"
}
alias grep=_setup_grep_alias