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?
|
||||
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)
|
||||
# Ignore VCS folders (if the necessary grep flags are available).
|
||||
VCS_FOLDERS="{.bzr,.cvs,.git,.hg,.svn}"
|
||||
|
||||
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
|
||||
_setup_grep_alias() {
|
||||
local GREP_OPTIONS
|
||||
# Color grep results.
|
||||
GREP_OPTIONS=(--color=auto)
|
||||
|
||||
# export grep settings
|
||||
alias grep="grep $GREP_OPTIONS"
|
||||
# Is grep argument $1 available?
|
||||
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
|
||||
unset GREP_OPTIONS
|
||||
unset VCS_FOLDERS
|
||||
unfunction grep-flag-available
|
||||
# Remove alias and setup function.
|
||||
unalias grep
|
||||
setopt localoptions norcexpandparam
|
||||
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