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>
This commit is contained in:
parent
ceee8d2807
commit
f7d5e4c618
@ -3,6 +3,9 @@
|
||||
const Interface = require('readline').Interface;
|
||||
const REPL = require('repl');
|
||||
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.createInternalRepl = createRepl;
|
||||
@ -63,7 +66,20 @@ function createRepl(env, opts, cb) {
|
||||
}
|
||||
|
||||
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 writing = false;
|
||||
var pending = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user