Last active
May 23, 2017 16:07
-
-
Save broofa/b9ed43204a1002705f1cc2291edb2183 to your computer and use it in GitHub Desktop.
Open github page for current repo/branch/file from command line (MacOSX)
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
#!/bin/bash | |
# File: git-hub | |
# | |
# Description: Open github webpage for the current repo+branch[+file] | |
# (for MacOSX, not tested on other platforms) | |
# | |
# Usage: git hub | |
# git hub <file> | |
# | |
# Installation: Save as "git-hub" in a directory in your PATH, then `chmod a+x git-hub` | |
ROOT=`git rev-parse --show-toplevel` | |
BRANCH=`git branch -vv | grep "^*" | sed -Ee "s/^\* *| .*//g"` | |
GDIR=`realpath --relative-to="${ROOT}" .` | |
URL=`git config --get remote.origin.url | sed -e "s/[^@]*@\([^:]*\):\(.*\)\.git/https:\/\/\1\/\2/"` | |
open $URL/tree/$BRANCH/$GDIR/$1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment