Skip to content

Instantly share code, notes, and snippets.

@josephholsten
Created August 17, 2010 20:25
Show Gist options
  • Save josephholsten/531853 to your computer and use it in GitHub Desktop.
Save josephholsten/531853 to your computer and use it in GitHub Desktop.
#!/bin/sh
base='http://github.com'
if [ $1 ]; then
file=`git ls-files --full-name $1`;
fi
current=`git status -s -b | head -1 | cut -d' ' -f2`
remote=`git config branch.$current.remote`
if [ "$remote" = "" ] ; then
remote='origin'
fi
branch=`git config branch.$current.merge | sed 's/.*\/\([^\/]*\)/\1/'`
repo=`git remote -v |
awk "\\$1 ~ /$remote/ {print \\$0}" |
awk '$2 ~ /github/ {print $2}' |
head -n 1 |
sed 's/.*[:/]\([^/]*\)\/\([^\.]*\)\.git/\1\/\2\/blob/'`
url=$base/$repo/$branch/$file
open $url
@josephholsten
Copy link
Author

FIXED:

  • prefer appropriate remote (via git config branch.$current.remote)
  • then prefer a remote named 'origin' (which may not exist)
  • prefer appropriate branch (via git config branch.$current.branch)

TODO

  • check if default origin remote exists before using it
  • prefer a remote named 'upstream', if no origin exists, then whichever
  • prefer a branch with the same name if nothing is specified, then master, then whatever

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment