#! /bin/bash


basename=`basename $0`
termBin=Eterm
defGeometry="80x50"


function usage {
   cat <<USAGE
$basename - Open new, named $termBin terminal window(s)

usage:
   te [OPTIONS] [title1] [title2] [...]

options:
   -g, --geometry WxH  Width and height of the term windows
                       Default: $defGeometry
   -e, --exit          Exit parent xterm window after opening child terms
   -h, --help          This help information

Not specifying a term title will use the $termBin default

2007-12-17  Dino Morelli <dino@ui3.info>

USAGE

   exit 1
}


# arg parsing

getoptResults=`getopt -o g:eh --long geometry,exit,help -n $basename -- "$@"`

if [ $? != 0 ] ; then usage ; fi

# Note the quotes around `$TEMP': they are essential!
eval set -- "$getoptResults"

while true ; do
	case "$1" in
      -g|--geometry) optGeometry="$2" ; shift 2 ;;
      -e|--exit) optExit=1 ; shift ;;
      -h|--help) optHelp=1 ; shift ;;
		--) shift ; break ;;
		*) echo "Internal error!" ; exit 1 ;;
	esac
done

# User asked for help

if [ "$optHelp" = 1 ]; then usage ; fi


# Create the xterm windows now

optGeometry="-g ${optGeometry:-$defGeometry}"

if [ $# -lt "1" ]
then
   $termBin $baseParams &
else
   for title in $*
   do
      params="$optGeometry -T $title -n $title"
      $termBin $params &
   done
fi


# Close parent term if user asked us to

if [ "$optExit" = 1 ]
then
   ppid=`ps -C te -o ppid=`
   kill -9 $ppid
fi
