Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: select w.o. ENTER



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=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]

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 PM Ray Andrews <rayandrews@xxxxxxxxxxx> 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.




--
Mark J. Reed <markjreed@xxxxxxxxx>


Messages sorted by: Reverse Date, Date, Thread, Author