zsh-users
 help / color / mirror / code / Atom feed
* Capturing STDOUT without subshells or file I/O
@ 2018-09-02 20:57 Ben Klein
  2018-09-03  0:40 ` Joey Pabalinas
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Ben Klein @ 2018-09-02 20:57 UTC (permalink / raw)
  To: zsh-users


[-- Attachment #1.1.1: Type: text/plain, Size: 1404 bytes --]

Hello Zshellers,

I have an interesting predicament, I with to capture the STDOUT (builtin
printf) of a ZSH function to a variable, in which the function should be
running in the current shell context.

Currently, I have this:

  p10k_render_prompt_from_spec p10k_left p10k_opts > $tmpd/prompt
  read -d $'\0' _P10K_RENDERED_OUTPUT_PROMPT < $tmpd/prompt
  p10k_render_prompt_from_spec p10k_right p10k_opts right > $tmpd/prompt
  read -d $'\0' _P10K_RENDERED_OUTPUT_RPROMPT < $tmpd/prompt

And that involves creating a temporary file (/tmp) which might be
mounted on a spinning drive, so performance might take a hit.

The other route using a pipe:

p10k_render_prompt_from_spec p10k_left p10k_opts | read -d $'\0'
_P10K_RENDERED_OUTPUT_PROMPT

Causes environment variables and changes made during the `render_prompt`
call to be ignored. (Ends up in a subshell...?)

Is there some way I can use a virtual FD, or perhaps Zsh provides some
kind of buffer I could use instead?

In the end, I'm looking for a way to connect STDOUT to STDIN between ZSH
functions/builtins without any subshells or file I/O. (It's fine if it
gets buffered until close-of-stream.)

-- 
*\Ben Klein*
Founder and Owner of Robosane, robobenklein@robosane.net
You can find me elsewhere online as 'robobenklein'.
If you need to contact me securely, I am also reachable via GPG, or on
Keybase.

[-- Attachment #1.1.2: Type: text/html, Size: 2005 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

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

end of thread, other threads:[~2018-09-21  6:59 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-02 20:57 Capturing STDOUT without subshells or file I/O Ben Klein
2018-09-03  0:40 ` Joey Pabalinas
2018-09-03 14:02 ` Daniel Shahaf
2018-09-03 18:43   ` Joey Pabalinas
2018-09-17 20:13     ` Ben Klein
2018-09-17 20:46       ` Daniel Shahaf
2018-09-17 21:01         ` Mikael Magnusson
2018-09-17 21:20           ` Bart Schaefer
2018-09-17 21:19       ` dana
2018-09-17 21:33         ` Bart Schaefer
2018-09-18  5:12 ` Sebastian Gniazdowski
2018-09-21  6:58   ` Oliver Kiddle

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