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

Re: Problem with fake-files style and cd



2009/2/14 Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>:
> 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.)

(No, I've modified the _cd completer a bit to only add $cdpath things
if the first component is already typed out, because when I'm sitting
in a dir with only one subdir and type cd <tab> i would like that
directory completed and not the 50 ones in my cdpath. I used to have a
~/code symlink to point to where my code dir really is, and both ~ and
that dir is in my $cdpath. This causes listings of this type though:
% cd code/<tab>
---- local directory
zsh/
---- directory in cdpath
zsh/

and this was mostly a feeble attempt to get around that by removing
the symlink and readding it as a fake directory.)

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

Thanks for the explanation, I gather that I can probably not make it
work easily, so for now I think I'll just put the symlink back :).
Actually, mkdir code does what I want...

Of course, my real question should have been if I can make the
completion listing remove duplicate entries when I have both a real
directotry and an entry in cdpath that matches, but I guess if you
have a real dir foo/bar and a cdpath dir foo/baz you want to be able
to complete to foo/baz too. Maybe it doesn't have to show up as a
cdpath entry at the foo point though, since the cd builtin won't
actually go there anyway?

-- 
Mikael Magnusson



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