From bfb91db4f6a580b4f90a511a79185db4aa3f34d3 Mon Sep 17 00:00:00 2001 From: Puck Meerburg Date: Sun, 19 May 2024 14:16:11 +0000 Subject: repl-interacter: save history after entering every line Fixes: https://git.lix.systems/lix-project/lix/issues/328 Change-Id: Iedd79ff5f72e84766ebd234c63856170afc624f0 --- doc/manual/rl-next/repl-fix-history.md | 9 +++++++++ src/libcmd/repl-interacter.cc | 2 ++ 2 files changed, 11 insertions(+) create mode 100644 doc/manual/rl-next/repl-fix-history.md diff --git a/doc/manual/rl-next/repl-fix-history.md b/doc/manual/rl-next/repl-fix-history.md new file mode 100644 index 000000000..1517f68e7 --- /dev/null +++ b/doc/manual/rl-next/repl-fix-history.md @@ -0,0 +1,9 @@ +--- +synopsis: "`nix repl` history is saved more reliably" +cls: 1164 +credits: puck +--- + +`nix repl` now saves its history file after each line, rather than at the end +of the session; ensuring that it will remember what you typed even after it +crashes. diff --git a/src/libcmd/repl-interacter.cc b/src/libcmd/repl-interacter.cc index 829383add..d3567e021 100644 --- a/src/libcmd/repl-interacter.cc +++ b/src/libcmd/repl-interacter.cc @@ -175,6 +175,8 @@ bool ReadlineLikeInteracter::getLine(std::string & input, ReplPromptType promptT if (!s) return false; + + write_history(historyFile.c_str()); input += s; input += '\n'; return true; -- cgit v1.2.3