summaryrefslogtreecommitdiff
blob: 7775cc4e888a44efbb659cf9d04ce54edf3390bc (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Gentoo Linux Bash Shell Command Completion
#
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License, v2 or later

source "@helpersdir@/gentoo-common.sh"

#
# portageq completion
#

_portageq() {
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    opts="config_protect_mask \
      config_protect \
      vdb_path \
      gentoo_mirrors \
      all_best_visible \
      match \
      best_visible \
      mass_best_visible \
      has_version \
      portdir \
      envvar \
      mass_best_version \
      best_version \
      pkgdir \
      portdir_overlay \
      distdir"

    if [[ $COMP_CWORD -eq 1 ]] ; then
    # would always be correct, but it's pretty slow...
    #COMPREPLY=($(compgen -W "$(portageq | grep '^   [[:lower:]]' | \
    #    sed -e 's/^.*[[:space:]]\([[:lower:]_]\+\)[[:space:]].*$/\1/')" \
    #    -- ${cur}))
    COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
    fi

    case "${prev}" in
    config*|vdb_path|gentoo_mirrors|*dir*)
        COMPREPLY=()
        ;;

    # this also isn't the fastest, but I welcome an alternative method
    envvar)
        COMPREPLY=($(compgen -W "$(env -i PATH="${PATH}" emerge -v --info | \
                cut -s -d = -f 1)" -- ${cur}))
        ;;

    *v@(isible|ersion)|match)
        COMPREPLY=($(compgen $nospace -W '/' -- $cur))
        ;;

    # $prev is a path, so complete on category/package
    */*)
            local x a=0
            for x in ${COMP_WORDS[@]} ; do
                # This is the only one
                if [[ "${x}" == "all_best_visible" ]] ; then
                    a=1
                    break
                fi
            done

            if [[ ${a} -eq 1 ]] ; then
                COMPREPLY=()
            else
                # Check for conditional.
#                cond="${cur%%[A-Za-z0-9]*}"
#                cur="${cur:${#cond}}"

#                if [[ -n "${cond}" ]] ; then
#                    _pkgname -A $cur
#                else
                    _pkgname -A $cur
#                fi
            fi
        ;;
    esac
} &&
complete -F _portageq portageq

# vim: ft=sh:et:ts=4:sw=4:tw=80