By quoting the ‘line’ variable we are making it a single word, but ‘getopts’ wants each option as its own word.
Previously bash completion would output an error for a line like: ‘ninja -vn targ‸’.
In addition to removing the quotes (to enable word expansion) I also used it as a regular variable, as that is what it is (not an array).
dir="."
line=$(echo ${COMP_LINE} | cut -d" " -f 2-)
# filter out all non relevant arguments but keep C for dirs
- while getopts C:f:j:l:k:nvd:t: opt "${line[@]}"; do
+ while getopts C:f:j:l:k:nvd:t: opt $line; do
case $opt in
C) dir="$OPTARG" ;;
esac