#!/bin/sh # # $NetBSD: ns-open,v 1.4 2001/01/12 23:11:05 tron Exp $ # # Simple script to open a URL in Netscape, starting a new process if necessary # If a netscape process is not running it will look for a valid netscape # binary in the colon separated NETSCAPE_PREFERRED list, which can be # overridden by the user in the environment. if [ -z "$NETSCAPE_PREFERRED" ]; then NETSCAPE_PREFERRED=communicator:navigator fi # Locate appropriate netscape binary and set NETSCAPE_BIN # If we cannot locate, do not fail with an error here as we may still be # able to use ns-remote to talk to an existing netscape process. # oldIFS="$IFS" IFS="${IFS}:" for prog in $NETSCAPE_PREFERRED ; do case $prog in /*) if [ -x $prog ]; then NETSCAPE_BIN=$prog break fi ;; *) for dir in $PATH;do if [ -x $dir/$prog ];then NETSCAPE_BIN=$dir/$prog break fi done ;; esac done IFS="$oldIFS" RAISE=-noraise # Check if there are any '-' options which would not be understood by ns-remote # Slightly involved to avoid changing $@ in case we need it for real netscape # for a do if [ "$SKIP_ARG" = 1 ];then NS_REMOTE_ARGS="$NS_REMOTE_ARGS $a" SKIP_ARG=0 continue fi case $a in -display | -id) SKIP_ARG=1 ;; -remote) REMOTE_SPECIFIED=1 SKIP_ARG=1 ;; -raise | -noraise) RAISE= ;; -* ) UNRECOGNISED_OPTION=1 ;; *) URL=`echo $a | sed -e 's/"/%22/g' -e 's/,/%2c/g' -e 's/\`/%60/g` break; ;; esac NS_REMOTE_ARGS="$NS_REMOTE_ARGS $a" done # If we recognised all the options, try ns-remote # if [ -z "$UNRECOGNISED_OPTION" ];then NS_REMOTE_ARGS="$NS_REMOTE_ARGS $RAISE" if [ -z "$REMOTE_SPECIFIED" ];then if [ -n "$URL" ];then # encode , " and ` to avoid problems with openURL(x,y) NS_REMOTE_ARGS="$NS_REMOTE_ARGS -remote openURL(${URL},new-window)" else NS_REMOTE_ARGS="$NS_REMOTE_ARGS -remote openBrowser" fi fi if ns-remote $NS_REMOTE_ARGS ; then exit 0 fi fi if [ -z "$NETSCAPE_BIN" ];then echo "Unable to locate netscape binary '$NETSCAPE_PREFERRED'" exit 1 fi case $1 in -*) $NETSCAPE_BIN $@ ;; *) # Since using ns-remote will return, we start netscape in the # background to give consistent behaviour. $NETSCAPE_BIN $@ & ;; esac exit 0