about summary refs log tree commit diff
path: root/Completion/Debian/Command/_auto-apt
blob: 92af817c1c494726ec1cf1e7cb1966fb9b725d55 (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
#compdef auto-apt

local expl prev ret

prev="$words[CURRENT-1]"

# if there is a command in arguments ?
if [[ -n $words[(r)(run|update|update-local|merge|del|check|list|search|debuilt|status)] ]] ; then

    # yes, add completion for command arguments and command options
    if [[ -n $words[(r)(update|update-local|merge)] && "$words[CURRENT]" = -* ]] ; then
	_wanted option expl 'option' compadd - "-a" && return 0;
    fi

    if [[ -n $words[(r)(check|list|search)] && "$words[CURRENT]" = -* ]] ; then
	_wanted option expl 'option' compadd - "-v" "-f" && return 0;
    fi

    case $prev in
	"run")
	    _wanted command expl 'command' _files -g '*(/,*)' && return 0 ;;
	"del")
	    _wanted package expl 'package' _deb_packages avail && return 0 ;;
    esac
else
    # no, add completion for commands or options (and options arguments)
    case $prev in 
	"-a")
	    local distribs
	    distribs=("main" "contrib" "non-free" "non-US" "none")
	    
	    _values -s , 'distribution' $distribs ;;
	"-p")
	    local hooks
	    hooks=("exec" "open" "access" "stat" "none")
	    _values -s , 'hook' $hooks ;;
	"-D")
	    _wanted file expl 'dbfile' _files ;;
	"-F")
	    _wanted file expl 'filedb' _files ;;
	*)
	    
	    local commands options
	    
	    commands=("run" "update" "update-local" "merge" "del" "check" "list" "search" "debuild" "status")
	    options=("-h" "-s" "-y" "-q" "-i" "-X" "-x" "-a" "-p" "-D" "-F" "-L")
	    
	    if [[ "$words[CURRENT]" = -* ]] ; then
		_wanted option expl 'option' compadd - $options
	    else
		_wanted command expl 'command' compadd $commands
	    fi
	    ;;
    esac

    return 0
fi