From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: Francisco Borges <francisco.borges@gmail.com>, zsh-users@zsh.org
Subject: Re: Always save first N bytes of output from all commands?
Date: Tue, 08 Jan 2019 15:43:10 +0000 [thread overview]
Message-ID: <1546962190.970784.1628862200.36C83046@webmail.messagingengine.com> (raw)
In-Reply-To: <CAHwuDSAqG7NqixnXNLOXcjMPwr+aE67=pokubRkq-MQBt8NQYQ@mail.gmail.com>
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
prev parent reply other threads:[~2019-01-08 15:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-08 14:53 Francisco Borges
2019-01-08 15:43 ` Daniel Shahaf [this message]
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=1546962190.970784.1628862200.36C83046@webmail.messagingengine.com \
--to=d.s@daniel.shahaf.name \
--cc=francisco.borges@gmail.com \
--cc=zsh-users@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).