diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2023-02-03 22:42:36 -0500 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2023-02-20 09:45:29 -0500 |
commit | 1bd03ad100e8813751b6c08b0c21ae8cf5a9c21d (patch) | |
tree | 2e625eda7966d2e10bf7316ae8fa352eaa100b27 /src/libcmd/editor-for.cc | |
parent | 57a2e46ee0890093c9882f961d7d95c56d7c0ad5 (diff) |
Split out `CmdRepl` and `editorFor`
The REPL itself and the `nix repl` CLI are conceptually different
things, and thus deserve to be in different files.
Diffstat (limited to 'src/libcmd/editor-for.cc')
-rw-r--r-- | src/libcmd/editor-for.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libcmd/editor-for.cc b/src/libcmd/editor-for.cc new file mode 100644 index 000000000..f674f32bd --- /dev/null +++ b/src/libcmd/editor-for.cc @@ -0,0 +1,20 @@ +#include "util.hh" +#include "editor-for.hh" + +namespace nix { + +Strings editorFor(const Path & file, uint32_t line) +{ + auto editor = getEnv("EDITOR").value_or("cat"); + auto args = tokenizeString<Strings>(editor); + if (line > 0 && ( + editor.find("emacs") != std::string::npos || + editor.find("nano") != std::string::npos || + editor.find("vim") != std::string::npos || + editor.find("kak") != std::string::npos)) + args.push_back(fmt("+%d", line)); + args.push_back(file); + return args; +} + +} |