@@ -44,6 +44,21 @@ _comp__init_blacklist_glob='@(acroread.sh)'
4444# Turn on extended globbing and programmable completion
4545shopt -s extglob progcomp
4646
47+ # Declare a compatibility function name
48+ # @param $1 Old function name
49+ # @param $2 New function name
50+ _comp_deprecate_func ()
51+ {
52+ if [[ $1 != [a-zA-Z_]* ([a-zA-Z_0-9]) ]]; then
53+ printf ' bash_completion: %s: %s\n' " $FUNCNAME " " \$ 1: invalid function name '$1 '" >&2
54+ return 2
55+ elif [[ $2 != [a-zA-Z_]* ([a-zA-Z_0-9]) ]]; then
56+ printf ' bash_completion: %s: %s\n' " $FUNCNAME " " \$ 2: invalid function name '$2 '" >&2
57+ return 2
58+ fi
59+ eval -- " $1 () { $2 \"\$ @\" ; }"
60+ }
61+
4762# A lot of the following one-liners were taken directly from the
4863# completion examples provided with the bash 2.04 source distribution
4964
@@ -2429,16 +2444,21 @@ _completion_loader()
24292444# Function for loading and calling functions from dynamically loaded
24302445# completion files that may not have been sourced yet.
24312446# @param $1 completion file to load function from in case it is missing
2432- # @param $2 ... function and its arguments
2433- _xfunc()
2447+ # @param $2 the xfunc name. When it does not start with ` _' ,
2448+ # `_comp_xfunc_${1//[^a-zA-Z0-9_]/_}_$2' is used for the actual name of the
2449+ # shell function.
2450+ # @param $3... if any, specifies the arguments that are passed to the xfunc.
2451+ _comp_xfunc ()
24342452{
2435- set -- " $@ "
2436- local srcfile= $1
2437- shift
2438- declare -F $1 &>/dev/null || __load_completion " $srcfile "
2439- " $@ "
2453+ local xfunc_name= $2
2454+ [[ $xfunc_name == _ * ]] ||
2455+ xfunc_name=_comp_xfunc_ ${1 // [^a-zA-Z0-9_] / _} _ $xfunc_name
2456+ declare -F " $xfunc_name " & > /dev/null || __load_completion " $1 "
2457+ " $xfunc_name " " ${ @: 3} "
24402458}
24412459
2460+ _comp_deprecate_func _xfunc _comp_xfunc
2461+
24422462# source compat completion directory definitions
24432463_comp__init_compat_dir=${BASH_COMPLETION_COMPAT_DIR:-/ etc/ bash_completion.d}
24442464if [[ -d $_comp__init_compat_dir && -r $_comp__init_compat_dir && -x $_comp__init_compat_dir ]]; then
0 commit comments