Prefix alpm_transflag_t members with ALPM
[pacman-ng.git] / contrib / zsh_completion.in
blob2131412c386a79a3d0a2429b250ff13cd51e52d0
1 #compdef pacman pacman.static=pacman
3 # copy this file to /usr/share/zsh/site-functions/_pacman
5 typeset -A opt_args
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]'
14         '-h[Display usage]'
17 # options for passing to _arguments: options common to all commands
18 _pacman_opts_common=(
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 -/'
22         '-v[Be more verbose]'
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         '-f[Overwrite conflicting files]'
36         '*:package file:_files -g "*.pkg.tar.*(.)"'
39 # options for passing to _arguments: subactions for --query command
40 _pacman_opts_query_actions=(
41         '-g[View all members of a package group]:*:package groups:->query_group'
42         '-o[Query the package that owns a file]:file:_files'
43         '-p[Package file to query]:*:package file:->query_file'
44         '-s[Search package names and descriptions]:*:search text:->query_search'
47 # options for passing to _arguments: options for --query and subcommands
48 _pacman_opts_query_modifiers=(
49         '-c[List package changelog]'
50         '-d[List packages installed as dependencies]'
51         '-e[List packages explicitly installed]'
52         '-i[View package information]'
53         '-ii[View package information including backup files]'
54         '-k[Check package files]'
55         '-l[List package contents]'
56         '-m[List installed packages not found in sync db(s)]'
57         '-t[List packages not required by any package]'
58         '-u[List packages that can be upgraded]'
61 # options for passing to _arguments: options for --remove command
62 _pacman_opts_remove=(
63         '-c[Remove all dependent packages]'
64         '-d[Skip dependency checks]'
65         '-k[Only remove database entry, do not remove files]'
66         '-n[Remove protected configuration files]'
67         '-s[Remove dependencies not required by other packages]'
68         '*:installed package:_pacman_completions_installed_packages'
71 # options for passing to _arguments: options for --sync command
72 _pacman_opts_sync_actions=(
73         '*-c[Remove old packages from cache]:*:clean:->sync_clean'
74         '*-cc[Remove all packages from cache]:*:clean:->sync_clean'
75         '-g[View all members of a package group]:*:package groups:->sync_group'
76         '-s[Search package names and descriptions]:*:search text:->sync_search'
79 # options for passing to _arguments: options for --sync command
80 _pacman_opts_sync_modifiers=(
81         '-d[Skip dependency checks]'
82         '-f[Overwrite conflicting files]'
83         '-i[View package information]'
84         '-l[List all packages in a repository]'
85         '-p[Print download URIs for each package to be installed]'
86         '-u[Upgrade all out-of-date packages]'
87         '-w[Download packages only]'
88         '-y[Download fresh package databases]'
89         '*--ignore[Ignore a package upgrade]:package:
90                 _pacman_completions_all_packages'
91         '*--ignoregroup[Ignore a group upgrade]:package group:
92                 _pacman_completions_all_groups'
93         '--asdeps[Install packages as non-explicitly installed]'
94         '--asexplicit[Install packages as explicitly installed]'
97 # handles --help subcommand
98 _pacman_action_help() {
99         _arguments -s : \
100                 "$_pacman_opts_commands[@]"
103 # handles cases where no subcommand has yet been given
104 _pacman_action_none() {
105         _arguments -s : \
106                 "$_pacman_opts_commands[@]"
109 # handles --query subcommand
110 _pacman_action_query() {
111         local context state line
112         typeset -A opt_args
113         
114 #       _arguments -s : \
115 #               "$_pacman_opts_common[@]" \
116 #               "$_pacman_opts_query_actions[@]" \
117 #               "$_pacman_opts_query_modifiers[@]"
118                 
119         case $state in
120                 query_file)
121                         _arguments -s : \
122                                 "$_pacman_opts_common[@]" \
123                                 "$_pacman_opts_query_modifiers[@]" \
124                                 '*:package file:_files -g "*.pkg.tar.*"'
125                                 ;;
126                 query_group)
127                         _arguments -s : \
128                                 "$_pacman_opts_common[@]" \
129                                 "$_pacman_opts_query_modifiers[@]" \
130                                 '*:groups:_pacman_completions_installed_groups'
131                                 ;;
132                 query_owner)
133                         _arguments -s : \
134                                 "$_pacman_opts_common[@]" \
135                                 "$_pacman_opts_query_modifiers[@]" \
136                                 '*:file:_files'
137                                 ;;
138                 query_search)
139                         _arguments -s : \
140                                 "$_pacman_opts_common[@]" \
141                                 "$_pacman_opts_query_modifiers[@]" \
142                                 '*:search text: '
143                                 ;;
144                 *)
145                         _arguments -s : \
146                                 "$_pacman_opts_common[@]" \
147                                 "$_pacman_opts_query_actions[@]" \
148                                 "$_pacman_opts_query_modifiers[@]" \
149                                 '*:package:_pacman_completions_installed_packages'
150                                 ;;
151         esac
154 # handles --remove subcommand
155 _pacman_action_remove() {
156         _arguments -s : \
157                 "$_pacman_opts_common[@]" \
158                 "$_pacman_opts_remove[@]"
161 # handles --sync subcommand
162 _pacman_action_sync() {
163         local context state line
164         typeset -A opt_args
165         
166 #       _arguments -s : \
167 #               "$_pacman_opts_common[@]" \
168 #               "$_pacman_opts_sync_actions[@]" #\
169 #               #"$_pacman_opts_sync_modifiers[@]"
170                 
171         case $state in
172                 sync_clean)
173                         _arguments -s : \
174                                 "$_pacman_opts_common[@]" \
175                                 "$_pacman_opts_sync_modifiers[@]" \
176                                 '*-c[Remove old packages from cache]' \
177                                 ;;
178                 sync_group)
179                         _arguments -s : \
180                                 "$_pacman_opts_common[@]" \
181                                 "$_pacman_opts_sync_modifiers[@]" \
182                                 '*:package group:_pacman_completions_all_groups'
183                                 ;;
184                 sync_search)
185                         _arguments -s : \
186                                 "$_pacman_opts_common[@]" \
187                                 "$_pacman_opts_sync_modifiers[@]" \
188                                 '*:search text: '
189                                 ;;
190                 *)
191                         _arguments -s : \
192                                 "$_pacman_opts_common[@]" \
193                                 "$_pacman_opts_sync_modifiers[@]" \
194                                 '*:package:_pacman_completions_all_packages'
195                                 ;;
196                 esac
199 # handles --upgrade subcommand
200 _pacman_action_upgrade() {
201         _arguments -s : \
202                 "$_pacman_opts_common[@]" \
203                 "$_pacman_opts_pkgfile[@]"
206 # handles --version subcommand
207 _pacman_action_version() {
208         # no further arguments
209         return 0
212 # provides completions for package groups
213 _pacman_completions_all_groups() {
214         local -a cmd groups
215         _pacman_get_command
216         groups=( $(_call_program groups $cmd[@] -Sg) )
217         typeset -U groups
218         compadd "$@" -a groups
221 # provides completions for packages available from repositories
222 # these can be specified as either 'package' or 'repository/package'
223 _pacman_completions_all_packages() {
224         local -a cmd packages repositories packages_long
225         _pacman_get_command
227         if compset -P1 '*/*'; then
228                 packages=( $(_call_program packages $cmd[@] -Sql ${words[CURRENT]%/*}) )
229                 typeset -U packages
230                 _wanted repo_packages expl "repository/package" compadd ${(@)packages}
231         else
232                 packages=( $(_call_program packages $cmd[@] -Sql) )
233                 typeset -U packages
234                 _wanted packages expl "packages" compadd - "${(@)packages}"
236                 repositories=(${(o)${${${(M)${(f)"$(<@sysconfdir@/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
237                 typeset -U repositories
238                 _wanted repo_packages expl "repository/package" compadd -S "/" $repositories
239         fi
242 # provides completions for package groups
243 _pacman_completions_installed_groups() {
244         local -a cmd groups
245         _pacman_get_command
246         groups=(${(o)${(f)"$(_call_program groups $cmd[@] -Qg)"}% *})
247         typeset -U groups
248         compadd "$@" -a groups
251 # provides completions for installed packages
252 _pacman_completions_installed_packages() {
253         local -a cmd packages packages_long
254         packages_long=(@localstatedir@/lib/pacman/local/*(/))
255         packages=( ${${packages_long#@localstatedir@/lib/pacman/local/}%-*-*} )
256         compadd "$@" -a packages
259 # provides completions for repository names
260 _pacman_completions_repositories() {
261         local -a cmd repositories
262         repositories=(${(o)${${${(M)${(f)"$(<@sysconfdir@/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
263         # Uniq the array
264         typeset -U repositories
265         compadd "$@" -a repositories
268 # builds command for invoking pacman in a _call_program command - extracts
269 # relevant options already specified (config file, etc)
270 # $cmd must be declared by calling function
271 _pacman_get_command() {
272         # this is mostly nicked from _perforce
273         cmd=( "pacman" )
274         integer i
275         for (( i = 2; i < CURRENT - 1; i++ )); do
276                 if [[ ${words[i]} = "--config" || ${words[i]} = "--root" ]]; then
277                         cmd+=( ${words[i,i+1]} )
278                 fi
279         done
282 # main dispatcher
283 _pacman() {
284         case $words[2] in
285                 -Q*g*) # ipkg groups
286                         _arguments -s : \
287                                 "$_pacman_opts_common[@]" \
288                                 "$_pacman_opts_query_modifiers[@]" \
289                                 '*:groups:_pacman_completions_installed_groups'
290                                 ;;
291                 -Q*o*) # file
292                         _arguments -s : \
293                                 "$_pacman_opts_common[@]" \
294                                 "$_pacman_opts_query_modifiers[@]" \
295                                 '*:package file:_files'
296                                 ;;
297                 -Q*p*) # file *.pkg.tar.*
298                         _arguments -s : \
299                                 "$_pacman_opts_common[@]" \
300                                 "$_pacman_opts_query_modifiers[@]" \
301                                 '*:package file:_files -g "*.pkg.tar.*"'
302                                 ;;
303                 -Q*)  _pacman_action_query    ;;
304                 -R*)  _pacman_action_remove   ;;
305                 -S*c*) # no completion
306                         return 0
307                         ;;
308                 -S*l*) # repos
309                         _arguments -s : \
310                                 "$_pacman_opts_common[@]" \
311                                 "$_pacman_opts_sync_modifiers[@]" \
312                                 '*:package repo:_pacman_completions_repositories' \
313                                 ;;
314                 -S*g*) # pkg groups
315                         _arguments -s : \
316                                 "$_pacman_opts_common[@]" \
317                                 "$_pacman_opts_sync_modifiers[@]" \
318                                 '*:package group:_pacman_completions_all_groups'
319                                 ;;
320                 -S*)  _pacman_action_sync     ;;
321                 -U*)  _pacman_action_upgrade  ;;
322                 -V*)  _pacman_action_version  ;;
323                 -h*)  _pacman_action_help     ;;
324                 -  )  _pacman_action_none     ;;
325                 *  )  return 1                ;;
326         esac
329 # run the main dispatcher
330 _pacman "$@"