#!/bin/sh

# This is a wrapper script meant to run in
# X11 on OSX, it will pass on URLs encountered
# in X11 to the default OSX browser, since
# they don't share clipboards. It can for
# example work with xchat2 running in X11,
# but it's meant for terminal IRC clients.
# This also extends to URLs encountered any-
# where in the terminal such as manpages
# etc. You will need the terminal called
# rxvt-unicode (available in MacPorts),
# and in your ~/.Xdefaults file you will
# need to tell urxvt the following:
#
# URxvt.font: xft:Monospace:size=16
# URxvt.perl-ext-common: default,matcher
# URxvt.urlLauncher: /Users/username/bin/urlwrapper_x11-osx.sh
# URxvt.matcher.button: 1
# URxvt.colorUL: #86a2be
# URxvt.underlineColor: #3465A4
#
# The URxvt.font line just sets the font to use,
# and the two underline options just colours the
# links, none of those options are necessary,
# they just make it look nicer ;-)
#
# Don't forget to change the urlLauncher line to
# the path and name you store the script under,
# it's safer to use the full pathname because
# X11 on OSX can be tricky with relative pathnames.




# First a check, if VALID_CHECK has a value,
# we know the url starts with http:// and can
# then open it in the default browser
VALID_CHECK=`echo "$1" | grep -i ^http\:\/\/`
if [ ! -z $VALID_CHECK ]; then
		open "$1"
# If VALID_CHECK had no value, it doesn't start
# with http:// and open won't be able to pass it
# on to the browser, so we'll need to put http://
# infront of the url
	else
		VALID_URL=`echo "$1" | sed 's/^/http\:\/\//'`
		open "$VALID_URL"
fi

