mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-03-13 03:12:21 +01:00
Setup grep alias lazily through a function
This saves an extra / initial call to `grep` during shell startup.
This commit is contained in:
parent
175b4a8073
commit
fec736f7f6
1 changed files with 20 additions and 19 deletions
41
lib/grep.zsh
41
lib/grep.zsh
|
|
@ -1,24 +1,25 @@
|
||||||
# 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"
|
# Is grep argument $1 available?
|
||||||
elif grep-flag-available --exclude=.cvs; then
|
grep-flag-available() {
|
||||||
GREP_OPTIONS+=" --exclude=$VCS_FOLDERS"
|
echo | grep $1 "" >/dev/null 2>&1
|
||||||
fi
|
}
|
||||||
|
|
||||||
# export grep settings
|
# Color grep results.
|
||||||
alias grep="grep $GREP_OPTIONS"
|
local GREP_OPTIONS="--color=auto"
|
||||||
|
|
||||||
# clean up
|
if grep-flag-available --exclude-dir=.cvs; then
|
||||||
unset GREP_OPTIONS
|
GREP_OPTIONS+=" --exclude-dir=$VCS_FOLDERS"
|
||||||
unset VCS_FOLDERS
|
elif grep-flag-available --exclude=.cvs; then
|
||||||
unfunction grep-flag-available
|
GREP_OPTIONS+=" --exclude=$VCS_FOLDERS"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Re-define alias.
|
||||||
|
alias grep="grep $GREP_OPTIONS"
|
||||||
|
|
||||||
|
# Clean up.
|
||||||
|
unfunction grep-flag-available
|
||||||
|
}
|
||||||
|
alias grep=_setup_grep_alias
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue