问题描述
_arguments \
'-project[project file]:project:->projects'
...
case "$state" in
...
projects)
local -a projects
projects=(*.project)
_multi_parts / projects
echo "$SELECTED_PROJECT" > /tmp/project
;;
...
如何从 _multi_parts / projects
访问用户选择的选项,以便完成脚本的其他部分可以访问变量 $SELECTED_PROJECT
?
我在 _arguments
声明中有其他选项,这些选项取决于用户选择的 project
,但我似乎找不到访问它的方法。
解决方法
在完成函数中,命令行中已经存在的词可用 in the $words
array。
您可以找到将 $words
与 _arguments
in the completion functions that ship with Zsh 结合使用的示例。