Skip to content

Instantly share code, notes, and snippets.

@broofa
Created December 22, 2017 18:28
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/15e1bf47b1d37d2bbc67e24f4f84e734 to your computer and use it in GitHub Desktop.
Save broofa/15e1bf47b1d37d2bbc67e24f4f84e734 to your computer and use it in GitHub Desktop.
Open GitHub web page on to current repo+branch+file
#!/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