about summary refs log tree commit diff
path: root/Completion/Linux/_rpm
blob: e90402a75897952b0fb1de217be0c76837c5b34e (plain) (blame)
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
#compdef rpm

# This uses `_arguments' in a state-machine kind of way. These states
# have names and before executing the default action for such a state
# we try to call a function with the name `_rpm_<state>'. If such a
# function exists, we return with its return status immediately. This
# allows users to override the default completions by simply defining
# these functions.
# The states (and possible values for the `<state>' above) are:
#
#  query
#    complete for `rpm -q' query
#  verify
#    complete for `rpm --verify'
#  install
#    complete for `rpm -i' or `rpm --install'
#  upgrade
#    complete for `rpm -U' or `rpm --upgrade'
#  uninstall
#    complete for `rpm -e' or `rpm --erase'
#  build_b
#    complete for `rpm -bx' (the stage `x' is already completed)
#  build_t
#    complete for `rpm -tx' (the stage `x' is already completed)
#  sigcheck
#    complete for `rpm --sigcheck'
#  rebuild
#    complete for `rpm --rebuild'
#  package
#    complete a RPM package name
#  package_file
#    complete a RPM package file name
#  package_or_file
#    the previous two together
#  tags
#    complete a tag name
#  capability
#    complete a capability
#  relocate
#    complete a `old=new' pair of paths

local ret=1 tmp expl

# Used by `_arguments', made local here.

local state lstate line
tyeset -A options

state=''

# Do simple completions or get the first state.

_arguments \
  '--rcfile:resource file:_files' \
  '--ftpproxy:FTP proxy server:_hosts' \
  '--ftpport:FTP port number:' \
  '-q:*:query:->query' \
  -{V,v,vv,y,-{setperms,setugids,querytags,initdb,showrc}} \
  '-pipe:*:pipe command:_command_names -e' \
  '--verify:*:verify:->verify' \
  -{i,-install}':*:install:->install' \
  -{U,-upgrade}':*:upgrade:->upgrade' \
  -{e,-erase}':*:uninstall:->uninstall' \
  -'b+:build stage:((p\:execute\ \%prep\ stage l\:do\ a\ list\ check c\:execute\ build\ stage i\:execute\ install\ stage b\:build\ a\ binary\ package a\:build\ binary\ and\ source\ packages)):*:build:->build_b' \
  -'t+:build stage:((p\:execute\ \%prep\ stage l\:do\ a\ list\ check c\:execute\ build\ stage i\:execute\ install\ stage b\:build\ a\ binary\ package a\:build\ binary\ and\ source\ packages)):*:build:->build_t' \
  --{rebuild,rmsource,recompile,resign,addsign}':*:RPM package:->package' \
  -{K,-checksig}':*:sigcheck:->sigcheck' \
  '--rebuilddb:*:rebuild:->rebuild' && ret=0

# As long as we have a state name...

while [[ -n "$state" ]]; do

  # First try to call a user-defined function.

  funcall ret _rpm_$state && return ret

  # Copy the state and reset `state', to simplify the test above.

  lstate="$state"
  state=''
  tmp=()

  # Dispatch...

  case "$lstate" in
  query)
    _arguments \
      -{v,vv} \
      '--rcfile:resource file:_files' \
      '--ftpproxy:FTP proxy server:_hosts' \
      '--ftpport:FTP port number:' \
      '--root:RPM root directory:_files -/' \
      '--dbpath:RPM database path:_files -/' \
      '--queryformat:RPM query format:->tags' \
      '-f:file:_files' \
      '-p:RPM package file:->package_file' \
      '--triggeredby:RPM package:->package' \
      '--whatprovides:RPM capability:->capability' \
      '--whatrequires:RPM capability:->capability' \
      '*:RPM package:->package_or_file' && ret=0
    ;;
  verify)
    _arguments \
      -{v,vv} \
      '--rcfile:resource file:_files' \
      '--ftpproxy:FTP proxy server:_hosts' \
      '--ftpport:FTP port number:' \
      --no{deps,md5,files} \
      '--root:RPM root directory:_files -/' \
      '--dbpath:RPM database path:_files -/' \
      '*:RPM package:->package' && ret=0
    ;;
  upgrade)
    tmp=( --oldpackage )
    ;&
  install)
    _arguments "$tmp[@]" \
      -{v,vv} \
      '--rcfile:resource file:_files' \
      '--ftpproxy:FTP proxy server:_hosts' \
      '--ftpport:FTP port number:' \
      -{-{badreloc,excludedocs,force,hash,allfiles,ignorearch,ignoreos,includedocs,justdb,nodeps,noorder,noscripts,notriggers,percent,replacefiles,replacepkgs,test},h} \
      '--relocate:relocate:->relocate' \
      '--prefix:package prefix directory:_files -/' \
      '--root:RPM root directory:_files -/' \
      '--dbpath:RPM database path:_files -/' \
      '*:pkg file:->package_file' && ret=0
    ;;
  uninstall)
    _arguments \
      -{v,vv} \
      '--rcfile:resource file:_files' \
      '--ftpproxy:FTP proxy server:_hosts' \
      '--ftpport:FTP port number:' \
      --{allmatches,justdb,nodeps,noorder,noscripts,notriggers} \
      '--root:RPM root directory:_files -/' \
      '--dbpath:RPM database path:_files -/' \
      '*:RPM package:->package' && ret=0
    ;;
  build_b)
    tmp=( '*:RPM package:->package' )
    ;&
  build_t)
    (( $#tmp )) || tmp=( '*:tar file:_files -g \*.\(\#i\)tar\(.\*\|\)' )

    _arguments \
      -{v,vv} \
      '--rcfile:resource file:_files' \
      '--ftpproxy:FTP proxy server:_hosts' \
      '--ftpport:FTP port number:' \
      --{short-circuit,clean,rmsource,sign,test} \
      '--buildroot:build root directory:_files -/' \
      '--buildarch:architecture for which to build:' \
      '--buildos:ositecture for which to build:' \
      '--timecheck:time check (seconds):' "$tmp[1]" && ret=0
    ;;
  sigcheck)
    _arguments \
      -{v,vv} \
      '--rcfile:resource file:_files' \
      '--ftpproxy:FTP proxy server:_hosts' \
      '--ftpport:FTP port number:' \
      --no{pgp,md5} \
      '*:RPM package file:->package_or_file' && ret=0
    ;;
  rebuild)
    _arguments \
      -{v,vv} \
      '--rcfile:resource file:_files' \
      '--ftpproxy:FTP proxy server:_hosts' \
      '--ftpport:FTP port number:' \
      '--root:RPM root directory:_files -/' \
      '--dbpath:RPM database path:_files -/' \
      '*:RPM source package file:->package_file' && ret=0
    ;;
  package_or_file)
    state=package_file
    ;&
  package)
    _description expl 'RPM package'
    compadd "$expl[@]" -M 'r:|-=* r:|=*' - $(rpm -qa) && ret=0
    ;;
  package_file)
    if compset -P ftp:; then
      _hosts -S/ && ret=0
    else
      _files -g '*.(#i)rpm' && ret=0
    fi
    ;;
  tags)
    if compset -P '*\{'; then
      _description expl 'RPM tag'
      compadd "$expl[@]" -M 'm:{a-z}={A-Z}' -S '}' - \
              "${(@)${(@f)$(rpm --querytags)}#RPMTAG_}" && ret=0
    else
      _message 'RPM format'
    fi
    ;;
  capability)
    _message 'RPM capability'
    ;;
  relocate)
    if compset -P '*\='; then
      _description expl 'new path'
    else
      _description expl 'old path'
    fi

    _files "$expl[@]" -/ && ret=0
    ;;
  esac
done

return ret