1 #compdef packer packer.static=packer
3 # copy this file to /usr/share/zsh/site-functions/_packer
7 # options for passing to _arguments: main packer commands
8 _packer_opts_commands=(
9 '-Ss[Search for a package.]:*:search text:->sync_search'
10 '-S[Install a package.]'
11 '-Syu[Sync with repositories.]'
12 '-Si[Show information for a package.]'
13 '-G[Just download and extract AUR tarball]'
14 '-h[Show packer usage.]'
17 # options for passing to _arguments: options common to all commands
19 '--ignore[Ignore packages listed here.]:package:_packer_completions_all_packages'
20 '--noconfirm[Do not ask user for confirmation.]'
21 '--noedit[Do not ask user if he wants to edit files.]'
22 '--auronly[Only perform commands for the AUR.]'
23 '--devel[Update development packages. (cvs, git, ...)]'
24 '--skipinteg[Skip the integrity checks.]'
27 # handles cases where no subcommand has yet been given
28 _packer_action_none() {
30 "$_packer_opts_commands[@]"
33 # handles --sync subcommand
34 _packer_action_sync() {
35 local context state line
39 # "$_packer_opts_common[@]" \
40 # "$_packer_opts_sync_actions[@]" #\
41 # #"$_packer_opts_sync_modifiers[@]"
46 "$_packer_opts_common[@]" \
51 "$_packer_opts_common[@]" \
52 '*:package:_packer_completions_all_packages'
57 # provides completions for package groups
58 _packer_completions_all_groups() {
61 groups=( $(_call_program groups $cmd[@] -Sg) )
63 compadd "$@" -a groups
66 # provides completions for packages available from repositories
67 # these can be specified as either 'package' or 'repository/package'
68 _packer_completions_all_packages() {
69 local -a cmd packages repositories packages_long
72 if compset -P1 '*/*'; then
73 packages=( $(_call_program packages $cmd[@] -Sql ${words[CURRENT]%/*}) )
75 _wanted repo_packages expl "repository/package" compadd ${(@)packages}
77 packages=( $(_call_program packages $cmd[@] -Sql) )
79 _wanted packages expl "packages" compadd - "${(@)packages}"
81 repositories=(${(o)${${${(M)${(f)"$(</etc/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
82 typeset -U repositories
83 _wanted repo_packages expl "repository/package" compadd -S "/" $repositories
87 # provides completions for package groups
88 _packer_completions_installed_groups() {
91 groups=(${(o)${(f)"$(_call_program groups $cmd[@] -Qg)"}% *})
93 compadd "$@" -a groups
96 # provides completions for installed packages
97 _packer_completions_installed_packages() {
98 local -a cmd packages packages_long
99 packages_long=(/var/lib/pacman/local/*(/))
100 packages=( ${${packages_long#/var/lib/pacman/local/}%-*-*} )
101 compadd "$@" -a packages
104 # provides completions for repository names
105 _packer_completions_repositories() {
106 local -a cmd repositories
107 repositories=(${(o)${${${(M)${(f)"$(</etc/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
109 typeset -U repositories
110 compadd "$@" -a repositories
113 # builds command for invoking pacman in a _call_program command - extracts
114 # relevant options already specified (config file, etc)
115 # $cmd must be declared by calling function
116 _packer_get_command() {
117 # this is mostly nicked from _perforce
120 for (( i = 2; i < CURRENT - 1; i++ )); do
121 if [[ ${words[i]} = "--config" || ${words[i]} = "--root" ]]; then
122 cmd+=( ${words[i,i+1]} )
130 -S*) _packer_action_sync ;;
131 -G*) _packer_action_sync ;;
132 - ) _packer_action_none ;;
137 # run the main dispatcher