#!/bin/sh # Usage: `git url` or `git url ` # # * copies the commit's github url to your clipboard # * prints out the log message # * opens the bugzilla page if it found a bug number # # Assumes that the canonical remote is named upstream. # Works on Linux function gh_remote_url() { name=$1 remote_line=$(git remote -v | grep push | grep $name) if [[ -z $remote_line ]]; then echo "Error: remote '$name' not found." exit 1 fi if [[ ! $(echo $remote_line | grep github) ]]; then echo "Error: $name is not on github!" exit 1 fi repo=$(echo $remote_line | sed 's/.*github.com[:\/]\([^ ]*\) .*/\1/' | sed 's/\.git//') echo "https://github.com/$repo" } REV=${1-HEAD} ROOT=$(gh_remote_url upstream) BUGZILLA='https://bugzilla.mozilla.org/show_bug.cgi?id=' HASH=$(git rev-parse $REV) MSG=$(git log --pretty=oneline --format=%s -1 $HASH) BUG=$(echo $MSG | grep -i 'bug [0-9]\+' | sed 's/.*bug \([0-9]\+\).*/\1/i') echo $ROOT/$HASH | xclip echo $MSG # Open the browser if we found a bug number. if [[ $BUG ]]; then xdg-open "${BUGZILLA}${BUG}#comment" > /dev/null fi