@@ -3303,47 +3303,65 @@ else
33033303 }
33043304fi
33053305
3306- # source compat completion directory definitions
3307- _comp__init_compat_dirs=()
3308- if [[ ${BASH_COMPLETION_COMPAT_DIR-} ]]; then
3309- _comp__init_compat_dirs+=(" $BASH_COMPLETION_COMPAT_DIR " )
3310- else
3311- _comp__init_compat_dirs+=(/etc/bash_completion.d)
3312- # Similarly as for the "completions" dir, look up from relative to
3313- # bash_completion, primarily for installed-with-prefix and
3314- # run-in-place-from-git-clone setups. Notably we do it after the system
3315- # location here, in order to prefer in-tree variables and functions.
3316- if [[ ${BASH_SOURCE%/* } == * /share/bash-completion ]]; then
3317- _comp__init_compat_dir=${BASH_SOURCE%/ share/ bash-completion/* } /etc/bash_completion.d
3318- elif [[ $BASH_SOURCE == * /* ]]; then
3319- _comp__init_compat_dir=" ${BASH_SOURCE%/* } /bash_completion.d"
3306+ # List custom/extra completion files to source on the startup
3307+ # # @param $1 path Path to "bash_completion"
3308+ # # @var[out] _comp__init_startup_configs
3309+ _comp__init_collect_startup_configs ()
3310+ {
3311+ local base_path=${1:- ${BASH_SOURCE[1]} }
3312+ _comp__init_startup_configs=()
3313+
3314+ # source compat completion directory definitions
3315+ local -a compat_dirs=()
3316+ local compat_dir
3317+ if [[ ${BASH_COMPLETION_COMPAT_DIR-} ]]; then
3318+ compat_dirs+=(" $BASH_COMPLETION_COMPAT_DIR " )
33203319 else
3321- _comp__init_compat_dir=./bash_completion.d
3322- fi
3323- [[ ${_comp__init_compat_dirs[0]} == " $_comp__init_compat_dir " ]] ||
3324- _comp__init_compat_dirs+=(" $_comp__init_compat_dir " )
3325- fi
3326- for _comp__init_compat_dir in " ${_comp__init_compat_dirs[@]} " ; do
3327- [[ -d $_comp__init_compat_dir && -r $_comp__init_compat_dir && -x $_comp__init_compat_dir ]] || continue
3328- _comp_expand_glob _comp__init_files ' "$_comp__init_compat_dir"/*'
3329- # shellcheck disable=SC2154
3330- for _comp__init_file in " ${_comp__init_files[@]} " ; do
3331- [[ ${_comp__init_file##*/ } != @ ($_comp_backup_glob | Makefile* | ${BASH_COMPLETION_COMPAT_IGNORE-} ) &&
3332- -f $_comp__init_file && -r $_comp__init_file ]] && . " $_comp__init_file "
3320+ compat_dirs+=(/etc/bash_completion.d)
3321+ # Similarly as for the "completions" dir, look up from relative to
3322+ # bash_completion, primarily for installed-with-prefix and
3323+ # run-in-place-from-git-clone setups. Notably we do it after the
3324+ # system location here, in order to prefer in-tree variables and
3325+ # functions.
3326+ if [[ ${base_path%/* } == * /share/bash-completion ]]; then
3327+ compat_dir=${base_path%/ share/ bash-completion/* } /etc/bash_completion.d
3328+ elif [[ $base_path == * /* ]]; then
3329+ compat_dir=" ${base_path%/* } /bash_completion.d"
3330+ else
3331+ compat_dir=./bash_completion.d
3332+ fi
3333+ [[ ${compat_dirs[0]} == " $compat_dir " ]] ||
3334+ compat_dirs+=(" $compat_dir " )
3335+ fi
3336+ for compat_dir in " ${compat_dirs[@]} " ; do
3337+ [[ -d $compat_dir && -r $compat_dir && -x $compat_dir ]] || continue
3338+ local compat_files
3339+ _comp_expand_glob compat_files ' "$compat_dir"/*'
3340+ local compat_file
3341+ for compat_file in " ${compat_files[@]} " ; do
3342+ [[ ${compat_file##*/ } != @ ($_comp_backup_glob | Makefile* | ${BASH_COMPLETION_COMPAT_IGNORE-} ) &&
3343+ -f $compat_file && -r $compat_file ]] &&
3344+ _comp__init_startup_configs+=(" $compat_file " )
3345+ done
33333346 done
3334- done
3335- unset -v _comp__init_compat_dirs _comp__init_compat_dir _comp__init_files _comp__init_file
33363347
3337- # source user completion file
3338- #
3339- # Remark: We explicitly check that $user_completion is not '/dev/null' since
3340- # /dev/null may be a regular file in broken systems and can contain arbitrary
3341- # garbages of suppressed command outputs.
3342- _comp__init_user_file=${BASH_COMPLETION_USER_FILE:- ~/ .bash_completion}
3343- [[ $_comp__init_user_file != " ${BASH_SOURCE[0]} " && $_comp__init_user_file != /dev/null && -r $_comp__init_user_file && -f $_comp__init_user_file ]] &&
3344- . " $_comp__init_user_file "
3345- unset -v _comp__init_user_file
3348+ # source user completion file
3349+ #
3350+ # Remark: We explicitly check that $user_completion is not '/dev/null'
3351+ # since /dev/null may be a regular file in broken systems and can contain
3352+ # arbitrary garbages of suppressed command outputs.
3353+ local user_file=${BASH_COMPLETION_USER_FILE:- ~/ .bash_completion}
3354+ [[ $user_file != " $base_path " && $user_file != /dev/null && -r $user_file && -f $user_file ]] &&
3355+ _comp__init_startup_configs+=(" $user_file " )
33463356
3357+ unset -f " $FUNCNAME "
3358+ }
3359+ _comp__init_collect_startup_configs " $BASH_SOURCE "
3360+ # shellcheck disable=SC2154
3361+ for _comp_init_startup_config in " ${_comp__init_startup_configs[@]} " ; do
3362+ . " $_comp_init_startup_config "
3363+ done
3364+ unset -v _comp__init_startup_configs _comp_init_startup_config
33473365unset -f have
33483366unset -v have
33493367
0 commit comments