diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-04-01 20:28:40 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-04-03 21:38:04 +0200 |
| commit | 0ee497280f6fb6e293d5bba1efb7bc63eea2a05e (patch) | |
| tree | 7c9589de4c0609b0c8f7b212ebab9c3fb7a04ce2 | |
| parent | b6248c95a1a9048716ade3f7a5c6ab4ee9d144aa (diff) | |
| download | vis-0ee497280f6fb6e293d5bba1efb7bc63eea2a05e.tar.gz vis-0ee497280f6fb6e293d5bba1efb7bc63eea2a05e.tar.xz | |
sam: implement > command
| -rw-r--r-- | sam.c | 30 |
1 files changed, 24 insertions, 6 deletions
@@ -78,8 +78,8 @@ static bool cmd_extract(Vis*, Win*, Command*, Filerange*); static bool cmd_select(Vis*, Win*, Command*, Filerange*); static bool cmd_print(Vis*, Win*, Command*, Filerange*); static bool cmd_files(Vis*, Win*, Command*, Filerange*); -static bool cmd_shell(Vis*, Win*, Command*, Filerange*); static bool cmd_pipein(Vis*, Win*, Command*, Filerange*); +static bool cmd_pipeout(Vis*, Win*, Command*, Filerange*); static bool cmd_filter(Vis*, Win*, Command*, Filerange*); static bool cmd_substitute(Vis*, Win*, Command*, Filerange*); static bool cmd_write(Vis*, Win*, Command*, Filerange*); @@ -99,7 +99,7 @@ static const CommandDef cmds[] = { { { "y" }, CMD_CMD|CMD_REGEX|CMD_REGEX_DEFAULT, "p", cmd_extract }, { { "X" }, CMD_CMD|CMD_REGEX|CMD_REGEX_DEFAULT, NULL, cmd_files }, { { "Y" }, CMD_CMD|CMD_REGEX|CMD_REGEX_DEFAULT, NULL, cmd_files }, - { { ">" }, CMD_SHELL, NULL, cmd_shell }, + { { ">" }, CMD_SHELL, NULL, cmd_pipeout }, { { "<" }, CMD_SHELL, NULL, cmd_pipein }, { { "|" }, CMD_SHELL, NULL, cmd_filter }, { { "w" }, CMD_ARGV|CMD_FORCE, NULL, cmd_write }, @@ -908,10 +908,6 @@ static bool cmd_files(Vis *vis, Win *win, Command *cmd, Filerange *range) { return ret; } -static bool cmd_shell(Vis *vis, Win *win, Command *cmd, Filerange *range) { - return false; -} - static bool cmd_substitute(Vis *vis, Win *win, Command *cmd, Filerange *range) { return false; } @@ -1055,3 +1051,25 @@ static bool cmd_pipein(Vis *vis, Win *win, Command *cmd, Filerange *range) { } return ret; } + +static bool cmd_pipeout(Vis *vis, Win *win, Command *cmd, Filerange *range) { + Filter filter; + buffer_init(&filter.err); + + const char *argv[] = { cmd->text, NULL }; + + int status = vis_pipe(vis, &filter, range, argv, NULL, read_stderr); + + if (vis->cancel_filter) + vis_info_show(vis, "Command cancelled"); + else if (status == 0) + ; //vis_info_show(vis, "Command succeded"); + else if (filter.err.len > 0) + vis_info_show(vis, "Command failed: %s", filter.err.data); + else + vis_info_show(vis, "Command failed"); + + buffer_release(&filter.err); + + return !vis->cancel_filter && status == 0; +} |
