Name the zsh completion function _<prog> so autoload works#1866
Open
apoorva-01 wants to merge 1 commit into
Open
Name the zsh completion function _<prog> so autoload works#1866apoorva-01 wants to merge 1 commit into
apoorva-01 wants to merge 1 commit into
Conversation
zsh autoloads a completion from a file in $fpath named after the command (e.g. _prog), and the function that file defines must match that filename. Typer generated _<prog>_completion, so a completion installed the standard packaged way - or via --install-completion, which writes the script to ~/.zfunc/_<prog> and autoloads it - silently failed: zsh autoloaded _prog but the file defined no _prog function. Generate _<prog> instead, in both the script shown by --show-completion / --install-completion and the source emitted for the _<PROG>_COMPLETE=source_zsh runtime path. The "#compdef"/"compdef" lines already register the completion, so dropping the suffix changes nothing else. Bash output is unchanged.
Contributor
|
Hey,
Thanks! I will not be replying to questions for this comment as I do not want to burden the maintainers time more. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1864.
Problem
zsh autoloads a completion from a file in
$fpathnamed after the command (say_prog), and the autoload convention requires the function that file defines to match the filename. Typer generated the function as_<prog>_completion, so when it's loaded that way the completion silently fails. zsh autoloads_prog, finds no_progfunction, and falls back to filename completion instead of command completion:It hits two paths. Packaging (
prog --show-completion=zsh > $fpath/_hf), which is what the issue reports. And--install-completion, which writes the script to~/.zfunc/_<prog>and addsfpath+=~/.zfunc; autoload -Uz compinit, so the same autoload route.Fix
Generate
_<prog>instead of_<prog>_completion. The#compdef/compdeflines already register the completion, so the_completionsuffix wasn't buying anything, and dropping it makes the function name match the autoloaded filename:The zsh script is rendered in two places,
get_completion_script(the--show-completion/--install-completionpath) andZshComplete.source()(the_<PROG>_COMPLETE=source_zshruntime path), so I updated both to keep them consistent. It's zsh-only. bash/fish/PowerShell output is unchanged (bash keeps_<prog>_completion, which has no filename constraint).Tests
Updated the three existing zsh completion assertions (
test_completion.py,test_completion_show.py,test_completion_install.py) to expect_<prog>and to check the old_completionsuffix is gone. They pass with the fix and fail without it. Fulltests/test_completion/suite passes locally (77 passed).ruff check/formatclean.