#!/bin/bash # Set to "window" if you prefer new Firebird windows instead of new tabs newtype=${MOZILLA_NEWTYPE:-"tab"} # Point this to your Firebird installation if not using the default export MOZILLA_FIVE_HOME="/usr/lib/MozillaFirebird" fbpath=${MOZILLA_FIVE_HOME} # Sanity check if [[ -z $DISPLAY ]]; then echo "DISPLAY is unset!" >&2 exit 1 fi # Filter out ampersands because declare doesn't like 'em, replace with ____AMPERSAND____ # This will cause problems in the unlikely event of handling a URL containing ____AMPERSAND____!!! # Validate the args and extract the url url='' declare -a args=(`echo "$@" | sed 's/\&/____AMPERSAND____/g'`) while [[ $# -ne 0 ]] ; do if [[ $1 == -* ]] ; then case ${1#-} in height|width|CreateProfile|P|UILocale|contentLocale|remote|edit|chrome) shift 2 ;; *) shift 1 ;; esac else if [[ -n $url ]] ; then echo "Usage error: more than one URL given" >&2 exit 255 else # put ampersands back in url=(`echo "${args[0]}" | sed 's/____AMPERSAND____/\&/g'`) shift 1 if [[ $url != *:* ]] ; then url=http://$url fi fi fi done # Try to start in an existing session; check all screens declare -a screens=( $(/usr/X11R6/bin/xdpyinfo | awk ' /^name of display:/ { disp = substr($NF, 0, index($NF, ".")-1) } /^number of screens:/ { for (i = 0; i < $NF; i++) printf("%s.%d\n", disp, i) }') ) for s in $DISPLAY "${screens[@]}"; do DISPLAY=${s} ${fbpath}/mozilla-xremote-client "openURL($url, new-$newtype)" \ && exit 0 done retval=$? if [[ $retval -eq 2 || $retval -eq 3 ]] ; then # 2 = No running windows found, so start a new instance # 3 = Thunderbird is running, but doesn't handle openURL command # (or it might be an unresponsive Firebird) # Put ampersands back in ${fbpath}/MozillaFirebird "`echo "${args[@]}" | sed 's/____AMPERSAND____/\&/g'`" && exit 0 retval=$? echo "MozillaFirebird exited with non-zero status ($retval)" >&2 elif [[ $retval -eq 1 ]] ; then echo "Unable to connect to X server" >&2 else echo "Unknown error $retval from mozilla-xremote-client" >&2 fi exit $retval