# .bashrc
#
# $Id: .bashrc,v 1.7 2002/10/02 18:51:54 dave Exp $
#

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

# Prompt colors
BRIGHT_WHITE="\[\033[1;39m\]"
NORMAL="\[\033[1;38m\]"
WHITE="\[\033[1;37m\]"
CYAN="\[\033[1;36m\]"
PURPLE="\[\033[1;35m\]"
BLUE="\[\033[1;34m\]"
YELLOW="\[\033[1;33m\]"
GREEN="\[\033[1;32m\]"
RED="\[\033[1;31m\]"
GRAY="\[\033[1;30m\]"

DARK_CYAN="\[\033[0;36m\]"
DARK_PURPLE="\[\033[0;35m\]"
DARK_BLUE="\[\033[0;34m\]"
DARK_YELLOW="\[\033[0;33m\]"
DARK_GREEN="\[\033[0;32m\]"
DARK_RED="\[\033[0;31m\]"
BLACK="\[\033[0;30m\]"

NO_COLOR="\[\033[0m\]"

BOLD="\[\033[0;37m\]"

export PS1="$WHITE-- \[$BLUE[\[$CYAN\u@\h\[$BLUE] \[$PURPLE\w\[$WHITE -- \$\[$NO_COLOR "

export PS2="$CYAN\[? $NO_COLOR"
export PS3="PS3\$ "
export PS4="PS4\$ "

#
# Environment
#
export PATH="$HOME/bin:/bin:/usr/bin:/usr/X11/bin:/usr/local/bin:/usr/X11R6/bin:/sbin:/usr/sbin:/usr/local/sbin"

export PAGER=less
export EDITOR=vim

# Unset any inherited CVSROOT
export CVSROOT=bgaiser@mars.pgp.com:/pgpsrc
export CVS_RSH=ssh

case `uname` in
Linux)
    if [ x$DISPLAY == x ] ; then
        export TERM=linux
    else
        export TERM=xterm
    fi
    export ARCM=`arch`
    ;;
Darwin)
    export TERM=vt100
    export ARCM=`arch`
    ;;
CYGWIN_NT-5.0|CYGWIN_NT_5.1)
    export TERM=vt100
    export ARCM=i386
    export PATH=$PATH:/c/WINDOWS:/c/WINDOWS/system32:/c/WINDOWS/system
    ;;
esac

# XXX # This sets the title of my xterms to be user@host
#if( `uname` == Darwin ) then
#    # Don't do this because Darwin sucks.
#    #alias precmd 'echo -n "]0;$USER@$HOST"'
#else
#    if ($?X || $?SSH_CLIENT || $?GDMSESSION) then
#        alias precmd 'echo -n "\033]0;$USER@$HOST\007"'
#        xhost +localhost >& /dev/null
#    endif
#endif
if [ $TERM == xterm ] ; then
    export PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
else
    export PROMPT_COMMAND=
fi

#
# aliases/functions
#
#alias ls='ls -F --color=auto'
alias dir='ls -l'
alias unmung='echo '
alias logout=exit

function sudo () {
    umask 022
    /usr/local/bin/sudo $*
    umask 077
}

alias pgpcvs='export CVSROOT=dallen@mars.cyphers.net:/pgpsrc ; export CVS_RSH=ssh'
alias gnomecvs='export CVSROOT=:pserver:anonymous@anoncvs.gnome.org:/cvs/gnome ; export CVS_RSH='

alias homecvs="export CVSROOT=/scratch/cvsroot ; export CVS_RSH="
alias reicvs="export CVSROOT=dave@cvs.sysrq.org:/scratch/cvsroot ; export CVS_RSH=ssh"
alias sysrqcvs="export CVSROOT=dave@sysrq.org:/imports/scratch/cvsroot ; export CVS_RSH=ssh"

function cvsstatus () {
    cvs -z3 status $* 2>&1 | grep Status: | grep -v Up-to-date
}

function pgperror () {
    grep -ih $* $HOME/src/pgp/libs2/pfl/common/pgpPFLErrors.h $HOME/src/pgp/libs2/pgpsdk/pub/include/pgpErrors.h
}


#
# Shell configuration
#
#unset addsuffix
#
# XXX This addsuffix is the option I need to turn off to make bash not print
# XXX '/' after completing directory names - I think visible-chars is 
# XXX supposed to do this, but doesn't seem to work with menu-complete
#
set -o noclobber

#bind 'TAB: menu-complete'
bind '"\C-g": insert-completions'

bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'

bind "set show-all-if-ambiguous on"

# These are the hostnames that I connect to the most often
export HOSTS="ranma \
              rei \
              morisato \
              godai \
              urd \
              luna \
              a-ko.sysrq.org \
              b-ko.sysrq.org \
              enigma.cyphers.net \
              mars.cyphers.net"
export USERS="dave@sysrq.org \
              dave@ranma.sysrq.org \
              dave@rei.sysrq.org \
              dallen@mars.cyphers.net \
              dallen@a-ko.sysrq.org \
              root@ranma.sysrq.org"

complete -A setopt set
complete -A setopt unset
complete -A variable export
complete -A alias alias
complete -A alias unalias
complete -o dirnames cd
complete -c man
complete -W "-INT -TERM -KILL" kill
complete -W "-INT -TERM -KILL" killall
complete -W "$HOSTS $USERS" ssh
complete -W "$HOSTS" traceroute
complete -W "$HOSTS" ping
complete -W "$HOSTS" telnet
complete -W "$HOSTS" ftp
complete -W "$HOSTS" ncftp

function generic_complete () {
    echo
    echo COMP_CWORD $COMP_CWORD
    echo COMP_LINE $COMP_LINE
    echo COMP_POINT $COMP_POINT
    echo COMP_WORDS ${COMP_WORDS[0]} ${COMP_WORDS[1]} ${COMP_WORDS[2]} ${COMP_WORDS[3]} ${COMP_WORDS[4]} ${COMP_WORDS[5]} ${COMP_WORDS[6]} ${COMP_WORDS[7]}
    echo
}

cvs_complete ()
{
    local cur prev

    COMPREPLY=()
    cur=${COMP_WORDS[COMP_CWORD]}
    prev=${COMP_WORDS[COMP_CWORD-1]}

    if [ $COMP_CWORD -eq 1 ] || [ "${prev:0:1}" = "-" ]; then
        COMPREPLY=( $( compgen -W 'add admin checkout commit diff \
        export history import log rdiff release remove rtag status \
        tag update' $cur ))
    # XXX
    #else
        #COMPREPLY=( $( compgen -f $cur ))
    fi
    return 0
}
complete -f -F cvs_complete cvs

function find_complete () {
    local cur prev

    COMPREPLY=()
    cur=${COMP_WORDS[COMP_CWORD]}
    prev=${COMP_WORDS[COMP_CWORD-1]}

    if [ $COMP_CWORD == 1 ] ; then
        true
    elif [ ${COMP_WORDS[$COMP_CWORD-1]} == -exec ] ; then
        COMPREPLY=( $( compgen -W 'grep' $cur ) )
    else
        COMPREPLY=( $( compgen -P - -W 'name exec type' ${cur:1:9} ) )
    fi
    return 0
}
complete -o dirnames -F find_complete find

#function rm_complete () {
#    local cur
#
#    cur=${COMP_WORDS[COMP_CWORD]}
#    if [[ ${COMP_WORDS[1]} == -rf ]] ; then
#        COMPREPLY=( $( for f in $(compgen -d $cur) ; do echo $f/ ; done ) )
#    else
#        COMPREPLY=( $( compgen -f $cur ) )
#    fi
#}
#complete -F rm_complete rm
#complete -f rm
#complete rm 'n/-rf/d/'
#
#function sudo_complete () {
#    # Program names for the first argument,
#    # Plain filenames for everything else
#}
#complete -F sudo_complete sudo


## Use this to fix problems with the backspace key you might have
#if [ `uname` == Linux ] ; then
#    stty erase `tput kbs`
#fi

# I'm paranoid - don't let anybody else read my files
umask 077
