Created
October 15, 2020 13:14
-
-
Save ricardoribas/6cd4f41158e191fca557118ba55ee90b to your computer and use it in GitHub Desktop.
open branch url
This file contains 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 characters
#!/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