forked from domenic/opener
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopener.js
31 lines (24 loc) · 896 Bytes
/
opener.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env node
"use strict";
var childProcess = require("child_process");
function opener(args, options, callback) {
// http://stackoverflow.com/q/1480971/3191
var command = process.platform === "win32" ? "start" :
process.platform === "darwin" ? "open" :
"xdg-open";
if (typeof args === "string") {
args = [args];
}
childProcess.exec(command + " " + args.join(" "), options, callback);
}
// Export `opener` for programmatic access.
// You might use this to e.g. open a website: `opener("http://google.com")`
module.exports = opener;
// If we're being called from the command line, just execute, using the command-line arguments.
if (require.main && require.main.id === module.id) {
opener(process.argv.slice(2), function (error) {
if (error) {
throw error;
}
});
}