Skip to content

Instantly share code, notes, and snippets.

@Floby
Created April 19, 2011 09:18
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Floby/927052 to your computer and use it in GitHub Desktop.
Save Floby/927052 to your computer and use it in GitHub Desktop.
open the default editor from node
var fs = require('fs');
var child_process = require('child_process');
var spawn = child_process.spawn;
function openEditor(file) {
var cp = spawn(process.env.EDITOR, [file], {
customFds: [
process.stdin,
process.stdout,
process.stderr
]
});
cp.on('exit', function() {
console.log('editor ended');
var content = fs.readFileSync(file, 'utf8');
console.log(content);
});
}
child_process.exec('mktemp', function(err, stdout, stderr) {
if(err) {
console.log(err);
return;
}
// remove the \n
openEditor(stdout.substr(0, stdout.length-1));
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment