summaryrefslogtreecommitdiff
path: root/completions/bash/apt
blob: d7104ec5a87c40fdc150aedad701133e116fc716 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Debian apt(8) completion                             -*- shell-script -*-

_apt()
{
    local sourcesdir="/etc/apt/sources.list.d"
    local cur prev words cword
    _init_completion || return

    # see if the user selected a command already
    local COMMANDS=(
        "list"
        "search"
        "show"
        "install" "remove" "purge" "autoremove"
        "update"
        "upgrade" "full-upgrade" "dist-upgrade"
        "edit-sources"
        "help")

    local command i
    for (( i=0; i < ${#words[@]}-1; i++ )); do
        if [[ ${COMMANDS[@]} =~ ${words[i]} ]]; then
            command=${words[i]}
            break
        fi
    done

    # supported options per command
    if [[ "$cur" == -* ]]; then
        case $command in
            install|remove|purge|upgrade|dist-upgrade|full-upgrade|autoremove)
                COMPREPLY=( $( compgen -W '--show-progress
                  --fix-broken --purge --verbose-versions --auto-remove
                  --simulate --dry-run
                  --download
                  --fix-missing
                  --fix-policy
                  --ignore-hold
                  --force-yes
                  --trivial-only
                  --reinstall --solver' -- "$cur" ) )
                return 0
                ;;
            update)
                COMPREPLY=( $( compgen -W '--list-cleanup 
                  ' -- "$cur" ) )
                return 0
                ;;
            list)
                COMPREPLY=( $( compgen -W '--installed --upgradable 
                  --manual-installed
                  -v --verbose
                  -a --all-versions
                  ' -- "$cur" ) )
                return 0
                ;;
            show)
                COMPREPLY=( $( compgen -W '-a --all-versions
                  ' -- "$cur" ) )
                return 0
                ;;
        esac
    fi

    # specific command arguments
    if [[ -n $command ]]; then
        case $command in
            remove|purge|autoremove)
                if [[ -f /etc/debian_version ]]; then
                    # Debian system
                    COMPREPLY=( $( \
                        _xfunc dpkg _comp_dpkg_installed_packages $cur ) )
                else
                    # assume RPM based
                    _xfunc rpm _rpm_installed_packages
                fi
                return 0
                ;;
            show|list)
                COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \
                    2> /dev/null ) )
                return 0
                ;;
            install)
                COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \
                    2> /dev/null ) )
                _filedir "*.deb"
                return 0
                ;;
            edit-sources)
                COMPREPLY=( $( compgen -W '$( command ls $sourcesdir )' \
                    -- "$cur" ) )
                return 0
                ;;
        esac
    fi

    # no command yet, show what commands we have
    if [ "$command" = "" ]; then
        COMPREPLY=( $( compgen -W '${COMMANDS[@]}' -- "$cur" ) )
    fi

    return 0
} &&
complete -F _apt apt

# ex: ts=4 sw=4 et filetype=sh