Remove the line set -e -u. Those settings are global to your shell session, not local to your function, and they conflict with the shell completion functions which are not immune to undefined variables (set -u). And since your function is well written, you need neither set -e nor set -u.