Re: select w.o. ENTER

"Mark J. Reed" <[email protected]> Wed, 6 May 2026 14:01:04 -0400
Newsgroups gmane.comp.shells.zsh.devel,gmane.comp.shells.zsh.user
Message-ID <CAA=-s3yhf+1TZXDQ-dLStth4HLfx3PYMh8N6Tr8m6B64_9zk8w@mail.gmail.com>
--0000000000003a32f9065129f350
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

That's just not how select(1) works. If you want a menu that lets the user
respond with a keypress, you need to roll your own.

chosen=3D0
while (( chosen < 1 || chosen >$#path )); do
    for (( i=3D1; i<$#path; ++i)); do
        printf '%d) %s\n' "$i" "${path[i]}"
    done
    printf '%s' "$PS3"
    read -k chosen
done
pith=3D$path[$chosen]


If I'm doing single-key input though I'm probably not also using text menus
anyway. I find it much more useful to have a select body that does a
pattern match so you can type the value instead of just the index.


On Wed, May 6, 2026 at 1:42=E2=80=AFPM Ray Andrews <[email protected]>=
 wrote:

>
>
> On 2026-05-06 09:54, Roman Perepelitsa wrote:
> > How do you want to select the 11th item? Which keys do you want to
> > press for that?
> Ha!  Good point, never thought of that.  But supposing it was a short
> list?  One might want the option.
>
>
>

--=20
Mark J. Reed <[email protected]>

--0000000000003a32f9065129f350
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">That&#39;s just not how select(1) works. If you want a men=
u that lets the user respond with a keypress, you need to roll your own.<di=
v><br></div><blockquote style=3D"margin:0 0 0 40px;border:none;padding:0px"=
><div><font face=3D"monospace">chosen=3D0</font></div><div><font face=3D"mo=
nospace">while (( chosen &lt; 1 || chosen &gt;$#path )); do</font></div><di=
v><font face=3D"monospace">=C2=A0 =C2=A0 for (( i=3D1; i&lt;$#path;=C2=A0++=
i)); do</font></div><div><font face=3D"monospace">=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 printf &#39;%d) %s\n&#39; &quot;$i&quot; &quot;${path[i]}&quot;</font><=
/div><div><font face=3D"monospace">=C2=A0 =C2=A0 done</font></div><div><fon=
t face=3D"monospace">=C2=A0 =C2=A0 printf &#39;%s&#39; &quot;$PS3&quot;</fo=
nt></div><div><font face=3D"monospace">=C2=A0 =C2=A0 read -k chosen</font><=
/div><div><font face=3D"monospace">done</font></div><div><font face=3D"mono=
space">pith=3D$path[$chosen]</font></div></blockquote><div><br></div><div>I=
f I&#39;m doing single-key input though I&#39;m probably not also using tex=
t menus anyway. I find it much more useful to have a select body that does =
a pattern match so you can type the value instead of just the index.</div><=
div><br></div></div><br><div class=3D"gmail_quote gmail_quote_container"><d=
iv dir=3D"ltr" class=3D"gmail_attr">On Wed, May 6, 2026 at 1:42=E2=80=AFPM =
Ray Andrews &lt;<a href=3D"mailto:[email protected]">rayandrews@eastli=
nk.ca</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"ma=
rgin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:=
1ex"><br>
<br>
On 2026-05-06 09:54, Roman Perepelitsa wrote:<br>
&gt; How do you want to select the 11th item? Which keys do you want to<br>
&gt; press for that?<br>
Ha!=C2=A0 Good point, never thought of that.=C2=A0 But supposing it was a s=
hort <br>
list?=C2=A0 One might want the option.<br>
<br>
<br>
</blockquote></div><div><br clear=3D"all"></div><div><br></div><span class=
=3D"gmail_signature_prefix">-- </span><br><div dir=3D"ltr" class=3D"gmail_s=
ignature">Mark J. Reed &lt;<a href=3D"mailto:[email protected]" target=3D=
"_blank">[email protected]</a>&gt;<br></div>

--0000000000003a32f9065129f350--