Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions openurl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ var spawn = require('child_process').spawn;

var command;

function isWSL() {
const fs = require('fs');
try {
const contents = fs.readFileSync('/proc/version', 'utf-8');
return Boolean(contents.match(/.*microsoft|wsl.*/i));
} catch (err) {
/* swallow */
return false;
}
}

switch(process.platform) {
case 'darwin':
command = 'open';
Expand All @@ -10,7 +21,7 @@ switch(process.platform) {
command = 'explorer.exe';
break;
case 'linux':
command = 'xdg-open';
command = isWSL() ? 'explorer.exe' : 'xdg-open';
break;
default:
throw new Error('Unsupported platform: ' + process.platform);
Expand Down Expand Up @@ -65,4 +76,4 @@ function mailto(recipients, fields, recipientsSeparator, callback) {
}

exports.open = open;
exports.mailto = mailto;
exports.mailto = mailto;