mirror of
https://github.com/NixOS/nix
synced 2025-07-06 21:41:48 +02:00
libutil: add editorFor heuristic
This commit is contained in:
parent
73ff84f6a8
commit
207a537343
4 changed files with 23 additions and 21 deletions
|
@ -178,6 +178,19 @@ Strings argvToStrings(int argc, char * * argv)
|
|||
return args;
|
||||
}
|
||||
|
||||
Strings editorFor(std::string filename, int lineno)
|
||||
{
|
||||
auto editor = getEnv("EDITOR", "cat");
|
||||
auto args = tokenizeString<Strings>(editor);
|
||||
if (lineno > 0 && (
|
||||
editor.find("emacs") != std::string::npos ||
|
||||
editor.find("nano") != std::string::npos ||
|
||||
editor.find("vim") != std::string::npos))
|
||||
args.push_back(fmt("+%d", lineno));
|
||||
args.push_back(filename);
|
||||
return args;
|
||||
}
|
||||
|
||||
std::string renderLabels(const Strings & labels)
|
||||
{
|
||||
std::string res;
|
||||
|
|
|
@ -190,6 +190,9 @@ public:
|
|||
|
||||
Strings argvToStrings(int argc, char * * argv);
|
||||
|
||||
/* Helper function to generate args that invoke $EDITOR on filename:lineno */
|
||||
Strings editorFor(std::string filename, int lineno);
|
||||
|
||||
/* Helper function for rendering argument labels. */
|
||||
std::string renderLabels(const Strings & labels);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue