Skip to content

Commit ff2b028

Browse files
committed
fix(compatdir): shadow compat files of the same name
1 parent 626d94c commit ff2b028

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

bash_completion

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3627,15 +3627,25 @@ _comp__init_collect_startup_configs()
36273627
[[ ${compat_dirs[0]} == "$compat_dir" ]] ||
36283628
compat_dirs+=("$compat_dir")
36293629
fi
3630+
local -A compat_visited=()
36303631
for compat_dir in "${compat_dirs[@]}"; do
36313632
[[ -d $compat_dir && -r $compat_dir && -x $compat_dir ]] || continue
36323633
local compat_files
36333634
_comp_expand_glob compat_files '"$compat_dir"/*' || continue
36343635
local compat_file
36353636
for compat_file in "${compat_files[@]}"; do
36363637
[[ ${compat_file##*/} != @($_comp_backup_glob|Makefile*|${BASH_COMPLETION_COMPAT_IGNORE-}) &&
3637-
-f $compat_file && -r $compat_file ]] &&
3638-
_comp__init_startup_configs+=("$compat_file")
3638+
-f $compat_file && -r $compat_file ]] || continue
3639+
3640+
# Disable the compat files with the same name as one of already
3641+
# selected ones. This allows users to override a compat file with
3642+
# another file with the same name placed in an earlier directory in
3643+
# "${compat_dirs[@]}".
3644+
local name=${compat_file##*/}
3645+
[[ ${compat_visited[$name]-} ]] && continue
3646+
compat_visited[$name]=set
3647+
3648+
_comp__init_startup_configs+=("$compat_file")
36393649
done
36403650
done
36413651

0 commit comments

Comments
 (0)