-
-
Save mythmon/5198536 to your computer and use it in GitHub Desktop.
I don't use a mac, and I don't have ack, and I didn't like some other things. I made it better.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Usage: `git url` or `git url <commitish>` | |
# | |
# * 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment