Browse Source

repl: default persistence to ~/.node_repl_history

Makes the REPL persistently save history by default to
~/.node_repl_history when in terminal mode.
This can be disabled by setting NODE_REPL_HISTORY="".

PR-URL: https://github.com/nodejs/io.js/pull/2224
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
v4.0.0-rc
Jeremiah Senkpiel 10 years ago
committed by Rod Vagg
parent
commit
f7d5e4c618
  1. 18
      lib/internal/repl.js

18
lib/internal/repl.js

@ -3,6 +3,9 @@
const Interface = require('readline').Interface; const Interface = require('readline').Interface;
const REPL = require('repl'); const REPL = require('repl');
const path = require('path'); const path = require('path');
const fs = require('fs');
const os = require('os');
const debug = require('util').debuglog('repl');
module.exports = Object.create(REPL); module.exports = Object.create(REPL);
module.exports.createInternalRepl = createRepl; module.exports.createInternalRepl = createRepl;
@ -63,7 +66,20 @@ function createRepl(env, opts, cb) {
} }
function setupHistory(repl, historyPath, ready) { function setupHistory(repl, historyPath, ready) {
const fs = require('fs'); if (!historyPath) {
try {
historyPath = path.join(os.homedir(), '.node_repl_history');
} catch (err) {
repl._writeToOutput('\nError: Could not get the home directory.\n' +
'REPL session history will not be persisted.\n');
repl._refreshLine();
debug(err.stack);
repl._historyPrev = _replHistoryMessage;
return ready(null, repl);
}
}
var timer = null; var timer = null;
var writing = false; var writing = false;
var pending = false; var pending = false;

Loading…
Cancel
Save