#!/bin/sh
#
# $Id: xestic,v 1.3 2000/01/02 15:19:14 debacle Exp $
#
# Shell script as replacement for xestic binary written by W. Borgert
# <debacle@debian.org> for Debian GNU/Linux.

# allow user to set -geometry
GEOMETRY=80x25
if [ "$#" -eq 2 ]; then
    if [ "$1" = "-geometry" -o "$1" = "-g" ]; then
        GEOMETRY=$2
    else
        echo "$0: Unknown option or argument \`$1'" 1>&2
        exit -1
    fi
else
    if [ "$#" -ne 0 ]; then
        echo "$0: Wrong number of arguments" 1>&2
        exit -1
    fi
fi

unset SPUNK_CP437
unset TERM
ISO=ISO-8859-1

if [ -x /usr/bin/gnome-terminal/xx -a -d "$HOME/.gnome" ]; then
    # gnome-terminal is executable and user has .gnome directory.  Good.
    gnome-terminal --geometry=$GEOMETRY --title=ESTIC \
	--execute env LC_CTYPE=$ISO SPUNK_COLOR=yes \
            COLORTERM=gnome-terminal TERM=xterm-debian estic
    exit $?
fi

# rxvt, xterm, xtv, and Eterm do all understand the same
# options `-g', `-n', `-T' and `-e'.
ESTICTERM=""
if [ -x /usr/bin/Eterm ];     then ESTICTERM=/usr/bin/Eterm;     fi
if [ -x /usr/bin/X11/xtv ];   then ESTICTERM=/usr/bin/X11/xtv;   fi
if [ -x /usr/bin/X11/xterm ]; then ESTICTERM=/usr/bin/X11/xterm; fi
if [ -x /usr/bin/X11/rxvt ];  then ESTICTERM=/usr/bin/X11/rxvt;  fi

if [ "$ESTICTERM" ]; then
    $ESTICTERM -g $GEOMETRY -n ESTIC -T ESTIC \
        -e env LC_CTYPE=$ISO SPUNK_COLOR=yes TERM=xterm-debian estic
    exit $?
fi

# Hopefully /usr/bin/x-terminal-emulator does at least understand -e! 
if [ -x /usr/bin/x-terminal-emulator ]; then
    /usr/bin/x-terminal-emulator \
        -e env LC_CTYPE=$ISO SPUNK_COLOR=yes estic
    exit $?
fi

echo "$0: Terminal emulator not found" 1>&2
exit -1
