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?
|
||||
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() {
|
||||
# Is grep argument $1 available?
|
||||
grep-flag-available() {
|
||||
echo | grep $1 "" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# export grep settings
|
||||
alias grep="grep $GREP_OPTIONS"
|
||||
# Color grep results.
|
||||
local GREP_OPTIONS="--color=auto"
|
||||
|
||||
# clean up
|
||||
unset GREP_OPTIONS
|
||||
unset VCS_FOLDERS
|
||||
unfunction grep-flag-available
|
||||
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
|
||||
|
||||
# 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