Skip to content

Commit

Permalink
Add compatibility with WSL
Browse files Browse the repository at this point in the history
  • Loading branch information
thijsputman authored and domenic committed Aug 12, 2018
1 parent 8488ce8 commit 11e582c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions opener.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@
"use strict";

var childProcess = require("child_process");
var os = require("os");

function opener(args, options, callback) {
var platform = process.platform;

// Attempt to detect Windows Subystem for Linux (WSL). WSL itself as Linux (which works in most cases), but in
// this specific case we need to treat it as actually being Windows. The "Windows-way" of opening things through
// cmd.exe works just fine here, whereas using xdg-open does not, since there is no X Windows in WSL.
if (platform === "linux" && os.release().indexOf("Microsoft") !== -1) {
platform = "win32";
}

// http://stackoverflow.com/q/1480971/3191, but see below for Windows.
var command;
switch (process.platform) {
switch (platform) {
case "win32": {
command = "cmd";
break;
Expand All @@ -32,15 +42,15 @@ function opener(args, options, callback) {
}

if (options && typeof options === "object" && options.command) {
if (process.platform === "win32") {
if (platform === "win32") {
// *always* use cmd on windows
args = [options.command].concat(args);
} else {
command = options.command;
}
}

if (process.platform === "win32") {
if (platform === "win32") {
// On Windows, we really want to use the "start" command. But, the rules regarding arguments with spaces, and
// escaping them with quotes, can get really arcane. So the easiest way to deal with this is to pass off the
// responsibility to "cmd /c", which has that logic built in.
Expand Down

0 comments on commit 11e582c

Please sign in to comment.