#! /bin/zsh

cd "`dirname "$0"`"
self="`basename "$0"`"

export DISPLAY=:1
export WINEPREFIX="/home/kevin/.wine"

if [[ "a$1" = "a-run-term" ]]; then
    xterm -e "./$self" -run-script
elif [[ "a$1" = "a-run-script" ]]; then
    shift
    clear
    echo "Start Timidity -iA"
    timidity -iA &
    timidity=$!
    echo "Set up X"
    xreset
    xrandr -s 640x480
    echo "Run Zork Grand Inquisitor"
    cd /home/kevin/Games/ZGI-DVD
    wine /home/kevin/Games/ZGI-DVD/zgiwin.exe
    echo "Kill timidity"
    kill $!
    echo "------------------------------------------------------------"
    zsh -i
fi

auth="$(xauth list | head -n 1 | sed -r 's|^.*\s(\S+)$|\1|')"
xauth add $disp MIT-MAGIC-COOKIE-1 "$auth"

startx "./$self" -run-term -- $DISPLAY -depth 16
