Skip to content

Instantly share code, notes, and snippets.

@jhsu
Created April 10, 2012 18:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhsu/2353398 to your computer and use it in GitHub Desktop.
Save jhsu/2353398 to your computer and use it in GitHub Desktop.

git-hub

This script opens a url to the github commit page

Install

add to a folder in $PATH (ie, /usr/local/bin, or if you have ~/bin part of your path). If the current branch is tracking a remote branch that is on github:

git hub # outputs the url to the most recent commit and opens it in default browser (if the commit has been pushed)
git hub -2 # opens the url to the 2nd most recent commit

git-hub takes options for git-log and opens the last item in the list (using tail -1)

#!/usr/bin/env bash
args="${1:--1}"
sha=`git log $args --pretty=format:'%h' | tail -1`
host=`git config --get remote."$(git config --get branch.master.remote)".url | sed 's/^git@//g' | sed 's/\.git$//g' | sed 's/\.com:/\.com\//g'`
url="http://$host/commit/$sha"
echo $url
open $url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment