From 0c596a9d6424a2e3aa118780e739ed6a09acbec2 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 3 May 2012 07:25:13 +0000 Subject: Add a ShellManager which handles executing shell commands ShellManager provides shell commands with environement variable to retrieve some internal values in the shell parameters. --- src/command_manager.cc | 41 ++--------------------------------------- 1 file changed, 2 insertions(+), 39 deletions(-) (limited to 'src/command_manager.cc') diff --git a/src/command_manager.cc b/src/command_manager.cc index 606c2513..800b3a04 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -3,11 +3,9 @@ #include "utils.hh" #include "assert.hh" #include "context.hh" +#include "shell_manager.hh" #include -#include -#include -#include namespace Kakoune { @@ -101,29 +99,7 @@ static void shell_eval(std::vector& params, const String& cmdline, const Context& context) { - int write_pipe[2]; - int read_pipe[2]; - - pipe(write_pipe); - pipe(read_pipe); - - if (pid_t pid = fork()) - { - close(write_pipe[0]); - close(read_pipe[1]); - close(write_pipe[1]); - - String output; - char buffer[1024]; - while (size_t size = read(read_pipe[0], buffer, 1024)) - { - if (size == -1) - break; - output += String(buffer, buffer+size); - } - close(read_pipe[0]); - waitpid(pid, NULL, 0); - + String output = ShellManager::instance().eval(cmdline, context); TokenList tokens = split(output); for (auto it = tokens.begin(); it != tokens.end(); ++it) @@ -131,19 +107,6 @@ static void shell_eval(std::vector& params, params.push_back(output.substr(it->first, it->second - it->first)); } - } - else - { - close(write_pipe[1]); - close(read_pipe[0]); - - dup2(read_pipe[1], 1); - dup2(write_pipe[0], 0); - - if (context.has_buffer()) - setenv("kak_bufname", context.buffer().name().c_str(), 1); - execlp("sh", "sh", "-c", cmdline.c_str(), NULL); - } } void CommandManager::execute(const CommandParameters& params, -- cgit v1.2.3