aboutsummaryrefslogtreecommitdiff
blob: 95811c89c2a1129a439477d6ce96b72fec5a9d5f (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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#compdef qatom qcache qcheck qdepends qfile qgrep qlist qlop qpkg qsearch qsize qtbz2 quse qxpak

# portage-utils-0.53

_portdir() {
  local mainreponame mainrepopath overlayname overlaypath

  if [[ -e /usr/share/portage/config/repos.conf ]]; then
    if [[ ${1} == "-o" ]]; then
      for overlayname in $(_parsereposconf -l); do
          overlaypath+=($(_parsereposconf ${overlayname} location))
      done

      source /etc/make.conf 2>/dev/null
      source /etc/portage/make.conf 2>/dev/null

      overlaypath+=(${(@)PORTDIR_OVERLAY})

      echo "${(@u)overlaypath}"
    else
      mainreponame=$(_parsereposconf DEFAULT main-repo)
      mainrepopath=$(_parsereposconf ${mainreponame} location)

      echo "${mainrepopath}"
    fi
  else
    source /usr/share/portage/config/make.globals 2>/dev/null
    source /etc/make.conf 2>/dev/null
    source /etc/portage/make.conf 2>/dev/null

    if [[ ${1} == "-o" ]]; then
      echo "${(@u)PORTDIR_OVERLAY}"
    else
      echo "${PORTDIR}"
    fi
  fi
}

_parsereposconf() {
  local v f insection section arr

  for f in /usr/share/portage/config/repos.conf \
    /etc/portage/repos.conf \
    /etc/portage/repos.conf/*.conf; do

    [[ -f ${f} ]] || continue
    insection=0
    declare -A arr
    IFS='= '

    while read -r name value; do
      [[ -z ${name} || ${name} == '#'* ]] && continue

      if [[ (${name} == '['*']') && (-z ${value}) ]]; then
        value=${name//(\]|\[)}
        name="section"
      fi
      arr[${name}]=${value}

      if [[ ${insection} == 1 && ${name} == "section" ]]; then
        break
      elif [[ ${name} == "section" ]]; then
        [[ ${value} == ${1} ]] && insection=1
        secname+=(${value})
      elif [[ ${insection} == 1 ]]; then
        if [[ ${name} == ${2} ]]; then
          v=${value}
        fi
      fi
      continue
    done < ${f}
  done

  if [[ ${1} == "-l" ]]; then
    echo "${(@)secname}"
  else
    echo "${v}"
  fi
}

local common_args PORTDIR

PORTDIR="$(_portdir)"

common_args=(
  '--root[Set the ROOT env var]:root directory:_files -/' \
  {'(--verbose)-v','(-v)--verbose'}'[Make a lot of noise]' \
  {'(--quiet)-q','(-q)--quiet'}'[Tighter output; suppress warnings]' \
  {'(--nocolor)-C','(-C)--nocolor'}'[Do not output color]' \
  {'(--help)-h','(-h)--help'}'[Print this help and exit]' \
  {'(--version)-V','(-V)--version'}'[Print version and exit]' \
)

case $service in
  qatom)
    _arguments -s $common_args \
      {'(--compare)-c','(-c)--compare'}'[Compare two atoms]'
    ;;
  qcache)
    local arch
    local -a arches allarches

    show_archs(){
      arches=(${(f)"$(<$PORTDIR/profiles/arch.list)"})
      for arch in $arches; do
        [[ $arch =~ '^[^#]' ]] && allarches+=( $arch )
      done
      _describe -t available-arches "arch" allarches
    }

    _arguments -s $common_args \
      {'(--matchpkg)-p','(-p)--matchpkg'}'[match pkgname]:package name:_gentoo_packages available_pkgnames_only' \
      {'(--matchcat)-c','(-c)--matchcat'}'[match catname]:category:_gentoo_packages category' \
      {'(--imlate)-i','(-i)--imlate'}'[list packages that can be marked stable on a given arch]' \
      {'(--dropped)-d','(-d)--dropped'}'[list packages that have dropped keywords on a version bump on a given arch]' \
      {'(--testing)-t','(-t)--testing'}'[list packages that have ~arch versions, but no stable versions on a given arch]' \
      {'(--stats)-s','(-s)--stats'}'[display statistics about the portage tree]' \
      {'(--all)-a','(-a)--all'}'[list packages that have at least one version keyworded for on a given arch]' \
      {'(--not)-n','(-n)--not'}"[list packages that aren't keyworded on a given arch]" \
      '*:arch:show_archs'
    ;;
  qcheck)
    _arguments -s $common_args \
      {'(--all)-a','(-a)--all'}'[List all packages]' \
      {'(--exact)-e','(-e)--exact'}'[Exact match (only CAT/PN or PN without PV)]' \
      {'(--skip)-s','(-s)--skip'}'[Ignore files matching regular expression]:regex' \
      {'(--update)-u','(-u)--update'}'[Update missing files, chksum and mtimes for packages]' \
      {'(--noafk)-A','(-A)--noafk'}'[Ignore missing files]' \
      {'(--badonly)-B','(-B)--badonly'}'[Only print pkgs containing bad files]' \
      {'(--nohash)-H','(-H)--nohash'}'[Ignore differing/unknown file chksums]' \
      {'(--nomtime)-T','(-T)--nomtime'}'[Ignore differing file mtimes]' \
      '--skip-protected[Ignore files in CONFIG_PROTECT-ed paths]' \
      {'(--prelink)-p','(-p)--prelink'}'[Undo prelink when calculating checksums]' \
      '*:packages:_gentoo_packages installed'
    ;;
  qdepends)
    _arguments -s $common_args \
      {'(--depend)-d','(-d)--depend'}'[Show DEPEND info (default)]' \
      {'(--rdepend)-r','(-r)--rdepend'}'[Show RDEPEND info]' \
      {'(--pdepend)-p','(-p)--pdepend'}'[Show PDEPEND info]' \
      {'(--key)-k','(-k)--key'}'[User defined vdb key]:vdb key' \
      {'(--query)-Q','(-Q)--query'}'[Query reverse deps]' \
      {'(--name-only)-N','(-N)--name-only'}'[Only show package name]' \
      {'(--all)-a','(-a)--all'}'[Show all DEPEND info]' \
      {'(--format)-f','(-f)--format'}'[Pretty format specified depend strings]' \
      '*:packages:_gentoo_packages installed'
    ;;
  qfile)
    _arguments -s $common_args \
      {'(--slots)-S','(-S)--slots'}'[Display installed packages with slots]' \
      {'(--root-prefix)-R','(-R)--root-prefix'}'[Assume arguments are already prefixed by $ROOT]' \
      {'(--from)-f','(-f)--from'}'[Read arguments from file <arg> ("-" for stdin)]' \
      {'(--max-args)-m','(-m)--max-args'}'[Treat from file arguments by groups of <arg> (defaults to 5000)]:number' \
      {'(--basename)-b','(-b)--basename'}'[Match any component of the path]' \
      {'(--orphans)-o','(-o)--orphans'}'[List orphan files]' \
      {'(--exclude)-x','(-x)--exclude'}"[Don't look in package <arg> (used with --orphans)]:package:_gentoo_packages installed" \
      {'(--exact)-e','(-e)--exact'}'[Exact match (used with --exclude)]' \
      '*:filename:_files'
    ;;
  qgrep)
    _arguments -s $common_args \
      {'(--invert-match)-I','(-I)--invert-match'}'[Select non-matching lines]' \
      {'(--ignore-case)-i','(-i)--ignore-case'}'[Ignore case distinctions]' \
      {'(--with-filename)-H','(-H)--with-filename'}'[Print the filename for each match]' \
      {'(--with-name)-N','(-N)--with-name'}'[Print the package or eclass name for each match]' \
      {'(--count)-c','(-c)--count'}'[Only print a count of matching lines per FILE]' \
      {'(--list)-l','(-l)--list'}'[Only print FILE names containing matches]' \
      {'(--invert-list)-L','(-L)--invert-list'}'[Only print FILE names containing no match]' \
      {'(--regexp)-e','(-e)--regexp'}'[Use PATTERN as a regular expression]' \
      {'(--extended)-x','(-x)--extended'}'[Use PATTERN as an extended regular expression]' \
      {'(--installed)-J','(-J)--installed'}'[Search in installed ebuilds instead of the tree]' \
      {'(--eclass)-E','(-E)--eclass'}'[Search in eclasses instead of ebuilds]' \
      {'(--skip-comments)-s','(-s)--skip-comments'}'[Skip comments lines]' \
      {'(--skip)-S','(-S)--skip'}'[Skip lines matching <arg>]:pattern' \
      {'(--before)-B','(-B)--before'}'[Print <arg> lines of leading context]:number' \
      {'(--after)-A','(-A)--after'}'[Print <arg> lines of trailing context]:number' \
      '*:pattern::'
    ;;
  qlist)
    _arguments -s $common_args \
      {'(--installed)-I','(-I)--installed'}'[Just show installed packages]' \
      {'(--slots)-S','(-S)--slots'}'[Display installed packages with slots]' \
      {'(--repo)-R','(-R)--repo'}'[Display installed packages with repository]' \
      {'(--umap)-U','(-U)--umap'}'[Display installed packages with flags used]' \
      {'(--columns)-c','(-c)--columns'}'[Display column view]' \
      '--show-debug[Show /usr/lib/debug files]' \
      {'(--exact)-e','(-e)--exact'}'[Exact match (only CAT/PN or PN without PV)]' \
      {'(--all)-a','(-a)--all'}'[Show every installed package]' \
      {'(--dir)-d','(-d)--dir'}'[Only show directories]' \
      {'(--obj)-o','(-o)--obj'}'[Only show objects]' \
      {'(--sym)-s','(-s)--sym'}'[Only show symlinks]' \
      '*:packages:_gentoo_packages installed'
    ;;
  qlop)
    _arguments -s $common_args \
      {'(--gauge)-g','(-g)--gauge'}'[Gauge number of times a package has been merged]' \
      {'(--time)-t','(-t)--time'}'[Calculate merge time for a specific package]' \
      {'(--human)-H','(-H)--human'}'[Print seconds in human readable format (needs -t)]' \
      {'(--list)-l','(-l)--list'}'[Show merge history]' \
      {'(--unlist)-u','(-u)--unlist'}'[Show unmerge history]' \
      {'(--sync)-s','(-s)--sync'}'[Show sync history]' \
      {'(--current)-c','(-c)--current'}'[Show current emerging packages]' \
      {'(--logfile)-f','(-f)--logfile'}'[Read emerge logfile instead of /var/log/emerge.log]:log:_files' \
      '*:packages:_gentoo_packages available'
    ;;
  qsearch)
    _arguments -s $common_args \
      {'(--all)-a','(-a)--all'}'[List the descriptions of every package in the cache]' \
      {'(--cache)-c','(-c)--cache'}'[Use the portage cache]' \
      {'(--ebuilds)-e','(-e)--ebuilds'}'[Use the portage ebuild tree]' \
      {'(--search)-s','(-s)--search'}'[Regex search package basenames]' \
      {'(--desc)-S','(-S)--desc'}'[Regex search package descriptions]' \
      {'(--name-only)-N','(-N)--name-only'}'[Only show package name]' \
      {'(--homepage)-H','(-H)--homepage'}'[Show homepage info]' \
      '*:pattern::'
    ;;
  qsize)
    _arguments -s $common_args \
      {'(--filesystem)-f','(-f)--filesystem'}'[Show size used on disk]' \
      {'(--all)-a','(-a)--all'}'[Size all installed packages]' \
      {'(--sum)-s','(-s)--sum'}'[Include a summary]' \
      {'(--sum-only)-S','(-S)--sum-only'}'[Show just the summary]' \
      {'(--megabytes)-m','(-m)--megabytes'}'[Display size in megabytes]' \
      {'(--kilobytes)-k','(-k)--kilobytes'}'[Display size in kilobytes]' \
      {'(--bytes)-b','(-b)--bytes'}'[Display size in bytes]' \
      {'(--ignore)-i','(-i)--ignore'}'[Ignore regexp string]:pattern' \
      '*:packages:_gentoo_packages installed'
    ;;
  quse)
    _arguments -s $common_args \
      {'(--exact)-e','(-e)--exact'}'[Show exact non regexp matching using strcmp]' \
      {'(--all)-a','(-a)--all'}'[Show annoying things in IUSE]' \
      {'(--keywords)-K','(-K)--keywords'}'[Use the KEYWORDS vs IUSE]' \
      {'(--license)-L','(-L)--license'}'[Use the LICENSE vs IUSE]' \
      {'(--describe)-D','(-D)--describe'}'[Describe the USE flag]' \
      {'(--format)-F','(-F)--format'}'[Use your own variable formats: -F NAME=]:format' \
      {'(--name-only)-N','(-N)--name-only'}'[Only show package name]' \
      '*:use flag:_gentoo_packages useflag'
    ;;
  qtbz2)
    _arguments -s $common_args \
      {'(--dir)-d','(-d)--dir'}'[Change to specified directory]:directory:_files -/' \
      {'(--join)-j','(-j)--join'}'[Join tar.bz2 + xpak into a tbz2]:*:tar.bz2 file and xpak file:_files -g \*.\(tar.bz2\|xpak\)' \
      {'(--split)-s','(-s)--split'}'[Split a tbz2 into a tar.bz2 + xpak]:tbz2 file:_files -g \*.tbz2' \
      {'(--tarbz2)-t','(-t)--tarbz2'}'[Just split the tar.bz2]:tbz2 file:_files -g \*.tbz2' \
      {'(--xpak)-x','(-x)--xpak'}'[Just split the xpak]:tbz2 file:_files -g \*.tbz2' \
      {'(--stdout)-O','(-O)--stdout'}'[Write files to stdout]'
    ;;
  qpkg)
    _arguments -s $common_args \
      {'(--clean)-c','(-c)--clean'}'[clean pkgdir of unused binary files]' \
      {'(--eclean)-E','(-E)--eclean'}'[clean pkgdir of files not in the tree anymore (slow)]' \
      {'(--pretend)-p','(-p)--pretend'}'[pretend only]' \
      {'(--pkgdir)-P','(-P)--pkgdir'}'[alternate package directory]:alternate pkgdir:_files -/' \
      '*:Installed packages:_gentoo_packages installed_versions'
    ;;
  qxpak)
    _arguments -s $common_args \
      {'(--list)-l','(-l)--list'}'[List the contents of an archive]:xpak archive:_files -g \*.xpak' \
      {'(--extract)-x','(-x)--extract'}'[Extract the contents of an archive]:xpak archive:_files -g \*.xpak' \
      {'(--create)-c','(-c)--create'}'[Create an archive of a directory/files]:*:archive name and files to archive:_files' \
      {'(--dir)-d','(-d)--dir'}'[Change to specified directory]:directory:_files -/' \
      {'(--stdout)-O','(-O)--stdout'}'[Write files to stdout]'
    ;;
esac

# vim: set et sw=2 sts=2 ts=2 ft=zsh: