Skip to content

Commit f7d5e4c

Browse files
Fishrock123rvagg
authored andcommitted
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: #2224 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Chris Dickinson <[email protected]> Reviewed-By: Roman Reiss <[email protected]>
1 parent ceee8d2 commit f7d5e4c

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

lib/internal/repl.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
const Interface = require('readline').Interface;
44
const REPL = require('repl');
55
const path = require('path');
6+
const fs = require('fs');
7+
const os = require('os');
8+
const debug = require('util').debuglog('repl');
69

710
module.exports = Object.create(REPL);
811
module.exports.createInternalRepl = createRepl;
@@ -63,7 +66,20 @@ function createRepl(env, opts, cb) {
6366
}
6467

6568
function setupHistory(repl, historyPath, ready) {
66-
const fs = require('fs');
69+
if (!historyPath) {
70+
try {
71+
historyPath = path.join(os.homedir(), '.node_repl_history');
72+
} catch (err) {
73+
repl._writeToOutput('\nError: Could not get the home directory.\n' +
74+
'REPL session history will not be persisted.\n');
75+
repl._refreshLine();
76+
77+
debug(err.stack);
78+
repl._historyPrev = _replHistoryMessage;
79+
return ready(null, repl);
80+
}
81+
}
82+
6783
var timer = null;
6884
var writing = false;
6985
var pending = false;

0 commit comments

Comments
 (0)