Skip to content

Instantly share code, notes, and snippets.

@mythmon
Forked from rlr/git-url
Last active December 15, 2015 03:59
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 mythmon/5198536 to your computer and use it in GitHub Desktop.
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.
#!/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