Last active
December 21, 2015 02:29
-
-
Save ex-nerd/6235705 to your computer and use it in GitHub Desktop.
Revisions
-
ex-nerd revised this gist
Aug 14, 2013 . 2 changed files with 51 additions and 43 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,43 +0,0 @@ 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 charactersOriginal 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" } -
ex-nerd created this gist
Aug 14, 2013 .There are no files selected for viewing
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 charactersOriginal 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" }