Your code relies on word splitting suggestions=( $(compgen ... ) ) and the completion gives me wrong results before you set IFS=$'\n'. When you tested your function, you might have had IFS set from some previous attempts (since compgen also splits using IFS, I believe that really is the case). It's also subject to pathname expansion which is not that important here but still might be an issue in some extreme cases. set -f might be a good idea.
I believe that creating a completion that correctly handles whitespace characters and globs is extremely painful. I may have missed something of course and I might embarrass myself :) Overall it's a great article giving insight in some less known parts of bash 👍

Your code relies on word splitting
suggestions=( $(compgen ... ) )and the completion gives me wrong results before you setIFS=$'\n'. When you tested your function, you might have hadIFSset from some previous attempts (sincecompgenalso splits usingIFS, I believe that really is the case). It's also subject to pathname expansion which is not that important here but still might be an issue in some extreme cases.set -fmight be a good idea.I believe that creating a completion that correctly handles whitespace characters and globs is extremely painful. I may have missed something of course and I might embarrass myself :) Overall it's a great article giving insight in some less known parts of
bash👍