How does this bash completion function work? (for cloudfoundry cli) -
i try understand bash completion function ? (for cloudfoundry cli)
i read https://debian-administration.org/article/317/an_introduction_to_bash_completion_part_2 , bash ref guide @ https://www.gnu.org/software/bash/manual/bash.html#programmable-completion can figure out how code in script cloudfoundry works: (copy /usr/local/etc/bash_completion.d/cf)
_cf() { # arguments except first 1 args=("${comp_words[@]:1:$comp_cword}") # split on newlines local ifs=$' ' # call completion (note first element of comp_words # executable itself) compreply=($(go_flags_completion=1 ${comp_words[0]} "${args[@]}")) return 0 } complete -f _cf cf in have installed plugins cf , see them in completion. (e.g. github.com cf-targets-plugin)
any hints me ? how word list generated ? (i assume in comp_words[])
this different samples like
compreply=( $(compgen -w "$worldist -- "$cur_opt") )
this speculative, because have not installed software.
apparently program generate list of available completions when invoked environment variable go_flags_completion set 1. code sets variable , calls program current arguments, , expects receive list of completions back.
this elegant solution context-based completions -- program knows parameters can accept current arguments, , bash doesn't have duplicate information or parse same arguments.
Comments
Post a Comment