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