我试着理解这个 bash 完成功能?(对于cloudfoundry cli)
我阅读 了https://debian-administration.org/article/317/An_introduction_to_bash_completion_part_2
以及 https://www.gnu.org/software/bash/manual/bash.html#Programmable-Completion 上的 bash 参考指南,但
可以计算了解 cloudfoundry 脚本中的代码是如何工作的:(复制自/usr/local/etc/bash_completion.d/cf
)
_cf() {
# All arguments except the first one
args=("${COMP_WORDS[@]:1:$COMP_CWORD}")
# Only split on newlines
local IFS=$'
'
# Call completion (note that the first element of COMP_WORDS is
# the executable itself)
COMPREPLY=($(GO_FLAGS_COMPLETION=1 ${COMP_WORDS[0]} "${args[@]}"))
return 0
}
complete -F _cf cf
已经为 cf 安装了一些插件,并希望看到它们完成。(例如 github.com cf-targets-plugin
)
对我有什么提示吗?词表是怎么产生的?(我假设它在COMP_WORDS[]
)
这与样本如此不同
COMPREPLY=( $(compgen -W "$worldist -- "$cur_opt") )