#!/bin/bash 

## A wrapper script around the xterm utility 
## which allows codelite to export LD_LIBRARY_PATH into the exterm
## shell
if [ $# -ne 2 ]; then
	echo "usage: codelite_xterm '<Title>' '<Program>'"
	exit 1
fi

program_title=$1
terminal_emulator=$(basename $(readlink -e /usr/bin/x-terminal-emulator))

title_opt="-T"
cmd_opt="-e"

case ${terminal_emulator} in
	"gnome-terminal")
		title_opt="-t"
		;;
	"terminator")
		cmd_opt="-x"
		;;
	*)
		;;
esac

if [ "${LD_LIBRARY_PATH}" = "" ]; then
	## LD_LIBRARY_PATH is not defined OR empty
	## Run xterm without the bash wrapper
	x-terminal-emulator "${title_opt}" "${program_title}" "${cmd_opt}" $2 2> /dev/null
else
	x-terminal-emulator "${title_opt}" "${program_title}" "${cmd_opt}" /bin/bash -c 'export LD_LIBRARY_PATH=$0;shift;$@' $LD_LIBRARY_PATH $@ 2> /dev/null
fi

