adaszko / complgen

Declarative bash/fish/zsh completions without writing shell scripts
Apache License 2.0
221 stars 7 forks source link

Completion for ZSH doesn't work in default path #38

Closed meator closed 9 months ago

meator commented 10 months ago

I have converted the usage/complgen.usage to ZSH completion script and put it into the standard ZSH completions directory, /usr/share/zsh/site-functions/_complgen. It doesn't work. It doesn't generate any warnings nor errors, but by looking around, I came across this warning:

/usr/share/zsh/site-functions/_complgen:377: command not found: compdef

All of the other completions in /usr/share/zsh/site-functions begin with #compdef ..., but not complgen. Are complgen's ZSH completion scripts incompatible with this type of completion script distribution?

I should note that I am not familiar with the completion systems of the major shells. I have hoped that this program would spare me from this.

adaszko commented 9 months ago

Under ZSH, the completion system needs to be initialized first to use any completion script, not just those generated by complgen.

Take a look at https://unix.stackexchange.com/a/477909

meator commented 9 months ago

All other completion scripts in that directory are fully functional. I believe the completion system is initialised well. But the complgen's one is the odd one out. I believe this could be related to the #compldef line.

adaszko commented 9 months ago

I don't think that's the problem. I won't be at a physical keyboard for another week or so but AFAIR there are two forms allowed -- with and without the compdef comment line.

That same completion script works fine when installed via homebrew.

Check if that completion script works if you source the generated file.

Make sure the said directory is listed in the $fpath zsh variable.

You may also need to rm ~/.zcompdump after putting the script in that directory.

If all the above fails, see if the completion works if you manually add the compdef line.

meator commented 9 months ago

Check if that completion script works if you source the generated file.

It works when sourcing manually with source or ..

Make sure the said directory is listed in the $fpath zsh variable.

/usr/share/zsh/site-functions is a standard ZSH directory for completions. All other completions in that directory are fully functional. /usr/share/zsh/site-functions is in my $fpath.

You may also need to rm ~/.zcompdump after putting the script in that directory.

I have tried this and it didn't change anything.

If all the above fails, see if the completion works if you manually add the compdef line.

When

#compdef complgen

is added to the beginning of that file, it starts working.

adaszko commented 9 months ago

That's strange. Looks like complgen needs a specific end-to-end test for that case. Current ones test generated scripts by sourcing them. I'll get to it when I'm at a physical keyboard again. Thanks for reporting.

adaszko commented 9 months ago

The generated zsh completions scripts should now work both when autoloaded or sourced. I want to implement on more new feature (aot fallbacks) and will then make a new release. Thanks again @meator!

meator commented 9 months ago

Ok, thanks!