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

Re: select item from list in modify-current-argument?

On Jun 4,  1:41am, Marc Weber wrote:
} select-one first uses echo to show the alternatives, then read to get
} the item index from the user.
} However because echo shows many lines the code copied from
} modify-current-argument get's confused.

I'd probably just do this:

_my_quickpath() {
    [[ -z "${words[CURRENT]}" ]] && (( CURRENT > 0 && --CURRENT ))
    compadd -Q -U $($HQUICKFILE --echo "${words[CURRENT]}")
compdef -k _my_quickpath menu-select ^g

I'm not entirely sure about the --CURRENT part but you get the idea.

If you insist on doing it yourself without using a completion widget,
then you need to replace line 24-25 of select-one with something along
the lines of

    local -a replies
    for i ({1..$#@}) { replies+=( "$i: ${${@[$i]}#$strip}" ) }
    read-from-minibuffer "$(print -c "${replies[@]}")"$'\n'

And then replace other calls to "read $opt" with a similar call to
read-from-minibuffer.  (Oh, it needs to be autoloaded first.)

This of course renders select-one unusuable outside of ZLE, so you'll
have to make a new function out out it if you want select-one for any
other purpose.

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