#!/bin/bash 

## A wrapper script around the xterm utility 
## which allows codelite to export LD_LIBRARY_PATH into the exterm
## shell

# Force xterm to provide at least a scrollbar, and 1000 lines of scrollback,
# in case the user hasn't set any preferences of his own in ~/.Xresources
terminal="xterm -sb -sl 1000"
program_title=$1

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

