zsh-workers
 help / color / mirror / code / Atom feed
* feature request
@ 2020-01-16 22:10 Yefim Vedernikoff
  2020-01-16 22:18 ` Eric Cook
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Yefim Vedernikoff @ 2020-01-16 22:10 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 305 bytes --]

What would it take to add a new environment variable like $OUTPUT to keep
track of the last output? I like the $(!!) solution from
https://stackoverflow.com/questions/24283097/reusing-output-from-last-command-in-bash
but I don't like that it redoes the work (especially if the work is
intensive).

-Yefim

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

* Re: feature request
  2020-01-16 22:10 feature request Yefim Vedernikoff
@ 2020-01-16 22:18 ` Eric Cook
  2020-01-16 23:17 ` Andreas Kusalananda Kähäri
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Eric Cook @ 2020-01-16 22:18 UTC (permalink / raw)
  To: zsh-workers

On 1/16/20 5:10 PM, Yefim Vedernikoff wrote:
> What would it take to add a new environment variable like $OUTPUT to keep
> track of the last output? I like the $(!!) solution from
> https://stackoverflow.com/questions/24283097/reusing-output-from-last-command-in-bash
> but I don't like that it redoes the work (especially if the work is
> intensive).
>
> -Yefim
>

The shell is ignorant of what a program writes (and how) to your terminal.

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

* Re: feature request
  2020-01-16 22:10 feature request 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
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Andreas Kusalananda Kähäri @ 2020-01-16 23:17 UTC (permalink / raw)
  To: Yefim Vedernikoff; +Cc: zsh-workers

On Thu, Jan 16, 2020 at 05:10:03PM -0500, Yefim Vedernikoff wrote:
> What would it take to add a new environment variable like $OUTPUT to keep
> track of the last output? I like the $(!!) solution from
> https://stackoverflow.com/questions/24283097/reusing-output-from-last-command-in-bash
> but I don't like that it redoes the work (especially if the work is
> intensive).
> 
> -Yefim

Even if this was possible, consider the memory resources needed to store
something like the output of the simple command "yes".

-- 
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden

.

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

* Re: feature request
  2020-01-16 22:10 feature request 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:35 ` Martijn Dekker
  4 siblings, 0 replies; 8+ messages in thread
From: Daniel Shahaf @ 2020-01-16 23:57 UTC (permalink / raw)
  To: zsh-workers

Yefim Vedernikoff wrote on Thu, 16 Jan 2020 22:10 +00:00:
> What would it take to add a new environment variable like $OUTPUT to 
> keep
> track of the last output? I like the $(!!) solution from
> https://stackoverflow.com/questions/24283097/reusing-output-from-last-command-in-bash
> but I don't like that it redoes the work (especially if the work is
> intensive).

Under tmux it might be solvable using «tmux list-panes -F
'#{history_size}'» in preexec() and «tmux capture-pane» afterwards.

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

* Re: feature request
  2020-01-16 22:10 feature request Yefim Vedernikoff
                   ` (2 preceding siblings ...)
  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
  4 siblings, 1 reply; 8+ messages in thread
From: Sebastian Gniazdowski @ 2020-01-17  1:49 UTC (permalink / raw)
  To: Yefim Vedernikoff; +Cc: Zsh hackers list

On Thu, 16 Jan 2020 at 23:11, Yefim Vedernikoff <hi@yef.im> wrote:
>
> What would it take to add a new environment variable like $OUTPUT to keep
> track of the last output? I like the $(!!) solution from
> https://stackoverflow.com/questions/24283097/reusing-output-from-last-command-in-bash
> but I don't like that it redoes the work (especially if the work is
> intensive).

I have a plugin in my TODO that would be defining global aliases OUT,
OUT2, etc. for the previous command's output, etc. It'll be based on
tmux capture-pane command. I'm not sure when the project will start,
any cooperation could speed this up.

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org

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

* Re: feature request
  2020-01-16 22:10 feature request Yefim Vedernikoff
                   ` (3 preceding siblings ...)
  2020-01-17  1:49 ` Sebastian Gniazdowski
@ 2020-01-17  2:35 ` Martijn Dekker
  2020-01-18 18:59   ` Vincent Lefevre
  4 siblings, 1 reply; 8+ messages in thread
From: Martijn Dekker @ 2020-01-17  2:35 UTC (permalink / raw)
  To: zsh-workers

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

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

* Re: feature request
  2020-01-17  1:49 ` Sebastian Gniazdowski
@ 2020-01-17  2:51   ` Sebastian Gniazdowski
  0 siblings, 0 replies; 8+ messages in thread
From: Sebastian Gniazdowski @ 2020-01-17  2:51 UTC (permalink / raw)
  To: Yefim Vedernikoff; +Cc: Zsh hackers list

On Fri, 17 Jan 2020 at 02:49, Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
>
> On Thu, 16 Jan 2020 at 23:11, Yefim Vedernikoff <hi@yef.im> wrote:
> >
> > What would it take to add a new environment variable like $OUTPUT to keep
> > track of the last output? I like the $(!!) solution from
> > https://stackoverflow.com/questions/24283097/reusing-output-from-last-command-in-bash
> > but I don't like that it redoes the work (especially if the work is
> > intensive).
>
> I have a plugin in my TODO that would be defining global aliases OUT,
> OUT2, etc. for the previous command's output, etc. It'll be based on
> tmux capture-pane command. I'm not sure when the project will start,
> any cooperation could speed this up.

Also, you could look at:

https://github.com/psprint/ztrace

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org

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

* Re: feature request
  2020-01-17  2:35 ` Martijn Dekker
@ 2020-01-18 18:59   ` Vincent Lefevre
  0 siblings, 0 replies; 8+ messages in thread
From: Vincent Lefevre @ 2020-01-18 18:59 UTC (permalink / raw)
  To: zsh-workers

On 2020-01-17 03:35:35 +0100, Martijn Dekker wrote:
> 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?

Something like that would be nice, but this may also depend on the
command. I have written some code some that some commands are automatically
piped to "less" (via an alias), for instance.

However, note that with a pipe, there can be issues due to buffering.
If zsh could run the command in a pty, this could be better.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

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

end of thread, other threads:[~2020-01-18 19:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-16 22:10 feature request 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
2020-01-18 18:59   ` Vincent Lefevre

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).