Created
July 10, 2015 20:03
-
-
Save ZevEisenberg/d95cde83055f6c707050 to your computer and use it in GitHub Desktop.
Function to open the GitHub page of the current repo
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
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