2023-02-04 03:42:36 +00:00
|
|
|
#include "util.hh"
|
|
|
|
#include "editor-for.hh"
|
2024-03-06 04:24:35 +00:00
|
|
|
#include "source-path.hh"
|
2023-02-04 03:42:36 +00:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2023-04-06 11:15:50 +00:00
|
|
|
Strings editorFor(const SourcePath & file, uint32_t line)
|
2023-02-04 03:42:36 +00:00
|
|
|
{
|
2023-04-06 11:15:50 +00:00
|
|
|
auto path = file.getPhysicalPath();
|
|
|
|
if (!path)
|
|
|
|
throw Error("cannot open '%s' in an editor because it has no physical path", file);
|
2023-02-04 03:42:36 +00:00
|
|
|
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));
|
2023-04-06 11:15:50 +00:00
|
|
|
args.push_back(path->abs());
|
2023-02-04 03:42:36 +00:00
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|