Removed /usr/local from CDPATH
[clearscm.git] / rc / bash_login
index 79d1c60..bd91f1c 100644 (file)
@@ -1,7 +1,7 @@
 ################################################################################
 #
 # File:         $RCSfile: bash_login,v $
-# Revision:        $Revision: 1.29 $
+# Revision:    $Revision: 1.29 $
 # Description:  bash startup file
 # Author:       Andrew@DeFaria.com
 # Created:      Mon Aug 20 17:35:01  2001
 # (c) Copyright 2000-2005, Andrew@DeFaria.com, all rights reserved.
 #
 ################################################################################
+# The following will set HOME, temporarily, to the directory of my $HOME so that
+# somebody other than me can envoke my startup scripts. I use this mainly for
+# when I become root with sudo -s and what a better environment that the bare
+# bones root environment gives you. Note that for us to be effective one must
+# source (or .) this file and if so the ${BASH_ARGV[0]} is the normal $0
+if [ -n "${BASH_ARGV[0]}" ]; then
+  home=$(dirname ${BASH_ARGV[0]})
+else
+  home=$HOME
+fi
+
+# Strip off .rc
+home=${home/%\/\.rc/}
+
+# Now set $HOME if $home is different.
+saved_home=$HOME
+if [ "$HOME" != "$home" ]; then
+  HOME=$home
+fi
+
 # Set ARCHITECTURE of the machine
 KERNEL=$(uname -s)
 if [[ $KERNEL = CYGWIN* ]]; then
@@ -21,17 +41,26 @@ elif [ $KERNEL = "SunOS" ]; then
   export ARCHITECTURE=sun
 elif [ $KERNEL = "FreeBSD" ]; then
   export ARCHITECTURE=$KERNEL
+elif [ $KERNEL = "Darwin" ]; then
+  export ARCHITECTURE=$KERNEL
 else
   export ARCHITECTURE=''
   echo "Warning: Unknown architecture ($KERNEL)"
 fi
 
-# Architectual differences (AKA Silly Sun)
-if [ $ARCHITECTURE = "sun" ]; then
-  alias id=/usr/xpg4/bin/id
-  alias tr=/usr/xpg4/bin/tr
-  
-  export id=/usr/xpg4/bin/id
+# Hack: Just set TERM to xterm
+if [ $ARCHITECTURE = 'sun' ]; then
+  id=/usr/xpg4/bin/id
+  tr=/usr/xpg4/bin/tr
+  TERM=xtermc
+else
+  id=id
+  tr=tr
+  if [ $ARCHITECTURE = 'cygwin' ]; then
+    TERM=cygwin
+  else
+    TERM=xterm
+  fi
 fi
 
 # Set colors
@@ -49,6 +78,7 @@ else
 fi
 
 export VISUAL=vi
+export EDITOR=vi
 
 # Terminal settings:
 if [ "$TERM" = ""        -o \
@@ -68,18 +98,10 @@ else
    export SYSNAME="*Unknown Systemname*:"
 fi
 
-# System dependencies
-# Note: I don't like doing this but an alias doesn't work...
-if [ $ARCHITECTURE = "sun" ]; then
-  id=/usr/xpg4/bin/id
-else
-  id=id
-fi
-
 umask 002
 
 if [ "$interactive" = "true" ]; then
-  stty tostop intr ^C kill ^X susp ^Z erase ^H -inpck -istrip -ixany -echok -echonl
+  stty tostop intr ^C kill ^X susp ^Z erase ^? -inpck -istrip -ixany -echok -echonl
 fi
 
 # Set adm_base
@@ -98,10 +120,23 @@ fi
 # Source bash_completion (if present) (too slow for Windows)
 if [ -r /etc/bash_completion -a $ARCHITECTURE != "cygwin" ]; then
   source /etc/bash_completion
+elif [ -r /usr/local/etc/bash_completion ]; then
+  source /usr/local/etc/bash_completion
 fi
 
-if [ -x ~/.rc/logout ]; then
-  trap "~/.rc/logout" 0
+# Windows aliases
+if [ $ARCHITECTURE = "cygwin" ]; then
+  alias ping=$(echo $SYSTEMROOT | tr '\\' '\/')/system32/ping
+  alias rdp=mstsc
+else
+  alias sys=systemctl
+fi
+
+# We specify /home/$USER here so that when we sudo to another user 
+# we will only trap logout if that user also has a ~/.rc/logout
+# (doubtfull).
+if [ -x /home/$USER/.rc/logout ]; then
+  trap "/home/$USER/.rc/logout" 0
 fi
 
 # ClearCase Stuff
@@ -130,14 +165,23 @@ set -o monitor
 set +u
 
 # Shell options
-shopt -s autocd
+if [ $ARCHITECTURE != 'Darwin' -a $ARCHITECTURE != 'sun' ]; then
+  ls /etc/*release > /dev/null 2>&1
+
+  if [ $? = 0 ]; then
+    if ! grep -qP '5\.(6|7|8|9|10)' /etc/*release; then
+      shopt -s autocd   > /dev/null 2>&1
+      shopt -s dirspell > /dev/null 2>&1
+    fi
+  fi
+fi
+
 shopt -s cdspell
-shopt -s dirspell
 shopt -s histappend
 shopt -s lithist
 
 # Aliases:
-if [ $ARCHITECTURE = "FreeBSD" ]; then
+if [ $ARCHITECTURE = "FreeBSD" -o $ARCHITECTURE = "Darwin" ]; then
   alias ls="ls -FG"
 else
   if [ -f ~/.rc/dircolors ]; then
@@ -149,7 +193,7 @@ else
   if [ $ARCHITECTURE = "sun" ]; then
     # Ugh! --color doesn't work on braindead SUN
     alias ls="ls -F"
-  else        
+  else
     alias ls="ls -F --color=auto"
   fi
 fi
@@ -157,6 +201,7 @@ fi
 alias ll="ls -la"
 alias whence="type -p"
 alias mroe=more
+alias gti=git
 
 if [ $ARCHITECTURE = "cygwin" ]; then
   alias host=nslookup
@@ -169,14 +214,18 @@ fi
 if [ -f "$SYSTEMDRIVE/Perl/bin/perl" ]; then
   alias asperl="$SYSTEMDRIVE/Perl64/bin/perl"
 fi
-  
-export LANG=C
 
-if [ $(type -p vim) ]; then
+if [ $(locale -a | grep -c en_US.utf8) != 0 ]; then
+  export LANG=en_US.utf8
+else
+  export LANG=C
+fi
+
+if [ "$(type -p vim)" ]; then
   alias vi=vim
 fi
 
-if [ $(type -p ncftp) ]; then
+if [ "$(type -p ncftp)" ]; then
   alias ftp=ncftp
   alias ftpput=ncftpput
   alias ftpget=ncftpget
@@ -184,13 +233,15 @@ fi
 
 #alias grep="grep -d skip"
 
-if [ "$TERM" = "hpterm"    -o \
-     "$TERM" = "hp"        -o \
-     "$TERM" = "dtterm"    -o \
-     "$TERM" = "sun-color" -o \
-     "$TERM" = "vt100"     -o \
-     "$TERM" = "vt220"     -o \
-     "$TERM" = "xterm"     -o \
+if [ "$TERM" = "hpterm"         -o \
+     "$TERM" = "hp"             -o \
+     "$TERM" = "dtterm"         -o \
+     "$TERM" = "sun-color"      -o \
+     "$TERM" = "vt100"          -o \
+     "$TERM" = "vt220"          -o \
+     "$TERM" = "xtermc"         -o \
+     "$TERM" = "xterm"          -o \
+     "$TERM" = "xterm-256color" -o \
      "$TERM" = "cygwin" ]; then
   alias cd=mycd
   alias pushd=mypushd
@@ -198,7 +249,7 @@ if [ "$TERM" = "hpterm"    -o \
 fi
 
 # Miscellaneous:
-if [ -x $(type -p less) ]; then
+if type -p less > /dev/null; then
    export LESS=eiXP"?f%f :[stdin] .?pt(%pt\%):?bt(%bt bytes):-.."
    alias more="less -sr"
    export PAGER="less -sr"
@@ -244,6 +295,11 @@ if [ -d /opt/clearscm/lib ]; then
   export PERL5LIB="$PERL5LIB:/opt/clearscm/lib"
 fi
 
+# Lessfile
+if type lessfile > /dev/null 2>&1; then
+  eval $(lessfile)
+fi
+
 # Client specific customizations
 for script in $(\ls ~/.rc/client_scripts); do
   # This is not working as long as ACLs are not supported from the remote
@@ -255,12 +311,29 @@ for script in $(\ls ~/.rc/client_scripts); do
      ! -d ~/.rc/client_scripts/$script ]; then
     source ~/.rc/client_scripts/$script
   fi
+
+  # Special case for cPanel. Above relies on just the execute bit but
+  # git tracks mode. So we can't have it executable while at home. So
+  # instead we will look if we are on a 10. network (i.e. at cPanel)
+  # verses a 192. network at home.
+  if [[ $(/bin/hostname -i) =~ 10\. && $script = "cPanel" ]]; then
+    source ~/.rc/client_scripts/$script
+  fi
 done
 
+# Set prompt as client customization may have changed things
+set_prompt
+
 # Set display to local
 export DISPLAY=${DISPLAY:-:0}
 
+# Reset home in case it changed
+HOME=$saved_home
+
+# Odd but Eclipse's Egit can't seem to work with defaria.com unless this is set.
+export GIT_SSH=/usr/bin/ssh
+
 # Now go home (in case we were not autmatically cd'ed there)
-if [ $(id -u) -ne 0 ]; then
+if [ $($id -u) -ne 0 ]; then
   cd
 fi