1 #compdef pacman pacman.static=pacman pacman-key makepkg
3 # copy this file to /usr/share/zsh/site-functions/_pacman
7 # options for passing to _arguments: main pacman commands
8 _pacman_opts_commands=(
9 '-Q[Query the package database]'
10 '-R[Remove a package from the system]'
11 '-S[Synchronize packages]'
12 '-U[Upgrade a package]'
13 '-V[Display version and exit]'
17 # options for passing to _arguments: options common to all commands
19 '-b[Alternate database location]:database_location:_files -/'
20 '-h[Display syntax for the given operation]'
21 '-r[Set alternate installation root]:installation root:_files -/'
23 '--cachedir[Alternate package cache location]:cache_location:_files -/'
24 '--config[An alternate configuration file]:config file:_files'
25 '--logfile[An alternate log file]:config file:_files'
26 '--noconfirm[Do not ask for confirmation]'
27 '--noprogressbar[Do not show a progress bar when downloading files]'
28 '--noscriptlet[Do not execute the install scriptlet if one exists]'
29 '--print[Only print the targets instead of performing the operation]'
32 # options for passing to _arguments: options for --upgrade commands
33 _pacman_opts_pkgfile=(
34 '-d[Skip dependency checks]'
35 '--dbonly[Only remove database entry, do not remove files]'
36 '--force[Overwrite conflicting files]'
37 '--needed[Do not reinstall up to date packages]'
38 '--recursive[Reinstall all dependencies of target packages]'
39 '*:package file:_files -g "*.pkg.tar*(.)"'
42 # options for passing to _arguments: subactions for --query command
43 _pacman_opts_query_actions=(
44 '-g[View all members of a package group]:*:package groups:->query_group'
45 '-o[Query the package that owns a file]:file:_files'
46 '-p[Package file to query]:*:package file:->query_file'
47 '-s[Search package names and descriptions]:*:search text:->query_search'
50 # options for passing to _arguments: options for --query and subcommands
51 _pacman_opts_query_modifiers=(
52 '-c[List package changelog]'
53 '-d[List packages installed as dependencies]'
54 '-e[List packages explicitly installed]'
55 '-i[View package information]'
56 '-ii[View package information including backup files]'
57 '-k[Check package files]'
58 '-l[List package contents]'
59 '-m[List installed packages not found in sync db(s)]'
60 '-t[List packages not required by any package]'
61 '-u[List packages that can be upgraded]'
64 # options for passing to _arguments: options for --remove command
66 '-c[Remove all dependent packages]'
67 '-d[Skip dependency checks]'
68 '-n[Remove protected configuration files]'
69 '-s[Remove dependencies not required by other packages]'
70 '--dbonly[Only remove database entry, do not remove files]'
71 '*:installed package:_pacman_completions_installed_packages'
74 # options for passing to _arguments: options for --sync command
75 _pacman_opts_sync_actions=(
76 '*-c[Remove old packages from cache]:*:clean:->sync_clean'
77 '*-cc[Remove all packages from cache]:*:clean:->sync_clean'
78 '-g[View all members of a package group]:*:package groups:->sync_group'
79 '-s[Search package names and descriptions]:*:search text:->sync_search'
80 '--dbonly[Only remove database entry, do not remove files]'
81 '--needed[Do not reinstall up to date packages]'
82 '--recursive[Reinstall all dependencies of target packages]'
85 # options for passing to _arguments: options for --sync command
86 _pacman_opts_sync_modifiers=(
87 '-d[Skip dependency checks]'
88 '-i[View package information]'
89 '-l[List all packages in a repository]'
90 '-p[Print download URIs for each package to be installed]'
91 '-u[Upgrade all out-of-date packages]'
92 '-w[Download packages only]'
93 '-y[Download fresh package databases]'
94 '*--ignore[Ignore a package upgrade]:package:
95 _pacman_completions_all_packages'
96 '*--ignoregroup[Ignore a group upgrade]:package group:
97 _pacman_completions_all_groups'
98 '--asdeps[Install packages as non-explicitly installed]'
99 '--asexplicit[Install packages as explicitly installed]'
100 '--force[Overwrite conflicting files]'
103 # handles --help subcommand
104 _pacman_action_help() {
106 "$_pacman_opts_commands[@]"
109 # handles cases where no subcommand has yet been given
110 _pacman_action_none() {
112 "$_pacman_opts_commands[@]"
115 # handles --query subcommand
116 _pacman_action_query() {
117 local context state line
121 # "$_pacman_opts_common[@]" \
122 # "$_pacman_opts_query_actions[@]" \
123 # "$_pacman_opts_query_modifiers[@]"
128 "$_pacman_opts_common[@]" \
129 "$_pacman_opts_query_modifiers[@]" \
130 '*:package file:_files -g "*.pkg.tar*"'
134 "$_pacman_opts_common[@]" \
135 "$_pacman_opts_query_modifiers[@]" \
136 '*:groups:_pacman_completions_installed_groups'
140 "$_pacman_opts_common[@]" \
141 "$_pacman_opts_query_modifiers[@]" \
146 "$_pacman_opts_common[@]" \
147 "$_pacman_opts_query_modifiers[@]" \
152 "$_pacman_opts_common[@]" \
153 "$_pacman_opts_query_actions[@]" \
154 "$_pacman_opts_query_modifiers[@]" \
155 '*:package:_pacman_completions_installed_packages'
160 # handles --remove subcommand
161 _pacman_action_remove() {
163 "$_pacman_opts_common[@]" \
164 "$_pacman_opts_remove[@]"
167 # handles --sync subcommand
168 _pacman_action_sync() {
169 local context state line
173 # "$_pacman_opts_common[@]" \
174 # "$_pacman_opts_sync_actions[@]" #\
175 # #"$_pacman_opts_sync_modifiers[@]"
180 "$_pacman_opts_common[@]" \
181 "$_pacman_opts_sync_modifiers[@]" \
182 '*-c[Remove old packages from cache]' \
186 "$_pacman_opts_common[@]" \
187 "$_pacman_opts_sync_modifiers[@]" \
188 '*:package group:_pacman_completions_all_groups'
192 "$_pacman_opts_common[@]" \
193 "$_pacman_opts_sync_modifiers[@]" \
198 "$_pacman_opts_common[@]" \
199 "$_pacman_opts_sync_modifiers[@]" \
200 '*:package:_pacman_completions_all_packages'
205 # handles --upgrade subcommand
206 _pacman_action_upgrade() {
208 "$_pacman_opts_common[@]" \
209 "$_pacman_opts_pkgfile[@]"
212 # handles --version subcommand
213 _pacman_action_version() {
214 # no further arguments
218 # provides completions for package groups
219 _pacman_completions_all_groups() {
222 groups=( $(_call_program groups $cmd[@] -Sg) )
224 compadd "$@" -a groups
227 # provides completions for packages available from repositories
228 # these can be specified as either 'package' or 'repository/package'
229 _pacman_completions_all_packages() {
230 local -a cmd packages repositories packages_long
233 if compset -P1 '*/*'; then
234 packages=( $(_call_program packages $cmd[@] -Sql ${words[CURRENT]%/*}) )
236 _wanted repo_packages expl "repository/package" compadd ${(@)packages}
238 packages=( $(_call_program packages $cmd[@] -Sql) )
240 _wanted packages expl "packages" compadd - "${(@)packages}"
242 repositories=(${(o)${${${(M)${(f)"$(<@sysconfdir@/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
243 typeset -U repositories
244 _wanted repo_packages expl "repository/package" compadd -S "/" $repositories
248 # provides completions for package groups
249 _pacman_completions_installed_groups() {
252 groups=(${(o)${(f)"$(_call_program groups $cmd[@] -Qg)"}% *})
254 compadd "$@" -a groups
257 # provides completions for installed packages
258 _pacman_completions_installed_packages() {
259 local -a cmd packages packages_long
260 packages_long=(@localstatedir@/lib/pacman/local/*(/))
261 packages=( ${${packages_long#@localstatedir@/lib/pacman/local/}%-*-*} )
262 compadd "$@" -a packages
265 # provides completions for repository names
266 _pacman_completions_repositories() {
267 local -a cmd repositories
268 repositories=(${(o)${${${(M)${(f)"$(<@sysconfdir@/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
270 typeset -U repositories
271 compadd "$@" -a repositories
274 # builds command for invoking pacman in a _call_program command - extracts
275 # relevant options already specified (config file, etc)
276 # $cmd must be declared by calling function
277 _pacman_get_command() {
278 # this is mostly nicked from _perforce
279 cmd=( "pacman" "2>/dev/null")
281 for (( i = 2; i < CURRENT - 1; i++ )); do
282 if [[ ${words[i]} = "--config" || ${words[i]} = "--root" ]]; then
283 cmd+=( ${words[i,i+1]} )
293 "$_pacman_opts_common[@]" \
294 "$_pacman_opts_query_modifiers[@]" \
295 '*:groups:_pacman_completions_installed_groups'
299 "$_pacman_opts_common[@]" \
300 "$_pacman_opts_query_modifiers[@]" \
301 '*:package file:_files'
303 -Q*p*) # file *.pkg.tar*
305 "$_pacman_opts_common[@]" \
306 "$_pacman_opts_query_modifiers[@]" \
307 '*:package file:_files -g "*.pkg.tar*"'
309 -Q*) _pacman_action_query ;;
310 -R*) _pacman_action_remove ;;
311 -S*c*) # no completion
316 "$_pacman_opts_common[@]" \
317 "$_pacman_opts_sync_modifiers[@]" \
318 '*:package repo:_pacman_completions_repositories' \
322 "$_pacman_opts_common[@]" \
323 "$_pacman_opts_sync_modifiers[@]" \
324 '*:package group:_pacman_completions_all_groups'
326 -S*) _pacman_action_sync ;;
327 -U*) _pacman_action_upgrade ;;
328 -V*) _pacman_action_version ;;
329 -h*) _pacman_action_help ;;
330 - ) _pacman_action_none ;;
337 '-a[Add the specified keys (empty for stdin)]: :_files'
338 '-d[Remove the Specified keyids]:*: :_keys'
339 '-e[Export the specified or all keyids]:*: :_keys'
340 '-f[List fingreprint for specidied or all keyids]:*: :_keys'
341 '-l[List the specified or all keys]:*: :_keys'
342 '-r[Fetch the specified keyids]:*: :_keys'
343 '-u[Update the trustdb of pacman]'
344 '-v[Verify the file specified by the signature]: :_files -g "*.sig"'
345 '-V[Show program version]'
350 '--add[Add the specified keys (empty for stdin)]: :_files'
351 '--delete[Remove the Specified keyids]:*: :_keys'
352 '--export[Export the specified or all keyids]:*: :_keys'
353 '--finger[List fingreprint for specidied or all keyids]:*: :_keys'
354 '--list-keys[List the specified or all keys]:*: :_keys'
355 '--recv-keys[Fetch the specified keyids]:*: :_keys'
356 '--updatedb[Update the trustdb of pacman]'
357 '--verify[Verify the file specified by the signature]: :_files -g "*.sig"'
358 '--version[Show program version]'
359 '--edit-key[Present a menu for key management task on keyids]:*: :_keys'
360 '--import[Imports pubring.gpg from dir(s)]: :_files -g "*.gpg"'
361 '--import-tb[Imports ownertrust values from trustdb.gpg in dir(s)]: :_files -g "*.gpg"'
362 '--init[Ensure the keyring is properly initialized]'
363 '--list-sigs[List keys and their signatures]:*: :_keys'
364 '--lsign-key[Locally sign the specified keyid]:*: :_keys'
365 '--populate[Reload the default keys from the (given) keyrings in '/usr/share/pacman/keyrings']: :_path_files -W /usr/share/pacman/keyrings'
366 '--refresh-keys[Update specified or all keys from a keyserver]:*: :_keys'
369 _pacman_key_options=(
370 '--config[Use an alternate config file (instead of /etc/pacman.con)]: :_files'
371 '--gpgdir[Set an alternate directory for GnuPG (instead of /etc/pacman.d/gnupg)]: :_files -/'
372 '--keyserver[Specify a keyserver to use if necessary]'
376 case $words[CURRENT] in
379 "$_pacman_key_options[@]" \
384 "$_pacman_key_options[@]" \
385 "$_key_shortopts[@]" \
390 while [[ $words[$i] != -* ]] && [[ $words[$i] != "pacman-key" ]];do
396 "$_pacman_key_options[@]" \
401 "$_pacman_key_options[@]" \
402 "$_key_shortopts[@]" \
413 keylist=$(pacman-key --list-keys 2>/dev/null | awk '
416 split($2, a, "/"); print a[2]
420 if (match($NF, /<[^>]+>/))
421 print substr($NF, RSTART + 1, RLENGTH - 2)
422 #this adds support for names as well if that is ever added
425 #for (i=2;i<NF;i++) {printf "%s%s",sep, $i;sep=" "}; printf "\n"
426 }' #|sed -e 's/(.*)//g' -e 's/^\ //g' -e 's/\ *$//g' |uniq
428 #keys=(${keylist//$'\n'/\/})
429 keys=(${(s:/:)${keylist//$'\n'/\/}})
430 _describe -t modules 'keys in keyring' keys && return 0
434 '*-s[Install missing dependencies with pacman]'
435 '*-i[Install package after successful build]'
436 '*-A[Ignore incomplete arch field in PKGBUILD]'
437 '*-c[Clean up work files after build]'
438 '*-d[Skip all dependency checks]'
439 '*-e[Do not extract source files (use existing src/ dir)]'
440 '*-f[Overwrite existing package]'
441 '*-g[Generate integrity checks for source files]'
442 '*-h[Show help message and exit]'
443 '*-L[Log package build process]'
444 '*-m[Disable colorized output messages]'
445 '*-o[Download and extract files only]'
446 '-p[Use an alternate build script (instead of 'PKGBUILD')]: :_files'
447 '*-r[Remove installed dependencies after a successful build]'
448 '*-R[Repackage contents of the package without rebuilding]'
449 '*-S[Generate a source-only tarball without downloading sources]'
452 _makepkg_action_none(){
454 "$_makepkg_shortopts[@]"\
455 "$_makepkg_longopts[@]"
458 '--ignorearch[Ignore incomplete arch field in PKGBUILD]'
459 '--clean[Clean up work files after build]'
460 '--nodeps[Skip all dependency checks]'
461 '--noextract[Do not extract source files (use existing src/ dir)]'
462 '--force[Overwrite existing package]'
463 '--geninteg[Generate integrity checks for source files]'
464 '--help[Show help message and exit]'
465 '--install[Install package after successful build]'
466 '--log[Log package build process]'
467 '--nocolor[Disable colorized output messages]'
468 '--nobuild[Download and extract files only]'
469 '--rmdeps[Remove installed dependencies after a successful build]'
470 '--repackage[Repackage contents of the package without rebuilding]'
471 '--syncdeps[Install missing dependencies with pacman]'
472 '--source[Generate a source-only tarball without downloading sources]'
473 '--allsource[Generate a source-only tarball including downloaded source]'
474 '--asroot[Allow makepkg to run as root user]'
475 '--check[Run check() function in the PKGBUILD]'
476 '--config[Use an alternate config file instead of '/etc/makepkg.conf']: :_files'
477 '--holdver[Prevent automatic version bumping for development PKGBUILDs]'
478 '--key[Specify key to use for gpg signing instead of the default]: :_keys'
479 '--nocheck[Do not run the check() function in the PKGBUILD]'
480 '--nosign[Do not create a signature for the package]'
481 '--pkg[Only build listed packages from a split package]'
482 '--sign[Sign the resulting package with gpg]'
483 '--skipchecksums[Do not verify checksums of the source files]'
484 '--skipinteg[do not perform any verification checks on source files]'
485 '--skippgpcheck[Do not verify source files with PGP signatures]'
486 '--noconfirm[do not ask for confirmation when resolving dependencies]'
487 '--noprogressbar[Do not show a progress bar when downloading files]'
490 case $words[CURRENT] in
493 "$_makepkg_shortopts[@]" \
494 "$_makepkg_longopts[@]"
498 "$_makepkg_longopts[@]"
500 - )_makepkg_action_none ;;
503 while [[ $words[i] != -* ]] && [[ $words[$i] != "makepkg" ]];do
509 "$_makepkg_shortopts[@]" \
510 "$_makepkg_longopts[@]"
514 "$_makepkg_longopts[@]"
516 - )_makepkg_action_none ;;
529 _pacman_zsh_comp "$@";;