In my last post about an alias that opened a URL from the command line, I said:

open is OS X specific. On Linux you’d want xdg-open or gnome-open, on Windows, start, under Cygwin, cygstart.

A friend of mine reminded me that I forgotten a simple option for Ruby developers, his cross platform solution, Launchy.

Launchy automatically makes the decision I outline above, providing both a Ruby API to open URLs and a command line wrapper, the latter being handy for aliases like mine.

To use, install launchy:

1
gem install launchy

or, if you’re going to use it in code, add:

1
gem 'launchy'

to your Gemfile and bundle install. Once installed it’s as simple as:

1
launchy stuff-things.net

or:

1
2
require 'launchy'
Launchy.open 'http://stuff-things.net'

Launchy turns up any number of places, for example the save_and_open_page functionality of Capybara.

With Launchy installed, you can modify my original aliases thusly:

Bash

1
alias view-on-gitub=$'launchy `git config --get remote.origin.url | awk -F: \'{ print "https://github.com/"$2}\'`'

(T)CSH

1
alias view-on-gitub 'launchy `git config --get remote.origin.url | awk -F: ' \' '{ print "https://github.com/"$2}' \' '`'

giving you a simple, cross platform alias.

Comments