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 != [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