我目前的解決方案是使用別名來限制我的智能選項對我的交互式輸入(而不是其他人的腳本)的使用。這是從我的bash_aliases grep的相關片段:
SMART_GREP_OPTIONS=
# Ensure colors are supported.
if [ -x /usr/bin/dircolors ]; then
SMART_GREP_OPTIONS=' --color=auto'
fi
# Make grep more like ack.
# Ignore binary files.
SMART_GREP_OPTIONS="$SMART_GREP_OPTIONS --binary-files=without-match"
# Check for exclude-dir to prevent invalid options in older versions of grep.
# Assume if we have exclude-dir, that we have exclude.
if /bin/grep --help | /bin/grep -- --exclude-dir &>/dev/null; then
# Ignore version control folders.
for PATTERN in .cvs .git .hg .svn; do
SMART_GREP_OPTIONS="$SMART_GREP_OPTIONS --exclude-dir=$PATTERN"
done
# Ignore temp files.
for PATTERN in *.swp; do
SMART_GREP_OPTIONS="$SMART_GREP_OPTIONS --exclude=$PATTERN"
done
fi
# This alias may override ghostscript. That's not a problem for me.
alias gs='grep $SMART_GREP_OPTIONS'
我做了我的大部分grepping從vim和使用vim-searchsavvy設置類似的選項(我不使用我的別名從VIM)。
另外:ack 2.0可以消除'-a'和'-u'標誌。 2.0中的默認值是選擇所有文本文件進行搜索,而不管文件類型如何。 – 2012-07-30 14:01:36
另外,請注意'ack -a'仍然不等於'grep',因爲ack仍然會忽略某些目錄和文件。 '-a'表示「所有文件類型」,而不是「所有文件」。 – 2013-04-11 21:34:47
從grep 2.20開始,不推薦使用GREP_OPTIONS:https://lists.gnu.org/archive/html/grep-commit/2014-09/msg00007.html – idbrii 2015-08-05 16:22:35