1#compdef aptitude
2
3local curcontext="$curcontext" state line cmds ret=1
4
5function _aptitude_release() {
6  #{{{
7  local expl releases
8  releases=(
9${${(M)${(f)"$(</etc/apt/sources.list)"}\
10:#[ $'\t']#deb(|-src)*}/(#b)[ $'\t']#[^ $'\t']##[ $'\t']##[^ $'\t']##[ $'\t']##([^ $'\t']##)*/$match[1]}
11  )
12  _wanted list expl release compadd ${expl} - ${(u)releases}
13  #}}}
14}
15
16# Helper function for -F / --display-format
17function _aptitude_format_strings() {
18  _values -s , 'format string' \
19    '%%[Literal %]' \
20    '%#number[Parameter replacement]' \
21    '%a[Action flag]' \
22    '%A[Action]' \
23    '%B[Broken count]' \
24    '%c[Current state flag]' \
25    '%C[Current state]' \
26    '%d[Description]' \
27    '%H[Hostname]' \
28    '%i[Pin priority]' \
29    '%I[Installed size]' \
30    '%m[Maintainer]' \
31    '%M[Automatic flag]' \
32    '%n[Program version]' \
33    '%N[Program name]' \
34    '%o[Download size]' \
35    '%p[Package name]' \
36    '%P[Priority]' \
37    '%r[Reverse depends count]' \
38    '%R[Abbreviated priority]' \
39    '%s[Section]' \
40    '%S[Trust status]' \
41    '%t[Archive]' \
42    '%T[Tagged]' \
43    '%u[Disk usage change]' \
44    '%v[Current version]' \
45    '%V[Candidate version]' \
46    '%Z[Size change]'
47}
48
49_arguments -C \
50  '(- 1 *)'{-h,--help}'[display help information]' \
51  '(- 1 *)--version[display version information]' \
52  '(-s --simulate)'{-s,--simulate}'[print actions without performing them]' \
53  '(-d --download-only)'{-d,--download-only}"[just download packages - don\'t install]" \
54  '(-P --prompt)'{-P,--prompt}'[always display a prompt]' \
55  '(-y --assume-yes)'{-y,--assume-yes}'[assume yes answer to questions]' \
56  '(-F --display-format)'{-F,--display-format}'[specify output format for search command]:format:_aptitude_format_strings' \
57  '(-O --sort)'{-O,--sort}'[specify sort order]:sort order:()' \
58  '(-w --width)'{-w,--width}'[specify output width]:width' \
59  '-f[aggressivley try to fix dependencies of broken packages]' \
60  '(-V --show-versions)'{-V,--show-versions}'[show which versions of packages will be installed]' \
61  '(-D --show-deps)'{-D,--show-deps}'[show brief explanations of automatic installations and removals]' \
62  '-Z[show disk space changes for each package]' \
63  '(-v --verbose)'{-v,--verbose}'[causes some commands to display extra information]' \
64  '(-R --without-recommends)'{-R,--with-recommends}'[install recommended packages when installing new packages]' \
65  '(--without-suggests)--with-suggests[install suggested packages when installing new packages]' \
66  '(-r --with-recommends)'{-r,--without-recommends}'[ignore recommended packages when installing new packages]' \
67  '(--with-suggests)--without-suggests[ignore suggested packages when installing new packages]' \
68  '(-t --target-release)'{-t,--target-release}'[set the release from which packages should be installed]:release:_aptitude_release' \
69  '(-q --quiet)'{-q=,--quiet=}'[less Output]:level' \
70  '--schedule-only[schedule operations to be performed in the future]' \
71  '--purge-unused[purge unused packages instead of removing]' \
72  '--visual-preview[start up the visual interface and display its preview screen]' \
73  '-S[load the extended state information from non-standard state file]:state file:_files' \
74  '-u[begin updating the package lists as soon as the program starts]' \
75  '-i[displays a download preview when the program starts]' \
76  '1: :->cmds' \
77  '*: :->args' && ret=0
78
79case $state in
80  cmds)
81    cmds=( ${${(M)${(f)"$(LC_ALL=C _call_program commands aptitude -h 2>/dev/null)"}:#* - *}/(#b) (*[^ ]) #- (*)/$match[1]:$match[2]:l})
82
83    _describe -t commands 'aptitude command' cmds && ret=0
84  ;;
85  args)
86    case $line[1] in
87      search)
88        _message -e patterns pattern
89      ;;
90      (download|show|changelog|why|why-not|build-dep|build-depends)
91        _deb_packages avail && ret=0
92      ;;
93      (remove|purge|hold|unhold|reinstall|forbid-version|markauto|unmarkauto)
94        _deb_packages installed && ret=0
95      ;;
96      install)
97        _deb_packages uninstalled && ret=0
98      ;;
99      *)
100        (( ret )) && _message 'no more arguments'
101      ;;
102    esac
103  ;;
104esac
105
106return ret
107