mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-20 03:02:29 +01:00
Merge c21685c13e into a9061f34d7
This commit is contained in:
commit
68069caa7e
1 changed files with 30 additions and 4 deletions
34
lib/grep.zsh
34
lib/grep.zsh
|
|
@ -3,11 +3,37 @@
|
|||
# Examples: http://rubyurl.com/ZXv
|
||||
#
|
||||
|
||||
# avoid VCS folders
|
||||
GREP_OPTIONS=
|
||||
for PATTERN in .cvs .git .hg .svn; do
|
||||
GREP_OPTIONS+="--exclude-dir=$PATTERN "
|
||||
done
|
||||
|
||||
# returns 0 if the first version number is greater than or equal to the second.
|
||||
# returns 1 if the first version number is greater than or equal to the second.
|
||||
function versionCompare() {
|
||||
local LEAST_VERSION=$(echo -e "$1\n$2" | sort -t '.' -g | head -n 1)
|
||||
if [[ $LEAST_VERSION = $1 ]]; then
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
# avoid VCS folders. This chooses a different argument based on grep version.
|
||||
# grep version 2.5+ is required for any support of this feature.
|
||||
function ignoreVCS() {
|
||||
local GREP_VERSION=$(grep --version | head -n 1 | sed -e 's/^.* \([0-9]\{1,\}\(\.[0-9a-z]\{1,\}\)\{1,\}\)-.*/\1/')
|
||||
|
||||
for PATTERN in .cvs .git .hg .svn; do
|
||||
# logically, if(GREP_VERSION >= 2.5.3)
|
||||
if versionCompare "2.5.3" $GREP_VERSION; then
|
||||
GREP_OPTIONS+="--exclude-dir=$PATTERN "
|
||||
# logically, if(GREP_VERSION >= 2.5)
|
||||
elif versionCompare "2.5" $GREP_VERSION; then
|
||||
GREP_OPTIONS+="--exclude=$PATTERN "
|
||||
fi
|
||||
done
|
||||
}
|
||||
ignoreVCS;
|
||||
unfunction versionCompare
|
||||
unfunction ignoreVCS
|
||||
|
||||
GREP_OPTIONS+="--color=auto"
|
||||
export GREP_OPTIONS="$GREP_OPTIONS"
|
||||
export GREP_COLOR='1;32'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue