Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Function to open the GitHub page of the current repo
function gh
{
local remoteURL=`git remote -v | grep fetch | awk -F ' ' '{print $2}'`
if [[ ! -z $remoteURL ]]; then
local isGitHubURL=`echo $remoteURL | grep -i github\.com`
if [[ ! -z $isGitHubURL ]]; then
local regex=".*github\.com[:/](.*)/(.*)\.git"
if [[ $remoteURL =~ $regex ]]; then
local owner=$match[1]
local repoName=$match[2]
local gitHubURL="https://github.com/${owner}/${repoName}"
# this line assumes that `open "someURL"` will work on your system.
# This is true for OS X; not sure about various Linuces.
open "$gitHubURL"
else
echo "URL does not match"
fi
else
echo "This repository is not a clone of a GitHub repo."
fi
else
echo "This repository does not have a remote URL."
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.