diff rc/bash @ 270:0e41725e7d38

Grep, GNU Grep, Solaris Grep, etc.
author Edho Arief <edho@myconan.net>
date Thu, 24 Nov 2011 15:21:33 +0700
parents cd48b7a5cddd
children 003b0c8870b3
line wrap: on
line diff
--- a/rc/bash	Thu Nov 24 15:10:24 2011 +0700
+++ b/rc/bash	Thu Nov 24 15:21:33 2011 +0700
@@ -35,12 +35,16 @@
 _has_gnu_ls=
 _has_gnu_grep=
 _ls="ls"
+_grep="grep"
+_has_posix_grep=y
+
 case "$(uname -s)" in
   Linux)
     _has_gnu_ls=y
     _has_gnu_grep=y
   ;;
   SunOS)
+    _has_posix_grep=n
     [ -x /usr/gnu/bin/ls ] && _has_gnu_ls=y
     [ -x /usr/gnu/bin/grep ] && _has_gnu_grep=y
     # Higher priority directories
@@ -61,6 +65,10 @@
       echo "No xterm-256color, using dtterm. Tmux title won't work."
     fi
     [ -f /usr/share/lib/terminfo/?/"${TERM}" ] || export TERM=dtterm
+    if command -v ggrep > /dev/null 2>&1; then
+      _has_gnu_grep=y
+      _grep="ggrep"
+    fi
   ;;
   OpenBSD)
     PATH="${PATH}:/usr/X11R6/bin"
@@ -86,11 +94,20 @@
 esac
 
 [ "${_has_gnu_ls}" = y ] && alias ls="${_ls} -F --color=auto"
-[ "${_has_gnu_grep}" = y ] && alias grep="grep --color=auto"
+if [ "${_has_gnu_grep}" = y ]; then
+  alias grep="${_grep} --color=auto"
+  _has_posix_grep=y
+fi
+if [ "${_has_posix_grep}" = y ]; then
+  alias fgrep="grep -F"
+  alias egrep="grep -E"
+fi
 
 unset _has_gnu_ls
 unset _has_gnu_grep
+unset _has_posix_grep
 unset _ls
+unset _grep
 
 # Custom application I usually install and safe to prioritize
 for i in {"${HOME}/app","/opt"}/{tmux,ruby19,node,tarsnap,symon,nginx}/{bin,sbin}; do