zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh Users <zsh-users@sunsite.dk>
Subject: Re: How do I complete from words in a file? (again)
Date: Sun, 11 Jan 2004 17:58:27 +0000	[thread overview]
Message-ID: <1040111175827.ZM20640@candle.brasslantern.com> (raw)
In-Reply-To: <20040111153729.GC4628@fruitcom.com>

On Jan 11,  4:37pm, Eric Smith wrote:
}
} For example I have keys in the form
} "_what_ever_" in certain files and want to type
} on the command line:
} _wh<tab>

I'm going to assume that "keys in certain files" means one key per line.
If it's more complicated than that, you'll have to describe file format
in more detail.

A week or so ago, you wrote:

} It would be as an argument to particular commands.

So the first general step is to put a file in a directory named in your
$fpath, that begins with a line similar to:

#compdef particular commands ...

where of course "particular commands ..." are actually the names of the
commands for which you want this to complete.  There are other ways to
use #compdef, documented under "Initialization" in the compsys manual.

The rest of the file is the body of the function that looks up possible
matches.  Note that it doesn't have to look up _actual_ matches, only
_possible_ matches -- that is, it can generate extra strings that do
not match and the completion internals will discard those.

In the case you've described, the function body can be very simple:

local keyfile
for keyfile in certain files
do
    compadd ${(f)"$(<$keyfile)"}
done

Again "certain files" there stands in for the actual file names, and the
${(f)"..."} expression is the standard idiom for reading a file and then
splitting it into one quoted shell word per line.

If you need to use a different key file for each command name, you can
either use multiple function files each with a different #compdef line,
or use a case statement instead of the loop above:

local keyfile command=$words[1]
case $command in
 (particular) keyfile=certain;;
 (commands)   keyfile=files;;
esac
compadd ${(f)"$(<$keyfile)"}

If that's not enough to get you where you want to go, you're going to
have to provide a more specific example of what you'd like to have.


      reply	other threads:[~2004-01-11 17:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-11 15:37 Eric Smith
2004-01-11 17:58 ` Bart Schaefer [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=1040111175827.ZM20640@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@sunsite.dk \
    /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).