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

Re: Implementing a menu (list) in a zsh script (as in command line)



rahul wrote:
> I am writing an application in zsh. I typically use read -k or vared for
> getting user input. However, I'd like the user to get a menu as he types or
> tabs, just as it happens on the zsh command line. I'd like him to be able
> to navigate the menu just as on the command line.

With vared, you should be able to configure a function that does
completion for your script by declaring it with zle -C:

zle -C complete-word complete-word _complete
bindkey '^I' complete-word

Looking at a script I have that does this, my _complete function starts
with:

_complete() {
  [[ "$compstate[insert]" = tab* ]] &&
      compstate[insert]="${compstate[insert]//tab /}"

I think this ensures that it does completion rather than inserting a tab
character in some cases.

You may need other tweaking, much of which may involve copying from your
.zshrc to, for example, setup menu completion as you like it loading the
complist module and so on.

The completion functions may also look a bit different to normal
completion functions if you do things like descriptions manually, e.g.
  compadd -X '%Bnames%b'

Oliver



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