From 103c46abc273266afcd5dbffa40151114234a02b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Br=C3=B8nner?= Date: Tue, 23 Feb 2016 23:19:49 +0100 Subject: [PATCH] Preserve readline history across sessions. Add rl_readline_name. --- README.md | 4 ++++ nix-repl.cc | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c5964fd5e..acdcd367f 100644 --- a/README.md +++ b/README.md @@ -102,3 +102,7 @@ example: nix-repl> config.networking.use config.networking.useDHCP config.networking.usePredictableInterfaceNames + +Input history is preserved by readline in ~/.nix-repl-history +The readline "application name" is nix-repl. This allows for nix-repl specific +settings in ~/.inputrc diff --git a/nix-repl.cc b/nix-repl.cc index 577efa8e2..1c878cd0e 100644 --- a/nix-repl.cc +++ b/nix-repl.cc @@ -20,6 +20,7 @@ using namespace nix; string programId = "nix-repl"; +const string historyFile = string(getenv("HOME")) + "/.nix-repl-history"; struct NixRepl @@ -91,8 +92,10 @@ void NixRepl::mainLoop(const Strings & files) reloadFiles(); if (!loadedFiles.empty()) std::cout << std::endl; + // Allow nix-repl specific settings in .inputrc + rl_readline_name = "nix-repl"; using_history(); - read_history(0); + read_history(historyFile.c_str()); string input; @@ -649,5 +652,7 @@ int main(int argc, char * * argv) store = openStore(); NixRepl repl(searchPath); repl.mainLoop(files); + + write_history(historyFile.c_str()); }); }