zsh-workers
 help / color / mirror / code / Atom feed
From: Martijn Dekker <martijn@inlv.org>
To: zsh-workers@zsh.org
Subject: Re: feature request
Date: Fri, 17 Jan 2020 03:35:35 +0100	[thread overview]
Message-ID: <5e9f916a-fc53-9b92-8231-d2fb7077205e@inlv.org> (raw)
In-Reply-To: <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 
very unhappy.

- M.

-- 
modernish -- harness the shell
https://github.com/modernish/modernish

  parent reply	other threads:[~2020-01-17  2:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-16 22:10 Yefim Vedernikoff
2020-01-16 22:18 ` Eric Cook
2020-01-16 23:17 ` Andreas Kusalananda Kähäri
2020-01-16 23:57 ` Daniel Shahaf
2020-01-17  1:49 ` Sebastian Gniazdowski
2020-01-17  2:51   ` Sebastian Gniazdowski
2020-01-17  2:35 ` Martijn Dekker [this message]
2020-01-18 18:59   ` Vincent Lefevre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5e9f916a-fc53-9b92-8231-d2fb7077205e@inlv.org \
    --to=martijn@inlv.org \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).