zsh-users
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: rahul <rahul2012@gmail.com>
Cc: zsh-users@zsh.org
Subject: Re: Implementing a menu (list) in a zsh script (as in command line)
Date: Mon, 31 Dec 2012 12:00:35 +0100	[thread overview]
Message-ID: <23676.1356951635@thecus.kiddle.eu> (raw)
In-Reply-To: <CACQNQ9P7WJCvuPCzJfxKsf=qZsXiNxsv5hxA-xG8WTJQDugMzw@mail.gmail.com>

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


      reply	other threads:[~2012-12-31 11:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-31  5:29 rahul
2012-12-31 11:00 ` Oliver Kiddle [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=23676.1356951635@thecus.kiddle.eu \
    --to=okiddle@yahoo.co.uk \
    --cc=rahul2012@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).