Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
seed the editing tmp file with the last line of history
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonjs committed Nov 5, 2011
1 parent 9c36c8f commit 80b5dbf
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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
Expand Down

0 comments on commit 80b5dbf

Please sign in to comment.