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
|
||||
GREP_OPTIONS+=(--exclude=$VCS_FOLDERS)
|
||||
fi
|
||||
|
||||
# Re-define alias.
|
||||
alias grep="grep $GREP_OPTIONS"
|
||||
|
||||
# Clean up.
|
||||
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.
|
||||
command grep $GREP_OPTIONS "$@"
|
||||
grep $GREP_OPTIONS "$@"
|
||||
}
|
||||
alias grep=_setup_grep_alias
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue