File: dpkg

package info (click to toggle)
bash-completion 1:2.1-4.3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 7,740 kB
  • sloc: exp: 8,230; makefile: 948; sh: 727; perl: 59; python: 26; xml: 13; ansic: 6
file content (160 lines) | stat: -rw-r--r-- 4,099 bytes parent folder | download | duplicates (3)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# This function is required by _dpkg and _dpkg-reconfigure -*- shell-script -*-

_have grep-status && {
_comp_dpkg_installed_packages()
{
    grep-status -P -e "^$1" -a -FStatus 'install ok installed' -n -s Package
}
} || {
_comp_dpkg_installed_packages()
{
    command grep -A 1 "Package: $1" /var/lib/dpkg/status | \
        command grep -B 1 -Ee "ok installed|half-installed|unpacked| \
            half-configured" \
            -Ee "^Essential: yes" | \
        command grep "Package: $1" | cut -d\  -f2
}
}

_have grep-status && {
_comp_dpkg_purgeable_packages()
{
    grep-status -P -e "^$1" -a -FStatus 'install ok installed' -o -FStatus 'deinstall ok config-files' -n -s Package
}
} || {
_comp_dpkg_purgeable_packages()
{
    command grep -A 1 "Package: $1" /var/lib/dpkg/status | \
        command grep -B 1 -Ee "ok installed|half-installed|unpacked| \
            half-configured|config-files" \
            -Ee "^Essential: yes" | \
        command grep "Package: $1" | cut -d\  -f2
}
}

# Debian dpkg(1) completion
#
_dpkg()
{
    local cur prev words cword split
    _init_completion -s || return

    _expand || return 0

    local i=$cword

    # find the last option flag
    if [[ $cur != -* ]]; then
        while [[ $prev != -* && $i -ne 1 ]]; do
            i=$((i-1))
            prev=${words[i-1]}
        done
    fi

    case $prev in
        -c|-i|-A|-I|-f|-e|-x|-X|--install|--unpack|--record-avail| \
        --contents|--info|--fsys-tarfile|--field|--control|--extract| \
        --vextract)
            _filedir '?(u|d)deb'
            return 0
            ;;
        -b|--build)
            _filedir -d
            return 0
            ;;
        -s|-p|-l|-W|--status|--print-avail|--list|--show)
            COMPREPLY=( $( apt-cache pkgnames "$cur" 2>/dev/null ) )
            return 0
            ;;
        -S|--search)
            _filedir
            return 0
            ;;
        -r|--remove)
            COMPREPLY=( $( _comp_dpkg_installed_packages "$cur" ) )
            return 0
            ;;
        -L|-P|--listfiles|--purge)
            COMPREPLY=( $( _comp_dpkg_purgeable_packages "$cur" ) )
            return 0
            ;;
    esac

    $split && return

    COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
    [[ $COMPREPLY == *= ]] && compopt -o nospace
} &&
complete -F _dpkg dpkg dpkg-query

# Debian dpkg-deb(1) completion
#
_dpkg_deb()
{
    local cur prev words cword split
    _init_completion -s || return

    _expand || return 0

    local i=$cword

    # find the last option flag
    if [[ $cur != -* ]]; then
        while [[ $prev != -* && $i -ne 1 ]]; do
            i=$((i-1))
            prev=${words[i-1]}
        done
    fi

    case $prev in
        -c|-I|-W|-f|-e|-x|-X|-R|--contents|--info|--show|--field|--control| \
        --extract|--vextract|--raw-extract|--fsys-tarfile)
            _filedir '?(u|d)deb'
            return 0
            ;;
        -b|--build)
            _filedir -d
            return 0
            ;;
    esac

    $split && return

    COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
    [[ $COMPREPLY == *= ]] && compopt -o nospace
} &&
complete -F _dpkg_deb dpkg-deb

# Debian GNU dpkg-reconfigure(8) completion
#
_dpkg_reconfigure()
{
    local cur prev words cword
    _init_completion || return

    local opt

    case $prev in
        -f|--frontend)
        opt=( $( printf '%s\n' /usr/share/perl5/Debconf/FrontEnd/* ) )
        opt=( ${opt[@]##*/} )
        opt=( ${opt[@]%.pm} )
        COMPREPLY=( $( compgen -W '${opt[@]}' -- "$cur" ) )
        return 0
        ;;
        -p|--priority)
        COMPREPLY=( $( compgen -W 'low medium high critical' -- "$cur" ) )
        return 0
        ;;
    esac

    if [[ "$cur" == -* ]]; then
        COMPREPLY=( $(compgen -W '--frontend --priority --all --unseen-only
                      --help --showold --force --terse' -- "$cur" ) )
    else
        COMPREPLY=( $( _comp_dpkg_installed_packages "$cur" ) )
    fi
} &&
complete -F _dpkg_reconfigure -o default dpkg-reconfigure

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