Skip to content

Instantly share code, notes, and snippets.

@fedescarpa
Created August 9, 2016 14:07
Show Gist options
  • Save fedescarpa/aa9ea3e8fa6dbe1d44b157ef90c965c4 to your computer and use it in GitHub Desktop.
Save fedescarpa/aa9ea3e8fa6dbe1d44b157ef90c965c4 to your computer and use it in GitHub Desktop.
Open current git repository in default browser
#!/bin/bash
GIT_REPO=$(git config -l | grep "remote.origin.url=git@")
HTTP_REPO=$(git config -l | grep "remote.origin.url=https://")
if [ -n "$GIT_REPO" ]; then
REPO=$(echo $GIT_REPO | awk 'BEGIN { FS = "git@" } { print $2 }' | awk 'BEGIN { FS = ":" } { print $1"/"$2 }')
else
if [ -n "$HTTP_REPO" ]; then
REPO=$(echo $HTTP_REPO | awk 'BEGIN { FS = "https://" } { print $2 }')
else
echo "GIT or HTTPS in remote.origin.url missing"
exit 1
fi
fi
echo "Opening $REPO"
sensible-browser "https://$REPO"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment