#!/bin/sh
set -eu

if [ -z "${GERBIL_HOME:-}" ]; then
    GERBIL_HOME=$(dirname $(cd ${0%/*} && echo $PWD))
    export GERBIL_HOME
fi

if [ $# -gt 0 ]; then
    case $1 in
        -:*)
            GSIOPTIONS=$1
            shift
            ;;
    esac
fi

if [ $# -gt 0 ]; then
    case $1 in
        --lang)
            export GERBIL_LANG=$2
            shift 2
            ;;
    esac
fi

if [ $# -eq 0 ]; then
    exec gsi ${GSIOPTIONS:-} $GERBIL_HOME/lib/gxi-init $GERBIL_HOME/lib/gxi-interactive -
else
    exec gsi ${GSIOPTIONS:-} $GERBIL_HOME/lib/gxi-init "$@"
fi
