What is the correct/best way of handling spaces and quotes in bash completion?
Here’s a simple example. I have a command called words (e.g., a dictionar
words
_foo () { words="bar one"$'\n'"bar two" COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} cur=${cur//\./\\\.} local IFS=$'\n' COMPREPLY=( $( grep -i "^$cur" <( echo "$words" ) | sed -e 's/ /\\ /g' ) ) return 0 } complete -o bashdefault -o default -o nospace -F _foo words