ohmyzsh/lib/grep.zsh
Daniel Hahler fec736f7f6 Setup grep alias lazily through a function
This saves an extra / initial call to `grep` during shell startup.
2015-01-07 03:36:40 +01:00

25 lines
660 B
Bash

# Ignore VCS folders (if the necessary grep flags are available).
VCS_FOLDERS="{.bzr,.cvs,.git,.hg,.svn}"
_setup_grep_alias() {
# Is grep argument $1 available?
grep-flag-available() {
echo | grep $1 "" >/dev/null 2>&1
}
# Color grep results.
local GREP_OPTIONS="--color=auto"
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