#!/bin/sh # # openurl 2006-03-06 # # (c) 2005, 2006 by Dirk Jagdmann # # published under the zlib/libpng license http://www.opensource.org/licenses/zlib-license.php # no argument ? if [ -z "$1" ] ; then exit 0 fi # check BROWSER variable if [ -z "$BROWSER" -o "$BROWSER" = openurl ] ; then export BROWSER=firefox fi # start up BROWSER if not running if ! $BROWSER -remote "ping()" > /dev/null 2>&1 then $BROWSER > /dev/null 2>&1 & sleep 3 while ! $BROWSER -remote "ping()" > /dev/null 2>&1 do sleep 2 done fi # if we have a valid syntax, then use it if [ "$1" = "-remote" ] ; then $BROWSER "$@" exit 0 fi # now open all URLS from the command line for i in "$@" do # check for an URL if perl -e 'exit 0 if $ARGV[0]=~/^((http)|(https)|(ftp)):\/\//;exit 1' "$i" then $BROWSER -remote "openURL($i)" # check for absolute path elif perl -e 'exit 0 if $ARGV[0]=~/^\//;exit 1' "$i" then $BROWSER -remote "openFILE(file:$i)" # it is a relative path else $BROWSER -remote "openFILE(file:$PWD/$i)" fi sleep 1 done