Skip to content

Commit

Permalink
repl: default persistence to ~/.node_repl_history
Browse files Browse the repository at this point in the 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: #2224
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Chris Dickinson <[email protected]>
Reviewed-By: Roman Reiss <[email protected]>
  • Loading branch information
Fishrock123 authored and rvagg committed Aug 4, 2015
1 parent ceee8d2 commit f7d5e4c
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/internal/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f7d5e4c

Please sign in to comment.