From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3977 invoked by alias); 11 Nov 2017 15:30:27 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 42011 Received: (qmail 3603 invoked by uid 1010); 11 Nov 2017 15:30:27 -0000 X-Qmail-Scanner-Diagnostics: from 195.159.176.226 by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(195.159.176.226):SA:0(-1.1/5.0):. Processed in 5.134098 secs); 11 Nov 2017 15:30:27 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RDNS_NONE autolearn=no autolearn_force=no version=3.4.1 X-Envelope-From: gcszd-zsh-workers@m.gmane.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | X-Injected-Via-Gmane: http://gmane.org/ To: zsh-workers@zsh.org From: Yuri D'Elia Subject: Automatic stdout/err redirection Date: Sat, 11 Nov 2017 16:12:54 +0100 Message-ID: <878tfc97d5.fsf@wavexx.thregr.org> Mime-Version: 1.0 Content-Type: text/plain X-Complaints-To: usenet@blaine.gmane.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) Cancel-Lock: sha1:AgUJVODderj2GHbmQoS0R2CxAYk= I've been thinking for a while about the ability to manipulate the output of the previous command without executing it again. It's such a common occurrence... Imagine the following desired behavior: - when executed interactively, each cmdline redirects the stdout to some temporary $FILE in _addition_ to stdout - we want to fool the pipeline into thinking that stdout is still a TTY and disable buffering (I don't want any change in regular command behavior) - stdout though is not directly flushed to the pty, it's actually filtered by something inbetween like "head -25" that shows the first 25 lines only, and then shows a message "truncated output" when this occurs, without flooding the terminal - the full output is still available in $FILE Working with such a setup would be generally much more convenient. The output of each command is temporarily saved, so that it can be re-used again into filters without executing the command again. Or simply less'ed (no more ugly scrollback buffer search needed!). No more terminal flooding in case of silly mistakes. I started thinking into how to use the preexec hook to achieve something like that, but it's definitely non-trivial. Most of the required pieces would be available, for example combining zpty with multiios, but the devil is in the details. The main issue would be using interactive programs, or programs that rely on escape sequences, such as [n]curses. Using "head" as a filter is not enough, one would need to implement something a bit more sophisticated, that detects the presence of escapes and disables any input processing. Icing on the cake would be to duplicate stdin itself (when it's coming from the tty) and attach a copy to the "head" filter itself, so that we could trap extra escape sequences and introduce some interactive behavior in the filter. An example would be a command to say "show me the output anyway" after the truncation limit has been hit. Just as a general opinion, what would you think about the behavior?