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

Re: No way to properly complete specific set of files



On Sat, 27 Apr 2013 05:12:27 -0500
Felipe Contreras <felipe.contreras@xxxxxxxxx> wrote:
> I have an array, let's say:
> 
>   files=('Documents' 'Downloads' 'Downloads/test' 'Videos')
> 
> And I want to complete those files, with all the niceties that _file has.
>...
> Am I missing something?

I don't think you're missing anything in the sense that there's anything
really designed for this, no...  to follow up on something Bart noted
earlier, the completion system is written in such a way that it doesn't
provide a lot of support for things that aren't done the way the
original author thought of.  It would be great to refactor it to be
both more general and more maintainable, but alas there are way too few
volunteers for that sort of exercise.

However, you can trick it to some extent:

_path_files -g "(${(j.|.)~files})"

relying on an extended_glob pattern to match any of the files.  That's
not perfect --- in particular if there are metacharacters in the
file names they'll confuse it.  Further, I think you're going to have
trouble with directories; you'd need to decide what the files were
within the current directory path, so you can't do stuff like complete
Downloads/test directly that way.  It's probably possible to work around
--- factor out the path that's already been completed --- but a bit
fiddly and not gaining a lot over what you're already doing.
 
-- 
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