Last active
August 29, 2015 14:08
-
-
Save andrewjtait/9114245e92b84d69aa43 to your computer and use it in GitHub Desktop.
GitHub Bash Function
This file contains hidden or 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 github { | |
branch="$(git rev-parse --abbrev-ref HEAD)" | |
url="$(git config --get remote.origin.url)" | |
url=${url/[email protected]:/http://github.com/} | |
url=${url/.git/} | |
if [[ $1 =~ "compare" ]]; then action="compare" | |
elif [[ $1 =~ "pr" ]]; then action="pull" | |
else action="tree"; fi | |
if [[ $2 != "" ]]; then base="$2..." | |
else base=""; fi | |
url="${url}/${action}/${base}${branch}" | |
echo "Opening ${url} $(\open ${url})" | |
} |
Thanks @andrewjtait!
One thing: I had to change if [[ $2 ]];
to if [[ $2 != "" ]];
to make it work (Mac OSX 10.9 using oh-my-zsh).
Thanks @kaelig, I've updated it with this fix.
I've added the following between line 10
and 11
elif [[ $1 =~ "pull" ]]; then action="pull"
To allow the following additional commands:
github pull
-> opens a GitHub pull request withmaster
github pull branchname
-> opens a GitHub pull request withbranchname
Thanks @brian-griffin. I've added this, but I've used pr
rather than pull
as it could be assumed it does something similar to git pull
.
a fork for the lazy typist in me https://gist.github.com/wheresrhys/2bd4ae944003fe57af50. Cheers for producing the original @andrewjtait
This has now been set up in a repository which is installable through Homebrew: https://github.com/andrewjtait/github-open
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This function can be added to your
.bash_profile
. It supports repositories cloned with SSH, and provides the following commands:github
-> opens GitHub repo and branchgithub compare
-> opens GitHub branch comparison withmaster
github compare branch_name
-> opens GitHub branch comparison withbranch_name
github pr
-> opens a GitHub pull request againstmaster
github pr branch_name
-> opens a GitHub pull request againstbranch_name