Created
April 19, 2011 09:18
-
-
Save Floby/927052 to your computer and use it in GitHub Desktop.
open the default editor from node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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