Skip to content

Instantly share code, notes, and snippets.

@ex-nerd
Last active December 21, 2015 02:29
Show Gist options
  • Save ex-nerd/6235705 to your computer and use it in GitHub Desktop.
Save ex-nerd/6235705 to your computer and use it in GitHub Desktop.

Revisions

  1. ex-nerd revised this gist Aug 14, 2013. 2 changed files with 51 additions and 43 deletions.
    43 changes: 0 additions & 43 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -1,43 +0,0 @@
    git_hub() {
    BRANCH=`git rev-parse --symbolic-full-name --abbrev-ref @{u} 2>/dev/null`
    if [[ $? != 0 ]]; then
    echo "Not currently in a git repository"
    return
    fi
    if [[ -z $BRANCH ]]; then
    echo "Can't determine current git branch name"
    return
    fi
    IFS_STORE="$IFS"
    IFS=$'\n'
    for REMOTE in `git remote`; do
    if [[ $BRANCH == "$REMOTE/"* ]]; then
    SHORT_BRANCH=${BRANCH#$REMOTE/}
    GITHUB_REPO=`git remote show "$REMOTE" | grep 'Fetch URL' | awk -F: '{ print $3 }' | sed -e 's,.git$,,'`
    if [[ $? != 0 ]]; then
    echo "Error loading github project info"
    break
    fi
    if [[ -z $BRANCH ]]; then
    echo "Couldn't determine github project info"
    break
    fi
    if [[ $SHORT_BRANCH == 'master' ]]; then
    # todo `git br -a | grep HEAD | ....`
    URL="https://github.com/$GITHUB_REPO/"
    else
    URL="https://github.com/$GITHUB_REPO/tree/$SHORT_BRANCH"
    fi
    echo "$URL"
    if [[ `uname` == 'Darwin' ]]; then
    open "$URL"
    elif `which xdg-open >/dev/null`; then
    xdg-open "$URL"
    else
    echo "Couldn't find URL opener"
    fi
    break
    fi
    done
    IFS="$IFS_STORE"
    }
    51 changes: 51 additions & 0 deletions git_hub.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    # Opens the current branch on github.com, if possible.
    # Would call this "github" but it conflicts with github's own CLI app to open their desktop app.
    git_hub() {
    BRANCH=`git rev-parse --symbolic-full-name --abbrev-ref @{u} 2>/dev/null`
    if [[ $? != 0 ]]; then
    echo "Not currently in a git repository"
    return
    fi
    if [[ -z $BRANCH ]]; then
    echo "Can't determine current git branch name"
    return
    fi
    IFS_STORE="$IFS"
    IFS=$'\n'
    FOUND=0
    for REMOTE in `git remote`; do
    if [[ $BRANCH == "$REMOTE/"* ]]; then
    FOUND=1
    SHORT_BRANCH=${BRANCH#$REMOTE/}
    GITHUB_REPO=`git remote show "$REMOTE" | grep 'Fetch URL' | awk -F: '{ print $3 }' | sed -e 's,.git$,,'`
    if [[ $? != 0 ]]; then
    echo "Error loading github project info"
    break
    fi
    if [[ -z $BRANCH ]]; then
    echo "Couldn't determine github project info"
    break
    fi
    # Check for 'master' Disabled because I need support odd repositories that don't use "master" as the default
    # TODO DEF_BRANCH=`git br -a | grep HEAD | ....`
    #if [[ $SHORT_BRANCH == 'master' ]]; then
    # URL="https://github.com/$GITHUB_REPO/"
    #else
    URL="https://github.com/$GITHUB_REPO/tree/$SHORT_BRANCH"
    #fi
    echo "$URL"
    if [[ `uname` == 'Darwin' ]]; then
    open "$URL"
    elif `which xdg-open >/dev/null`; then
    xdg-open "$URL"
    else
    echo "Couldn't find URL opener"
    fi
    break
    fi
    done
    if [[ $FOUND == 0 ]]; then
    echo "This branch does not appear to be tracking a remote."
    fi
    IFS="$IFS_STORE"
    }
  2. ex-nerd created this gist Aug 14, 2013.
    43 changes: 43 additions & 0 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    git_hub() {
    BRANCH=`git rev-parse --symbolic-full-name --abbrev-ref @{u} 2>/dev/null`
    if [[ $? != 0 ]]; then
    echo "Not currently in a git repository"
    return
    fi
    if [[ -z $BRANCH ]]; then
    echo "Can't determine current git branch name"
    return
    fi
    IFS_STORE="$IFS"
    IFS=$'\n'
    for REMOTE in `git remote`; do
    if [[ $BRANCH == "$REMOTE/"* ]]; then
    SHORT_BRANCH=${BRANCH#$REMOTE/}
    GITHUB_REPO=`git remote show "$REMOTE" | grep 'Fetch URL' | awk -F: '{ print $3 }' | sed -e 's,.git$,,'`
    if [[ $? != 0 ]]; then
    echo "Error loading github project info"
    break
    fi
    if [[ -z $BRANCH ]]; then
    echo "Couldn't determine github project info"
    break
    fi
    if [[ $SHORT_BRANCH == 'master' ]]; then
    # todo `git br -a | grep HEAD | ....`
    URL="https://github.com/$GITHUB_REPO/"
    else
    URL="https://github.com/$GITHUB_REPO/tree/$SHORT_BRANCH"
    fi
    echo "$URL"
    if [[ `uname` == 'Darwin' ]]; then
    open "$URL"
    elif `which xdg-open >/dev/null`; then
    xdg-open "$URL"
    else
    echo "Couldn't find URL opener"
    fi
    break
    fi
    done
    IFS="$IFS_STORE"
    }