aboutsummaryrefslogtreecommitdiff
path: root/src/libcmd/editor-for.cc
blob: f674f32bd30f26a6f849d63992085ee3a9e53484 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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;
}

}