#! /bin/sh
+if [ -z "$1" ]; then
+ branch="`git rev-parse --abbrev-ref HEAD`"
+ remote="`git config --get branch.$branch.remote`"
+elif [ -n "$2" ]; then
+ echo "Usage: git open [remote_name]" >&2
+ exit 1
+else
+ remote="$1"
+fi
+
+if [ -z "$remote" ]; then
+ echo "Cannot find remote for branch $branch" >&2
+ echo "Usage: git open [remote_name]" >&2
+ exit 1
+fi
+
browser_section="`git config --get web.browser`"
browser_cmd="`git config --get browser.\"$browser_section\".cmd`"
if [ -z "$browser_cmd" ]; then
browser_cmd="webbrowser -n"
fi
-exec $browser_cmd "`git config --get remote.$1.url`"
+
+exec $browser_cmd "`git config --get remote.$remote.url`"