#!/bin/sh
# most terminal emulators do not understand the '-hold' option
# which is often used when running xterm. This wrapper
# simulates that behaviour no matter which terminal is used

# this program expects the window title as the first argument
# so it should be called like this:
# terminal-wrapper "src2pkg-dnd - Help" -hold -e echo "$HELP_TEXT"
# where "src2pkg-dnd - Help" is the desired window title

if [ "`echo -n ${*} | grep '\-hold '`" != "" ];then 
 EXECCOMMAND="`echo -n ${*} | grep -o ' \-e .*' | sed -e 's/ \-e //'`" 
 if [ "$EXECCOMMAND" != "" ];then 
  echo '#!/bin/sh' > /tmp/hold_terminal.sh 
  echo "$EXECCOMMAND"  >> /tmp/hold_terminal.sh 
  echo 'echo' >> /tmp/hold_terminal.sh
  echo 'echo Use SHIFT+PG_UP or SHIFT+PG_DN to scroll contents' >> /tmp/hold_terminal.sh
  echo 'echo -n "Press ENTER key to close this window. "' >> /tmp/hold_terminal.sh 
  echo 'read ' >> /tmp/hold_terminal.sh 
  chmod +x /tmp/hold_terminal.sh 
  TITLE=$1 $TERMINAL_EMULATOR -title "$TITLE" -e /tmp/hold_terminal.sh
  rm -f /tmp/hold_terminal.sh
  exit 0
 fi 
fi 

#exec $TERMINAL_EMULATOR "${@}" &
TITLE=$1 shift ; CMND="${@}" 
exec $TERMINAL_EMULATOR -title "$TITLE" -e $CMND

