DEV Community

kethmars
kethmars

Posted on

Nice tip - open your Github project page from CL

Hey hey!

There's this bash_profile alias I've been using and probably it's helpful for you too:

For MacOS:

alias gh="open \`git remote -v | grep git@github.com | grep fetch | head -1 | cut -f2 | cut -d' ' -f1 | sed -e's/:/\//' -e 's/git@/http:\/\//'\`"

For Linux (provided by Shawn McElroy in the comments, thank you):
alias gh="$BROWSER $(git remote -v | grep git@github.com | grep fetch | head -1 | cut -f2 | cut -d' ' -f1 | sed -e's/:/\//' -e 's/git@/http:\/\//'\)"

After that, just use the command gh. It will open your browser with the currently active Git project in Github.

Top comments (3)

Collapse
 
autoferrit profile image
Shawn McElroy •

In Linux there's no open command. You should be able to do this if your default browser is set

alias gh="$BROWSER $(git remote -v | grep git@github.com | grep fetch | head -1 | cut -f2 | cut -d' ' -f1 | sed -e's/:/\//' -e 's/git@/http:\/\//'\)"

It may work on osx as well if you set $BROWSER in your terminal somewhere. Note, I'm on my phone so I couldn't try this but it should be right

Collapse
 
kethmars profile image
kethmars •

Oh wow! Thank you! I edited the article, specified environments and added your script there.

Collapse
 
autoferrit profile image
Shawn McElroy •

Ooh, good point. Both should work. BROWSER may not always be set either probably