# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

eval `/opt/local/bin/lesspipe.sh`

function dir_access_color {
  local DIR="${1-$PWD}" COLOR=0
  [[ -r "$DIR" ]] && COLOR=1 # red
  [[ -w "$DIR" ]] && COLOR=2 # green
  tput -S <<<$'bold\nsetaf '"$COLOR"
}

function nfmxtermtitle {
  local HOST="$(cut -d. -f1 <<< "$HOSTNAME")"
  local DIR="$(dirs +0)"
  DIR="${DIR%/}/"

  # gnome-terminal doesn't mind, but xterm refuses to set the title if
  # it contains non-ASCII characters.  So, use x instead of ×.
  local TITLE="${XTTITLE-${USER}@${HOST}}: ${DIR} [$$] ${COLUMNS}x${LINES}"
  local ICON="${XTTITLE-$USER}: ${DIR}"
}

# If running interactively, then:
if [ "$PS1" ]; then
    # Use 256 colors in xterm and gnome-terminal
    case "$(ps h -o comm "$PPID")" in
      gnome-terminal)
      TERM=gnome-256color
      ;;
      xterm)
      TERM=xterm-256color
    esac
    # don't put duplicate lines in the history. See bash(1) for more options
    export HISTCONTROL=ignoredups

    # enable color support of ls and also add handy aliases
    alias ls='ls -G'

    # set a fancy prompt
    PS1=$(for ((i=1;i<SHLVL; ++i)); do
        echo -n " ";
    done)
    PS1="$PS1""`whoami`"' in \[$(dir_access_color)\]\w\['"$(tput setaf 3)$(tput bold)"'\]\$\['"$(tput sgr0)"'\] '

    # If this is an xterm set the title to user@host:dir
    case "$TERM" in
      xterm*|gnome*)
          PROMPT_COMMAND='nfmxtermtitle'
          ;;
      *)
          ;;
    esac

    # enable programmable completion features (you don't need to enable
    # this, if it's already enabled in /etc/bash.bashrc).
    if [ -f /etc/bash_completion ]; then
      . /etc/bash_completion
    fi
fi

export LESS_TERMCAP_mb=$'\E[01;36m'
export LESS_TERMCAP_md=$'\E[01;31m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;32m'

export WWW_HOME='http://www.google.com/'
export PATH="/Applications/Vim.app/Contents/MacOS:/opt/local/bin:/usr/local/graphicslibs/lib/:/usr/local/graphicslibs/bin:/Users/sarah/bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
export EDITOR="vim"
export SVN_EDITOR=$EDITOR
export REPOS="file:///usr/local/svn/general_repos"
export LESSOPEN='| /opt/local/bin/lesspipe.sh %s'