Created
October 9, 2017 22:17
-
-
Save nick-f/43064054846d1a68de5e702685b588ec to your computer and use it in GitHub Desktop.
Shell function to open the current repo's GitHub page
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
alias gho=githubOpen | |
function githubOpen() { | |
if [ ! -d .git ] ; | |
then echo "ERROR: This isnt a git directory" && return false; | |
fi | |
git_url=`git config --get remote.origin.url` | |
if [[ "${git_url}" == git@github* ]]; then | |
if [[ "${git_url}" == *.git ]]; then | |
repo_owner=`echo "${git_url}" | sed -Ene 's#git@github.com:([^/]*)/(.*).git#\1#p'` | |
repo_name=`echo "${git_url}" | sed -Ene 's#git@github.com:([^/]*)/(.*).git#\2#p'` | |
else | |
repo_owner=`echo "${git_url}" | sed -Ene 's#git@github.com:([^/]*)/(.*)#\1#p'` | |
repo_name=`echo "${git_url}" | sed -Ene 's#git@github.com:([^/]*)/(.*)#\2#p'` | |
fi | |
url="https://github.com/${repo_owner}/${repo_name}" | |
elif [[ "${git_url}" == https://github* ]]; then | |
url=${git_url%.git} | |
else | |
echo "ERROR: Remote origin is invalid" && return false; | |
fi | |
open "${url}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment