diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-21 15:43:33 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-21 15:59:37 +1200 |
commit | 04d93adfe06bb12a63463dfc9a2d5734ed556c36 (patch) | |
tree | 7cdcfdf81dbcdcacd53d1854d35b74ae126162a3 /bash/bashrc | |
parent | Anticipate Bath versions > 4 (diff) | |
download | dotfiles-04d93adfe06bb12a63463dfc9a2d5734ed556c36.tar.gz dotfiles-04d93adfe06bb12a63463dfc9a2d5734ed556c36.zip |
Use dynamic completion if available
Diffstat (limited to 'bash/bashrc')
-rw-r--r-- | bash/bashrc | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/bash/bashrc b/bash/bashrc index a24a34fe..e7973562 100644 --- a/bash/bashrc +++ b/bash/bashrc @@ -108,9 +108,24 @@ fi # Load POSIX shell functions, Bash-specific scripts, and Bash completion files, # in that order -for sh in "$ENV" \ - "$HOME"/.bashrc.d/*.bash \ - "$HOME"/.bash_completion.d/*.bash ; do +for sh in "$ENV" "$HOME"/.bashrc.d/*.bash ; do [[ -e $sh ]] && source "$sh" done unset -v sh + +# If we have dynamic completion loading (Bash>=4.0), use it +if ((BASH_VERSINFO[0] >= 4)) ; then + _completion_loader() { + [[ -n $1 ]] || return + compspec=$HOME/.bash_completion.d/$1.bash + [[ -f $compspec ]] || return + source "$compspec" >/dev/null 2>&1 && return 124 + } + +# If not, load all of the completions up now +else + for sh in "$HOME"/.bash_completion.d/*.bash ; do + [[ -e $sh ]] && source "$sh" + done + unset -v sh +fi |