From b6248c95a1a9048716ade3f7a5c6ab4ee9d144aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 1 Apr 2016 19:49:57 +0200 Subject: sam: implement r (read) command in terms of < cat It replaces current range with the file content. However in the common case the range is actually defaults to the whole file which is probably not what is expected. --- sam.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'sam.c') diff --git a/sam.c b/sam.c index c2d1b8c..eac4813 100644 --- a/sam.c +++ b/sam.c @@ -964,7 +964,19 @@ static bool cmd_write(Vis *vis, Win *win, Command *cmd, Filerange *range) { } static bool cmd_read(Vis *vis, Win *win, Command *cmd, Filerange *range) { - return false; + + bool ret = false; + Buffer buf; + buffer_init(&buf); + + if (!buffer_put0(&buf, "cat ") || !buffer_append0(&buf, cmd->text)) + goto out; + + Command pipe_cmd = { .text = buf.data }; // FIXME + ret = cmd_pipein(vis, win, &pipe_cmd, range); +out: + buffer_release(&buf); + return ret; } static ssize_t read_stdout(void *context, char *data, size_t len) { -- cgit v1.2.3