From 5c78717c51bb9a046694d7de0ba695011591e986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sat, 1 Nov 2014 11:11:20 +0100 Subject: Improve usage as a filter When used as in echo Hello World | vis | cat prevent intermediate writes to stdout, only save to stdout when also quiting the editor. --- vis.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/vis.c b/vis.c index fb7ea0c..696d0f2 100644 --- a/vis.c +++ b/vis.c @@ -1416,8 +1416,12 @@ static bool cmd_write(Filerange *range, const char *argv[]) { if (!argv[1]) argv[1] = text_filename_get(text); if (!argv[1]) { - if (text_fd_get(text) == STDIN_FILENO) - return text_range_write(text, range, STDOUT_FILENO) >= 0; + if (text_fd_get(text) == STDIN_FILENO) { + if (strchr(argv[0], 'q')) + return text_range_write(text, range, STDOUT_FILENO) >= 0; + editor_info_show(vis, "No filename given, use 'wq' to write to stdout"); + return false; + } editor_info_show(vis, "Filename expected"); return false; } -- cgit v1.2.3