Created
May 13, 2011 11:33
-
-
Save aurelian/970381 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Opens the github page for the current git repository and branch in your browser | |
# | |
# based on this: http://jasonneylon.wordpress.com/2011/04/22/opening-github-in-your-browser-from-the-terminal/ | |
# + works with current branch | |
# + pass file: gh foo/bar.txt #=> https://github.com/o/o/tree/master/foo/bar.txt | |
# + pass commit sh: gh 5116fba #=> https://github.com/o/o/commits/5116fba | |
# | |
function gh() { | |
giturl=$(git config --get remote.origin.url) | |
if [ "$giturl" == "" ] | |
then | |
echo "Not a git repository or no remote.origin.url set" | |
return 1; | |
fi | |
giturl=${giturl/git\@github\.com\:/https://github.com/} | |
giturl=${giturl/\.git//} | |
if [ $(git name-rev $1 2> /dev/null | grep -c $1) -eq "1" ] | |
then | |
part="commit/$1" | |
else | |
part=$(git symbolic-ref HEAD) | |
part="tree/"${part/refs\/heads\//}"/"$1 | |
fi | |
echo "$giturl$part" | |
open "$giturl$part" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment