function setup_supported_version {
  local package_entry=$(ups list -aK+ $1)
  if [ -z "$package_entry" ]
  then
      echo "$1 is not available -- ignoring"
      return
  fi

  ups_list_pattern='"(.*)" "(.*)" ".*" "(.*)" ".*"'
  if [[ ! $package_entry =~ $ups_list_pattern ]]
  then
      echo "Malformed ups list entry for $1 -- fatal error"
      exit 1
  fi

  local product=${BASH_REMATCH[1]}
  local version=${BASH_REMATCH[2]}
  local quals=${BASH_REMATCH[3]}
  [ -n "$quals" ] && quals="-q $quals" || quals=""
  setup $product $version $quals
}

# Setup UPS products
source /products/setup
setup_supported_version larwirecell
setup_supported_version spdlog
setup_supported_version cmake
setup_supported_version git
setup_supported_version gdb

path-remove ()
{
    local IFS=':';
    local NEWPATH;
    local DIR;
    local PATHVARIABLE=${2:-PATH};
    for DIR in ${!PATHVARIABLE};
    do  
        if [ "$DIR" != "$1" ]; then
            NEWPATH=${NEWPATH:+$NEWPATH:}$DIR;
        fi;
    done;
    export $PATHVARIABLE="$NEWPATH"
}

path-prepend ()
{
    path-remove "$1" "$2";
    local PATHVARIABLE="${2:-PATH}";
    export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}"
}

path-append ()
{
    path-remove "$1" "$2";
    local PATHVARIABLE="${2:-PATH}";
    export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
}

find-fhicl ()
{
    fhicl_file=$1;
    for path in `echo $FHICL_FILE_PATH  | sed -e 's/:/\n/g'`;
    do  
        find $path -name "$fhicl_file" 2> /dev/null;
    done
}

#####################
# user specific stuff
#####################
list ()
{
    echo $1 | tr ':' '\n'
}

termtitle ()
{
    printf "\033]0;$*\007"
}

export TERM=xterm-256color
export HOME=/home/yuhw/
export DISPLAY=:1001
export XAUTHORITY=/home/yuhw/.Xauthority
bind '"\e[A":history-search-backward' #PageUp
bind '"\e[B":history-search-forward' #PageDown
set autolist
set autoexpand
export PS1='[kyle]$(pwd)\n$'
alias ls='ls --color=auto'
alias ll='ls -lh'


