I have an autocompletion script, with this snippet:
_arguments \
'-project[project file]:project:->projects'
...
case "$state" in
...
projects)
local -a projects
projects=(*.project)
_multi_parts / projects
echo "$SELECTED_PROJECT" > /tmp/project
;;
...
How can I get access to the user-selected option from _multi_parts / projects
such that there is a variable $SELECTED_PROJECT
that is accessible to other parts of the completion script?
I have other options in the _arguments
declaration that are dependent on which project
the user has selected, but I can't seem to find a way to get access to it.
Inside a completion function, the words that are already present on the command line are available in the
$words
array.You can find examples of using
$words
with_arguments
in the completion functions that ship with Zsh.