From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22459 invoked from network); 11 Jan 2004 17:58:50 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 11 Jan 2004 17:58:50 -0000 Received: (qmail 809 invoked by alias); 11 Jan 2004 17:58:30 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 6990 Received: (qmail 793 invoked from network); 11 Jan 2004 17:58:30 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 11 Jan 2004 17:58:30 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [4.11.8.53] by sunsite.dk (MessageWall 1.0.8) with SMTP; 11 Jan 2004 17:58:29 -0000 Received: (from schaefer@localhost) by candle.brasslantern.com (8.11.6/8.11.6) id i0BHwS220641 for zsh-users@sunsite.dk; Sun, 11 Jan 2004 09:58:28 -0800 X-Authentication-Warning: candle.brasslantern.com: schaefer set sender to schaefer@closedmail.com using -f From: Bart Schaefer Message-Id: <1040111175827.ZM20640@candle.brasslantern.com> Date: Sun, 11 Jan 2004 17:58:27 +0000 In-Reply-To: <20040111153729.GC4628@fruitcom.com> Comments: In reply to Eric Smith "How do I complete from words in a file? (again)" (Jan 11, 4:37pm) References: <20040111153729.GC4628@fruitcom.com> X-Mailer: Z-Mail (5.0.0 30July97) To: Zsh Users Subject: Re: How do I complete from words in a file? (again) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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 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.