zsh-workers
 help / color / mirror / code / Atom feed
* select item from list in modify-current-argument?
@ 2011-06-03 23:41 Marc Weber
  2011-06-04 18:32 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Marc Weber @ 2011-06-03 23:41 UTC (permalink / raw)
  To: zsh-workers

I have my own tool for selecting paths
(github.com/MarcWeber/path-selector).

I'd like to use it within ZSH.

I came up with this:
http://dpaste.com/550269/

(You can replace line 78 by 79)

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.
ctl-l redraws the current line but drops some history.
zle -R does not help

Is there an even better way to implement select-one?

Pointing me to sample code will be enough.

Marc Weber


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: select item from list in modify-current-argument?
  2011-06-03 23:41 select item from list in modify-current-argument? Marc Weber
@ 2011-06-04 18:32 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2011-06-04 18:32 UTC (permalink / raw)
  To: Marc Weber, zsh-workers

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.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-06-04 18:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-03 23:41 select item from list in modify-current-argument? Marc Weber
2011-06-04 18:32 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).