#!/usr/local/bin/bash
#
# $dotat: rcfiles/bashrc,v 1.81 2003/04/11 18:28:22 fanf2 Exp $

addpath () {
    [ -d $1 ] && PATH=$PATH:$1
}
if grep ^fanf: /etc/passwd > /dev/null
then
	export FANFUSER=fanf
        export FANFHOME=~fanf
else
	export FANFUSER=fanf2
	export FANFHOME=~fanf2
fi
PATH=$FANFHOME/bin
addpath /usr/X11R6/bin
addpath /opt/exim/bin
addpath /opt/local/bin
addpath /opt/local2/bin
addpath /usr/local/exim/bin
addpath /usr/local/sbin
addpath /usr/local/bin
addpath /usr/gnu/bin
addpath /usr/freeware/bin
addpath /usr/xpg4/bin
addpath /usr/sbin
addpath /usr/etc
addpath /usr/bin
addpath /sbin
addpath /bin
addpath /opt/SUNWmd/sbin
addpath /opt/SUNWspro/bin
addpath /usr/ccs/bin
addpath /home/cvs/bin
addpath /usr/bsd
addpath /usr/games
export PATH
unset addpath

if ! type manpath > /dev/null 2>&1
then
    addmanpath () {
	[ -d $1 ] && MANPATH=$MANPATH:$1
    }
    MANPATH=/usr/share/man
    addmanpath /usr/local/man
    addmanpath /usr/opt/SUNWmd/man
    addmanpath /usr/local/lib/perl5/man
    addmanpath /usr/local/lib/perl5/5.00503/man
    export MANPATH
    unset addmanpath
fi

export PAGER=`which less`
case $PAGER in
    /*)
	export LESS='-i -j20 -M -R -s -S -#1'
	export LESSCHARSET=latin1
	eval $(lesspipe)
	;;
    *)
	export PAGER=`which more`
	;;
esac

FANFCFLAGS=`echo						\
	-pipe -O -g -ansi -U__STRICT_ANSI__ -pedantic -W -Wall	\
	-Wbad-function-cast -Wcast-align -Wcast-qual		\
	-Wchar-subscripts -Winline -Wmissing-prototypes		\
	-Wnested-externs -Wpointer-arith -Wredundant-decls	\
	-Wshadow -Wstrict-prototypes -Wwrite-strings`

SGML_ROOT=/usr/local/share/sgml
SGML_CATALOG_FILES=${SGML_ROOT}/jade/catalog
SGML_CATALOG_FILES=${SGML_ROOT}/iso8879/catalog:$SGML_CATALOG_FILES
SGML_CATALOG_FILES=${SGML_ROOT}/html/catalog:$SGML_CATALOG_FILES
SGML_CATALOG_FILES=${SGML_ROOT}/docbook/4.1/catalog:$SGML_CATALOG_FILES
SGML_CATALOG_FILES=/usr/doc/share/sgml/catalog:$SGML_CATALOG_FILES
SGML_CATALOG_FILES=/usr/doc/en_US.ISO8859-1/share/sgml/catalog:$SGML_CATALOG_FILES
export SGML_CATALOG_FILES

export CDROM=/dev/acd0c
export CVS_RSH=`which ssh`
export EDITOR=`which vi`
export FTP_PASSIVE_MODE='yes'
export ORGANIZATION='dotat labs'
export SHELL=`which bash`


# aliases

unalias -a

for util in tar diff
do
    case `type -p g$util` in
        /*)  alias $util=g$util ;;
    esac
done

case `type -p gnuls` in
    "") alias l='ls -FC' ;;
    *)  alias l='gnuls -FC --color=yes' ;;
esac
alias  la='l -a'
alias  ll='la -l'
alias lld='ll -d'

alias    ..='cd ..'
alias   ...='cd ../..'
alias  ....='cd ../../..'
alias .....='cd ../../../..'

alias cta=cat
alias act=cat

alias mkae=make
alias amke=make

alias csv=cvs

alias which='type -p'

# functions

rgrep () {
    grep -r "$@" . | less
}

manf () {
    nroff -man "$@" | less
}

cd () {
    local dir=${1:-~}
    if expr "x$dir" : '[@0-9A-Za-z.-]*:' >/dev/null
    then
	xsh "$dir"
    else
	builtin cd "$dir" 2>/dev/null || {
	    builtin cd "${dir%/l}" && echo "${dir%/l}"
	}
    fi
}

cdplay () {
	cdcontrol play "$@"
	cdstat
}

forhost () {
	for host in $HOSTLIST
	do
		echo "#### $host" 1>&2
		ssh $host "$@"
	done
}

forhost_wrapper () {
	local name
	name=$1
	shift
	eval "HOSTLIST_$name=\"\$@\"
	$name () {
		HOSTLIST=\"\$HOSTLIST \$HOSTLIST_$name\"
		if set | grep ^HOSTLIST_\$1 >/dev/null 2>&1
		then
			\"\$@\"
		else
			forhost \"\$@\"
		fi
		unset HOSTLIST
	}"
}

forhost_wrapper ppswx  maroon plum purple gold rose brown snow canvas
forhost_wrapper ppsw   maroon plum purple gold rose brown
forhost_wrapper hermes red orange yellow green

# magic shell things

set -PH
shopt -s cdspell checkhash checkwinsize extglob histappend

if [ "$PS1" ]
then
	hi='\[\e[1m\]'
	lo='\[\e[0m\]'
	xt='\[\e]0;\H (\u) \w\a\]'
	export PS2=''
	export PS1=$hi'\u@\H:\w'$lo'\n'$hi': $? ; '$lo
	case $TERM in xterm*) export PS1=$xt$PS1 ;; esac
	unset hi lo xt
fi

case $TERM in
    xterm*)
	if [ -f $FANFHOME/.terminfo/x/$TERM ]
	then
		export TERMINFO=$FANFHOME/.terminfo
	else
		export TERM=xterm
	fi
	;;
esac
