#---------------------
# bash/2 startup file
#---------------------

# Emulate some UNIX programs
alias sh=${BASH}
alias /bin/sh=${BASH}
alias clear='echo -e -n "\E[2J"'

# Disallow symlinks to disallow BASH to cache current working directory
set -P

export HOSTFILE=$ETC'/hosts'

if [ -z "$HOST" ] ; then
	export HOST=${HOSTNAME}
fi

# if this is not an interactive shell -- skip the following
if [ -z "$PS1" ]; then
	return
fi

#--------------------------------------------------[ For interactive shell ]----

# for os/2 terminal display a nifty logo and set a colored prompt
if [ $TERM = "os2" ] && [ $SHLVL = "1" ] ; then
	echo -e "\E[1;31m"
	echo -e "\E[1;33mGNU BASH for OS/2 version "${BASH_VERSION}
	echo -e "\E[1;31m"

# Since BASH cannot assume something about terminals, we have to point him
# whenever characters in prompt are "visible" or "invisible" by using
# \[ (start invisible) and \] (end invisible) characters
	export PS1="\[\e[1;37m\][\[\e[33m\]${SHLVL}\[\e[37m\]|\[\e[32m\]\h\[\e[37m\]|\[\e[36m\]\w\[\e[37m\]]\[\e[0;36m\]"
	export PS2="\[\e[1;37m\]>\[\e[0;36m\]"
fi

# bogus
alias ls='ls -CF --color=auto'
alias ll='ls -l --color=auto'
alias dir='ls -ba --color=auto'
alias dot='ls .[a-zA-Z0-9_]* --color=auto'
alias /='cd /'
alias \~='cd ~'
alias ..='cd ..'

alias m='more'
alias r='fc -s'

# OS/2-specific
alias cls='clear'
alias os2help='help.cmd'
alias start='$COMSPEC /c start /c'
# Note that this DETACH can be used only for simple commands,
# for complex expressions using '&' is recommended
detach()
{
 $@ &
 echo -e "\E[AThe Process Identification Number is $!."
}

alias a:='cd a:'
alias b:='cd b:'
alias c:='cd c:'
alias d:='cd d:'
alias e:='cd e:'
alias f:='cd f:'
alias g:='cd g:'
alias h:='cd h:'
alias i:='cd i:'
alias j:='cd j:'
alias k:='cd k:'
alias l:='cd l:'
alias m:='cd m:'
alias n:='cd n:'
alias o:='cd o:'
alias p:='cd p:'
alias q:='cd q:'
alias r:='cd r:'
alias s:='cd s:'
alias t:='cd t:'
alias u:='cd u:'
alias v:='cd v:'
alias w:='cd w:'
alias x:='cd x:'
alias y:='cd y:'
alias z:='cd z:'

# A semicolon-separated list of shell patterns which
# matches lines that are not to be added to the history
HISTIGNORE="&;[ ]*;?"

# 4os/2-like (and even better :-)
eset()
{
	tmpfile="${TMP-/tmp}/eset.tmp";
	for tmp in $@; do
# This is not multitask-safe :-)
	 echo export ${tmp}=\"${!tmp}\" >>${tmpfile}
	done
	${EDITOR:epm} ${tmpfile}
	${tmpfile}
	rm -f ${tmpfile}
}

# Show tasks matching given substring
gogrep()
{
	go | grep -e "P-ID PPID" -e "---- ----" -e "$@" -i
}

# Set terminal type
term()
{
        TERM=$1
	export TERM
}

rot13()
{
	if [ $# = 0 ] ; then
		tr "[a-m][n-z][A-M][N-Z]" "[n-z][a-m][N-Z][A-M]"
	else
		tr "[a-m][n-z][A-M][N-Z]" "[n-z][a-m][N-Z][A-M]" < $1
	fi
}

function setenv()
{
	if [ $# -ne 2 ] ; then
		echo "setenv: Too few arguments"
	else
		export $1="$2"
	fi
}
