How should a function passed to _arguments for zsh shell completion look like?

575 Views Asked by At

In my completion function, I'd like to add an option which possible arguments depend on which files are on the system. I have no troubles getting that list of possible arguments, but I have no idea what I should do with it.

This guide talks about FUNCTION as possible action for _arguments. (For some reason I didn't find it in the official docs) And that works well, the function specified is indeed called. But what should I now do with that list? I tried returning it and printing it. In both cases nothing happened.

_files manages to do it somehow, but from looking at the source code I didn't find anything useful. I probably have to store it in some variable, but where?

My code so far:

#compdef _command command

function _command {
    local line

    _arguments -C \
        '(-)'{-h,--help}'[Show help]' \
        '(-u --update -p --platform)'{-u,--update}'[Update]' \
        '(-p --platform -u --update)'{-p,--platform}'[Platform]:whatshouldiputhere:_get_all_platforms' \
        "*::arg:->args"
}

function _get_all_platforms {
    # I know how to get the list of possible completions but I have no idea what to do with it
}

1

There are 1 best solutions below

0
Armali On

But what should I now do with that list?

You should pass it as arguments to the compadd builtin command:

This builtin command can be used to add matches directly …