Fix zsh completion error on fresh macOS installations #10
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.
Problem
On fresh macOS installations with zsh, users encounter the following error when opening a new terminal:
(eval):2: command not found: compdefThis occurs because the zsh completion system hasn't been initialized before the
duckman completion zshcommand runs, which requires thecompdeffunction. On fresh installations,compdefis only available aftercompinithas been called.Solution
This PR adds an initialization step that ensures
compinitruns before loading the duckman completion script. This guarantees that the completion system is properly initialized whencompdefis called.Changes:
autoload -Uz compinit 2>/dev/null && compinit 2>/dev/nullline before the completion eval2>/dev/nullsuppresses any warnings if compinit has already been called (making it safe to run multiple times)Testing
I've tested this fix on a fresh macOS installation. After adding the new line, opening a new terminal no longer produces the
command not found: compdeferror, and duckman completion works correctly. I also verified it works correctly with oh-my-zsh installed, where compinit is already called by the framework.