Launchy

less than 1 minute read

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:

gem install launchy

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

gem 'launchy'

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

launchy stuff-things.net

or:

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

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

(T)CSH

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.

Tags: ,

Updated:

Comments