mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-03-20 03:13:33 +01:00
From grep version 2.21, using environment variable `GREP_OPTIONS' to set common parameters to grep calls is deprecated. As an alternative, we use a custom function to pass in our defined `GREP_OPTIONS`, while at the same time preserving any aliases that called grep. If we choose the alias way as suggested in the grep documentation, we'll overwrite any already defined grep aliases, or get overwritten by any subsequently defined user aliases.
28 lines
703 B
Bash
28 lines
703 B
Bash
#
|
|
# Color grep results
|
|
# Examples: http://rubyurl.com/ZXv
|
|
#
|
|
|
|
# color grep output
|
|
GREP_OPTIONS="--color=auto"
|
|
|
|
# avoid VCS folders (if the necessary grep flags are available)
|
|
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
|
|
elif grep-flag-available --exclude=.cvs; then
|
|
for PATTERN in .cvs .git .hg .svn; do
|
|
GREP_OPTIONS+=" --exclude=$PATTERN"
|
|
done
|
|
fi
|
|
unfunction grep-flag-available
|
|
|
|
# define grep wrapper (GREP_OPTIONS env var is deprecated)
|
|
eval "function grep {
|
|
command grep $GREP_OPTIONS \"\$@\"
|
|
}"
|
|
unset GREP_OPTIONS
|