Skip to content

Instantly share code, notes, and snippets.

@hail2u
Forked from ku/gopen
Created February 18, 2012 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hail2u/1856938 to your computer and use it in GitHub Desktop.
Save hail2u/1856938 to your computer and use it in GitHub Desktop.
open corresponding URL of the repository of current directory (for msys)
#!/bin/sh
GIT='git'
FETCH_URL=`$GIT remote show origin -n | sed -n '/Fetch URL/p' | awk '{print $3}' | sed -E 's/[:@]/ /g' `
HOST=`echo $FETCH_URL | awk '{print $2}' `
REPOS=`echo $FETCH_URL | awk '{print $3}' | sed 's/.git$//'`
ORIGIN="http://$HOST/"
BRANCH=`$GIT branch | grep -F '*' | sed 's/^* //'`
echo $REPOS | 'egrep' -q '^gist/'
if [ $? = 0 ]; then
GIST=YES
else
GIST=NO
fi
if test "x$1" = "x" ; then
if test $GIST = "YES" ; then
URL="$ORIGIN$REPOS"
else
if test "x$BRANCH" = "x(no branch)"; then
URL="$ORIGIN$REPOS"
else
URL="$ORIGIN$REPOS/tree/$BRANCH"
fi
fi
else
if test $GIST = "YES" ; then
URL="$ORIGIN$REPOS/$1"
else
URL="$ORIGIN$REPOS/commit/$1"
fi
fi
echo $URL
open "$URL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment