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

Re: Problem with fake-files style and cd



Mikael Magnusson wrote:
> I want to complete foo/ in ~, and when I do this
> zstyle ':completion::complete:cd::' fake-files $HOME:foo
> I get the completion without the trailing /, if I do
> zstyle ':completion::complete:cd::' fake-files $HOME:foo/
> I get a trailing slash _and_ a trailing space. Is there a bug or did I
> miss something obvious? When I don't get the slash I don't get a space
> either.

It's not really a bug, no.  fake-files isn't handled by _cd, it's
handled by _path_files, in other words it's a generic adder of fake
files; it has never tried to guess the context in which the file is
being added, nor is it documented to do so.  So it can't know that when
you add a fake file "foo" it's a directory.  Since it's a generic fake
*file*, there's nothing special about adding a slash, it just adds the
full match; and since it's a generic *fake* file it can't test what's
there to see how to handle it.  (There's some support for things that
spring into existence when referenced; is that not the case here?  If it
is this might be a bug but I'm not going to be able to look at it on my
system.)

I can see it would be convenient to add special support for a "/" at the
end of fake files along the lines of your second attempt; however, there
is no simple, elegant, bug-free way of adding anything to _path_files
(you're lucky if you get one of the three).  In this case I couldn't see
anything better than horribly ad-hoc tricks along the lines of "if you
get a single match at this point in the file and it's got a slash at the
end then remove the slash and add it again as a removable suffix".
It's probably doable, but horribly ad-hoc tricks usually don't fit into
any of the three categories above.

Users are encouraged to look at _path_files for themselves as an
exercise.

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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