aboutsummaryrefslogtreecommitdiff
path: root/sam.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-04-01 19:49:57 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-04-03 21:38:04 +0200
commitb6248c95a1a9048716ade3f7a5c6ab4ee9d144aa (patch)
treebbfff0b42beac7a9cb1c51e109baffebef2b8989 /sam.c
parentd2ae7bc7a5e85ecc7de5188778c20d7ac7282b34 (diff)
downloadvis-b6248c95a1a9048716ade3f7a5c6ab4ee9d144aa.tar.gz
vis-b6248c95a1a9048716ade3f7a5c6ab4ee9d144aa.tar.xz
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.
Diffstat (limited to 'sam.c')
-rw-r--r--sam.c14
1 files changed, 13 insertions, 1 deletions
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) {