bashrc: Add aliases for egrep and fgrep.
[profile] / bashrc
diff --git a/bashrc b/bashrc
index a172640..7f4cd74 100644 (file)
--- a/bashrc
+++ b/bashrc
@@ -1,6 +1,4 @@
-# -*-sh-*-
-#
-# $Id: .bashrc,v 1.6 1996/12/08 20:33:42 mdw Exp $
+# -*- mode: sh; coding: utf-8 -*-
 #
 # Bash session things
 #
@@ -16,49 +14,49 @@ __mdw_bashrc=done
 
 if [ -t 0 ]; then
 
-  if [ "$TERM" = "dumb" ]; then
-    if (( EUID == 0 )); then PS1="# "; else PS1="\$ "; fi
-    PS2="> "
-    PS4="+ "
+  case "$TERM" in
+    linux*|screen*|xterm*|vt100*|eterm*)
+      bold="\[$(tput bold)\]" unbold="\[$(tput sgr0)\]" nl="\[\r\]" ;;
+    *)
+      bold='' unbold='' nl='' ;;
+  esac
+
+  if (( EUID == 0 )); then
+    left=`echo « | iconv -f utf8 -t //translit`
+    right=`echo » | iconv -f utf8 -t //translit`
   else
-    
-    case "$TERM" in
-      linux*|screen*|xterm*|vt100*)
-       bold='\[\e[1m\]' unbold='\[\e[m\]' nl='\[\r\]' ;;
+    case $USER in
+      mdw|mwooding)
+       u="" left="[" right="]"
+       ;;
       *)
-       bold='' unbold='' nl='' ;;
+       u="\\u@" left="{" right="}"
+       ;;
     esac
-
-    if (( EUID == 0 )); then
-      left="«" right="»"
+    if [ "$__mdw_tty" = "`tty`" ]; then
+      left="<" right=">"
     else
-      case $USER in
-        mdw|mwooding)
-         u="" left="[" right="]"
-         ;;
-       *)
-         u="\\u@" left="{" right="}"
-         ;;
-      esac
-      if [ "$__mdw_tty" = "`tty`" ]; then
-       left="<" right=">"
-      else
-        export __mdw_tty="`tty`"
-      fi
-    fi
-
-    if [ -z "$SSH_CLIENT" ] &&
-      [ "$__mdw_sechost" != "`hostname`" ]
-      then
-      sec_l='(' sec_r=')'
+      export __mdw_tty="`tty`"
     fi
+  fi
 
-    PS1="$nl$bold$left$sec_l$u\\h$sec_r \\w$right$unbold"
-    PS2="$PS1 $bold>$unbold "
+  if [ -z "$SSH_CLIENT" ] &&
+    [ "$__mdw_sechost" != "`hostname`" ]
+    then
+    sec_l='(' sec_r=')'
   fi
 
+  PS1="$nl$bold$left$sec_l$u\\h$sec_r \\w$right$unbold"
+  PS2="$PS1 $bold>$unbold "
+
 fi # is stdin a tty?
 
+# --- Pagers are less useful within Emacs ---
+
+case "$INSIDE_EMACS" in
+  22.*,comint) export PAGER=cat ;;
+esac
+
 # --- Little preferences ---
 
 notify=1
@@ -86,7 +84,7 @@ shopt -u shift_verbose
 shopt -s sourcepath
 
 # --- Set the CDPATH ---
-# 
+#
 # CDPATH=~/src:/usr/src:/usr/lib:/usr/share
 # dots=..
 # i=6
@@ -100,8 +98,7 @@ shopt -s sourcepath
 # --- Some colour `ls' support ---
 
 [ "${TMPDIR+yes}" ] || eval `tmpdir -b`
-if [ -x /usr/bin/dircolors -o -x /usr/local/bin/dircolors ] &&
-   [ "$TERM" != "dumb" ]; then
+if [ -x /usr/bin/dircolors -o -x /usr/local/bin/dircolors ]; then
   eval `dircolors -b ~/.dircolors`
 else
   unset LS_COLORS
@@ -115,6 +112,22 @@ ls () {
   fi
 }
 
+# --- Some colour `grep' support ---
+
+export GREP_COLORS="mt=01;31:ms=01;31:mc=031;31:fn=36:ln=36:bn=36:se=34"
+
+greplike () {
+  declare grep=$1; shift
+  if [ -t 1 ]; then
+    command $grep ${GREP_COLORS+--color=auto} "$@"
+  else
+    command $grep "$@"
+  fi
+}
+alias grep="greplike grep"
+alias egrep="greplike egrep"
+alias fgrep="greplike fgrep"
+
 # --- Set up some simple aliases ---
 
 alias cx='chmod a+x'
@@ -123,13 +136,16 @@ alias ssync="rsync -e ssh"
 alias rootly=$__MDW_ROOTLY
 alias r=rootly
 alias re="rootly $EDITOR"
-alias pstree="pstree -Ghl"
+alias pstree="pstree -hl"
 alias cdtmp='cd ${TMPDIR-/tmp}'
 alias pushtmp='pushd ${TMPDIR-/tmp}'
 alias e="$EDITOR"
 alias svn="svnwrap svn"
 alias @="ssh"
 
+[ -r /etc/bash_completion ] && . /etc/bash_completion
+[ -r $HOME/.bash_completion ] && . $HOME/.bash_completion
+
 # --- Make `xt' start an xterm, maybe logging into a remote host ---
 
 xt () {
@@ -234,13 +250,13 @@ pathhack () {
        continue
        ;;
       --)
-        shift
+       shift
        break
        ;;
       [-+]*)
-        ;;
+       ;;
       *)
-        break
+       break
        ;;
     esac
     hack=${arg#[+-]}
@@ -251,16 +267,16 @@ pathhack () {
     }
     case "$arg,$force,:$PATH:" in
       -*,*,*:"$dir":*)
-        path-remove path "$dir"
+       path-remove path "$dir"
        ;;
       +*,t,*:"$dir":*)
-        path-remove path "$dir"
+       path-remove path "$dir"
        path-add path "$dir"
        ;;
       +*,nil,*:"$dir":*)
-        ;;
+       ;;
       +*,*)
-        path-add path "$dir"
+       path-add path "$dir"
        ;;
     esac
     shift