Skip to content

repl: add .clearhistory command#64450

Open
bitpshr wants to merge 1 commit into
nodejs:mainfrom
bitpshr:repl/add-clearhistory-command
Open

repl: add .clearhistory command#64450
bitpshr wants to merge 1 commit into
nodejs:mainfrom
bitpshr:repl/add-clearhistory-command

Conversation

@bitpshr

@bitpshr bitpshr commented Jul 12, 2026

Copy link
Copy Markdown

This pull request adds a .clearhistory REPL command that clears the current session history, both in memory and in the persistent history file when one is configured.

It clears the in-memory history array, resets the navigation index, and truncates the backing file through the open handle. Any pending debounced flush is cancelled first so it cannot rewrite the file after it has been cleared.

Fixes: #63905

Add a `.clearhistory` REPL command that clears the in-memory session
history and truncates the persisted history file when one is configured.
Any pending debounced flush is cancelled first so it cannot rewrite the
file after it has been cleared.

Fixes: nodejs#63905
Signed-off-by: Paul Bouchon <mail@bitpshr.net>
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. repl Issues and PRs related to the REPL subsystem. labels Jul 12, 2026
@bnb

bnb commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

This feels a bit off to me. The functionality makes sense, I could see wanting this. But I'm not sure if it's clear when I'd want this vs .clear and the naming is too similar. Is there a more concise name, potentially?

@bitpshr

bitpshr commented Jul 13, 2026

Copy link
Copy Markdown
Author

@bnb good call. A few options:

  • .history clear: reads like history -c in a shell, keeps .clear unambiguous, and leaves room for .history to do more later (listing the entries, for instance). Bare .history would just print a short usage line for now.
  • .forget: short and distinct, though on its own it's a little vague about what's being forgotten.
  • .resetHistory (or .wipeHistory): still a single command, just renamed off the clear prefix so it stops shadowing .clear, but not really any more concise.

I lean toward .history clear. It's the most concise as a base command and it sidesteps the overlap with .clear entirely.

@SudhansuBandha

Copy link
Copy Markdown
Contributor

@bnb This functionality will help users to remove commands/contents from previous sessions if they are trying to use same variables or functions with different purpose in subsequent new sessions. Without this functionality user will have to delete/clear contents of the history file to achieve the same.

I would also agree that the name can be changed since it is quite similar to that of clear command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. repl Issues and PRs related to the REPL subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

REPL: Add .clearhistory command

4 participants