diff options
author | zimbatm <zimbatm@zimbatm.com> | 2019-10-23 16:48:28 +0200 |
---|---|---|
committer | zimbatm <zimbatm@zimbatm.com> | 2019-10-23 16:48:28 +0200 |
commit | 207a537343ace1d39ac125059456d832a5237f2e (patch) | |
tree | f3f25ceaaffcb480c6130a4896e4d79c87ad90e6 /src/libutil/args.cc | |
parent | 73ff84f6a820ac1c6e0fe502692432c8945fd8b0 (diff) |
libutil: add editorFor heuristic
Diffstat (limited to 'src/libutil/args.cc')
-rw-r--r-- | src/libutil/args.cc | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libutil/args.cc b/src/libutil/args.cc index 7af2a1bf7..35ec3e4ab 100644 --- a/src/libutil/args.cc +++ b/src/libutil/args.cc @@ -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; |