diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2012-05-03 07:25:13 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2012-05-03 07:25:13 +0000 |
| commit | 0c596a9d6424a2e3aa118780e739ed6a09acbec2 (patch) | |
| tree | 8912ec38926bc2228c38fe44fe724f3da2e36038 /src/command_manager.cc | |
| parent | 2a291e6868f43ffe0f2068f51b12bbea3152eb55 (diff) | |
Add a ShellManager which handles executing shell commands
ShellManager provides shell commands with environement variable
to retrieve some internal values in the shell parameters.
Diffstat (limited to 'src/command_manager.cc')
| -rw-r--r-- | src/command_manager.cc | 41 |
1 files changed, 2 insertions, 39 deletions
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 <algorithm> -#include <cstring> -#include <sys/types.h> -#include <sys/wait.h> namespace Kakoune { @@ -101,29 +99,7 @@ static void shell_eval(std::vector<String>& 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<String>& 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, |
