Skip to content

Instantly share code, notes, and snippets.

@kriskhaira
Forked from whobutsb/github_repo.sh
Last active November 22, 2017 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kriskhaira/8283d829244229e335d499e38ec6c4d8 to your computer and use it in GitHub Desktop.
Save kriskhaira/8283d829244229e335d499e38ec6c4d8 to your computer and use it in GitHub Desktop.
Shell script to open the current GitHub or GitLab project URL
# 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 != git@github.com:* && $git_url != git@gitlab.com:* ]]; then
echo "ERROR: Remote origin is invalid" && return false;
fi
url=${git_url%.git};
if [[ $url == git@github.com:* ]]; then
url=$(echo $url | sed 's,git@github.com:,https://github.com/,g');
elif [[ $url == git@gitlab.com:* ]]; then
url=$(echo $url | sed 's,git@gitlab.com:,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