Skip to content

Commit

Permalink
repl: save to a default file in the home tmp directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Fishrock123 committed Jul 22, 2015
1 parent 2d71e31 commit d78f505
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/internal/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const Interface = require('readline').Interface;
const REPL = require('repl');
const path = require('path');
const fs = require('fs');
const os = require('os');

module.exports = Object.create(REPL);
Expand Down Expand Up @@ -52,15 +53,25 @@ function createRepl(env, cb) {
}

const repl = REPL.start(opts);
if (opts.terminal && env.NODE_REPL_HISTORY_FILE) {
if (opts.terminal) {
return setupHistory(repl, env.NODE_REPL_HISTORY_FILE, cb);
}
repl._historyPrev = _replHistoryMessage;
cb(null, repl);
}

function setupHistory(repl, historyPath, ready) {
const fs = require('fs');
// default to using <homedir>/tmp/node_history_file
if (typeof historyPath !== 'string') {
const tmpdir = path.join(os.homedir(), 'tmp')
try {
fs.mkdirSync(tmpdir);
} catch (err) {
if (err.code !== 'EEXIST') throw err;
}
historyPath = path.join(tmpdir, 'node_repl_history');
}

var timer = null;
var writing = false;
var pending = false;
Expand Down

0 comments on commit d78f505

Please sign in to comment.