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
  • Save mythmon/5198536 to your computer and use it in GitHub Desktop.
Save mythmon/5198536 to your computer and use it in GitHub Desktop.

Revisions

  1. mythmon revised this gist Mar 19, 2013. 1 changed file with 30 additions and 12 deletions.
    42 changes: 30 additions & 12 deletions git-url
    Original file line number Diff line number Diff line change
    @@ -5,25 +5,43 @@
    # * prints out the log message
    # * opens the bugzilla page if it found a bug number
    #
    # Set up the github url with `git config github.url <url>`.
    # Only for the Mac.
    # Assumes that the canonical remote is named upstream.
    # Works on Linux

    if [[ $1 ]]; then
    REV=$1
    else
    REV='HEAD'
    fi
    function gh_remote_url() {
    name=$1

    ROOT=$(git config github.url)
    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 --short $REV)
    HASH=$(git rev-parse $REV)
    MSG=$(git log --pretty=oneline --format=%s -1 $HASH)
    BUG=$(echo $MSG | ack -i 'bug (\d+)' --output='$1')

    echo $ROOT/$HASH | pbcopy
    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
    open $BUGZILLA$BUG
    xdg-open "${BUGZILLA}${BUG}#comment" > /dev/null
    fi
  2. @rlr rlr created this gist Mar 19, 2013.
    29 changes: 29 additions & 0 deletions git-url
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/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
    #
    # Set up the github url with `git config github.url <url>`.
    # Only for the Mac.

    if [[ $1 ]]; then
    REV=$1
    else
    REV='HEAD'
    fi

    ROOT=$(git config github.url)
    BUGZILLA='https://bugzilla.mozilla.org/show_bug.cgi?id='
    HASH=$(git rev-parse --short $REV)
    MSG=$(git log --pretty=oneline --format=%s -1 $HASH)
    BUG=$(echo $MSG | ack -i 'bug (\d+)' --output='$1')

    echo $ROOT/$HASH | pbcopy
    echo $MSG

    # Open the browser if we found a bug number.
    if [[ $BUG ]]; then
    open $BUGZILLA$BUG
    fi