#!/bin/sh
# Launch a default browser
# License : GNU GPL
# (c) Eko M. Budi, 2004
# (c) Vector Linux, 2004

# Change this to reorder
if [ -z "$BROWSER_LIST" ]; then
  BROWSER_LIST="firefox opera galeon epiphany mozilla konqueror firebird dillo"
fi

case "$1" in 
  "-h"|"--help")
  echo browser
  echo Usage: browser [URL]
  echo Launching any browser to access the URL
  exit 0
  ;;
esac

if [ "$BROWSER" ]; then
   PROG=`which $BROWSER 2> /dev/null`
   echo Browser=$PROG
fi

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

if [ ! -z "$PROG" ]; then
  case `basename "$PROG"` in
    *firefox|*firebird|*galeon|*mozilla|*konqueror)
       echo "Opening remotely ..."
       if [ -z "$*" ]; then
         $PROG -raise -remote openURL\(:blank,new-window\) && exit
       else
         $PROG -remote openURL\("$*",new-window\) && exit
       fi
       echo "Opening directly ..."
       exec $PROG $@
       ;;
    opera)
       echo "Opening remotely ..."
       if [ -z "$*" ]; then
         $PROG -raise -remote openURL\(\) && exit
       else
         $PROG -remote openURL\("$*",new-window\) && exit
       fi
       echo "Opening directly ..."
       exec $PROG $@
       ;;
    *) 
       echo "Opening directly ..."
       exec $PROG $@
       ;;
  esac
fi

message "ERROR" "Could not launch: " "$PROG_LIST" 
exit 1

