+ if [[ "$cur" == -* ]]; then # option
+ # Depending on whether '--' is one of the previous words we
+ # complete either on local options, i.e. those of the program
+ # to execute, or call the program to print possible completions
+ # (to a subcommand).
+ local_opts=true
+ for ((i=0; i < $COMP_CWORD; i++)); do
+ [[ "${COMP_WORDS[$i]}" != '--' ]] && continue
+ local_opts=false
+ break
+ done
+ if [[ "$local_opts" == "true" ]]; then
+ result="-- $($prg --help | awk "$script")"
+ COMPREPLY=($(compgen -W "$result" -- $cur))
+ return
+ fi
+ fi
+ # We need to call the program with --complete to get the possible
+ # completions. Before that, all local options must be discarded.
+ IFS=' '
+ n=0
+ for word in $line; do
+ ((n > 0)) && ! [[ "$word" == -* ]] && break
+ line="${line##*( )}" # remove leading whitespace
+ line="${line##+([^ ])}"
+ line="${line##*( )}"
+ let n++
+ [[ "$word" == '--' ]] && break
+ done
+ IFS="$OLD_IFS"
+ s=$((${#COMP_LINE} - ${#line})) # how many characters have been cut
+ if (($COMP_POINT > $s)); then
+ COMP_POINT=$(($COMP_POINT - $s))
+ else
+ COMP_POINT=0
+ fi
+ COMP_LINE="$line"
+ #echo "line: $COMP_LINE, point: $COMP_POINT"
+ export COMP_LINE COMP_POINT
+ result=($($prg --complete))