2022-01-15 19:00:35 +09:00
|
|
|
#! bash oh-my-bash.module
|
2022-01-02 00:25:30 +09:00
|
|
|
|
2017-03-20 19:51:00 +07:00
|
|
|
# is x grep argument available?
|
2022-01-02 00:25:30 +09:00
|
|
|
_omb_grep_flag_available() {
|
|
|
|
echo | grep $1 "" >/dev/null 2>&1
|
2017-03-20 19:51:00 +07:00
|
|
|
}
|
|
|
|
|
2022-01-02 00:25:30 +09:00
|
|
|
_omb_grep_options=()
|
2017-03-20 19:51:00 +07:00
|
|
|
|
|
|
|
# color grep results
|
2022-01-02 00:25:30 +09:00
|
|
|
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)
|
2022-01-02 00:25:30 +09:00
|
|
|
_omb_grep_vcs_folders="{.bzr,CVS,.git,.hg,.svn}"
|
2017-03-20 19:51:00 +07:00
|
|
|
|
2022-01-02 00:25:30 +09: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
|
2022-01-02 00:25:30 +09:00
|
|
|
if ((${#_omb_grep_options[@]} > 0)); then
|
2022-07-03 13:12:07 +09:00
|
|
|
_omb_util_alias grep="grep ${_omb_grep_options[*]}"
|
2022-07-14 22:12:51 +09:00
|
|
|
_omb_util_alias fgrep="fgrep ${_omb_grep_options[*]}"
|
|
|
|
_omb_util_alias egrep="egrep ${_omb_grep_options[*]}"
|
2021-07-27 17:21:59 -04:00
|
|
|
fi
|
2017-03-20 19:51:00 +07:00
|
|
|
|
|
|
|
# clean up
|
2022-01-02 00:25:30 +09:00
|
|
|
unset -v _omb_grep_options
|
|
|
|
unset -v _omb_grep_vcs_folders
|
|
|
|
unset -f _omb_grep_flag_available
|