#!/bin/sh

# Comment this line to avoid focussing the window the tab opens in.
FOCUSTAB=yes

CLASS='Navigator\.Firefox'
URL=$1



LOCAL_WINDOW=$(wmctrl -lx | awk '{print $3 " " $2 " " $1}' | grep ^"$CLASS $(wmctrl -d | grep '*' | cut -d ' ' -f 1)")
if [ -n "$LOCAL_WINDOW" ]; then
	WINID=$(echo "$LOCAL_WINDOW" | awk '{print $3}')
	[ -n "$FOCUSTAB" ] && wmctrl -i -a $WINID
	firefox -new-tab "$URL"
else
	firefox -new-window "$URL"
fi

