Skip to content

Instantly share code, notes, and snippets.

@zph

zph/git-browse Secret

Last active December 19, 2015 19:18
Show Gist options
  • Select an option

  • Save zph/6b0171954c36146e307e to your computer and use it in GitHub Desktop.

Select an option

Save zph/6b0171954c36146e307e to your computer and use it in GitHub Desktop.
#!/usr/bin/env sh
# git-browse, the @bantik revision with banter by @ZPH
git config --get remote.origin.url | \
ruby -ne 'puts %{https://github.com/#{$_.split(/.com[\:\/]/)[-1].gsub(".git","")}}' | \
xargs open
@CoralineAda

Copy link
Copy Markdown

git config --get remote.origin.url | ruby -ne 'puts %{https://github.com/#{$_.split(":")[-1]}}' | xargs open

@zph

zph commented Jul 16, 2013

Copy link
Copy Markdown
Author

Hmmm, git@github.com... (my code) only works for that style.
Yours works for git@github.com style & like it better, cleaner.

I just tried it out on a non git@github origin, ie https:// and it errors.

I'll see if I can modify yours to work with either git@github or https:// variations.

@zph

zph commented Jul 16, 2013

Copy link
Copy Markdown
Author

Handles git@github or https:// style --

git config --get remote.origin.url | ruby -ne 'puts %{https://github.com/#{$_.split(/.com[\:\/]/)[-1].delete(".git")}}'

@CoralineAda

Copy link
Copy Markdown

Sweet, let's keep this going. It's fun. :)

@CoralineAda

Copy link
Copy Markdown

Fails on git@github.com:AptsCom/reporting-webclient.git, the result is https://github.com/ApsCom/reporn-webclen

Trying another rev...

@zph

zph commented Jul 16, 2013

Copy link
Copy Markdown
Author

=) True!

Very fun!

Wouldn't be much of a one liner anymore, but we could make it capture the url (ie handle non-github pages, like bitbucket.org) via regex and use that for building final URL.

Gimme a min.

@CoralineAda

Copy link
Copy Markdown

git config --get remote.origin.url | ruby -ne 'puts %{https://github.com/#{$_.split(/.com[\:\/]/)[-1].gsub(".git","")}}' | xargs open

@zph

zph commented Jul 16, 2013

Copy link
Copy Markdown
Author
%r{(?<hostname_url>[\.\w]+)[/:](?<username>[-\w]+)/(?<repo>[-\w]+)}

How's that for a work of art?

@zph

zph commented Jul 16, 2013

Copy link
Copy Markdown
Author

Yours looks like it works for either configuration as long as it's a github location 😄

@zph

zph commented Jul 16, 2013

Copy link
Copy Markdown
Author

In honor of my new method of the day, you could even replace .gsub with .delete(".git")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment