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

Re: Programmatically loading completion for another command?



On 2022-05-27 19:46, Daniel Shahaf wrote:
Bart Schaefer wrote on Fri, 27 May 2022 17:03 +00:00:
On Fri, May 27, 2022 at 9:30 AM Vorpal <zsh@xxxxxxxxx> wrote:

* How do I trigger loading that file from my completion so I can offer
completions to the flag --makepkg-args? Is it even possible?

Something like this should work, no other wrapper needed:

   service=makepkg _sequence $_comps[makepkg]

Thanks a lot! That works mostly as expected. There is one issue in that exclusivity in the argument completion of makepkg is ignored. Is there another option than _sequence that would handle that or do I have to invent my own thing that "simulates" the proper $words array (and possibly other things?) to the inner completion function?


In my install the service dispatcher function is _pkgtool not _pacman,

There's two different makepkg(1) tools, it seems: the one completed by
zsh's _pkgtool file, and Arch Linux' tool, completed by
<https://gitlab.archlinux.org/pacman/pacman/-/blob/master/scripts/completion/zsh_completion.in>.

I am indeed doing this on Arch Linux, which is the relevant tool for me. As this is related to the system package manager and the tool I'm writing completions for is specific to Arch Linux, being able to support both is not really a concern (and doesn't even make sense).

I was more concerned for possibly future changes to how the pacman/makepkg completion was implemented breaking my completion script. However if $_comps is the official way to do it that significantly reduces the risk of that.

However it seems to me that a generic helper on the following form would a useful addition to the standard zsh distribution in that case:

_complete_for()
{
    service=$1 $_comps[$1]
}

(I don't care about the name, bikeshed it all you want).

I already included that (under a non-conflicting name) in my completion file for now as I need to not just complete makepkg in this manner but also makechrootpkg (which is defined in _devtools instead of _pacman).


so using $_comps[makepkg] in the call to _sequence should get the
right one, whichever.

(Nod over to Daniel on the _services thread.)

Best regards,
Arvid Norlander




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