oh-my-bash/lib/grep.sh

33 lines
824 B
Bash
Raw Normal View History

#! bash oh-my-bash.module
2017-03-20 19:51:00 +07:00
# is x grep argument available?
_omb_grep_flag_available() {
echo | grep $1 "" >/dev/null 2>&1
2017-03-20 19:51:00 +07:00
}
_omb_grep_options=()
2017-03-20 19:51:00 +07:00
# color grep results
if _omb_grep_flag_available --color=auto; then
_omb_grep_options+=( "--color=auto" )
2017-03-20 19:51:00 +07:00
fi
# ignore VCS folders (if the necessary grep flags are available)
_omb_grep_vcs_folders="{.bzr,CVS,.git,.hg,.svn}"
2017-03-20 19:51:00 +07:00
if _omb_grep_flag_available --exclude-dir=.cvs; then
_omb_grep_options+=( "--exclude-dir=$_omb_grep_vcs_folders" )
elif _omb_grep_flag_available --exclude=.cvs; then
_omb_grep_options+=( "--exclude=$_omb_grep_vcs_folders" )
2017-03-20 19:51:00 +07:00
fi
# export grep settings
if ((${#_omb_grep_options[@]} > 0)); then
alias grep="grep ${_omb_grep_options[*]}"
fi
2017-03-20 19:51:00 +07:00
# clean up
unset -v _omb_grep_options
unset -v _omb_grep_vcs_folders
unset -f _omb_grep_flag_available