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

Re: Recursive Completition



On Aug 18, 11:09pm, Karoly Negyesi wrote:
}
} ls **/Kernel.php[Tab]
} 
} autocompletes to
} 
} core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Kernel.php
} 
} that's really great!

Glad you like it, but you should understand the difference between
_completion_ and _expansion_ before going any further.  What you've
done right there is _expansion_ -- replace a glob pattern with the
thing(s) it matches (expands to).  This happens to be handled as part
of the completion system if you've run "compinit" but it's really not
quite the same thing, because it isn't applying any contextual clues
to the pattern, it's just expanding it.

Note that the default behavior is to try expansion first and complete
only if that fails.
 
} Even better would be if I could have
} 
} ls **/Kern[tab]
} 
} do that (and not just for ls, but everything else).

Here the glob pattern doesn't match (because there's no file named
"Kern" anywhere downstream), so it doesn't expand to anything.  If
you tried

ls **/Kern*[tab]

you'd get something (possibly many somethings).

Fortunately there's a way to move this out of the realm of expansion
and into that of completion; to whit, simply assert that you want
completion to act as if it were using glob patterns:

setopt globcomplete

Now when you try

ls **/Kern[tab]

the completion system behaves as if you'd inserted a * just before [tab],
and offers you the list of matching items as choices.

It's not quite as intutive when encountering a possible branch part way
down the **/ expansion -- you may be offered a set of directories as the
alternatives with no obvious way to choose one of them and then go on
with the same completion.  This gets easier if you force menu-selection
to occur.

} Oh, and maybe display the menu while I am writing a wishlist :)

That's all independently controlled by things like 

setopt automenu
zstyle ':completion:*' menu 'yes=long' 'select=9'

and so on.  There's a bunch of stuff about this toward the end of
section 6.5.2 http://zsh.sourceforge.net/Guide/zshguide06.html#l158
of the user guide.

} Perfect would be just
} 
} ls Kern[tab]
} 
} to do that. I am aware of the performance implications -- could this
} be restricted to the user's home dir only so it doesnt try to read the
} whole OS when in the root.

This one would require that you create a new widget or a new completion
function to insert the implicit leading **/ in the right contexts.  It's
certainly do-able, but I'm going to leave it as an exercise for someone
else, this time.



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