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

Re: Automatic stdout/err redirection

On Nov 11,  4:12pm, Yuri D'Elia wrote:
} 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...
} Just as a general opinion, what would you think about the behavior?

This has come up before and for practical purposes it just doesn't work
to try to build this into the shell, not least because of the trouble
you called out with interactive or "fullscreen" commands like editors.

It's also what the script(1) command is expressly designed for.

There are a couple of possible approaches:

1. Run your entire zsh session inside "script", capturing everything to
the same file.  Use preexec and precmd to output boundary markers so
that the typescript file can be sliced up later into the output of
individiual commands vs. the output of the shell between commands, and
have widgets or other functions to selectively grab the previous output.

2. Use preexec or an accept-line wrapper or zle-line-finish hook to run
each command inside "script -c '...'".  This gets tricky as you have to
differentiate external commands from shell builtins in order to avoid
breaking the semantics of assignments etc., and loops or if/else are a
difficult problem to address.

You could also write your own "script"-alike using zpty, but that would
end up looking very much like option #1 above, I think.  With #1 you
could even have the typescript file accessible through the zsh/mapfile
module for access to the sections.

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