#!/bin/sh
unset cdDepth PATHS_SET SHOW_REMINDER

tab='	'

# find colset in parameters
colset="$XWIN_COLSET"
next=0
havecol=0
list=""
drop=0
for a in "$@"; do
  drop=0
  case x"$a" in
    x-h | x-help)
      echo "$0 [xterm opts] -colset color-set [xterm opts]"
      echo "where color-set can be:"
      echo "  paleb*|blue|hp            - light blue"
      echo "  gold|yellow|solaris|sun   - golden"
      echo "  darkblue|dark*|aix        - dark blue"
      echo "  osf*|cinnamon|red         - deep red"
      echo "  linux|paley*|lighty*      - pale yellow"
      echo "  green                     - darkish green"
      echo "  white|*                   - white (default)"
      echo "  darkgreen                 - a deeper green"
      echo "some users have fixed colors:"
      echo "  tibadmin:  green"
      echo "  triarch:   cinnamon"
      echo "  *:         darkblue"
      echo "for xterm options try -help"
      drop=1
      exit
      ;;
    x-colset)
      [ $havecol = 0 ] && next=1
      drop=1
      ;;
    x-colset*)
      colset=`echo "$a"|sed -e 's/-colset//'`
      havecol=1
      drop=1
      ;;
    *)
      if [ $next = 1 ] && [ $havecol = 0 ]
      then
        colset="$a"
        havecol=1
        next=0
        drop=1
      fi
      case x"$a" in
        x-T)
          have_T=1
          ;;
        x-n)
          have_n=1
          ;;
      esac
      ;;
  esac
  # [ $drop = 0 ] && echo "adding $a"
  # [ $drop = 1 ] && echo "dropping $a"
  [ $drop = 0 ] && list="$list$tab$a"
done

if [ x$colset = x ]
then
  case $USER in
    tibadmin)
      colset=green
      ;;
    triarch)
      colset=cinnamon
      ;;
    *)
      colset=darkblue
      ;;
  esac
fi

case $colset in
  paleb*|blue|hp)
    bgcolour="#78a0d4"
    fgcolour="white"
    crcolour="red"	# "#a42a2a"	# "grey"
    ;;
  gold|yellow|solaris|sun)
    bgcolour="#fedc40"
    fgcolour="black"
    crcolour="#FF8000"
    ;;
  darkblue|darkb*|aix)
    bgcolour="#2f5378"
    fgcolour="white"
    crcolour="#789fd3"
    ;;
  osf*|cinnamon|red)
    bgcolour="#a42a2a"
    fgcolour="yellow"
    crcolour="red"
    ;;
  linux|paley*|lighty*)
    bgcolour="lightYellow"
    fgcolour="black"
    crcolour="red"
    ;;
  green)
    bgcolour="#3f7f00"
    fgcolour="#ffff80"
    crcolour="#00f000"
    ;;
  darkgreen)
    bgcolour="#0c6864"
    fgcolour="#ffffff"
    crcolour="#00f000"
    ;;
  white|*)
    bgcolour="white"
    fgcolour="black"
    crcolour="black"
    ;;
esac
    
fonts="-font 6x13 -fb 6x13b"
opts="-sb -sl 9000"

colours="-fg $fgcolour -bg $bgcolour -cr $crcolour"
# title="-T '`whoami`@`hostname`' -n '(`whoami`@`hostname`)'"
title=""
[ "$have_T" = 1 ] || title="$title -T `whoami`@`hostname`"
[ "$have_n" = 1 ] || title="$title -n (`whoami`@`hostname`)"

# echo xterm $opts $fonts $colours $title $list &
trap "" 1
[ -n "$colset" ] && XWIN_COLSET="$colset" && export XWIN_COLSET
xterm $opts $fonts $colours $title $list &
