#! /bin/sh
PATH=${PATH}:/usr/local/bin:/usr/local/netscape:/usr/local/lib/netscape

xbrowser="netscape"
tbrowser="lynx -force_html"
tmpdir=/tmp

URL="$1"
if [ -z "$URL" ]; then
    cat > $tmpdir/tmp.html
    URL=file://tmp/tmp.html
fi

# Assume file: URL if no type specified
# while we're at it, encode commas since they don't work with this interface
URL=`echo "file:$URL" | sed -e 's/^file:\([a-z][a-z]*:\)/\1/' -e 's/,/%2C/g'`

case $URL in
    file:*)
	IFS=:
	set $URL
	shift
	file="$@"
	IFS=
	newfile="$tmpdir/tmp_`basename $file`"
	cp $file $newfile
	URL=file:$newfile
	;;
esac

if [ -n "$DISPLAY" ]; then
    (netscape -remote "openURL($URL,new-window)" 2>/dev/null 1>/dev/null ) \
	|| ($xbrowser "$URL" 2>1 1>/dev/null &)
else
    $tbrowser "$URL"
fi

#echo "Press enter to continue."
#read enter
exit 0
