#!/usr/bin/env bash

#Workaround for Unity gnome shell
export UBUNTU_MENUPROXY=0

# Ubuntu overlay scrollbars are not working well with the 1px boundaries in the monodevelop shell
export LIBOVERLAY_SCROLLBAR=0


#this script should be in $PREFIX/bin
MONO_EXEC="exec -a monodevelop mono"
EXE_PATH="${0%%/bin/monodevelop}/lib/monodevelop/bin/MonoDevelop.exe"

_MD_REDIRECT_LOG="${MD_REDIRECT_LOG:-${XDG_CONFIG_HOME:-$HOME/.config}/MonoDevelop/log}"

##NOTE: remove this for stable releases
if [ -z "$MD_NO_DEBUG" ]; then
	_MONO_OPTIONS=${MONO_OPTIONS:---debug}
else
	_MONO_OPTIONS=$MONO_OPTIONS
fi

MONO_RECOMMENDED_VERSION_FOR_SGEN=3.0
if pkg-config --atleast-version=$MONO_RECOMMENDED_VERSION_FOR_SGEN mono; then
	MONO_OPTIONS="$MONO_OPTIONS --gc=sgen"
fi

# Monodevelop menus don't work with Ubuntu appmenu
export UBUNTU_MENUPROXY=0

if [ -n "$_MD_REDIRECT_LOG" ]; then
	mkdir -p `dirname "$_MD_REDIRECT_LOG"`
	$MONO_EXEC $_MONO_OPTIONS "$EXE_PATH" $* 2>&1 | tee "$_MD_REDIRECT_LOG"
else
	$MONO_EXEC $_MONO_OPTIONS "$EXE_PATH" $*
fi

