summaryrefslogtreecommitdiff
blob: b72bcbd93379771873660efc6189e888ac281d24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License, v2 or later
# $Id$

# Check for interactive bash and that we haven't already been sourced.
[ -z "$BASH_VERSION" -o -z "$PS1" -o -n "$BASH_COMPLETION" ] && return

# Check for recent enough version of bash.
bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.}
if [ $bmajor -gt 3 ] || [ $bmajor -eq 3 -a $bminor -ge 2 ]; then
    _load_completions() {
    declare f x loaded_pre=false
    for f; do
        if [[ -f $f ]]; then
        # Prevent loading base twice, initially and via glob
        if $loaded_pre && [[ $f == */base ]]; then
            continue
        fi

        # Some modules, including base, depend on the definitions
        # in .pre.  See the ebuild for how this is created.
        if ! $loaded_pre; then
            if [[ ${BASH_COMPLETION-unset} == unset ]]; then
            BASH_COMPLETION="@GENTOO_PORTAGE_EPREFIX@/usr/share/bash-completion/base"
            fi
            source "@GENTOO_PORTAGE_EPREFIX@/usr/share/bash-completion/.pre"
            loaded_pre=true
        fi

        source "$f"
        fi
    done

    # Clean up
    $loaded_pre && source "@GENTOO_PORTAGE_EPREFIX@/usr/share/bash-completion/.post"
    unset -f _load_completions  # not designed to be called more than once
    }

    # 1. Load base, if eselected.  This was previously known as
    #    /etc/bash_completion
    # 2. Load completion modules, maintained via eselect bashcomp --global
    # 3. Load user completion modules, maintained via eselect bashcomp
    # 4. Load user completion file last, overrides modules at user discretion
	# This order is subject to change once upstream decides on something.
    _load_completions \
    "@GENTOO_PORTAGE_EPREFIX@/etc/bash_completion.d/base" \
    ~/.bash_completion.d/base \
    "@GENTOO_PORTAGE_EPREFIX@/etc/bash_completion.d/"* \
    ~/.bash_completion.d/* \
    ~/.bash_completion
fi
unset bash bmajor bminor