Skip to content

Instantly share code, notes, and snippets.

@rrelmy
Forked from kriskhaira/gsite.sh
Created November 22, 2017 09:35
Show Gist options
  • Save rrelmy/fe5288b16d1f01fa5dd556870761e360 to your computer and use it in GitHub Desktop.
Save rrelmy/fe5288b16d1f01fa5dd556870761e360 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