mirror of
https://github.com/samsonjs/repl-edit.git
synced 2026-03-25 09:25:49 +00:00
seed the editing tmp file with the last line of history
This commit is contained in:
parent
9c36c8f9c3
commit
80b5dbf3c9
1 changed files with 14 additions and 1 deletions
15
lib/index.js
15
lib/index.js
|
|
@ -98,7 +98,7 @@ function extendRepl(aRepl) {
|
|||
|
||||
function edit(cmdFile, editor) {
|
||||
editor = editor || process.env['VISUAL'] || process.env['EDITOR']
|
||||
// TODO seed the file with repl.context._ if the file doesn't exist yet
|
||||
|
||||
var fds = [process.openStdin(), process.stdout, process.stdout]
|
||||
, args = [cmdFile]
|
||||
|
||||
|
|
@ -108,6 +108,19 @@ function edit(cmdFile, editor) {
|
|||
args = words.slice(1).concat(args)
|
||||
editor = words[0]
|
||||
}
|
||||
|
||||
// seed the file with repl.context._ if the file doesn't exist yet
|
||||
try {
|
||||
fs.statSync(cmdFile)
|
||||
}
|
||||
catch (e) {
|
||||
// skip history[0], it's the .edit command
|
||||
var lastCmd = theRepl.rli.history[1]
|
||||
if (lastCmd && lastCmd[0] !== '.') {
|
||||
fs.writeFileSync(cmdFile, lastCmd)
|
||||
}
|
||||
}
|
||||
|
||||
pause()
|
||||
spawn(editor, args, {customFds: fds}).on('exit', function(code) {
|
||||
// some editors change the terminal resulting in skewed output, clean up
|
||||
|
|
|
|||
Loading…
Reference in a new issue