Skip to content

feat(__load_completion): load in-tree before system data dirs #823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -2587,19 +2587,28 @@ complete -F _minimal ''

__load_completion()
{
local -a dirs=(${BASH_COMPLETION_USER_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion}/completions)
local IFS=: dir cmd="${1##*/}" compfile
[[ $cmd ]] || return 1
for dir in ${XDG_DATA_DIRS:-/usr/local/share:/usr/share}; do
dirs+=($dir/bash-completion/completions)
done
_comp_unlocal IFS

# Lookup order:
# 1) User installed completions.
local -a dirs=(
${BASH_COMPLETION_USER_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion}/completions
)
# 2) Completions relative to the main script. This is primarily for
# run-in-place-from-git-clone setups, where we want to prefer
# in-tree completions over ones possibly coming with a system
# installed bash-completion. (Due to usual install layouts, this
# often hits the correct completions in system installations, too.)
if [[ $BASH_SOURCE == */* ]]; then
dirs+=("${BASH_SOURCE%/*}/completions")
else
dirs+=(./completions)
fi
# 3) Completions in the system data dirs.
for dir in ${XDG_DATA_DIRS:-/usr/local/share:/usr/share}; do
dirs+=($dir/bash-completion/completions)
done
_comp_unlocal IFS

local backslash=
if [[ $cmd == \\* ]]; then
Expand Down