Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] _hdiutil: run candidate-collecting loops outside the pipeline subshell
- X-seq: zsh-workers 54634
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Clay Caviness <clay@xxxxxxxxxx>
- Cc: zsh-workers@xxxxxxx
- Subject: Re: [PATCH] _hdiutil: run candidate-collecting loops outside the pipeline subshell
- Date: Fri, 29 May 2026 20:40:10 +0200
- Arc-authentication-results: i=1; mx.google.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=5rF78/1vyVFcuFLKX3dPmbdx+LMIt2iNs4GG31qf6z8=; fh=QxJsPNQOlgRkGlHNK1PESJOipvlriq0v/QRyIe+59jE=; b=O3OW9qyBNTEmhw9WVqkQgBoyCLEn4fFG2NSJ3PKaPESf4AI3dzD1/qe4Ko0GRziUKU YvER03jUn8E44nLGUzn5TuyRpilnybBd9kAQ5CR0DQkRkKllnKna0C2Mb6qagEQHWE5Y Ykzcyiz+ex1Jt+SgHGYqjD9tEDIgUu9JVuQ2n8/zt3nWzhtYCUk8bD2ogqo2QkHKMSMY eW7W2gVPpWlVSYPuyD9I7WwmtzCqSlCHR/9p6Yv3sd1H9sfHQY6lHNtec1bNhWBy41oq XmXib4pFTd0rVQatLJiao0wZ1EhzYPb5oe9rsqo59aPEiKnz09+0SoL442EJ1VMIi+2T zoAg==; darn=zsh.org
- Arc-seal: i=1; a=rsa-sha256; t=1780080024; cv=none; d=google.com; s=arc-20240605; b=SfSmY5J+jJ0WPyhpsYdO0vkJ5q8IgWoQdRGEMRA5JSwyY41Uxypf43uR1eAWpjGesd yEM27wWoK/A2Dxzo4O/yAe+lu+wzCxn8sJ2uq67mzfpFvoSHLCKNDJvxTxEmN1mmB4sP 7nxVO5jSFXkNF0chTa6riz1fe2Qt1xd2sRFlxCb3HV1trdWtIbvxS45SwCw4Tt0KB3Sz JXJqEQkfJke3aOvNuzRIfLin9xG1htLs37cNUtwqkEj7Kss9sqrRgAYISc111+8vqzdj tkI3jAuGTWCEhviC1pdewHzuEc8tOzxS70NJU2Z9NEL5HUYQAD7zxhR7mqwsDgcEAXDQ Q4Fg==
- Archived-at: <https://zsh.org/workers/54634>
- In-reply-to: <CANU2Hre7vkud-DQC=V5-ys-ZKcbyCZxC3oNjBCMeBDXmzxCOUQ@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CANU2Hre7vkud-DQC=V5-ys-ZKcbyCZxC3oNjBCMeBDXmzxCOUQ@mail.gmail.com>
On Fri, May 29, 2026 at 7:40 PM Clay Caviness <clay@xxxxxxxxxx> wrote:
>
> The `_hdiutil_disk` and `_hdiutil_device` helpers each use the following pattern:
>
> _call_program ... hdiutil ... | while read; do
> arr+=( ... )
> done
> # ... use $arr ...
>
> Because every component of a zsh pipeline runs in its own subshell, the array assignments happen in the right-hand subshell and are lost by the time the subsequent `_describe` / `_wanted` call runs in the parent shell. The practical effect is that `hdiutil eject <TAB>` (which dispatches to _hdiutil_disk via the detach|eject branch) never offers any candidates, even when disk images are attached. _hdiutil_device has the same shape and the same problem for `hdiutil burn -device <TAB>`.
% echo hello | read; echo $REPLY
hello
> The fix involves feeding the loop via process substitution so the loop body runs in the parent shell, allowing the array to persist. I also made REPLY local and switched to `read -r` so backslashes in the output are not mangled.
I guess local REPLY and read -r changes make sense, but there
shouldn't be any need to use < <() syntax here. Did you also stop to
wonder why one of the sites uses a bare "hdiutil" while the other
hardcodes "/usr/bin/hdiutil"? That seems quite odd to me.
> Patch follows.
> ---
> From 2026acc22c87dc98cb985748133f7fee24ebbab5 Mon Sep 17 00:00:00 2001
> From: Clay Caviness <clay@xxxxxxxxxx>
> Date: Fri, 29 May 2026 13:33:39 -0400
> Subject: [PATCH] _hdiutil: run candidate-collecting loops outside the pipeline
> subshell
>
> Signed-off-by: Clay Caviness <clay@xxxxxxxxxx>
> ---
> Completion/Darwin/Command/_hdiutil | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/Completion/Darwin/Command/_hdiutil b/Completion/Darwin/Command/_hdiutil
> index 20e69cbc5..ada55bf1d 100644
> --- a/Completion/Darwin/Command/_hdiutil
> +++ b/Completion/Darwin/Command/_hdiutil
> @@ -4,22 +4,24 @@
> #
> _hdiutil_disk() {
> local -a disk_desc
> - _call_program devices hdiutil info | while read; do
> + local REPLY
> + while read -r REPLY; do
> local disk_name="${${(M)REPLY[(w)1]%/dev/disk*}#/dev/}"
> if (( #disk_name )); then
> disk_desc+=( "$disk_name:${${(M)REPLY% *}#?}" )
> fi
> - done
> + done < <(_call_program devices hdiutil info)
> _describe -t devices disk disk_desc
> }
>
> _hdiutil_device() {
> local -a device_desc
> - _call_program devices /usr/bin/hdiutil burn -list | while read; do
> + local REPLY
> + while read -r REPLY; do
> if [[ "$REPLY" == [:space:]#IOService:* ]]; then
> device_desc+=( "$REPLY" )
> fi
> - done
> + done < <(_call_program devices /usr/bin/hdiutil burn -list)
> local expl
> _wanted devices expl device compadd "$device_desc[@]"
> }
> --
> 2.50.1 (Apple Git-155)
>
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author