zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org, zsh-users@zsh.org
Cc: dominik.vogt@gmx.de
Subject: Re: Completions from file with zcompsys
Date: Tue, 20 Jun 2017 10:27:27 -0700	[thread overview]
Message-ID: <170620102727.ZM5792@torch.brasslantern.com> (raw)
In-Reply-To: <20170620074605.GA3709@gmx.de>

On Jun 20,  8:46am, Dominik Vogt wrote:
}
} Are there some quick instructions instructions or a
} cheat sheet on the new completion system somewhere?

http://zsh.sourceforge.net/Guide/zshguide06.html#l144   (perhaps?)

} And I want to type things like
} 
}   $ foo Cheno<TAB>alb<TAB>   # -> Chenopodium album
}   $ foo Che*a<TAB>           # -> Chenopodium a
} 
} (using menu completion, not expanding the * to all matching
} completions).

The latter one could be tricky because you will have to prevent the "*"
from being expanded as a file glob.

Do you want the expansions exactly as you wrote them, or should the
spaces be quoted?  E.g. do you want to end up with something like one
of

    $ foo 'Chenopodium album'
    $ foo Chenopodium\ album          <-- this one is the easy one below

or instead

    $ foo Chenopodium album

?? The latter will be a bit more work because you will have to account
for the first word when completing the second word.

In any case, the procedure is to create a function that produces a list
of words and then passes them to the "compadd" builtin.  The list does
not have to be filtered against the command line (except in the "a bit
more work" case I just mentioned) because compadd will take care of
that part.  Then you pass the names of that function and of the command
to the "compdef" function.

You can also pass a string to be eval'd to compdef, so the simplest answer
to your question is (guessing at a file name)

    compdef 'compadd ${(f)"$(<~/latin-plant-names.txt)"}' foo

Then to get the "*"-expansion you will need to add the _match function
to your completer zstyle.  Example might be

    zstyle ':completion:*' completer _complete _match

but adjust the placement of _match to fit whatever your current list of
completers contains.  It would normally be anywhere after _complete.

If the above doesn't satisfy, we can go into more detail about how to
change or remove the quoting.


  reply	other threads:[~2017-06-20 17:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-20  7:46 Dominik Vogt
2017-06-20 17:27 ` Bart Schaefer [this message]
2017-06-20 18:02   ` Dominik Vogt
2017-06-20 19:32     ` Bart Schaefer
2017-06-20 21:42       ` Dominik Vogt
2017-06-20 23:31         ` Bart Schaefer

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=170620102727.ZM5792@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=dominik.vogt@gmx.de \
    --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).