initial checkin
[zsh-lovers.git] / zsh_people / bruno_bonfils / functions / _auto-apt
1 #compdef auto-apt
2
3 # Bruno Bonfils, <asyd@zshfr.org>
4
5 local expl prev ret
6
7 prev="$words[CURRENT-1]"
8
9 # if there is a command in arguments ?
10 if [[ -n $words[(r)(run|update|update-local|merge|del|check|list|search|debuilt|status)] ]] ; then
11
12     # yes, add completion for command arguments and command options
13     if [[ -n $words[(r)(update|update-local|merge)] && "$words[CURRENT]" = -* ]] ; then
14         _wanted option expl 'option' compadd - "-a" && return 0;
15     fi
16
17     if [[ -n $words[(r)(check|list|search)] && "$words[CURRENT]" = -* ]] ; then
18         _wanted option expl 'option' compadd - "-v" "-f" && return 0;
19     fi
20
21     case $prev in
22         "run")
23             _wanted command expl 'command' _files -g '*(/,*)' && return 0 ;;
24         "del")
25             _wanted package expl 'package' _deb_packages avail && return 0 ;;
26         "search")
27             _arguments ':pattern:' && return 0 ;; 
28     esac
29
30 else
31
32     # no, add completion for commands or options (and options arguments)
33     compset -P "*,"
34
35     case $prev in 
36         "-a")
37             local distribs
38             distribs=("main" "contrib" "non-free" "non-US" "none")
39             
40             _wanted distribution expl 'distribution' compadd -q -S, $distribs ;;
41         "-p")
42             local hooks
43             hooks=("exec" "open" "access" "stat" "none")
44             _wanted hook expl 'hook' compadd -q -S, $hooks ;;
45         "-D")
46             _wanted file expl 'dbfile' _files ;;
47         "-F")
48             _wanted file expl 'filedb' _files ;;
49         *)
50             
51             local commands options
52             
53             commands=("run" "update" "update-local" "merge" "del" "check" "list" "search" "debuild" "status")
54             options=("-h" "-s" "-y" "-q" "-i" "-X" "-x" "-a" "-p" "-D" "-F" "-L")
55             
56             if [[ "$words[CURRENT]" = -* ]] ; then
57                 _wanted option expl 'option' compadd - $options
58             else
59                 _wanted command expl 'command' compadd $commands
60             fi
61             ;;
62     esac
63
64     return 0
65 fi