259be8d4935f34f31cb93b25a3753ef15e57bb49
[profile.git] / .profile.d / grep.bashrc
1 # profile-required: TERM.bashrc
2 # Use colours for grep if possible.
3 if grep -V 2>/dev/null | grep GNU >/dev/null; then
4   alias grep='grep --color=auto'
5
6   # Old versions of grep understand GREP_COLOR.
7   export GREP_COLOR='0;33'
8
9   # Newer versions allow setting colours based on context, using GREP_COLORS.
10   # cx: Lines of context; sl: Matching lines; mt: Search string; fn: Filename
11   # ln: Line number; bn: Byte offset; se: Separators.
12   colours=$(tput colors 2>/dev/null)
13   [ -z "$colours" ] && colours=0
14   if [ $colours = 256 ]; then
15     export GREP_COLORS='cx=38;5;246:sl=:mt=33:fn=38;5;25:ln=38;5;82:bn=33:se=38;5;246'
16   elif [ $colours -gt 88 ]; then
17     export GREP_COLORS='cx=38;5;84:sl=:mt=33:fn=38;5;22:ln=38;5;44:bn=33:se=38;5;84'
18   else
19     export GREP_COLORS='cx=31:sl=:mt=33:fn=36:ln=34:bn=33:se=31'
20   fi
21 fi