1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-21 10:40:53 +03:00

ShellManager::eval now takes an additional env_var map

This commit is contained in:
Maxime Coste 2012-05-29 05:19:27 +00:00
parent e57ddd3bab
commit 8fedbbf07b
4 changed files with 17 additions and 8 deletions

View File

@ -99,7 +99,7 @@ static void shell_eval(std::vector<String>& params,
const String& cmdline,
const Context& context)
{
String output = ShellManager::instance().eval(cmdline, context);
String output = ShellManager::instance().eval(cmdline, context, {});
TokenList tokens = split(output);
for (auto it = tokens.begin(); it != tokens.end(); ++it)

View File

@ -215,7 +215,7 @@ void do_pipe(Editor& editor, int count)
editor.buffer().begin_undo_group();
for (auto& sel : const_cast<const Editor&>(editor).selections())
{
String new_content = ShellManager::instance().eval(cmdline, main_context);
String new_content = ShellManager::instance().eval(cmdline, main_context, {});
editor.buffer().modify(Modification::make_erase(sel.begin(), sel.end()));
editor.buffer().modify(Modification::make_insert(sel.begin(), new_content));
}

View File

@ -12,7 +12,8 @@ ShellManager::ShellManager()
{
}
String ShellManager::eval(const String& cmdline, const Context& context)
String ShellManager::eval(const String& cmdline, const Context& context,
const EnvVarMap& env_vars)
{
int write_pipe[2];
int read_pipe[2];
@ -61,12 +62,18 @@ String ShellManager::eval(const String& cmdline, const Context& context)
assert(false);
assert(name.length() > 0);
auto local_var = env_vars.find(name);
if (local_var != env_vars.end())
setenv(("kak_" + name).c_str(), local_var->second.c_str(), 1);
else
{
auto env_var = m_env_vars.find(name);
if (env_var != m_env_vars.end())
{
String value = env_var->second(context);
setenv(("kak_" + name).c_str(), value.c_str(), 1);
}
}
++it;
}

View File

@ -11,13 +11,15 @@ namespace Kakoune
class Context;
typedef std::function<String (const Context&)> EnvVarRetriever;
typedef std::unordered_map<String, String> EnvVarMap;
class ShellManager : public Singleton<ShellManager>
{
public:
ShellManager();
String eval(const String& cmdline, const Context& context);
String eval(const String& cmdline, const Context& context,
const EnvVarMap& env_vars);
void register_env_var(const String& name, EnvVarRetriever retriever);