# Bourne Again SHell init file.
#
#set -xv

#  Henry Grebler    20 Jan 10  BSD.
#  Henry Grebler    14 Jan 10  Arch Linux.
#  Henry Grebler    31 Mar 00  On Linux (possibly elsewhere), need to set
#				stty stuff in .bashrc for xterms.
#  Henry Grebler    31 Oct 99  Use HMG_LD_LIBRARY_PATH if set.
#  Henry Grebler    19 Apr 99  Only change soft limit on core size. Hard
#				limit "cannot be increased once it is set".
#  Henry Grebler    29 Mar 99  Don't put duplicates on the history stack.
#  Henry Grebler    16 Mar 99  Enable su on Linux.
#  Henry Grebler    18 Feb 99  New bash (2) under Solaris 2.6 is driving me
#				crazy - it disables the meta key; turn it back
#				on.
#  Henry Grebler    11 Mar 98  Remove dsd; modify dsdt.
#  Henry Grebler    11 Mar 98  Add pgpck.
#  Henry Grebler    23 Dec 97  Set noclobber.
#  Henry Grebler     9 Sep 97  (CMGA) Add newline to PS1 always.
#  Henry Grebler     5 Aug 97  Don't try to avoid core files on HP (N/A).
#  Henry Grebler     1 Jul 97  Minor change in su for HP (handle su -).
#  Henry Grebler    31 Dec 96  Change prompt to have colon after hostname.
#  Henry Grebler    31 Jul 96  bash (and only bash) sometimes has a different
#				answer for pwd. Print both if different.
#  Henry Grebler    24 Jul 96  Add /usr/local/lib to LD_LIBRARY_PATH.
#  Henry Grebler    22 Mar 96  Always set LD_LIBRARY_PATH.
#  Henry Grebler    23 Nov 95  su on HP clears HOME.
#  Henry Grebler     6 Jul 95  Avoid problems if on wyse.
#  Henry Grebler    20 Mar 95  Fix PATH for non-login stuff.
#  Henry Grebler    16 Feb 95  Fix prompt to reflect new bash features.
#  Henry Grebler    12 Dec 94  Change 'nice' from alias to function.
#  Henry Grebler     9 Dec 94  For SunOS, disable flush.
#  Henry Grebler    20 Sep 94  Add alias for 'nice'.
#  Henry Grebler    13 Sep 94  Make bdx faster.
#  Henry Grebler    10 Mar 94  Move IF, IFNOT to .bashrc.
#  Henry Grebler    31 Dec 93  Only do some stuff if interactive.

#	Only do this stuff if NOT interactive (eg XVISION)

if [ "$PS1" = "" ]
then
PATH=$PATH:/usr/openwin/bin:/usr/openwin/demo:/usr/openwin/demo/xview
export PATH
fi

if [ "$HMG_LD_LIBRARY_PATH" != "" ]
then
	LD_LIBRARY_PATH=$HMG_LD_LIBRARY_PATH
else
	LD_LIBRARY_PATH=/usr/openwin/lib:/usr/dt/lib:/opt/SUNWmotif/lib:/usr/local/lib
fi
export LD_LIBRARY_PATH

#	Only do stuff if interactive

if [ "$PS1" != "" ]
then
	echo "Starting .bashrc"

	stty erase "^H"

#	A few lines to get around some HP idiosyncrasy

	if [ "$HOME" = "" ]
	then
		export HOME=$HMGHOME
	fi
	export HMGHOME=$HOME

	export LESS='-if -j 10'
	[ "$TERM" = vt100 ] && TERM=xterm

#----------------------------------------------------------------------#
#	Handle some annoying su situations
#----------------------------------------------------------------------#

HP_su () {
	if [ "$1" = "-" ]
	then
		/bin/su "$@"
	else
	        if [ "$1" = "" ]
	        then
	                p1=root
	        else
	                p1=$1
	        fi
        	/bin/su $p1 -rcfile $HMGHOME/.bashrc
	fi
}

#----------------------------------------------------------------------#
Linux_su () {
	if [ "$1" = "-" ]
	then
		/bin/su "$@"
	else
	        if [ "$1" = "" ]
	        then
	                command su -p
	        else
	                command su -p $1
	        fi
	fi
}

#----------------------------------------------------------------------#
BSD_su () {
	if [ "$1" = "-" ]
	then
		/usr/bin/su "$@"
	elif [ "$1" = "" ]
        then
                command su -m root -c /bin/bash
        else
                command su -m root "$@"
        fi

}

#-----------------------------------------------------------------------

	if [ "$HMGPATH" != "" ]
	then
		export PATH=$HMGPATH
	fi

	history_control=ignoredups
	HISTCONTROL=ignoredups

# Do the same things as csh does

IF(){
	if  [ $TEST_VALUE = 0 ]; then  $*; fi
}

IFNOT(){
	if  [ $TEST_VALUE != 0 ]; then  $*; fi
}

	source ~/bash/csh-compat

	source ~/.ENV./.cshrc_bash

#	Bash-only abbrevs and stuff

#set -xv
#builtin set -xv

	bind 'set convert-meta on'

	if [ `uname` = SunOS ]
	then
		stty flush ^-
	fi

	alias bd builtin dirs
	alias bdx 'builtin dirs |tr " " "\012" |awk "{print NR-1, \$0}"'

	setenv ignoreeof
	set -o noclobber	# Don't allow output redirection to an 
#				  existing file (>)

	if [ `tty | wc -c` -eq 10 -a "`echo $TERM | cut -c1-2`" != wy ]
	then
		setenv PS1 "`tty | cut -c9`-"'\[\033[1m\]`date "+%b%d"` \t `uname` \h:`pwd` \$\n\$\[\033[0m\] '
	else
		setenv PS1 '\[\033[1m\]`date "+%b%d"` \t `uname` \h:`pwd` \$\n\$\[\033[0m\] '
	fi
	set mail = /var/spool/mail/henryg

# 25aug92	For some reason, the "al" commands below failed
#		so I changed them to "alias"

	alias bhelp 'builtin help'
#	alias dirs csh -c dirs
	alias dsdt dsd -t
	alias ax . $HOME/bash/ax.bash

	alias ph '$* >& phant.log &'
	alias pgpck 'pgp -o /dev/null'

	alias sav 'declare save_directory=`pwd`'

	alias h history

set +xv
#	Define stuff for Bash which it cannot handle through aliases

	source ~/.ENV./.kshrc_bash

	alias w '(pwd; /bin/pwd ) | uniq'

#----------------------------------------------------------------------#
	uname=`uname -s`
	case "$uname" in
		HP-UX)	alias su HP_su;;
		Linux)	alias su Linux_su
			ulimit -Sc 0	# avoid core files
			;;
		FreeBSD)
			alias su BSD_su
			ulimit -Sc 0	# avoid core files
			unset TERMCAP
			;;
	esac

#----------------------------------------------------------------------#
echo "End of .bashrc"
[ -r $HOME/motd ] && cat $HOME/motd
fi
