-
-
Save kriskhaira/8283d829244229e335d499e38ec6c4d8 to your computer and use it in GitHub Desktop.
Shell script to open the current GitHub or GitLab project 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
# Opens the current GitHub or GitLab project URL | |
# | |
# Based on work by: | |
# | |
# whobutsb (Twitter: @SteveBarbera) | |
# https://gist.github.com/whobutsb/71ec536858957b6010d862f08ccc38f3 | |
# | |
# ShaydeNofziger (Twitter: @TheMindOfShayde) | |
# https://dev.to/shayde/open-the-github-project-page-of-a-repo-from-terminal | |
# https://twitter.com/ThePracticalDev/status/854380399937638400 | |
# | |
# Modified to add compatibility with GitLab | |
function gsite() { | |
if [ ! -d .git ] ; | |
then echo "ERROR: This isn't a git directory" && return false; | |
fi | |
git_url=`git config --get remote.origin.url` | |
if [[ $git_url != [email protected]:* && $git_url != [email protected]:* ]]; then | |
echo "ERROR: Remote origin is invalid" && return false; | |
fi | |
url=${git_url%.git}; | |
if [[ $url == [email protected]:* ]]; then | |
url=$(echo $url | sed 's,[email protected]:,https://github.com/,g'); | |
elif [[ $url == [email protected]:* ]]; then | |
url=$(echo $url | sed 's,[email protected]:,https://gitlab.com/,g'); | |
fi | |
open $url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment