#!/bin/sh
# A Run box
#
# License : GNU GPL
# (c) Eko M. Budi, 2004
# (c) Vector Linux, 2004
PROG=$RUN_PROG
PROG_LIST=$RUN_PROG_LIST
[ -z "$PROG_LIST" ] && PROG_LIST="grun"

case "$1" in
  -h|--help)
     echo "Usage: " `basename $0` "[options]"
     echo "Launch one of: $PROG_LIST"
     exit 0
     ;;
  --read-command)
     rm -f $HOME/.run_command
     echo -n "Command: "
     read
     echo $REPLY > $HOME/.run_command
     exit 0
esac

# default run box using xterm :)
default_run()
{
   if [ ! -f $HOME/.bash_run ]; then
echo '#.bash_run
# Profile for run box
echo Type command line here. Use up/down keys for history
PS1="Run:"
PS2=""' > $HOME/.bash_run
   fi
   xterm -geometry 60x1 -title Run -e run_command --read-command
   if [ -f $HOME/.run_command ]; then
      REPLY=`cat $HOME/.run_command`
      rm $HOME/.run_command
      if [ "$REPLY" ]; then
        exec $REPLY
        message "ERROR" "Could not run $REPLY"
      fi
   fi
}

if [ "$PROG" ]; then
   PROG=`which $PROG 2> /dev/null`
fi
if [ -z "$PROG" ]; then
  for TRY in $PROG_LIST ; do
    echo Trying $TRY ...
    PROG=`which $TRY 2> /dev/null`
    [ $? = 0 ] && break
  done
fi

case "$PROG" in
"")
   default_run
   ;;
*)
   exec $PROG $@
esac
