CommandManager::execute can take an optional EnvVarMap argument which is used for shell evaluation

This commit is contained in:
Maxime Coste 2012-05-29 05:42:26 +00:00
parent 8fedbbf07b
commit 96c440fcaa
2 changed files with 15 additions and 9 deletions

View File

@ -79,7 +79,8 @@ struct command_not_found : runtime_error
}; };
void CommandManager::execute(const String& command_line, void CommandManager::execute(const String& command_line,
const Context& context) const Context& context,
const EnvVarMap& env_vars)
{ {
TokenList tokens = split(command_line); TokenList tokens = split(command_line);
if (tokens.empty()) if (tokens.empty())
@ -92,14 +93,15 @@ void CommandManager::execute(const String& command_line,
it->second - it->first)); it->second - it->first));
} }
execute(params, context); execute(params, context, env_vars);
} }
static void shell_eval(std::vector<String>& params, static void shell_eval(std::vector<String>& params,
const String& cmdline, 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); TokenList tokens = split(output);
for (auto it = tokens.begin(); it != tokens.end(); ++it) for (auto it = tokens.begin(); it != tokens.end(); ++it)
@ -110,7 +112,8 @@ static void shell_eval(std::vector<String>& params,
} }
void CommandManager::execute(const CommandParameters& params, void CommandManager::execute(const CommandParameters& params,
const Context& context) const Context& context,
const EnvVarMap& env_vars)
{ {
if (params.empty()) if (params.empty())
return; return;
@ -132,7 +135,7 @@ void CommandManager::execute(const CommandParameters& params,
{ {
shell_eval(expanded_params, shell_eval(expanded_params,
begin->substr(1, begin->length() - 2), begin->substr(1, begin->length() - 2),
context); context, env_vars);
if (not expanded_params.empty()) if (not expanded_params.empty())
{ {
command_it = m_commands.find(expanded_params[0]); command_it = m_commands.find(expanded_params[0]);
@ -155,7 +158,7 @@ void CommandManager::execute(const CommandParameters& params,
if (param->front() == '`' and param->back() == '`') if (param->front() == '`' and param->back() == '`')
shell_eval(expanded_params, shell_eval(expanded_params,
param->substr(1, param->length() - 2), param->substr(1, param->length() - 2),
context); context, env_vars);
else else
expanded_params.push_back(*param); expanded_params.push_back(*param);
} }

View File

@ -9,6 +9,7 @@
#include "utils.hh" #include "utils.hh"
#include "completion.hh" #include "completion.hh"
#include "memoryview.hh" #include "memoryview.hh"
#include "shell_manager.hh"
namespace Kakoune namespace Kakoune
{ {
@ -54,8 +55,10 @@ public:
DeferredShellEval = 2, DeferredShellEval = 2,
}; };
void execute(const String& command_line, const Context& context); void execute(const String& command_line, const Context& context,
void execute(const CommandParameters& params, 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); Completions complete(const String& command_line, size_t cursor_pos);