From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28455 invoked from network); 11 Aug 2002 03:30:32 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 11 Aug 2002 03:30:32 -0000 Received: (qmail 15748 invoked by alias); 11 Aug 2002 03:30:18 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 5222 Received: (qmail 15736 invoked from network); 11 Aug 2002 03:30:17 -0000 Message-ID: <3D55DA25.3080107@base2.cc> Date: Sat, 10 Aug 2002 20:29:41 -0700 From: Byron Foster User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020618 X-Accept-Language: en-us, en MIME-Version: 1.0 To: zsh-users@sunsite.dk Subject: Re: Completion question References: <3D53667B.8050202@base2.cc> <15699.28431.791243.550522@wischnow.berkom.de> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sven Wischnowsky wrote: > Byron Foster wrote: > > >>Hello, >> >> I can't figure out how to configure the completion system so that >>only directories are listed after typing 'rm -r ' at the command line, >>but without the the '-r' option only list files. Can I do this by only >>using styles, or do I need to write an _rm function? Im using zsh 4.0.4 >> >>so far for only listing files I have >> >>zstyle ':completion:*:complete:rm:*' file-patterns '*(^-/):files' >> >>Of course this breaks 'rm -r' > > > You can always use the `-e' option and then have a look at the $words > array, which is one of the special parameters set by the completion > code. It contains the word on the line. So: > > zstyle -e ':completion:*:complete:rm:*' file-patterns ' > if (( $words[(I)-r] )); then > reply=("*(-/):directories") > else > reply=("*(^-/):files") > fi' Thanks, that works nicely for both rm and cp. > Even if there were a function for `rm' which would do option parsing, > there currently were no way of smuggling code into it to take > advantage of the information about options on the line gathered there. > Except for that `-e' thing above (if a `_rm' function would use > _arguments we should have $opt_args available inside that code). I don't know enough, even though I'm learning, about the guts of the completion functions to really follow what you are saying. However, couldn't you just do what you did in the style definition, but do it in the _rm function? that is select tags based on the contents of $words. Doesn't the _arguments function do this for you? Again, I don't know allot about these function, so I may be making no sense. Thanks, Byron