Skip to content

Commit

Permalink
Load user completions from $BASH_COMPLETION_USER_DIR/completions
Browse files Browse the repository at this point in the history
Fall back to XDG_DATA_HOME/bash-completion/completions or
~/.local/share/bash-completion/completions if not set.

Thanks to Raphaël Droz.
  • Loading branch information
scop committed Feb 16, 2015
1 parent caaa474 commit 1d25d72
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1d25d72

Please sign in to comment.