#!/bin/bash
# some magic to find out the real location of this script dealing with symlinks
DIR=`readlink "$0"` || DIR="$0";
DIR=`dirname "$DIR"`;
cd "$DIR"
DIR=`pwd`
cd - > /dev/null 
# disable parameter expansion to forward all arguments unprocessed to the VM
set -f

# parse vm options and image
for arg in "$@"
do
   if [[ $arg == -* ]];
   then
      VMOPTIONS="$VMOPTIONS $arg"
      shift
   else
      break
   fi
done
IMAGE=$1
shift
# if no image has been provided use the installed one
if [ -z "$IMAGE" ];
then
   IMAGE=$DIR/Pharo.image
fi

# run the VM and pass along all arguments as is
"$DIR"/"vm/Pharo.app/Contents/MacOS/Pharo" $VMOPTIONS $IMAGE "$@"
