Re: select w.o. ENTER

Ray Andrews <[email protected]> Wed, 6 May 2026 11:19:12 -0700
Newsgroups gmane.comp.shells.zsh.devel,gmane.comp.shells.zsh.user
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------0yP4OnDF7WwSJDf0WLbev0DL
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit



On 2026-05-06 11:01, Mark J. Reed wrote:
> 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.
I figured it would be doable but I didn't suspect it would be this easy:
>
>     chosen=0
>     while (( chosen < 1 || chosen >$#path )); do
>         for (( i=1; i<$#path; ++i)); do
>             printf '%d) %s\n' "$i" "${path[i]}"
>         done
>         printf '%s' "$PS3"
>         read -k chosen
>     done
>     pith=$path[$chosen]
>
>
... mind, pressing ENTER isn't exactly difficult.

Thanks Mark

--------------0yP4OnDF7WwSJDf0WLbev0DL
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <br>
    <br>
    <div class="moz-cite-prefix">On 2026-05-06 11:01, Mark J. Reed
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAA=-s3yhf+1TZXDQ-dLStth4HLfx3PYMh8N6Tr8m6B64_9zk8w@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">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.</div>
    </blockquote>
    I figured it would be doable but I didn't suspect it would be this
    easy:
    <blockquote type="cite"
cite="mid:CAA=-s3yhf+1TZXDQ-dLStth4HLfx3PYMh8N6Tr8m6B64_9zk8w@mail.gmail.com">
      <div dir="ltr">
        <div><br>
        </div>
        <blockquote style="margin:0 0 0 40px;border:none;padding:0px">
          <div><font face="monospace">chosen=0</font></div>
          <div><font face="monospace">while (( chosen &lt; 1 || chosen
              &gt;$#path )); do</font></div>
          <div><font face="monospace">    for (( i=1;
              i&lt;$#path; ++i)); do</font></div>
          <div><font face="monospace">        printf '%d) %s\n' "$i"
              "${path[i]}"</font></div>
          <div><font face="monospace">    done</font></div>
          <div><font face="monospace">    printf '%s' "$PS3"</font></div>
          <div><font face="monospace">    read -k chosen</font></div>
          <div><font face="monospace">done</font></div>
          <div><font face="monospace">pith=$path[$chosen]</font></div>
        </blockquote>
        <br>
      </div>
    </blockquote>
    ... mind, pressing ENTER isn't exactly difficult.<br>
    <br>
    Thanks Mark<br>
    <br>
  </body>
</html>

--------------0yP4OnDF7WwSJDf0WLbev0DL--