aboutsummaryrefslogtreecommitdiff
path: root/src/nix/repl.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-11-06 10:44:21 +0100
committerEelco Dolstra <edolstra@gmail.com>2019-11-06 10:56:33 +0100
commit88c452d1603eb809358e509d5dca9c40c512cd20 (patch)
tree41d3162e57fbbd0d5e10e35eed84d4b2b5e9e936 /src/nix/repl.cc
parent9ff4060d2691c1a7dc2f8be65d117f43c3335714 (diff)
parent35732a95bcdc0a4b4492845205e6283fcc88fd0d (diff)
Merge remote-tracking branch 'origin/master' into flakes
Diffstat (limited to 'src/nix/repl.cc')
-rw-r--r--src/nix/repl.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/nix/repl.cc b/src/nix/repl.cc
index 0fa1594cc..2b4d1a2c4 100644
--- a/src/nix/repl.cc
+++ b/src/nix/repl.cc
@@ -22,6 +22,7 @@ extern "C" {
#include "shared.hh"
#include "eval.hh"
#include "eval-inline.hh"
+#include "attr-path.hh"
#include "store-api.hh"
#include "common-eval-args.hh"
#include "get-drvs.hh"
@@ -440,6 +441,7 @@ bool NixRepl::processLine(string line)
<< " <x> = <expr> Bind expression to variable\n"
<< " :a <expr> Add attributes from resulting set to scope\n"
<< " :b <expr> Build derivation\n"
+ << " :e <expr> Open the derivation in $EDITOR\n"
<< " :i <expr> Build derivation, then install result into current profile\n"
<< " :l <path> Load Nix expression and add it to scope\n"
<< " :p <expr> Evaluate and print expression recursively\n"
@@ -466,6 +468,34 @@ bool NixRepl::processLine(string line)
reloadFiles();
}
+ else if (command == ":e" || command == ":edit") {
+ Value v;
+ evalString(arg, v);
+
+ Pos pos;
+
+ if (v.type == tPath || v.type == tString) {
+ PathSet context;
+ auto filename = state.coerceToString(noPos, v, context);
+ pos.file = state.symbols.create(filename);
+ } else if (v.type == tLambda) {
+ pos = v.lambda.fun->pos;
+ } else {
+ // assume it's a derivation
+ pos = findDerivationFilename(state, v, arg);
+ }
+
+ // Open in EDITOR
+ auto args = editorFor(pos);
+ auto editor = args.front();
+ args.pop_front();
+ runProgram(editor, args);
+
+ // Reload right after exiting the editor
+ state.resetFileCache();
+ reloadFiles();
+ }
+
else if (command == ":t") {
Value v;
evalString(arg, v);