From d859d6c4341cfc735e3c373a777ee512f800817a Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Sat, 9 Mar 2024 18:13:08 -0800 Subject: [PATCH] `:print` strings directly in `nix repl` Strings are now printed directly when evaluated by `:print`, rather than escaped. This makes it easier to debug multi-line strings or strings containing quotes, like the results of `builtins.readFile`, `lib.toShellArg`, and so on. ``` nix-repl> "cuppy\ndog\ncity" "cuppy\ndog\ncity" nix-repl> :p "cuppy\ndog\ncity" cuppy dog city ``` --- src/libcmd/repl.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index 75f20d635..1a93a54fe 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -542,6 +542,7 @@ ProcessLineResult NixRepl::processLine(std::string line) << " :l, :load Load Nix expression and add it to scope\n" << " :lf, :load-flake Load Nix flake and add it to scope\n" << " :p, :print Evaluate and print expression recursively\n" + << " Strings are printed directly, without escaping.\n" << " :q, :quit Exit nix-repl\n" << " :r, :reload Reload all files\n" << " :sh Build dependencies of derivation, then start\n" @@ -749,7 +750,11 @@ ProcessLineResult NixRepl::processLine(std::string line) else if (command == ":p" || command == ":print") { Value v; evalString(arg, v); - printValue(std::cout, v); + if (v.type() == nString) { + std::cout << v.string_view(); + } else { + printValue(std::cout, v); + } std::cout << std::endl; }