1*cdf0e10cSrcweir#!/bin/sh 2*cdf0e10cSrcweir 3*cdf0e10cSrcweir# tries to locate the executable specified 4*cdf0e10cSrcweir# as first parameter in the user's path. 5*cdf0e10cSrcweirwhich() { 6*cdf0e10cSrcweir if [ ! -z "$1" ]; then 7*cdf0e10cSrcweir for i in `echo $PATH | sed -e 's/^:/.:/g' -e 's/:$/:./g' -e 's/::/:.:/g' -e 's/:/ /g'`; do 8*cdf0e10cSrcweir if [ -x "$i/$1" -a ! -d "$i/$1" ]; then 9*cdf0e10cSrcweir echo "$i/$1" 10*cdf0e10cSrcweir break; 11*cdf0e10cSrcweir fi 12*cdf0e10cSrcweir done 13*cdf0e10cSrcweir fi 14*cdf0e10cSrcweir} 15*cdf0e10cSrcweir 16*cdf0e10cSrcweir# checks for the original mozilla start script(s) 17*cdf0e10cSrcweir# and restrict the "-remote" semantics to those. 18*cdf0e10cSrcweirrun_mozilla() { 19*cdf0e10cSrcweir if file "$1" | grep "script" > /dev/null && grep "NPL" "$1" > /dev/null; then 20*cdf0e10cSrcweir "$1" -remote 'ping()' 2>/dev/null >/dev/null 21*cdf0e10cSrcweir if [ $? -eq 2 ]; then 22*cdf0e10cSrcweir "$1" "$2" & 23*cdf0e10cSrcweir else 24*cdf0e10cSrcweir "$1" -remote "openURL($2, new-window)" & 25*cdf0e10cSrcweir fi 26*cdf0e10cSrcweir else 27*cdf0e10cSrcweir "$1" "$2" & 28*cdf0e10cSrcweir fi 29*cdf0e10cSrcweir} 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir# checks the browser value for a %s as defined in 32*cdf0e10cSrcweir# http://www.catb.org/~esr/BROWSER/index.html 33*cdf0e10cSrcweirrun_browser() { 34*cdf0e10cSrcweir echo "$1|$2" | awk ' 35*cdf0e10cSrcweir{ 36*cdf0e10cSrcweir FS="|"; 37*cdf0e10cSrcweir $syscmd=""; 38*cdf0e10cSrcweir if (index($1,"%s") > 0) { 39*cdf0e10cSrcweir $syscmd=sprintf($1,$2); 40*cdf0e10cSrcweir } else { 41*cdf0e10cSrcweir $syscmd=sprintf("%s \"%s\"",$1,$2); 42*cdf0e10cSrcweir } 43*cdf0e10cSrcweir system($syscmd " &"); 44*cdf0e10cSrcweir}' > /dev/null 45*cdf0e10cSrcweir} 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir# special handling for mailto: uris 48*cdf0e10cSrcweirif echo $1 | grep '^mailto:' > /dev/null; then 49*cdf0e10cSrcweir # check for xdg-email 50*cdf0e10cSrcweir mailer=`which xdg-email` 51*cdf0e10cSrcweir if [ ! -z "$mailer" ]; then 52*cdf0e10cSrcweir $mailer "$1" & 53*cdf0e10cSrcweir exit 0 54*cdf0e10cSrcweir fi 55*cdf0e10cSrcweir # check $MAILER variable 56*cdf0e10cSrcweir if [ ! -z "$MAILER" ]; then 57*cdf0e10cSrcweir $MAILER "$1" & 58*cdf0e10cSrcweir exit 0 59*cdf0e10cSrcweir fi 60*cdf0e10cSrcweir # mozilla derivates may need -remote semantics 61*cdf0e10cSrcweir for i in thunderbird mozilla netscape; do 62*cdf0e10cSrcweir mailer=`which $i` 63*cdf0e10cSrcweir if [ ! -z "$mailer" ]; then 64*cdf0e10cSrcweir run_mozilla "$mailer" "$1" 65*cdf0e10cSrcweir exit 0 66*cdf0e10cSrcweir fi 67*cdf0e10cSrcweir done 68*cdf0e10cSrcweir # handle all non mozilla mail clients below 69*cdf0e10cSrcweir # .. 70*cdf0e10cSrcweirelse 71*cdf0e10cSrcweir # check for xdg-open 72*cdf0e10cSrcweir browser=`which xdg-open` 73*cdf0e10cSrcweir if [ ! -z "$browser" ]; then 74*cdf0e10cSrcweir $browser "$1" & 75*cdf0e10cSrcweir exit 0 76*cdf0e10cSrcweir fi 77*cdf0e10cSrcweir # check $BROWSER variable 78*cdf0e10cSrcweir if [ ! -z "$BROWSER" ]; then 79*cdf0e10cSrcweir $BROWSER "$1" & 80*cdf0e10cSrcweir exit 0 81*cdf0e10cSrcweir fi 82*cdf0e10cSrcweir # mozilla derivates may need -remote semantics 83*cdf0e10cSrcweir for i in firefox mozilla netscape; do 84*cdf0e10cSrcweir browser=`which $i` 85*cdf0e10cSrcweir if [ ! -z "$browser" ]; then 86*cdf0e10cSrcweir run_mozilla "$browser" "$1" 87*cdf0e10cSrcweir exit 0 88*cdf0e10cSrcweir fi 89*cdf0e10cSrcweir done 90*cdf0e10cSrcweir # handle all non mozilla browers below 91*cdf0e10cSrcweir # .. 92*cdf0e10cSrcweirfi 93*cdf0e10cSrcweirexit 1 94