From 0fd5a9d995d5f8c310f203272a1a9296f17fb486 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 22 Jan 2021 17:17:13 +1100 Subject: [PATCH] Slight code cleanup in generate_env --- src/shell_manager.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/shell_manager.cc b/src/shell_manager.cc index 591a708d..8f6e57ac 100644 --- a/src/shell_manager.cc +++ b/src/shell_manager.cc @@ -136,31 +136,31 @@ Vector generate_env(StringView cmdline, const Context& context, const Sh { static const Regex re(R"(\bkak_(quoted_)?(\w+)\b)"); - Vector kak_env; + Vector env; for (auto&& match : RegexIterator{cmdline.begin(), cmdline.end(), re}) { StringView name{match[2].first, match[2].second}; - Quoting quoting = match[1].matched ? Quoting::Shell : Quoting::Raw; auto match_name = [&](const String& s) { return s.substr(0_byte, name.length()) == name and s.substr(name.length(), 1_byte) == "="; }; - if (any_of(kak_env, match_name)) + if (any_of(env, match_name)) continue; - auto var_it = shell_context.env_vars.find(name); try { + Quoting quoting = match[1].matched ? Quoting::Shell : Quoting::Raw; + auto var_it = shell_context.env_vars.find(name); String value = var_it != shell_context.env_vars.end() ? var_it->value : join(ShellManager::instance().get_val(name, context) | transform(quoter(quoting)), ' ', false); StringView quoted{match[1].first, match[1].second}; - kak_env.push_back(format("kak_{}{}={}", quoted, name, value)); + env.push_back(format("kak_{}{}={}", quoted, name, value)); } catch (runtime_error&) {} } - return kak_env; + return env; } }