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

Re: rm(1) completion definition



Nikolai Weibull wrote:
> 1.  It seems that my trick to disable --force and --recursive on
> non-GNU systems doesn't work.  Does the specifications have to match

This is better done as:
  args=( ${args:#*--(force|recursive)\[*} )

The ! syntax is intended for a different purpose: where you have an
option that may appear earlier on the command-line and you don't want to
complete it but _arguments needs to know what it's exclusion lists and
arguments are.

> 2.  I'm not sure if the zstyle thing is correct, but it's definitely
> what you want it to do.  Is there a better way to achieve the same
> effect?

The problem with the zstyle stuff is that you've used single quotes so
$curcontext is not expanded. Personally, I think it is fundamentally
wrong to ever define zstyles in completion functions. They are meant
for user-customisation and can sometimes get in the way of
customisations. The very specific context for them can make them hard
to override.

At some point in the past, there was a problem with ignore-line that
meant that if you tried to do something like:
  rm foo dir/foo
It wouldn't complete foo in the subdirectory. I can't reproduce this now
so perhaps it was a bit more subtle or perhaps it got fixed.

The right way to do this would be to work out exactly what can't be
completed and build up a suitable glob pattern to pass to _files with
-g.

One other point: I really hope that running rm --version can't possibly
actually result in a file or files being removed on some system. I'm a
bit uneasy about it. Perhaps you should try using rm --help instead
because there's no `r' in help.

Oliver



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