Zsh Mailing List Archive
Messages sorted by:
Re: feature request
- X-seq: zsh-workers 45321
- From: Martijn Dekker <martijn@xxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: feature request
- Date: Fri, 17 Jan 2020 03:35:35 +0100
- In-reply-to: <CAPpbRf4oedgkPqr2ZpvOeBg7vOESz52RdYRZ=Q2ARUOsk4jWRQ@mail.gmail.com>
- List-help: <mailto:firstname.lastname@example.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:email@example.com>
- List-unsubscribe: <mailto:firstname.lastname@example.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAPpbRf4oedgkPqr2ZpvOeBg7vOESz52RdYRZ=Q2ARUOsk4jWRQ@mail.gmail.com>
Op 16-01-20 om 23:10 schreef Yefim Vedernikoff:
What would it take to add a new environment variable like $OUTPUT to keep
track of the last output?
The standard 'tee' utility does something like what you want: it copies
its standard input both to a file and to standard output. So if you want
to save the output of a command, you pipe it into 'tee' like this:
somecommand | tee OUTPUT
That's not a variable, but maybe it's close enough for you. Instead of
$OUTPUT, you can use $(< OUTPUT).
What it would take to implement your feature request to make this
permanent and transparent? Zsh would have to capture standard output
(and probably standard error) itself, so it can transparently act like
'tee' except for duplicating output to a variable instead of a file.
One way to deal with commands producing huge or infinite output would be
to cap the size and delete old lines if the threshold is exceeded --
like terminal scrollback buffers do.
So it's possible, but also non-trivial, and it would have a serious
drawback: since this requires capturing standard output, the commands
you run would not consider themselves connected to a terminal, so e.g.
'ls' would not produce output in columns and colours by default. And
full-screen editors might have no idea what to do.
To experiment with this side effect, start a new zsh process (to avoid
screwing up your current session) and then try some process substitutions:
exec > >(tee stdout.txt) 2> >(tee stderr.txt)
to log standard output and standard error separately, or
exec > >(tee output.txt) 2>&1
to combine them. As expected, 'ls' output becomes very boring. As for
editors, oddly enough, emacs seems to completely ignore that it's not on
a terminal, but vim acts like it's on a 1970s teletype, and joe becomes
modernish -- harness the shell
Messages sorted by: