mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-03-20 03:13:33 +01:00
Merge bd505c9db3 into efd6d4d593
This commit is contained in:
commit
411b6a3813
1 changed files with 33 additions and 20 deletions
53
lib/grep.zsh
53
lib/grep.zsh
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue