Skip to content

Instantly share code, notes, and snippets.

@bingeboy
Forked from Floby/editor.js
Created February 28, 2014 04:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bingeboy/9265187 to your computer and use it in GitHub Desktop.
Save bingeboy/9265187 to your computer and use it in GitHub Desktop.
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