aboutsummaryrefslogtreecommitdiff
path: root/_eix
blob: 07726ef04a2c8811bf127be3933f3e323f50260c (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#compdef eix

# options from eix --help
# eix 0.10.3 (gcc-4.2.2, x86_64-pc-linux-gnu)
#


# category of options
local   global_exclusives_opts  \
        global_special          \
        global_output           \
        local_misc              \
        local_search_field      \
        local_type_of_pattern

global_exclusives_opts=(
    {'(--help)-h','(-h)--help'}'[show help and exit]'
    {'(--version)-V','(-V)--version'}'[show version and exit]'
    '--dump[dump variables to stdout]'
    '--dump-defaults[dump default values of variables]'
    '--print[print the expanded value of a variable]'
    '--print-all-useflags[print all IUSE words used in some version]'
    '--print-all-keywords[print all KEYWORDS used in some version]'
    '--print-all-slots[print all SLOT strings used in some version]'
    '--print-all-provides[print all PROVIDE strings used in some package]'
    '--print-all-licenses[print all LICENSE strings used in some package]'
    '--print-world-sets[print the world sets]'
    '--print-overlay-path[print the path of specified overlay]'
    '--print-overlay-label[print label of specified overlay]'
)

global_special=(
    {'(--test-non-matching)-t','(-t)--test-non-matching'}'[print non-matching entries of /etc/portage/package.* and non-matching names of installed packages]'
    {'(--quick)-Q','(-Q)--quick'}"[(toggle) don't read unguessable slots of installed packages]"
    '--care[always read slots of installed packages]'
    '--cache-file[use another cache-file instead of /var/cache/eix]'
)

global_output=(
    {'(--quiet)-q','(-q)--quiet'}'[(toggle) (no) output]'
    {'(--nocolor)-n','(-n)--nocolor'}'[do not use ANSI color codes]'
    {'(--force-color)-F','(-F)--force-color'}'[force colorful output]'
    {'(--pure-packages)-\\*','(-\\*)--pure-packages'}'[Omit printing of overlay names and package number]'
    '--only-names[print with format <category>/<name>]'
    {'(--compact)-c','(-c)--compact'}'[(toggle) compact search results]'
    {'(--verbose)-v','(-v)--verbose'}'[(toggle) verbose search results]'
    {'(--versionsort)-x','(-x)--versionsort'}'[(toggle) sort output by slots/versions]'
    {'(--versionlines)-l','(-l)--versionlines'}'[(toggle) print available versions line-by-line]' \
    '--format[format string for normal output]'
    '--format-compact[format string for compact output]'
    '--format-verbose[format string for verbose outp]'
)

local_misc=(
    {'(--installed)-I','(-I)--installed'}'[Next expression only matches installed packages]'
    {'(--multi-installed)-i','(-i)--multi-installed'}'[Match packages installed in several versions]'
    {'(--dup-packages)-d','(-d)--dup-packages'}'[Match duplicated packages]'
    {'(--dup-versions)-D','(-D)--dup-versions'}'[Match packages with duplicated versions]'
    {'(--slotted)-1','(-1)--slotted'}'[Match packages with a nontrivial slot]'
    {'(--slots)-2','(-2)--slots'}'[Match packages with two different slots]'
    {'(--upgrade)-u','(-u)--upgrade'}'[Match packages without best slotted version]'
    '--stable[Match packages with a stable version]'
    '--testing[Match packages with a testing or stable version]'
    '--non-masked[Match packages with a non-masked version]'
    '--system[Match system packages]'
    '--installed-unstable[Match packages with a non-stable installed version]'
    '--installed-testing[Match packages with a testing installed version]'
    '--installed-masked[Match packages with a masked installed version]'
    '--world[Match world packages]'
    '--world-all[Match packages of world or of a world set]'
    '--world-set[Match packages of a world set]'
    {'(--overlay)-O','(-O)--overlay'}'[Match packages from overlays]'
    '--in-overlay[OVERLAY Match packages from OVERLAY]'
    '--only-in-overlay[OVERLAY Match packages only in OVERLAY]'
    {'(--installed-overlay)-J','(-J)--installed-overlay'}'[Match packages installed from overlays]'
    '--installed-from-overlay[OVERLAY Packages installed from OVERLAY]'
    '--installed-in-some-overlay[Packages with an installed version provided by some overlay]'
    '--installed-in-overlay[OVERLAY Packages with an installed version provided from OVERLAY]'
    '--restrict-fetch[Match packages with a fetch restriction]'
    '--restrict-mirror[Match packages with a mirror restriction]'
    '--restrict-primaryuri[Match packages with RESTRICT=primaryuri]'
    '--restrict-binchecks[Match packages with RESTRICT=binchecks]'
    '--restrict-strip[Match packages with RESTRICT=strip]'
    '--restrict-test[Match packages with RESTRICT=test]'
    '--restrict-userpriv[Match packages with RESTRICT=userpriv]'
    '--restrict-installsources[Match packages with RESTRICT=installsources]'
    '--restrict-bindist[Match packages with RESTRICT=bindist]'
    '--properties-interactive[Match packages with PROPERTIES=interactive]'
    '--properties-live[Match packages with PROPERTIES=live]'
    '--properties-virtual[ Match packages with PROPERTIES=virtual]'
    '--properties-set[Match packages with PROPERTIES=set]'
    {'(--test-obsolete)-T','(-T)--test-obsolete'}'[Match packages with obsolete entries in /etc/portage/package.*]'
    {'(--not)-!','(-!)--not'}'[(toggle) Invert the expression]'
    {'(--pipe)-\\|','(-\\|)--pipe'}'[Use input from pipe of emerge -pv]'
)

local_search_field=(
    {'(--description)-S','(-S)--description'}'[description]'
    {'(--category-name)-A','(-A)--category-name'}'["category/name"]'
    {'(--category)-C','(-C)--category'}'[category]'
    {'(--name)-s','(-s)--name'}'[name (default)]'
    {'(--homepage)-H','(-H)--homepage'}'[homepage]'
    {'(--license)-L','(-L)--license'}'[license]'
    {'(--provide)-P','(-P)--provide'}'[provides]'
    {'(--use)-U','(-U)--use'}'[useflag (of the ebuild)]'
    '--installed-with-use[enabled useflag (of installed package)]'
    '--installed-without-use[disabled useflag (of installed package)]'
)

local_type_of_pattern=(
    {'(--regex)-r','(-r)--regex'}'[Pattern is a regexp (default)]'
    {'(--exact)-e','(-e)--exact'}'[Pattern is the exact string]'
    {'(--substring)-z','(-z)--substring'}'[Pattern is a substring]'
    {'(--begin)-b','(-b)--begin'}'[Pattern is the beginning of the string]'
    '--end[Pattern is the end       of the string]'
    {'(--pattern)-p','(-p)--pattern'}'[Pattern is a wildcards-pattern]'
    {'(--fuzzy)-f','(-f)--fuzzy'}'[Use fuzzy-search with a max. levenshtein-distance m (default: 2)]'
)


local prev="$words[CURRENT-1]"  # previous word
local _gentoo_packages_scope    # used to restrict the package scope (installed,category,useflag...)

# global exclusiv opts, no more completion.
if (( $words[(I)(-[[:alnum:]]#(h|V)[[:alnum:]]#|--(help|version|dump|dump-defaults))] )); then
    return 0
# already have a --print ARG option. no more completion.
elif (( $words[(I)(--print)] )) && [[ "$prev" != '--print' ]]; then
    return 0
else
    case "$prev" in
# eix variables for --print
        '--print' )
        local vars
        vars=(${${(M)${(f)"$(eix --dump)"}##[A-Z]*}%%\=*})
        _values 'variables' $vars
        return 0
        ;;

# files for --cache-file
        '--cache-file' )
            _arguments -s '*:filename:_files'
            return 0
        ;;

# overlays for --only-in-overlay|--in-overlay|--installed-from-overlay|--installed-in-overlay
        --((only-|)in|installed-(from|in))-overlay )
            for f in /etc/make.conf /etc/make.globals; do
                [[ -z "$PORTDIR_OVERLAY" && -r "$f" ]] &&
	                local PORTDIR_OVERLAY="`. "$f" 2>/dev/null; echo ${PORTDIR_OVERLAY}`"
            done

            _values 'overlays' $=PORTDIR_OVERLAY
            return 0
        ;;

# useflags for -U|--use|--installed-with-use|--installed-without-use
        (-[[:alnum:]]#U|--(use|installed-with(out|)-use)) )
            _gentoo_packages_scope='*:package:_gentoo_packages useflag'
        ;;

# category for -C|--category
        -([[:alnum:]]#C|-category) )
            _gentoo_packages_scope='*:package:_gentoo_packages category'
        ;;

        * )
            #if (( $words[(I)(-[[:alnum:]]#2[[:alnum:]]#|--slots)] )); then
            #    local pkgs
            #    pkgs=(${${(f)"$(eix -2 --only-names)"}##*/})
            #    _values 'packages' $pkgs && return 0

        # installed packages for -i|--installed|-I|--multi-installed|-T|--test-obsolete
            if (( $words[(I)(-[[:alnum:]]#(i|I|T)[[:alnum:]]#|--(((multi-|)installed)|test-obsolete))] )); then
                _gentoo_packages_scope='*:package:_gentoo_packages installed'
        # only packages names (no category) for -s|--name
            elif (( $words[(I)(-[[:alnum:]]#s[[:alnum:]]#|--name)] )); then
                _gentoo_packages_scope='*:package:_gentoo_packages available_pkgnames_only'
            else # default
                _gentoo_packages_scope='*:package:_gentoo_packages available'
            fi
        ;;
    esac
fi

_arguments -s   $global_exclusives_opts     \
                $global_special             \
                $global_output              \
                $local_misc                 \
                $local_search_field         \
                $local_type_of_pattern      \
                $_gentoo_packages_scope     &&
    return 0