From 96c440fcaa72113e974b4bf467f708a64e0b0ac4 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 29 May 2012 05:42:26 +0000 Subject: [PATCH] CommandManager::execute can take an optional EnvVarMap argument which is used for shell evaluation --- src/command_manager.cc | 17 ++++++++++------- src/command_manager.hh | 7 +++++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/command_manager.cc b/src/command_manager.cc index d348d976..fe9cc9ee 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -79,7 +79,8 @@ struct command_not_found : runtime_error }; void CommandManager::execute(const String& command_line, - const Context& context) + const Context& context, + const EnvVarMap& env_vars) { TokenList tokens = split(command_line); if (tokens.empty()) @@ -92,14 +93,15 @@ void CommandManager::execute(const String& command_line, it->second - it->first)); } - execute(params, context); + execute(params, context, env_vars); } static void shell_eval(std::vector& params, const String& cmdline, - const Context& context) + const Context& context, + const EnvVarMap& env_vars) { - String output = ShellManager::instance().eval(cmdline, context, {}); + String output = ShellManager::instance().eval(cmdline, context, env_vars); TokenList tokens = split(output); for (auto it = tokens.begin(); it != tokens.end(); ++it) @@ -110,7 +112,8 @@ static void shell_eval(std::vector& params, } void CommandManager::execute(const CommandParameters& params, - const Context& context) + const Context& context, + const EnvVarMap& env_vars) { if (params.empty()) return; @@ -132,7 +135,7 @@ void CommandManager::execute(const CommandParameters& params, { shell_eval(expanded_params, begin->substr(1, begin->length() - 2), - context); + context, env_vars); if (not expanded_params.empty()) { command_it = m_commands.find(expanded_params[0]); @@ -155,7 +158,7 @@ void CommandManager::execute(const CommandParameters& params, if (param->front() == '`' and param->back() == '`') shell_eval(expanded_params, param->substr(1, param->length() - 2), - context); + context, env_vars); else expanded_params.push_back(*param); } diff --git a/src/command_manager.hh b/src/command_manager.hh index d6923ce2..54d67b80 100644 --- a/src/command_manager.hh +++ b/src/command_manager.hh @@ -9,6 +9,7 @@ #include "utils.hh" #include "completion.hh" #include "memoryview.hh" +#include "shell_manager.hh" namespace Kakoune { @@ -54,8 +55,10 @@ public: DeferredShellEval = 2, }; - void execute(const String& command_line, const Context& context); - void execute(const CommandParameters& params, const Context& context); + void execute(const String& command_line, const Context& context, + const EnvVarMap& env_vars = EnvVarMap()); + void execute(const CommandParameters& params, const Context& context, + const EnvVarMap& env_vars = EnvVarMap()); Completions complete(const String& command_line, size_t cursor_pos);