Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Automatic stdout/err redirection



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?



Messages sorted by: Reverse Date, Date, Thread, Author