zsh-users
 help / Atom feed
* Always save first N bytes of output from all commands?
@ 2019-01-08 14:53 Francisco Borges
  2019-01-08 15:43 ` Daniel Shahaf
  0 siblings, 1 reply; 2+ messages in thread
From: Francisco Borges @ 2019-01-08 14:53 UTC (permalink / raw)
  To: zsh-users

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

Hi,

Is there an easy easy way to *always* save the (first N bytes) of the
output all commands? Or least save the output of the very last command?

Something like always having

 | tee ~/.output_history/$TTY/${HISTCMD}.out

but ideally with a control over the number of bytes written. Is something
like that possible?

Right now I resort to insert-last-command-output function (original by pws
at http://www.zsh.org/mla/users/2005/msg00550.html while answering a
question of mine...). To re-execute a command and insert its output in the
command line. Sometimes it is fast enough and sometimes it is slow. I know
we have "keep" (./share/zsh/functions/keeper) distributed with Zsh itself,
but keep much like tee has to be manually inserted into the command itself
and that it becomes less awesome.

I work on OSX and I bet I can write AppleScript code to... somehow fetch
the output and insert in the buffer but it I'd rather a (portable)
Zsh-based solution.

Any ideas other than going the AppleScript route?
-- 
Francisco

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

* Re: Always save first N bytes of output from all commands?
  2019-01-08 14:53 Always save first N bytes of output from all commands? Francisco Borges
@ 2019-01-08 15:43 ` Daniel Shahaf
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Shahaf @ 2019-01-08 15:43 UTC (permalink / raw)
  To: Francisco Borges, zsh-users

Francisco Borges wrote on Tue, 08 Jan 2019 15:53 +0100:
> Is there an easy easy way to *always* save the (first N bytes) of the
> output all commands? Or least save the output of the very last command?
> 
> Something like always having
> 
>  | tee ~/.output_history/$TTY/${HISTCMD}.out
> 
> but ideally with a control over the number of bytes written. Is something
> like that possible?
> 
> Right now I resort to insert-last-command-output function (original by pws
> at http://www.zsh.org/mla/users/2005/msg00550.html while answering a
> question of mine...). To re-execute a command and insert its output in the
> command line. Sometimes it is fast enough and sometimes it is slow. I know
> we have "keep" (./share/zsh/functions/keeper) distributed with Zsh itself,
> but keep much like tee has to be manually inserted into the command itself
> and that it becomes less awesome.

You could wrap the accept-line widget with something along these lines:

accept-line() {
  PREBUFFER="{ $PREBUFFER"; BUFFER+=" }"
  BUFFER+="| tee >(head -c 1024 > /path/to/file)"
  zle .accept-word -- "$@"
}
zle -N accept-line

(untested)

However, commands that check if their stdout isatty() (the C equivalent
of «[[ -t 1 ]]») will with this change think it's not a tty.  ls(1)
without arguments is the standard example of this.  You could probably
fix that by creating a pty, but I don't have an example of that.

> I work on OSX and I bet I can write AppleScript code to... somehow fetch
> the output and insert in the buffer but it I'd rather a (portable)
> Zsh-based solution.
> 
> Any ideas other than going the AppleScript route?

Cheers,

Daniel

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-08 14:53 Always save first N bytes of output from all commands? Francisco Borges
2019-01-08 15:43 ` Daniel Shahaf

zsh-users

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-users

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.users


AGPL code for this site: git clone https://public-inbox.org/ public-inbox