I have a script cmd
that runs tasks. cmd
lives in multiple directories. Each instance of cmd
defines it's own tasks which become the arguments.
I'd like each copy of cmd
to generate it's own completions on demand.
./cmd tasks
will output a list of newline separated arguments available in each copy of the script.
$./cmd tasks
delete
dump
help
other
The following zsh _cmd
works as needed when running ./cmd
:
#compdef cmd
args=( $(./cmd tasks) )
_arguments '*: :(${args})'
But as the path ./cmd
is static in that definition, the completion fails when I run /somedir/cmd
or any pathed variant.
There seems to be a lack of something like a $0
for the triggering command available in the _cmd
completion definition.
I can see there's certain ways to call _arguments
that return control and populate some extra state:
local context state line state_descr
_arguments -C '*::arg:->args'
But again, I haven't seen anything like $0
from the incoming command being populated. I haven't created a completion before so using _arguments
might not event be the right way about doing this it was just the first workable solution I happened upon when attempting this.
How can I define a zsh completion that generates the available arguments from the command that triggered the completion?