Skip to content

Instantly share code, notes, and snippets.

@ricardoribas
Created October 15, 2020 13:14
Show Gist options
  • Save ricardoribas/6cd4f41158e191fca557118ba55ee90b to your computer and use it in GitHub Desktop.
Save ricardoribas/6cd4f41158e191fca557118ba55ee90b to your computer and use it in GitHub Desktop.
open branch url
#!/bin/bash
REPOSITORY_URL=$(git remote -v \
| awk '/fetch/{print $2}' \
| sed -Ee 's#(git@|git://)#http://#' -e 's@com:@com/@' -e 's/(-[a-zA-Z]*):/\//' \
| sed -e 's/\.git//g'
)
BRANCH_NAME=$(git branch | grep "*" | awk '{ print $2 }')
echo "repository url: $REPOSITORY_URL"
if [[ $REPOSITORY_URL == *"github.com"* ]]; then
echo "opening github repository..."
open "$REPOSITORY_URL/tree/$BRANCH_NAME"
fi
if [[ $REPOSITORY_URL == *"bitbucket.org"* ]]; then
echo "opening bitbucket repository..."
open "$REPOSITORY_URL/branch/$BRANCH_NAME"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment