Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save benjaminfauchald/97a55fe5c70e2c6d4f5ecf0057ae058a to your computer and use it in GitHub Desktop.
Save benjaminfauchald/97a55fe5c70e2c6d4f5ecf0057ae058a to your computer and use it in GitHub Desktop.
Cross platform check with JS shell exec
const exec = require('child_process').exec;
function openURL(url) {
let opener;
switch (process.platform) {
case 'darwin':
opener = 'open';
break;
case 'win32':
opener = 'start';
break;
default:
opener = 'xdg-open';
break;
}
return exec(`${opener} "${url.replace(/"/g, '\\\"')}"`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment