Describe the bug
When --show-completion=zsh output is installed as an autoloaded file in $fpath (the standard packaging convention), zsh completion silently fails because the generated function name doesn't match the autoloaded filename.
Reproduction
Output:
#compdef hf
_hf_completion() {
eval $(env _TYPER_COMPLETE_ARGS="${words[1,$CURRENT]}" _HF_COMPLETE=complete_zsh hf)
}
compdef _hf_completion hf
Install as packages do:
hf --show-completion=zsh > /usr/share/zsh/site-functions/_hf
Then in zsh:
% hf <Tab> # only shows filenames, no command completions
Root cause
zsh's compinit reads #compdef hf and registers hf → autoload _hf. The autoloaded file /usr/share/zsh/site-functions/_hf must define a function named _hf. But Typer generates _hf_completion, so the autoload produces no matching function and completion fails silently.
Why this only affects packaging, not --install-completion
--install-completion writes compdef _hf_completion hf into .zshrc. When sourced, compdef registers the function by whatever name it has — the filename is irrelevant. But when installed as an autoloaded file in $fpath, the filename IS the function name.
Suggested fix
Generate _{prog_name} instead of _{prog_name}_completion. The _completion suffix serves no purpose — the #compdef directive already wires up the completion.
#compdef hf
_hf() {
eval $(env _TYPER_COMPLETE_ARGS="${words[1,$CURRENT]}" _HF_COMPLETE=complete_zsh hf)
}
compdef _hf hf
This matches zsh autoload convention and keeps --install-completion working (since compdef can reference any name).
Workaround (for package maintainers)
hf --show-completion=zsh | sed 's/_hf_completion/_hf/g' > _hf
Environment
- Typer 0.26.7 (latest)
- zsh 5.9
Describe the bug
When
--show-completion=zshoutput is installed as an autoloaded file in$fpath(the standard packaging convention), zsh completion silently fails because the generated function name doesn't match the autoloaded filename.Reproduction
Output:
Install as packages do:
hf --show-completion=zsh > /usr/share/zsh/site-functions/_hfThen in zsh:
Root cause
zsh's
compinitreads#compdef hfand registershf→ autoload_hf. The autoloaded file/usr/share/zsh/site-functions/_hfmust define a function named_hf. But Typer generates_hf_completion, so the autoload produces no matching function and completion fails silently.Why this only affects packaging, not
--install-completion--install-completionwritescompdef _hf_completion hfinto.zshrc. When sourced,compdefregisters the function by whatever name it has — the filename is irrelevant. But when installed as an autoloaded file in$fpath, the filename IS the function name.Suggested fix
Generate
_{prog_name}instead of_{prog_name}_completion. The_completionsuffix serves no purpose — the#compdefdirective already wires up the completion.This matches zsh autoload convention and keeps
--install-completionworking (sincecompdefcan reference any name).Workaround (for package maintainers)
Environment