1
1
# dpkg(1) and related commands completion -*- shell-script -*-
2
2
3
- if _comp_have_command grep-status; then
4
- _comp_xfunc_dpkg_installed_packages ()
5
- {
6
- grep-status -P -e " ^${1-} " -a -FStatus ' ok installed' -n -s Package
7
- }
8
-
9
- _comp_xfunc_dpkg_purgeable_packages ()
10
- {
11
- grep-status -P -e " ^${1-} " -a -FStatus ' ok installed' -o -FStatus ' ok config-files' -n -s Package
12
- }
13
- else
14
- _comp_xfunc_dpkg_installed_packages ()
15
- {
16
- command awk -F ' \n' -v RS=" " "
17
- index(\$ 1, \" Package: ${1-} \" ) == 1 &&
3
+ # @since 2.12
4
+ _comp_xfunc_dpkg_installed_packages ()
5
+ {
6
+ local pkgs
7
+ pkgs=$(
8
+ grep-status -P -e " ^${cur-} " -a \
9
+ -FStatus ' ok installed' \
10
+ -n -s Package 2> /dev/null ||
11
+ command awk -F ' \n' -v RS=" " "
12
+ index(\$ 1, \" Package: ${cur-} \" ) == 1 &&
18
13
\$ 2 ~ /ok installed|half-installed|unpacked|half-configured|^Essential: yes/ {
19
14
print(substr(\$ 1, 10));
20
15
}" /var/lib/dpkg/status 2> /dev/null
21
- }
16
+ )
17
+ _comp_compgen -a -- -W ' $pkgs'
18
+ }
22
19
23
- _comp_xfunc_dpkg_purgeable_packages ()
24
- {
25
- command awk -F ' \n' -v RS=" " "
26
- index(\$ 1, \" Package: ${1-} \" ) == 1 &&
20
+ # @since 2.12
21
+ _comp_xfunc_dpkg_purgeable_packages ()
22
+ {
23
+ local pkgs
24
+ pkgs=$(
25
+ grep-status -P -e " ^${cur-} " -a \
26
+ -FStatus ' ok installed' -o -FStatus ' ok config-files' \
27
+ -n -s Package 2> /dev/null ||
28
+ command awk -F ' \n' -v RS=" " "
29
+ index(\$ 1, \" Package: ${cur-} \" ) == 1 &&
27
30
\$ 2 ~ /ok installed|half-installed|unpacked|half-configured|config-files|^Essential: yes/ {
28
31
print(substr(\$ 1, 10));
29
32
}" /var/lib/dpkg/status 2> /dev/null
30
- }
31
- fi
33
+ )
34
+ _comp_compgen -a -- -W ' $pkgs'
35
+ }
32
36
33
37
# @since 2.12
34
38
_comp_xfunc_dpkg_held_packages ()
@@ -38,8 +42,22 @@ _comp_xfunc_dpkg_held_packages()
38
42
_comp_compgen -a -- -W ' $pkgs'
39
43
}
40
44
41
- _comp_deprecate_func _comp_dpkg_installed_packages _comp_xfunc_dpkg_installed_packages
42
- _comp_deprecate_func _comp_dpkg_purgeable_packages _comp_xfunc_dpkg_purgeable_packages
45
+ # @deprecated 2.12 use _comp_xfunc_dpkg_installed_packages instead
46
+ _comp_dpkg_installed_packages ()
47
+ {
48
+ local COMPREPLY=() cur=" ${1-} "
49
+ # shellcheck disable=SC2119
50
+ _comp_xfunc_dpkg_installed_packages
51
+ printf " %s\n" " ${COMPREPLY[@]} "
52
+ }
53
+ # @deprecated 2.12 use _comp_xfunc_dpkg_purgeable_packages instead
54
+ _comp_dpkg_purgeable_packages ()
55
+ {
56
+ local COMPREPLY=() cur=" ${1-} "
57
+ # shellcheck disable=SC2119
58
+ _comp_xfunc_dpkg_purgeable_packages
59
+ printf " %s\n" " ${COMPREPLY[@]} "
60
+ }
43
61
44
62
# Debian dpkg(1) completion
45
63
#
@@ -86,11 +104,11 @@ _comp_cmd_dpkg()
86
104
return
87
105
;;
88
106
--remove | --verify | -${noargopts} [rV])
89
- COMPREPLY=( $( _comp_xfunc_dpkg_installed_packages " $cur " ) )
107
+ _comp_xfunc_dpkg_installed_packages
90
108
return
91
109
;;
92
110
--listfiles | --purge | -${noargopts} [LP])
93
- COMPREPLY=( $( _comp_xfunc_dpkg_purgeable_packages " $cur " ) )
111
+ _comp_xfunc_dpkg_purgeable_packages
94
112
return
95
113
;;
96
114
--debug | -${noargopts} D)
@@ -161,7 +179,7 @@ _comp_cmd_dpkg_reconfigure()
161
179
COMPREPLY=($( compgen -W ' --frontend --priority --all --unseen-only
162
180
--help --showold --force --terse' -- " $cur " ) )
163
181
else
164
- COMPREPLY=( $( _comp_xfunc_dpkg_installed_packages " $cur " ) )
182
+ _comp_xfunc_dpkg_installed_packages
165
183
fi
166
184
} &&
167
185
complete -F _comp_cmd_dpkg_reconfigure -o default dpkg-reconfigure
0 commit comments