#!/bin/bash
set -e

DIR="$(dirname $0)"

DICTIONARIES="$DIR/dictionaries/"

for i in "$DIR"/jars/* ; do CLASSPATH="$CLASSPATH:$i" ; done
CLASSPATH="$(echo -n "$CLASSPATH" | sed 's/^://')"

mkdir -p ~/.luan_editor

set +m

if [[ "$(uname)" == "Darwin" ]]; then  # Mac
	java -Ddictionaries="$DICTIONARIES" -Xdock:name="Luan Editor" -Duser.home="$HOME" -classpath "$CLASSPATH" luan.Luan classpath:luan_editor/editor.luan "$@" 2>&1 | grep --line-buffered -v 'NSRemoteView\|NSSavePanel' | tee ~/.luan_editor/error.log &
else
	java -Duser.home="$HOME" -Ddictionaries="$DICTIONARIES" -classpath "$CLASSPATH" luan.Luan classpath:luan_editor/editor.luan "$@" 2>&1 | tee ~/.luan_editor/error.log &
fi
