Zsh completion scripts (Effect's internal completions/zsh), built on
_arguments specs with a state machine for subcommands.
Functions#
generate#
generate(executable, descriptor) -> str| Parameter | Type | Description |
|---|---|---|
executable | str | |
descriptor | CommandDescriptor |
Returns str
def generate(executable: str, descriptor: CommandDescriptor) -> str:
safe = _sanitize(executable)
lines = [
f"#compdef {executable}",
f"###-begin-{executable}-completions-###",
"#",
"# Static completion script for Zsh",
"#",
"# Installation:",
f"# {executable} --completions zsh > ~/.zsh/completions/_{executable}",
"# then add ~/.zsh/completions to your fpath",
"#",
"",
]
_function(descriptor, [], lines)
lines.append("# Handle both direct invocation and autoload")
lines.append('if [[ "${zsh_eval_context[-1]}" == "loadautofunc" ]]; then')
lines.append(f' _{safe} "$@"')
lines.append("else")
lines.append(f" compdef _{safe} {executable}")
lines.append("fi")
lines.append(f"###-end-{executable}-completions-###")
return "\n".join(lines)