• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var spawn = require('child_process').spawn;
2
3module.exports = function (file, opts, cb) {
4    if (typeof opts === 'function') {
5        cb = opts;
6        opts = {};
7    }
8    if (!opts) opts = {};
9
10    var ed = /^win/.test(process.platform) ? 'notepad' : 'vim';
11    var editor = opts.editor || process.env.VISUAL || process.env.EDITOR || ed;
12    var args = editor.split(/\s+/);
13    var bin = args.shift();
14
15    var ps = spawn(bin, args.concat([ file ]), { stdio: 'inherit' });
16
17    ps.on('exit', function (code, sig) {
18        if (typeof cb === 'function') cb(code, sig)
19    });
20};
21