conf2/zsh/.oh-my-zsh/lib/grep.zsh

29 lines
645 B
Bash
Raw Normal View History

# is x grep argument available?
grep-flag-available() {
echo | grep $1 "" >/dev/null 2>&1
}
2019-01-12 15:47:23 +00:00
GREP_OPTIONS=""
2019-01-12 15:47:23 +00:00
# color grep results
if grep-flag-available --color=auto; then
GREP_OPTIONS+=" --color=auto"
fi
2019-01-12 15:47:23 +00:00
# ignore VCS folders (if the necessary grep flags are available)
VCS_FOLDERS="{.bzr,CVS,.git,.hg,.svn}"
2020-06-11 14:41:32 +00:00
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"
2020-06-11 14:41:32 +00:00
fi
2019-01-12 15:47:23 +00:00
# export grep settings
alias grep="grep $GREP_OPTIONS"
# clean up
unset GREP_OPTIONS
unset VCS_FOLDERS
unfunction grep-flag-available