jashkenas / journo

A quick-and-dirty (literate) blogging engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`open` command

mgutz opened this issue · comments

You asked about cross-platform open command, these are the aliases I use in my dotfiles

Windows: start
Linux (ubuntu, debian): xdg-open
OSX: open

There is also a package that takes care of this - https://github.com/jjrdn/node-open

node-open approximately does the following:

opener = {darwin: "open", win32: "start"}[process.platform] ? "xdg-open"
exec "#{opener} http://localhost:1234"

There's a complication: for some reason node-open bundles vendor/xdg-open shell script.

(What does xdg-open do? It detects the desktop environment and calls into gvfs-open, gnome-open, kde-open etc.)

To stop worrying about whether xdg-open exists or not, you could use Python webbrowser module instead:

opener = {darwin: "open", win32: "start"}[process.platform] ? "python -m webbrowser -t"
exec "#{opener} http://localhost:1234"

I fudged the commit message, but this should be fixed now.