Last active
October 5, 2020 21:08
-
-
Save Anoesj/300077068c0df1f0b70081f3e78f6e93 to your computer and use it in GitHub Desktop.
Run `repo` in the CLI to go to the repository on GitHub/Bitbucket on the active branch
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
# Add in .bashrc/.zshrc etc. | |
# Print/open link to repository, preferably to currently active branch | |
function repo () { | |
if [ "$(git rev-parse --is-inside-work-tree)" = "true" ]; then | |
REPO_URL=$(git config --get remote.origin.url | sed "s~git@\(.*\):\(.*\).git~https:\/\/\1\/\2~") | |
BRANCH=$(git branch --show-current) | |
# BRANCH=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/') # if the line above doesn't work | |
URL="" | |
if [[ $REPO_URL = *"github.com"* ]]; then | |
URL="$REPO_URL/tree/$BRANCH" | |
elif [[ $REPO_URL = *"bitbucket.org"* ]]; then | |
URL="$REPO_URL/branch/$BRANCH" | |
else | |
URL="$REPO_URL" | |
fi | |
echo "Opening $URL" | |
# open $URL # macOS | |
xdg-open $URL &> /dev/null # Ubuntu | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment