Load user completions from $BASH_COMPLETION_USER_DIR/completions

Fall back to XDG_DATA_HOME/bash-completion/completions or
~/.local/share/bash-completion/completions if not set.

Thanks to Raphaël Droz.
master
Ville Skyttä 2015-02-16 22:14:58 +02:00
parent caaa4745e4
commit 1d25d72ca8
1 changed files with 7 additions and 5 deletions

View File

@ -1960,13 +1960,15 @@ complete -F _minimal ''
_completion_loader()
{
# $1=_EmptycmD_ already for empty cmds in bash 4.3, set to it for earlier
local cmd="${1:-_EmptycmD_}" compdir=./completions compfile
local cmd="${1:-_EmptycmD_}" compdir=./completions compfile dir
[[ $BASH_SOURCE == */* ]] && compdir="${BASH_SOURCE%/*}/completions"
for compfile in "${cmd##*/}" "${cmd##*/}".bash _"${cmd##*/}"; do
compfile="$compdir/$compfile"
# Avoid trying to source dirs; https://bugzilla.redhat.com/903540
[[ -f "$compfile" ]] && . "$compfile" &>/dev/null && return 124
for dir in ${BASH_COMPLETION_USER_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion}/completions $compdir; do
for compfile in "${cmd##*/}" "${cmd##*/}".bash _"${cmd##*/}"; do
compfile="$dir/$compfile"
# Avoid trying to source dirs; https://bugzilla.redhat.com/903540
[[ -f "$compfile" ]] && . "$compfile" &>/dev/null && return 124
done
done
# Need to define *something*, otherwise there will be no completion at all.