Skip to content

Instantly share code, notes, and snippets.

@stefansundin
Last active April 8, 2017 01:33
Show Gist options
  • Save stefansundin/2d91d45580763cda29af to your computer and use it in GitHub Desktop.
Save stefansundin/2d91d45580763cda29af to your computer and use it in GitHub Desktop.
#!/bin/bash
# https://gist.github.com/stefansundin/2d91d45580763cda29af
# Easily open a repo in a browser, just run `git open`
# Linux users need to change "open" to "xdg-open".
# Example installation instructions:
# curl -fL -o /usr/local/bin/git-open https://gist.githubusercontent.com/stefansundin/2d91d45580763cda29af/raw/git-open
# chmod +x /usr/local/bin/git-open
ORIGIN=`git config --get remote.origin.url | sed -e 's/\.git$//'`
if [ -z "$ORIGIN" ]; then
echo "This repository doesn't seem to have an origin remote configured."
exit 1
fi
if [[ "$ORIGIN" == "http"* ]]; then
# http origin
echo "$ORIGIN"
open "$ORIGIN"
else
# ssh origin
URL=`echo "$ORIGIN" | sed -e 's/:/\//' -e 's/[^@]*@/https:\/\//'`
echo "$URL"
open "$URL"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment