1
0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-10-03 17:31:33 +02:00
zsh/Completion/Linux/_rpm

252 lines
8.0 KiB
Plaintext
Raw Normal View History

1999-09-06 11:04:47 +02:00
#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
2000-04-01 22:43:43 +02:00
# function exists, we return with its return status immediately. This
1999-09-06 11:04:47 +02:00
# 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
# Used by `_arguments', made local here.
2000-04-01 22:43:43 +02:00
local curcontext="$curcontext" state lstate line
typeset -A opt_args
1999-09-06 11:04:47 +02:00
state=''
2000-05-30 05:54:35 +02:00
local ret=1
local -a tmp expl commonopts packageopts
commonopts=(
'*-v[verbose mode]'
'--rcfile:resource file:_files'
'--ftpproxy:FTP proxy server:_hosts'
'--ftpport:FTP port number:'
'--httpproxy:HTTP proxy server:_hosts'
'--httpport:HTTP port number:'
)
packageopts=(
'-a[query all packages]'
'-p+[query uninstalled package file]:*:RPM package file:->package_file'
'-f[specify file to query owner of]:file:_files'
'--triggeredby:RPM package:->package'
'--whatprovides:RPM capability:->capability'
'--whatrequires:RPM capability:->capability'
)
pathopts=(
'--root:RPM root directory:_files -/'
'--dbpath:RPM database path:_files -/'
)
1999-09-06 11:04:47 +02:00
# Do simple completions or get the first state.
2000-04-01 22:43:43 +02:00
_arguments -C -s \
2000-05-30 05:54:35 +02:00
'--help[print help message]' \
'--version[print version number]' \
"${commonopts[@]}" \
2000-04-01 22:43:43 +02:00
'-q+[query mode]:*:query:->query' \
2000-05-30 05:54:35 +02:00
--{querytags,initdb,showrc} \
2000-04-01 22:43:43 +02:00
'--pipe:pipe command:_command_names -e' \
-{V,y}'[verify mode]:*:verify:->verify' \
'--verify[verify mode]:*:verify:->verify' \
2000-05-30 05:54:35 +02:00
'--setperms[set file permissions]:*:package:->setattrs' \
'--setugids[set file owner/group]:*:package:->setattrs' \
'(--install)-i+[install mode]:*:install:->install' \
'(-i)--install:*:install:->install' \
'(--upgrade)-U+[upgrade mode]:*:upgrade:->upgrade' \
'(-U)--upgrade:*:upgrade:->upgrade' \
'(--freshen)-F+[freshen mode]:*:upgrade:->upgrade' \
'(-F)--freshen:*:upgrade:->upgrade' \
'(--erase)-e+[uninstall mode]:*:uninstall:->uninstall' \
'(-e)--erase:*:uninstall:->uninstall' \
'-b+[build mode (spec file)]: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' \
'(-b)-t+[build mode (tar file)]: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' \
--{resign,addsign}':*:RPM package:->package_file' \
'--rmsource:*:spec file:->spec_file' \
--{rebuild,recompile}':*:Src RPM files:->package_src' \
2000-05-30 05:54:35 +02:00
'(--checksig)-K+[signature check mode]:*:sigcheck:->sigcheck' \
'(-K)--checksig:*:sigcheck:->sigcheck' \
1999-09-06 11:04:47 +02:00
'--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.
2000-04-01 22:43:43 +02:00
_funcall ret _rpm_$state && return ret
1999-09-06 11:04:47 +02:00
# Copy the state and reset `state', to simplify the test above.
lstate="$state"
state=''
tmp=()
# Dispatch...
case "$lstate" in
query)
# --dump requires on of -{l,c,d}
# --triggers requires --script
2000-04-01 22:43:43 +02:00
_arguments -s \
2000-05-30 05:54:35 +02:00
-q "${commonopts[@]}" "${packageopts[@]}" "${pathopts[@]}" \
1999-09-06 11:04:47 +02:00
'--queryformat:RPM query format:->tags' \
2000-05-30 05:54:35 +02:00
'-i[display package information]' \
'--changelog[display change log]' \
'-l[display package file list]' \
'-s[show file states]' \
'-d[documentation files only]' \
'-c[configuration files only]' \
'--dump[show all information]' \
2000-05-30 05:54:35 +02:00
--provides \
-{R,-requires}'[list dependencies]' \
'--scripts[show (un)install scripts]' \
'--triggers[show trigger scripts]' \
1999-09-06 11:04:47 +02:00
'*:RPM package:->package_or_file' && ret=0
;;
2000-05-30 05:54:35 +02:00
setattrs)
_arguments -s --set{perm,ugids} "${packageopts[@]}" && ret = 0
;;
1999-09-06 11:04:47 +02:00
verify)
2000-04-01 22:43:43 +02:00
_arguments -s \
2000-05-30 05:54:35 +02:00
'(-y --verify)-V' '(-V --verify)-y' '(-y -V)--verify' \
"${commonopts[@]}" "${pathopts[@]}" \
1999-09-06 11:04:47 +02:00
--no{deps,md5,files} \
'*:RPM package:->package' && ret=0
;;
upgrade)
2000-05-30 05:54:35 +02:00
tmp=( '(--upgrade)-U' '(-U)--upgrade' '(--force)--oldpackage' )
1999-09-06 11:04:47 +02:00
;&
install)
2000-05-30 05:54:35 +02:00
(( $#tmp )) || tmp=( '(--install)-i' '(-i)--install' )
2000-04-01 22:43:43 +02:00
_arguments -s "$tmp[@]" \
2000-05-30 05:54:35 +02:00
"${commonopts[@]}" "${pathopts[@]}" \
'--excludepath:exclude files in following path:_files -/' \
1999-09-06 11:04:47 +02:00
'--relocate:relocate:->relocate' \
'--prefix:package prefix directory:_files -/' \
2000-05-30 05:54:35 +02:00
'(-h)--hash' '(--hash)-h' \
'(--replacepkgs --replacefiles --oldpackage)--force' \
'(--force)--'{replacefiles,replacepkgs} \
--{badreloc,excludedocs,allfiles,ignorearch,ignoreos,includedocs,justdb,nodeps,noorder,noscripts,notriggers,percent,test} \
1999-09-06 11:04:47 +02:00
'*:pkg file:->package_file' && ret=0
;;
uninstall)
2000-04-01 22:43:43 +02:00
_arguments -s \
2000-05-30 05:54:35 +02:00
'(-e)--erase' '(--erase)-e' \
"${commonopts[@]}" "${pathopts[@]}" \
1999-09-06 11:04:47 +02:00
--{allmatches,justdb,nodeps,noorder,noscripts,notriggers} \
'*:RPM package:->package' && ret=0
;;
build_b)
2000-04-01 22:43:43 +02:00
tmp=( '*:spec file:_files -g \*.spec' )
1999-09-06 11:04:47 +02:00
;&
build_t)
(( $#tmp )) || tmp=( '*:tar file:_files -g \*.\(\#i\)tar\(.\*\|\)' )
2000-04-01 22:43:43 +02:00
_arguments -s \
2000-05-30 05:54:35 +02:00
"${commonopts[@]}" "${pathopts[@]}" \
1999-09-06 11:04:47 +02:00
--{short-circuit,clean,rmsource,sign,test} \
'--target:specify a build target:->target'\
1999-09-06 11:04:47 +02:00
'--buildroot:build root directory:_files -/' \
'--buildarch:architecture for which to build:->target' \
1999-09-06 11:04:47 +02:00
'--buildos:ositecture for which to build:' \
'--timecheck:time check (seconds):' "$tmp[1]" && ret=0
;;
sigcheck)
2000-04-01 22:43:43 +02:00
_arguments -s \
2000-05-30 05:54:35 +02:00
'(-K)--checksig' '(--checksig)-K' \
"${commonopts[@]}" \
1999-09-06 11:04:47 +02:00
--no{pgp,md5} \
'*:RPM package file:->package_file' && ret=0
1999-09-06 11:04:47 +02:00
;;
rebuild)
2000-04-01 22:43:43 +02:00
_arguments -s \
2000-05-30 05:54:35 +02:00
"${commonopts[@]}" "${pathopts[@]}" \
1999-09-06 11:04:47 +02:00
'*:RPM source package file:->package_file' && ret=0
;;
target)
_wanted target expl 'Target platforms' \
compadd $(_call target rpm --showrc 2> /dev/null |grep 'compatible archs'|sed 's/.*: //') && ret=0
;;
package_or_file)
state=package_file
;&
1999-09-06 11:04:47 +02:00
package)
2000-04-01 22:43:43 +02:00
_wanted packages expl 'RPM package' \
compadd -M 'r:|-=* r:|=*' - $(_call packages rpm -qa 2> /dev/null) && ret=0
1999-09-06 11:04:47 +02:00
;;
spec_file)
_wanted specfiles expl 'spec file' \
_files -g \*.spec && ret=0
;;
1999-09-06 11:04:47 +02:00
package_file)
_wanted files expl 'RPM package file' \
_files -g '*.(#i)rpm' && ret=0
if [[ -prefix 1 (f|ht)tp:// ]]; then
_wanted urls expl 'URL of RPM package file' \
_urls -f -g '*.(#i)rpm' "${expl[@]}" && ret=0
1999-09-06 11:04:47 +02:00
else
_wanted urls expl 'URL of RPM package file' \
compadd -S '' "${expl[@]}" ftp:// http:// && ret=0
1999-09-06 11:04:47 +02:00
fi
;;
package_src)
_files -g \*.src\(\#i\).rpm
;&
1999-09-06 11:04:47 +02:00
tags)
if compset -P '*%*\{'; then
2000-04-01 22:43:43 +02:00
_wanted tags expl 'RPM tag' \
compadd -M 'm:{a-z}={A-Z}' -S '\}' - \
"${(@)${(@f)$(_call tags rpm --querytags 2> /dev/null)}#RPMTAG_}" && ret=0
1999-09-06 11:04:47 +02:00
else
_message 'RPM format'
fi
;;
capability)
_message 'RPM capability'
;;
relocate)
2000-04-01 22:43:43 +02:00
if compset -P '*='; then
_description directories expl 'new path'
1999-09-06 11:04:47 +02:00
else
2000-04-01 22:43:43 +02:00
_description directories expl 'old path'
1999-09-06 11:04:47 +02:00
fi
_files "$expl[@]" -/ && ret=0
;;
esac
done
return ret