Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Always save first N bytes of output from all commands?
- X-seq: zsh-users 23832
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Francisco Borges <francisco.borges@xxxxxxxxx>, zsh-users@xxxxxxx
- Subject: Re: Always save first N bytes of output from all commands?
- Date: Tue, 08 Jan 2019 15:43:10 +0000
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=message-id:from:to:mime-version :content-transfer-encoding:content-type:date:in-reply-to :references:subject; s=fm2; bh=YnjARaJsB6jt3KKfSjcWHB2GZXkgyZHW0 h0gHITud48=; b=NqOJXnNOGktq5rM0vr1Pz8t90M0wQheWkAwtIZu3pdsJR6tk0 qd6UIIDsAZrYikdFnqGv29xOBfGurP5FYe2lRFPOANcA+08KG4BpvbuLo9c3CCcI WOWTy4/HMZ9RxguXGkfPMVixmc/MHxd7YbnztJgslafAkHR+Xku+wyBErvBLut3z W+iKzAnq6adG6DuRzkU/INnqJWyb1/0swWYI1cV/9GTOna8HZvsstBKF4fN5f+rx RqiHugBPnHO8C0Us0PidApipnC3D80n0UeVmhMw9RpMZaqsBwFqvHkbsKc0FgZ/g wSihONsswVNxQ+TN3NT0SDrXaYg17YJOYfyfg==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=YnjARaJsB6jt3KKfSjcWHB2GZXkgyZHW0h0gHITud 48=; b=hIkMr/Zwue1r3A9SwZQpag0UaGD9nFDQpznsVYR0e80Vk5EK6kWQMxDMZ db3BruDZ2htbZ5V+ib1NXiFcDFsLKe+T305bjlRBiwFktN/OkpdQlzmw8e5xkMEu /U34AuqCwkyDib48E+m0Cmk+21yg49PVz+fGfera9RenTQMEARUOiHq0hAxYNFl7 ryuq0EblOc/70rcf0CNy/1nY3xiUVSWcOy42Bw/pftL4TY3R77aoTR/M6YoDA/gG 5k9/Lzzj4Wr8ydq81aeRmVtfoUrgZHi9bQ8kvKyFe7IifvkVJjyH6+TAVvlA5Xt7 WbQTjbV8ZTtkk/AojVtSbLtyjqGOA==
- In-reply-to: <CAHwuDSAqG7NqixnXNLOXcjMPwr+aE67=pokubRkq-MQBt8NQYQ@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author