node/deps/npm/node_modules/editor/index.js

21 lines
595 B
JavaScript
Raw Normal View History

2013-05-15 05:37:59 +08:00
var spawn = require('child_process').spawn;
module.exports = function (file, opts, cb) {
if (typeof opts === 'function') {
cb = opts;
opts = {};
}
if (!opts) opts = {};
var ed = /^win/.test(process.platform) ? 'notepad' : 'vim';
var editor = opts.editor || process.env.VISUAL || process.env.EDITOR || ed;
2014-08-01 00:05:30 +08:00
var args = editor.split(/\s+/);
var bin = args.shift();
2013-05-15 05:37:59 +08:00
2014-08-01 00:05:30 +08:00
var ps = spawn(bin, args.concat([ file ]), { stdio: 'inherit' });
2013-05-15 05:37:59 +08:00
ps.on('exit', function (code, sig) {
if (typeof cb === 'function') cb(code, sig)
});
};