Skip to content

Instantly share code, notes, and snippets.

@broofa
Last active May 23, 2017 16:07
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 broofa/b9ed43204a1002705f1cc2291edb2183 to your computer and use it in GitHub Desktop.
Save broofa/b9ed43204a1002705f1cc2291edb2183 to your computer and use it in GitHub Desktop.
Open github page for current repo/branch/file from command line (MacOSX)
#!/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