I'm writing a zsh completion for some program, and parts of it involves completing resource routes (/they/look/like/this
).
I have a command mycmd
that I can use to generate some completion candidates of resource routes, and provide completions for my program, using:
_multi_parts '/' "($(mycmd /some/resource/id))"
Now, I would like to implement a specific behavior to match resources that contain the last identifier in my query, not only those that start with it.
For example, $(mycmd "/resource/identifier/bc")
gives completions like :
/resource/identifier/abc456/
/resource/identifier/123abcXYZ/
We get resource names whose identifier contains bc
, which is the intended behavior.
Now here is the problem: zsh completion prevents these completions from showing up, because none of them matches "/resource/identifier/bc*"
, the default pattern for zsh.
I read the documentation for ZSH _multi_parts
, compadd
. It appears that using -M <pattern>
described in compadd
doc and available for _multi_parts
could do the trick, by specifying a custom pattern for completion as described in ZSH Matching Control documentation. However this doc is lacking useful examples and is overall very obscure to me.
I spent hours of trials and errors to find the right pattern argument for _multi_parts -M <pattern>
to achieve what I want with no success. Any hint on this would be much appreciated.
EDIT: actually, simply ignoring the last resource identifier bc
would also work. I did not manage to do this either using -M
.