compdef cmd1=service
can be used to define a completion alias, however, that works only when the arguments are going to be the same.
For example, consider a helper script which rewrites some arguments before executing another command:
| What is typed | What is executed |
|---------------+----------------------------|
| s | systemctl |
| s q | systemctl status |
| s q foo | systemctl status foo |
| s j foo | journalctl --unit foo |
| s r foo | sudo systemctl restart foo |
We can ask the script to print the arguments it would execute, so e.g. PRINT_ONLY=1 s
would print just systemctl
.
Assuming completion is already set up for systemctl
/ journalctl
/ sudo
, how would one define a zsh completion for such a script? Rather than redundantly reimplementing completion for those commands, how to implement completion for s
such that the completion system is invoked with a transformed command -- i.e. something like function _s() { get_completions $(PRINT_ONLY=1 s "$@") ; }
?