mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-03-13 03:12:21 +01:00
grep: use a function instead of aliases, and auto-add '-r' for dirs
This commit is contained in:
parent
330f02a245
commit
bd505c9db3
1 changed files with 14 additions and 5 deletions
19
lib/grep.zsh
19
lib/grep.zsh
|
|
@ -15,14 +15,23 @@ _setup_grep_alias() {
|
||||||
elif grep-flag-available --exclude=.cvs; then
|
elif grep-flag-available --exclude=.cvs; then
|
||||||
GREP_OPTIONS+=(--exclude=$VCS_FOLDERS)
|
GREP_OPTIONS+=(--exclude=$VCS_FOLDERS)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Re-define alias.
|
|
||||||
alias grep="grep $GREP_OPTIONS"
|
|
||||||
|
|
||||||
# Clean up.
|
# Clean up.
|
||||||
unfunction grep-flag-available
|
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.
|
# Run it on first invocation.
|
||||||
command grep $GREP_OPTIONS "$@"
|
grep $GREP_OPTIONS "$@"
|
||||||
}
|
}
|
||||||
alias grep=_setup_grep_alias
|
alias grep=_setup_grep_alias
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue