##
##  @l_prefix@/etc/bash/profile -- Global Bash Profile
##

#   welcome and goodbye message ;)
echo "$HOSTNAME: user $USER, login at `date`"
trap 'echo "$HOSTNAME: user $USER, logout at `date`"' 0

#   initially adjust $PWD to symbolic path
cd $HOME

#   provide user and host information in default prompt
PS1="\u@\h\$ "

#   session timeout
export TMOUT=3600

#   environment permissions
umask 022
ulimit -c 16384
if [ ".$PS1" != . ]; then
    mesg y
fi

#   history functionality
shopt -s histappend
HISTSIZE=100
HISTFILESIZE=100
alias h='history | $PAGER'

#   various additional variables
export TMPDIR=/tmp
export TEMPDIR=$TMPDIR
export BLOCKSIZE=1024

#   turn on extended globbing
shopt -s extglob no_empty_cmd_completion

#   make directory commands see only directories
complete -d cd mkdir rmdir pushd

#   make file commands see only (their) files
complete -f cat less more ln strip
complete -f -X '*.bz2' bzip2
complete -f -X '!*.bz2' bunzip2
complete -f -X '!*.zip' unzip
complete -f -X '*.gz' gzip
complete -f -X '*.Z' compress
complete -f -X '!*.+(Z|gz|tgz|Gz)' gunzip zcat zmore
complete -f -X '!*.Z' uncompress zmore zcat
complete -f -X '!*.+(gif|jpg|jpeg|GIF|JPG|bmp)' xv display
complete -f -X '!*.+(ps|PS|ps.gz)' gv gs mgv
complete -f -X '!*.+(dvi|DVI)' dvips xdvi
complete -f -X '!*.+(pdf|PDF)' acroread xpdf
complete -f -X '!*.texi*' makeinfo texi2dvi texi2html
complete -f -X '!*.+(tex|TEX)' tex latex
complete -f -X '!*.+(c|cc|C|h|hh|H)' cc gcc

#   make signal and job commands see only signals/jobs
complete -A signal kill -P '%'
complete -A stopped -P '%' bg
complete -j -P '%' fg jobs

#   make user/group commands see only users/groups
complete -u passwd su finger
complete -u passwd

#   make network commands see only hostnames
complete -A hostname ssh rsh telnet rlogin ftp ping host traceroute nslookup dig

#   make internal commands see only their possibilities
complete -v export local readonly unset
complete -A setopt set
complete -A shopt shopt
complete -A helptopic help
complete -a unalias
complete -A binding bind

#   convinient root priviledge switching
root () {
    if [ $# -eq 0 -o ".$1" = ".-i" ]; then
        ssh -t -x root@localhost cd $PWD \&\& exec ${SHELL-/bin/sh}
    elif [ ".$1" = ".-l" ]; then
        ssh -x root@localhost cd $PWD \&\& `history | tail -2 | head -1 | cut -c8-`
    elif [ ".$1" = ".-t" ]; then
        shift
        ssh -t -x root@localhost cd $PWD \&\& "$@"
    else
        ssh -x root@localhost cd $PWD \&\& "$@"
    fi
}

#   suck in the Bourne-Shell environment of all OpenPKG packages
eval `@l_prefix@/etc/rc -p all env:sh`

#   path to user environment init script
if [ -f "$HOME/.bashrc" ]; then
    BASH_ENV=$HOME/.bashrc
    . $BASH_ENV
fi

