mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-07 23:31:07 +00:00
fix(cli): defer zsh compdef registration until compinit is available (#56555)
The generated zsh completion script called compdef at source time, which fails with 'command not found: compdef' when loaded before compinit. Replace with a deferred registration that tries immediately, and if compdef is not yet available, queues a self-removing precmd hook that retries on first prompt. Handles repeated sourcing (deduped hook entry) and shells that never run compinit (completion simply never registers, matching zsh model). Add real zsh integration test verifying no compdef error on source and successful registration after compinit. Fixes #14289
This commit is contained in:
@@ -411,7 +411,23 @@ _${rootCmd}_root_completion() {
|
||||
|
||||
${generateZshSubcommands(program, rootCmd)}
|
||||
|
||||
compdef _${rootCmd}_root_completion ${rootCmd}
|
||||
_${rootCmd}_register_completion() {
|
||||
if (( ! $+functions[compdef] )); then
|
||||
return 0
|
||||
fi
|
||||
|
||||
compdef _${rootCmd}_root_completion ${rootCmd}
|
||||
precmd_functions=(\${precmd_functions:#_${rootCmd}_register_completion})
|
||||
unfunction _${rootCmd}_register_completion 2>/dev/null
|
||||
}
|
||||
|
||||
_${rootCmd}_register_completion
|
||||
if (( ! $+functions[compdef] )); then
|
||||
typeset -ga precmd_functions
|
||||
if [[ -z "\${precmd_functions[(r)_${rootCmd}_register_completion]}" ]]; then
|
||||
precmd_functions+=(_${rootCmd}_register_completion)
|
||||
fi
|
||||
fi
|
||||
`;
|
||||
return script;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user