zsh-workers
 help / color / mirror / code / Atom feed
* Automatic stdout/err redirection
@ 2017-11-11 15:12 Yuri D'Elia
  2017-11-11 23:36 ` Bart Schaefer
  2017-11-12 12:00 ` Sebastian Gniazdowski
  0 siblings, 2 replies; 3+ messages in thread
From: Yuri D'Elia @ 2017-11-11 15:12 UTC (permalink / raw)
  To: zsh-workers

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?


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-11-12 12:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-11 15:12 Automatic stdout/err redirection Yuri D'Elia
2017-11-11 23:36 ` Bart Schaefer
2017-11-12 12:00 ` Sebastian Gniazdowski

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).