Skip to content

Instantly share code, notes, and snippets.

@cokert
Last active December 12, 2019 19:25
Show Gist options
  • Save cokert/08a16603e7c0256a0f5e23931c3778be to your computer and use it in GitHub Desktop.
Save cokert/08a16603e7c0256a0f5e23931c3778be to your computer and use it in GitHub Desktop.
This is a shell script to open the current folder and branch in GitHub
#! /usr/bin/env zsh
if git rev-parse --git-dir > /dev/null 2>&1; then
: # This is a valid git repository (but the current working
# directory may not be the top level.
# Check the output of the git rev-parse command if you care)
REMOTE=`git remote -v`
BRANCH=`git status`
CURPATH=`git rev-parse --show-toplevel`
DIR=`pwd`
REMOTE=`git remote -v | head -n 1 | tr -d '[:space:]' | sed -e 's/origin\(.*\)(fetch)/\1/'`
REMOTE="${REMOTE//.git/}"
BRANCH=`git status | head -n 1 | sed -e 's/On branch\(.*\)/\1/' | tr -d '[:space:]'`
PATHINREPO="${DIR//$CURPATH/}"
open $REMOTE/tree/$BRANCH$PATHINREPO
else
: # this is not a git repository
echo "Not in a git repo"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment