-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
repl: add history support for REPL #434
Conversation
Adds support for saving command history for REPL. When the binary is run without any arguments or with the `-i` flag, it will default to saving the command history to ~/.node_history. Otherwise, it is disabled by default. The path to which the history is saved can be changed by setting the `NODE_HISTORY_PATH` environment variable. Saving history can be disabled by setting the `NODE_DISABLE_HISTORY` environment variable.
IMO, the persistent history support need to move to the readline.createInterface({
input: process.stdin,
output: process.stdout,
history: '~/.node_history'
}); Anyway, I'm +1 |
Thanks for the PR. While I'm +1 on adding persistent history, I'm -1 on this approach: not all repls should share the same history file. I'd like to see:
Ideally, I'd also move the builtin-lib autoloading to Thoughts on this @iojs/tc? Am I missing anything that would make supporting persistent history onerous? |
Would it make sense for |
Yep – if we go this route it should be added to both readline and repl as parameter taking an array of strings representing history entries. |
|
||
self.useHistory = !!useHistory; | ||
if (self.useHistory) { | ||
self.historyPath = process.env['NODE_HISTORY_PATH'] || historyPath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be dangerous with setuid binaries. (Hopefully no one does that but...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The repl readme contains examples of how to hook up a REPL to a net.Socket
for remote inspection – I'm not sure if anyone does this in practice but I feel like it could certainly run afoul of the setuid problem.
A module that's only run when the REPL would be started on the CLI, which only handled things like auto-loading of native modules and persistent history, would sidestep these problems.
I agree with @chrisdickinson; the current approach is not bad but it could be generalized more. Moving some of the logic to lib/readline.js is also a good idea. |
@chrisdickinson it is used in practice, as evidenced by the popularity of replify: |
@evanlucas I suggest to take a look how i moved history work in readline, i think we can combine in some way PR. #442 |
Maybe its just me, but it feels a little bit odd how a regular |
Closing per #394 (comment) |
Adds support for saving command history for REPL. When the binary is
run without any arguments or with the
-i
flag, it will default tosaving the command history to ~/.node_history. Otherwise, it is
disabled by default.
The path to which the history is saved can be changed by setting the
NODE_HISTORY_PATH
environment variable. Saving history can bedisabled by setting the
NODE_DISABLE_HISTORY
environment variable.See #394