Qualify custom bash func name (#730)

* Qualify custom bash func name

 - fixes issue where multiple cobra apps using custom bash completion
 would have their __custom_func collide
 - support fallback to plain __custom_func to maintain compatibility

#694

* Improve tests for bash completion __custom_func

 - check for the correct number of occurrences of function name

#694
This commit is contained in:
Paul
2018-08-21 11:12:02 -05:00
committed by Eric Paris
parent ff0d02e855
commit 6fd8e29b07
3 changed files with 21 additions and 5 deletions

View File

@ -129,7 +129,13 @@ __%[1]s_handle_reply()
fi
if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
declare -F __custom_func >/dev/null && __custom_func
if declare -F __%[1]s_custom_func >/dev/null; then
# try command name qualified custom func
__%[1]s_custom_func
else
# otherwise fall back to unqualified for compatibility
declare -F ___custom_func >/dev/null && __custom_func
fi
fi
# available in bash-completion >= 2, not always present on macOS