Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Completion question



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' 

This doesn't catch the case where the `-r' option is put together with
other options in the same string (like `-ir').

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).


Bye
  Sven

-- 
Sven Wischnowsky                          wischnow@xxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author