Command-line utility to visit github page of a named gem

I’m working in a Rails stack that involves a lot of convolutedly inter-related dependencies, which I’m not yet all that familiar with.

I often want to go visit the github page of one of the dependencies, to check out the README, issues/PRs, generally root around in the source, etc.  Sometimes I want to clone and look at the source locally, but often in addition to that I’m wanting to look at the github repo.

So I wrote a little utility to let me do gem-visit name_of_gem and it’ll open up the github page in a browser, using the MacOS open utility to open your default browser window.

The gem doesn’t need to be installed, it uses the API (hooray!) to look up the gem by name, and look at it’s registered “Homepage” and “Source Code” links. If either one is a link, it’ll prefer that. Otherwise, it’ll just send you to the Homepage, or failing that, to the page.

It’s working out well for me.

I wrote it in ruby (naturally), but with no dependencies, so you can just drop it in your $PATH, and it just works. I put ~/bin on my $PATH, so I put it there.

I’ll give to give you a gist of it (yes, i’m not maintaining it at present), but thinking about the best way to distribute this if I wanted to maintain it…. Distributing as a ruby gem doesn’t actually seem great, with the way people use ruby version switchers, you’d have to make sure to get it installed for every version of ruby you might be using to get the command line to work in them all.

Distributing as a homebrew package seems to actually make a lot of sense, for a very simple command-line utility like this. But homebrew doesn’t really like niche/self-submitted stuff, and this doesn’t really meet the requirements for what they’ll tolerate. But homebrew theoretically supports a third-party ‘tap’, and I think a github repo itself can be such a ‘tap’, and hypothetically I could set things up so you could cask tap my_github_url, and install (and later upgrade or uninstall!) with brew… but I haven’t been able to figure out how to do that from the docs/examples, just verified that it oughta be possible!  Anyone want to give me any hints or model examples?  Of a homebrew formula that does nothing but install a simple one-doc bash script, and is a third-party tap hosted  on github?


3 thoughts on “Command-line utility to visit github page of a named gem”

  1. True. The launchy gem sounds interesting. There might be ways to use gem dependencies in an easy to install way, maybe the newish “bundler/inline” stuff intended for single-file scripts like this one. But I don’t totally have my head wrapped around how, and it meets my needs as it is. If I figured out how to provide a brew-based install (which is interesting to me), that might give me a push to try to figure out a reasonable way to do dependencies for a command-line script. The trick is making sure they are available regardless of your ruby version switching choices. There might be a way to do it with bundler/inline. (And of course a brew-based install would be OSX only too.)

    Anyone is of course welcome to take my code and try to take it further. But it was 30 minutes of hacking that meets my needs well.

    If you are on any environment that can execute a command through ruby system() that will open a browser window, there’s a constant at the top of the file you can change to the appropriate command.

  2. The script could easily support the `BROWSER` ENV var that, it kind of looks like is pretty much all launchy does in the end anyway, but with some OS-dependent defaults that the README says it has but I can’t find in the source yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s