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

Re: Completion question



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




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