* No way to properly complete specific set of files
@ 2013-04-27 10:12 Felipe Contreras
2013-04-28 18:12 ` Peter Stephenson
0 siblings, 1 reply; 4+ messages in thread
From: Felipe Contreras @ 2013-04-27 10:12 UTC (permalink / raw)
To: zsh-workers; +Cc: Felipe Contreras Garza
Hi,
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.
I could do the same as _git and others do:
_multi_parts -f -- / files
But that doesn't work; the files are not detected. And it doesn't
complete the same way.
Or I could use _path_files, as somebody suggested on the list, but
that doesn't limit the list of files.
It would have been very easy to tell _path_files which files to
complete, but no, I have to manually implement the completion myself:
---
#compdef foobar
_foobar_1 ()
{
_multi_parts -f -- / $1
}
_foobar_2 ()
{
_path_files
}
_foobar_3 ()
{
local -a list
local pfx="" cur="${words[CURRENT]}" file
case "$cur" in
?*/*)
pfx="${cur%/*}"
cur="${cur##*/}"
pfx="${pfx}/"
;;
esac
for file in ${(P)1}; do
case "$file" in
${pfx}*)
file="${file##$pfx}"
;;
*)
continue
;;
esac
case "$file" in
?*/*)
list+="${file%%/*}"
;;
*)
list+="${file}"
;;
esac
done
compadd -Q -p "${pfx-}" -f -a list
}
_foobar ()
{
local -a files
files=('Documents' 'Downloads' 'Downloads/test' 'Videos')
_foobar_3 files
return 0
}
_foobar
---
Am I missing something?
--
Felipe Contreras
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: No way to properly complete specific set of files
2013-04-27 10:12 No way to properly complete specific set of files Felipe Contreras
@ 2013-04-28 18:12 ` Peter Stephenson
2013-04-28 23:42 ` Bart Schaefer
2013-04-29 5:39 ` Felipe Contreras
0 siblings, 2 replies; 4+ messages in thread
From: Peter Stephenson @ 2013-04-28 18:12 UTC (permalink / raw)
To: Felipe Contreras, zsh-workers
On Sat, 27 Apr 2013 05:12:27 -0500
Felipe Contreras <felipe.contreras@gmail.com> 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@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: No way to properly complete specific set of files
2013-04-28 18:12 ` Peter Stephenson
@ 2013-04-28 23:42 ` Bart Schaefer
2013-04-29 5:39 ` Felipe Contreras
1 sibling, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2013-04-28 23:42 UTC (permalink / raw)
To: zsh-workers
On Apr 28, 7:12pm, Peter Stephenson wrote:
}
} _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.
Wouldn't
_path_files -g "(${(j.|.)~${(@q)files}})"
do it?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: No way to properly complete specific set of files
2013-04-28 18:12 ` Peter Stephenson
2013-04-28 23:42 ` Bart Schaefer
@ 2013-04-29 5:39 ` Felipe Contreras
1 sibling, 0 replies; 4+ messages in thread
From: Felipe Contreras @ 2013-04-29 5:39 UTC (permalink / raw)
To: Peter Stephenson; +Cc: zsh-workers, Felipe Contreras Garza
On Sun, Apr 28, 2013 at 1:12 PM, Peter Stephenson
<p.w.stephenson@ntlworld.com> wrote:
> On Sat, 27 Apr 2013 05:12:27 -0500
> Felipe Contreras <felipe.contreras@gmail.com> 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.
Yeah, but the next question is; why didn't the author think of that?
It seems like fairly obvious to me that somebody eventually would come
up with that need, and it seems many have done so, and they are using
_multi_parts for that (e.g. _git and _hg), but doesn't work nicely
either.
Too bad.
Cheers.
--
Felipe Contreras
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-04-29 5:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-27 10:12 No way to properly complete specific set of files Felipe Contreras
2013-04-28 18:12 ` Peter Stephenson
2013-04-28 23:42 ` Bart Schaefer
2013-04-29 5:39 ` Felipe Contreras
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).