aboutsummaryrefslogtreecommitdiff
path: root/src/nix/command.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-11-08 15:13:32 +0100
committerEelco Dolstra <edolstra@gmail.com>2019-11-08 15:13:32 +0100
commit0d6774468cf109c9cb6502cb81f1219c6e68ee37 (patch)
treedebd7144ff2ddbd193a75d390e9050f4c428adca /src/nix/command.cc
parent48f0a76372d5e5be86f6522c760ae1f6c12dbd65 (diff)
Move editorFor srom libutil to nix
libutil should not depend on libexpr.
Diffstat (limited to 'src/nix/command.cc')
-rw-r--r--src/nix/command.cc14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/nix/command.cc b/src/nix/command.cc
index 532f331a7..97c2fcf1c 100644
--- a/src/nix/command.cc
+++ b/src/nix/command.cc
@@ -1,6 +1,7 @@
#include "command.hh"
#include "store-api.hh"
#include "derivations.hh"
+#include "nixexpr.hh"
namespace nix {
@@ -153,4 +154,17 @@ void StorePathCommand::run(ref<Store> store)
run(store, *storePaths.begin());
}
+Strings editorFor(const Pos & pos)
+{
+ auto editor = getEnv("EDITOR", "cat");
+ auto args = tokenizeString<Strings>(editor);
+ if (pos.line > 0 && (
+ editor.find("emacs") != std::string::npos ||
+ editor.find("nano") != std::string::npos ||
+ editor.find("vim") != std::string::npos))
+ args.push_back(fmt("+%d", pos.line));
+ args.push_back(pos.file);
+ return args;
+}
+
}