Given an example wrapper shell function:
app() {
setsid "$@"
}
In Bash, you can do complete -F _command app to automatically give app completions for all commands (not just binaries on the path but also the arguments afterwards).
How can you do this in ZSH? I have some leads with _normal and -command-line- but I've been unable to figure out the correct command to put in a .zshrc.
Update:
Just wanted to document something interesting, this produces a SIGSEGV:
autoload -U compinit && compinit
compdef _normal app
# Attempt tab completion of app:
# _normal:1: maximum nested function level reached; increase FUNCNEST?
FUNCNEST=999
# Attempt tab completion of app again
# !!! ZSH crashes (see coredumpctl) !!!
Updated shorter answer:
Turns out
_commandactually does exist in ZSH as well! I didn't find the manpages very clear on this but here's your answer:It's also helpful to note that after
compinityou can runecho $_comps[ls]to get the completion command of any command (the output here is_ls).Original answer:
Figured it out:
This was somewhat a duplicate of this question: How do I dynamically select a completion function in zsh?
If someone knows a shorter solution like what Bash has then please answer as that would be nice.