1#compdef auto-apt
2
3local expl prev="$words[CURRENT-1]"
4
5# if there is a command in arguments ?
6if [[ -n $words[(r)(run|update|update-local|merge|del|check|list|search|debuilt|status)] ]] ; then
7
8  # yes, add completion for command arguments and command options
9  if [[ -n $words[(r)(update|update-local|merge)] && "$words[CURRENT]" = -* ]] ; then
10    _wanted option expl 'option' compadd - "-a" && return;
11  fi
12
13  if [[ -n $words[(r)(check|list|search)] && "$words[CURRENT]" = -* ]] ; then
14    _wanted option expl 'option' compadd - "-v" "-f" && return;
15  fi
16
17  case $prev in
18    run) _wanted command expl 'command' _files -g '*(/,*)' && return ;;
19    del) _wanted package expl 'package' _deb_packages avail && return ;;
20  esac
21else
22  _arguments \
23    '-a:distribution:_values -s , distribution main contrib non-free non-US none' \
24    '-p:hook:_values -s , hook exec open access stat none' \
25    '-D:dbfile:_files' \
26    '-F:filedb:_files' \
27    -h -s -y -q -i -X -x -L \
28    '*:command:(run update update-local merge del check list search debuild status)' && return
29fi
30
31return 1
32