Skip to content

Instantly share code, notes, and snippets.

Last active May 23, 2017 16:07
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Open github page for current repo/branch/file from command line (MacOSX)
# 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