lib, perl: formatting changes
[aurutils.git] / completions / zsh / _aur
blobcc5642105355582591a5f5f3e9e876c0f226c797
1 #compdef aur
4 # AUR supports third party extension of subcommands. This completion does too:
6 # In order to define completion for an aur subcommand "aur-mycmd" you need to
7 # create a file _aur-mycmd:
8 # * The first line should be: #compdef aur-mycmd
9 # * The second line should be: #description Description of Mycmd goes here
11 # Then the normal completion function follows, using _arguments or whatever you
12 # prefer.
14 # This completion mechanism was taken from the _git completion bundled with zsh.
17 # Helper to list valid repo-add attributes
18 __aur_list_attributes() {
19     declare -a attrs
20     attrs=("${(@f)$(aur repo --list-attr 2>/dev/null)}")
21     if [[ ${#attrs} -eq 0 ]]; then
22         _message "attr (no attributes found)"
23     else
24         _values attr $attrs
25     fi
28 # Helper to call out to makepkg/makechrootpkg completion
29 __aur_complete_for()
31     service=$1 $_comps[$1]
34 declare -ga _aur_build_sync_args
35 # Flags that are used by both aur-build and aur-sync
36 # Prevents having to duplicate them in both places
37 _aur_build_sync_args=(
38     + options
39     # Build args
40     '*'{--margs=,--makepkg-args=}'[additional (comma separated) makepkg arguments]:arguments:_sequence __aur_complete_for
41  makepkg'
42     '--makepkg-conf=[the makepkg.conf to use for makepkg, for chroot also inside the container]:configuration file: _files'
43     '(-A --ignore-arch)'{-A,--ignore-arch}'[ignore a missing or incomplete arch field in the build script]'
44     '(-c --chroot)'{-c,--chroot}'[build packages inside a systemd-nspawn container with archbuild]'
45     '(-D --directory)'{-D,--directory=}'[the base directory for containers]:directory: _files -/'
46     '(-f --force)'{-f,--force}'[continue the build process if a package with the same name is found]'
47     '(-L --log)'{-L,--log}'[enable logging to a text file in the build directory]'
48     '(-n --no-confirm)'{-n,--no-confirm}'[do not wait for user input when installing or removing build dependencies]'
49     '(-r --rmdeps)'{-r,--rmdeps}'[remove dependencies installed by makepkg]'
50     '(-S --sign --gpg-sign)'{-S,--sign,--gpg-sign}'[sign build packages and the database with gpg]'
51     '(-T --temp)'{-T,--temp}'[build in a temporary container]'
52     '(-U --user)'{-U,--user=}'[run the host makepkg instance as the specified user]:user: _users'
53     '*--bind-rw=[bind a directory read-write to the container]:directory: _files -/'
54     '*--bind=[bind a directory read-only to the container]:directory: _files -/'
56     # repo-add
57     '--new[only add packages that are not already in the database]'
58     '--prevent-downgrade[do not add packages to the database if a newer version is already present]'
59     '(-R --remove)'{-R,--remove}'[remove old package files from disk when updating their entry in the database]'
60     '(-v --verify)'{-v,--verify}'[verify the pgp signature of the database before updating]'
62     # Repo args
63     '--pacman-conf=[the pacman.conf used for syncing and retriving local repositories, for chroot also used inside the container]:configuration file: _files'
64     '--root=[the root directory for the repository]:directory: _files -/'
65     '(-d --database)'{-d,--database=}'[the name of the pacman database]:repository: _aur_repositories'
68 _aur-build() {
69     local -a args
71     args=(
72         # Note! Many flags are shared with aur-build and defined in a common $_aur_build_sync_args
74         # Options
75         '(-a --arg-file)'{-a,--arg-file=}'[a text file describing directories containing PKGBUILD relative to the current directory]:file: _files'
76         '--dry-run[display the package names without building anything]'
77         '--no-sync[do not sync the local repository after building]'
78         '--pkgver[run makepkg -od before checking existing packages]'
80         # Makechrootpkg options
81         '(-N --namcap)'{-N,--namcap}'[run namcap on the build package]'
82         '--checkpkg[run checkpkg on the build package]'
84         # makepkg options
85         '--no-check[do not run the check function in the PKGBUILD]'
86         '(-s --syncdeps)'{-s,--syncdeps}'[install missing dependencies using pacman]'
87         '(-C --clean)'{-C,--clean}'[clean up leftover work files and directories after a successful build]'
88         '--buildscript[read the package script instead of the PKGBUILD]:: _files'
89     )
90     _arguments -s $args $_aur_build_sync_args
93 _aur-chroot() {
94     local -a args
96     args=(
97         # Operations
98         '(-B --build)'{-B,--build}'[build a package inside the container with makechrootpkg]'
99         '(-U --update)'{-U,--update}'[update or create the /root copy of the container with arch-nspawn]'
100         '--create[create a new container with mkarchroot]'
102         # Other options
103         '*--bind-rw=[bind a directory read-write to the container]:directory: _files -/'
104         '*--bind=[bind a directory read-only to the container]:directory: _files -/'
105         '(-D --directory)'{-D,--directory=}'[the base directory for containers]:directory: _files -/'
106         '*'{--makechrootpkg-args=,--cargs=}'[additional (comma separated) arguments to be passed to makechrootpkg for --build]:arguments:_sequence __aur_complete_for
107      makechrootpkg'
108         '*'{--makepkg-args=,--margs=}'[additional (comma separated) makepkg arguments for makechrootpkg]:arguments:_sequence __aur_complete_for
109      makepkg'
110         '(-M --makepkg-conf)'{-M,--makepkg-conf=}'[the makepkg.conf to use inside the container]:configuration file: _files'
111         '--path[print the path to the container template]'
112         
113         + '(pacman_conf)'
114         {-C,--pacman-conf=}'[the pacman.conf to use inside the container]:configuration file: _files'
115         {-x,--suffix=}'[the path component SUFFIX in the pacman configuration, default to extra]:suffix: '
117         + positional
118         '*:pkgname: _aur_packages'
119     )
120     _arguments -s -S $args
123 _aur-depends() {
124     local -a args
126     args=(
127         # Dependency options
128         '--no-checkdepends[do not consider checkdepends when resolving dependencies]'
129         '--no-depends[do not consider depends when resolving dependencies]'
130         '--no-makedepends[do not consider makedepends when resolving dependencies]'
131         '--optdepends[consider optdepends when resolving dependencies]'
133         + '(mode)'
134         {-G,--graph}'[print dependency information (AUR-only) to stdout as edges]'
135         {-b,--pkgbase}'[print dependency information (AUR-only) to stdout as pkgbase, in total order]'
136         {-n,--pkgname}'[print dependency information (AUR-only) to stdout as pkgname, in total order]'
137         {-a,--pkgname-all}'[print dependency information to stdout as pkgname in total order]'
138         {-t,--table}'[output dependency information as a tab separated table]'
140         + positional
141         '*:pkgname: _aur_packages'
142     )
143     _arguments -s $args
146 _aur-fetch() {
147     local -a args
148     local -A sync_types
150     sync_types[reset]="discard local changes"
151     sync_types[merge]="run git-merge to incorporate upstream changes"
152     sync_types[rebase]="run git-rebase to incorporate upstream changes"
153     sync_types[fetch]="only run git-fetch"
155     local -a sync_type_strings=()
156     local k
157     for k in ${(k)sync_types}; do
158         sync_type_strings+=( "${k}\\:${sync_types[${k}]// /\\ }" )
159     done
161     args=(
162         '--existing[if a package has no matching repository on AUR, ignore it instead of running git-clone]'
163         '(-r --recurse)'{-r,--recurse}'[download packages and their dependencies with aur-depends]'
164         '--results=[write colon-delimited output to FILE]:file: _files'
165         '--discard[discard uncommited changes if git-rebase or git-merge result in new commits]'
166         "(--sync)--rebase[${sync_types[rebase]}, alias for --sync=rebase]"
167         "(--sync)--reset[${sync_types[reset]}, alias for --sync=reset]"
168         "(--sync)--fetch-only[${sync_types[fetch]}, alias for --sync=fetch]"
169     )
170     # This is to handle the fact that -r/--recurse changes the meaning of positional arguments
171     if [[ $words[(ie)-r] -le ${#words} || $words[(ie)--recurse] -le ${#words} ]]; then
172         _arguments -s $args '*:pkgname: _aur_packages'
173     else
174         _arguments -s $args '*:pkgbase: _aur_packages -b'
175     fi
180 _aur-graph() {
181     local -a args
183     args=(
184         '*:files: _files -g .SRCINFO'
185     )
186     _arguments -s $args
189 _aur-pkglist() {
190     local -a args
192     args=(
193         + '(source)'
194         {-b,--pkgbase}'[retrieve pkgbase.gz instead of packages.gz]'
195         '--users[retrieve users.gz instead of packages.gz]'
196         {-i,--info}'[retrieve AUR metadata from search-type requests]'
197         {-s,--search}'[retrieve AUR metadata from info-type requests]'
199         + '(mode)'
200         {-F,--fixed-strings}'[interpret the given pattern as a list of fixed strings separated by newline]'
201         {-P,--perl-regexp}'[interpret the given pattern as a Perl compatible regular expression]'
202         '--plain[print the package list to standard output (default)]'
203         {-J,--json}'[interpret the given pattern as a jq pattern (default for --search and --info)]'
204         {-q,--quiet}'[update the package list and print its path to standard output]'
206         + options
207         '(-t --ttl)'{-t,--ttl}'[set the delay in seconds before a new list is retrived (defaullt 300)]:delay in seconds: '
208         '(-v --verify)'{-v,--verify}'[verify checksums of the compressed list with sha256sum]'
209     )
210     _arguments -s $args
213 _aur-query() {
214     local -a args
216     args=(
217         '(-b --by)'{-b,--by=}'[argument for package search (--type=search)]:by:(name name-desc maintainer depends makedepends optdepends checkdepends)'
218         '(-r --raw)'{-r,--raw}'[do not process results (implied by --type=info)]'
219         '(-t --type)'{-t,--type=}'[type of request]:type:(search info)'
220         '*:pkgname: _aur_packages'
221     )
222     _arguments -s $args
225 _aur-repo() {
226     local -a args
228     args=(
229         + '(operations)'
230         '(upgrade)'{-F,--attr=}'[list the attribute ATTR]:attr: __aur_list_attributes'
231         '(upgrade)'{-l,--list}'[list the contents of a local repository]'
232         '(upgrade)'{-t,--table}'[list the contents of a local repository with more detail]'
233         '(upgrade)'{-J,--json}'[list the local repository in JSON format]'
234         '(upgrade)'{-f,--format=}'[format output according to key]:key:(%a %b %c %C %d %D %e %f %F %g %M %n %O %P %U %v)'
235         '(upgrade)--list-path[list the paths of configured local repositories]'
236         '(upgrade)--list-repo[list the names of configured local repositories]'
237         '(upgrade)--list-attr[list valid attributes for repositories generated by repo-add]'
238         '(upgrade)--path[list the resolved path of the selected pacman repository]'
240         + upgrade
241         '(operations -u --upgrades)'{-u,--upgrades}'[check package update with aur-vercmp]'
242         '(operations -a --all)'{-a,--all}'[use aur-vercmp --all when checking for upgrades, implies --upgrades]'
244         + options
245         '--status[print status information to standard output]'
246         '(-c --config)'{-c,--config=}'[set an alternate pacman.conf file path]:config file: _files'
247         '(-d --database --repo)'{-d,--database=,--repo=}'[the name of a pacman repository]:repository: _aur_repositories --all'
248         '(-q --quiet)'{-q,--quiet}'[only print package names]'
249         '(-r --root)'{-r,--root=}'[the path to the root of a local repository]:path: _files -/'
250         '(-S --sync)'{-S,--sync}'[query repositories in DBPATH/sync]'
251     )
252     _arguments -s $args
255 _aur-repo-filter() {
256     local -a args
258     args=(
259         '(-a --all --sync)'{-a,--all,--sync}'[query all available pacman repositories (pacsift --sync)]'
260         '--config=[set an alternate pacman.conf file path]:config file: _files'
261         '(-d --database)'{-d,--database=}'[restrict output to pacman repository]:repository: _aur_repositories --all'
262         '--sysroot[set an alternative system root]:path: _files -/'
263     )
264     _arguments -s $args
267 _aur-search() {
268     local -a args
270     # Groups (+ name) are used to simplify handling of options being exclusive
271     # Groups with () in the name are auto-exlusive with themselves
272     args=(
273         + '(type)'
274         {-i,--info}'[Use the info interface]'
275         {-s,--search}'[Use the searchby interface (default)]'
277         + '(format)'
278         # %a (Arch) is a valid AUR field, but only contained in .SRCINFO which
279         # is not retrieved by aur-search. Leave it out.
280         '(-f --format)'{-f,--format=}'[format output according to key]:key:(%b %c %C %d %D %e %g %K %L %m %M %n %o %O %p %P %S %U %v %w)'
281         {-q,--short}'[only display package name, version and description]'
282         {-v,--verbose}'[display more package information]'
283         '--table[display output in tsv format]'
285         + options
286         '(-a --any)'{-a,--any}'[show the union of results instead of the intersection]'
287         '(-r --json)'{-r,--json}'[display results as json]'
288         '(-k --key)'{-k,--key=}'[sort results via key]:key:(Name Version NumVotes Description PackageBase URL Popularity OutOfDate Maintainer FirstSubmitted LastModified)'
290         + '(search_by)'
291         {-d,--desc}'[search by package name and description]'
292         {-m,--maintainer}'[search by maintainer]'
293         {-n,--name}'[search by package name]'
294         '--depends[search for packages with keywords in depends]'
295         '--makedepends[search for packages with keywords in makedepends]'
296         '--optdepends[search for packages with keywords in optdepends]'
297         '--checkdepends[search for packages with keywords in checkdepends]'
299         + positional
300     )
301     # Determine if this is an info search by checking if the index of -i or --info in the words
302     # array is less than the length of the array.
303     if [[ $words[(ie)-i] -le ${#words} || $words[(ie)--info] -le ${#words} ]]; then
304         _arguments -s $args '*:search term: _aur_packages'
305     else
306         _arguments -s $args '*:search term: '
307     fi
310 _aur-srcver() {
311     local -a args
313     args=(
314         '--buildscript[read the package script instead of the PKGBUILD]:: _files'
315         {-j,--jobs=}'[set the amount of makepkg processes run in parallel]:number of jobs: '
316         '--no-prepare[do not run the prepare() function in the PKGBUILD]'
317         '*:pkgbase: _aur_packages --pkgbase'
318     )
319     _arguments -s $args
322 _aur-sync() {
323     local -a args
325     # Groups (+ name) are used to simplify handling of options being exclusive
326     args=(
327         # Note! Many flags are shared with aur-build and defined in a common $_aur_build_sync_args
328         
329         '--continue[do not download package files]'
330         '--format=[generate diffs with git-diff or git-log]:format:((diff\:use\ git-diff log\:use\ git-log))'
331         '--ignore-file=[ignore package upgrades listed in FILE]:file: _files'
332         '--no-check[do not handle checkdepends]'
333         '--no-graph[do not verify the AUR dependency graph with aur-graph]'
334         '--no-view[do not present build files for inspection]'
335         '--pkgver[run makepkg -od --noprepare before the build process]'
336         '(--no-provides)--provides-from=:directories: _dir_list -s, -S'
337         '(--provides-from)--no-provides[do not take virtual dependencies (provides) in pacman sync repositories into account to resolve package dependencies]'
338         '(-o --no-build)'{-o,--no-build}'[print target packages and their paths instead of building them]'
339         '(-u --upgrades)'{-u,--upgrades}'[update all obsolete AUR packages in a local repository]'
340         '*--ignore=:package: _aur_local_packages'
342         # These overwrite each other and are thus mutually exlusive
343         + '(no_ver)'
344         '--no-ver[disable version checking for packages]'
345         '--no-ver-argv[disable version checking for packages specified on the command line or upgrade candidates from --upgrades]'
346         '--rebuild[alias for -f --nover-argv]'
347         '--rebuild-all[alias for -f --nover]'
348         '--rebuild-tree[as --rebuild-tree, but append all packages in the repository (see -d) as targets]'
350        + positional
351         '*:packages: _aur_packages'
352     )
353     _arguments -s $args $_aur_build_sync_args
356 _aur-vercmp() {
357     local -a args
359     args=(
360         '(-a --all -c --current)'{-a,--all}'[show packages with an older or equal version in the AUR]'
361         '(-c --current -a --all)'{-c,--current}'[changes format to print packages with an equal or newer version to stdout]'
362         '(-p --path)'{-p,--path}'[read package versions from FILE instead of the AUR]: _files'
363         '(-q --quiet)'{-q,--quiet}'[only print package names to standard output]'
364         '(-u --upair)'{-u,--upair}'[print unpairable lines from file FILENUM where filenum is 1 or 2]:file number:(1 2)'
365     )
366     _arguments -s $args
369 _aur-view() {
370     local -a args
372     args=(
373         '--format=[generate diffs with git-diff or git-log]:format:((diff\:use\ git-diff log\:use\ git-log))'
374         '(-a --arg-file)'{-a,--arg-file}'[a textfile describing git repositories relative to the current directory]: file: _files'
375         '--revision=[the revision used for comparing changes (defaults to HEAD)]:revision: '
376         '--no-patch[suppress patch output, only showing a summary]'
377         '(-a --arg-file)*:repositories: _files -/'
378     )
379     _arguments -s $args
382 # Main entry point and handler of top level completion
383 _aur() {
384     local context state state_descr line
385     typeset -A opt_args
387     local -A cmds
388     cmds[build]="build packages to a local repository"
389     cmds[chroot]="build pacman packages with systemd-nspawn"
390     cmds[depends]="retrieve dependencies using aurweb"
391     cmds[fetch]="fetch packages from a location"
392     cmds[format]="parse JSON input"
393     cmds[graph]="print package/dependency directed graph"
394     cmds[pkglist]="print the AUR package list"
395     cmds[query]="send requests to the aurweb RPC interface"
396     cmds[repo-parse]="parse contents of pacman repositories"
397     cmds[repo-filter]="filter packages in the Arch Linux repositories"
398     cmds[repo]="manage local repositories"
399     cmds[search]="search for AUR packages"
400     cmds[srcver]="list version of VCS packages"
401     cmds[sync]="download and build AUR packages automatically"
402     cmds[vercmp]="check packages for AUR updates"
403     cmds[view]="inspect git repositories"
405     for k in ${(k)_aur_third_party_commands}; do
406         cmds[$k]=$_aur_third_party_commands[$k]
407     done
409     local -a descs=()
410     local k
411     for k in ${(k)cmds}; do
412         descs+=( "${k}\\:${cmds[${k}]// /\\ }" )
413     done
415     _arguments -C \
416         "1:command:((${descs} --version\:display\ version))" \
417         '*::arg:->options'
419     case $state in
420         options)
421             if [[ ${cmds[${words[1]}]} != "" ]]; then
422                 _aur-${words[1]}
423             fi
424             ;;
425     esac
428 # Based on code in _git, this allows third party commands extending aur and allows
429 # completions for them.
431 # Load any _aur-* definitions so that they may be completed as commands.
432 declare -gA _aur_third_party_commands
433 _aur_third_party_commands=()
435 local file input
436 for file in ${^fpath}/_aur-*~(*~|*.zwc)(-.N); do
437   local name=${${file:t}#_aur-}
438   if (( $+_aur_third_party_commands[$name] )); then
439     continue
440   fi
442   local desc=
443   integer i=1
444   while read input; do
445     if (( i == 2 )); then
446       if [[ $input == '#description '* ]]; then
447         desc=${input#\#description }
448       fi
449       break
450     fi
451     (( i++ ))
452   done < $file
454   _aur_third_party_commands+=([$name]=$desc)
455 done
457 _aur