Skip to content

Commit 3fbf99e

Browse files
authored
Merge pull request #1051 from akinomyoga/refactor-api-8
refactor(completions/*): apply API renaming
2 parents 11cc3bb + 3c7fe7b commit 3fbf99e

File tree

32 files changed

+264
-276
lines changed

32 files changed

+264
-276
lines changed

completions/_svn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ _comp_cmd_svn()
3434
return
3535
;;
3636
--encoding)
37-
_comp_xfunc iconv charsets
37+
_comp_compgen -x iconv charsets
3838
return
3939
;;
4040
--editor-cmd | --diff-cmd | --diff3-cmd)

completions/_yum

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,27 @@ _comp_cmd_yum__list()
1818
fi
1919
}
2020

21-
# TODO:API: rename per conventions, rework to use vars rather than outputting
22-
_yum_repolist()
21+
_comp_cmd_yum__compgen_repolist()
2322
{
2423
# -d 0 causes repolist to output nothing as of yum 3.2.22:
2524
# http://yum.baseurl.org/ticket/83
2625
# Drop first ("repo id repo name") and last ("repolist: ...") rows
27-
yum --noplugins -C repolist "$1" 2>/dev/null |
28-
command sed -ne '/^repo\s\s*id/d' -e '/^repolist:/d' \
29-
-e 's/[[:space:]].*//p'
26+
_comp_compgen_split -- "$(
27+
yum --noplugins -C repolist "$1" 2>/dev/null |
28+
command sed -ne '/^repo\s\s*id/d' -e '/^repolist:/d' \
29+
-e 's/[[:space:]].*//p'
30+
)"
3031
}
3132

32-
# TODO:API: rename per conventions, rework to use vars rather than outputting
33-
_yum_plugins()
33+
_comp_cmd_yum__compgen_plugins()
3434
{
3535
local -a files
3636
_comp_expand_glob files '/usr/lib/yum-plugins/*.py{,c,o}'
37-
((${#files[@]})) &&
37+
((${#files[@]})) || return
38+
_comp_compgen -U files split -- "$(
3839
printf '%s\n' "${files[@]}" |
39-
command sed -ne 's|.*/\([^./]*\)\.py[co]\{0,1\}$|\1|p' | sort -u
40+
command sed -ne 's|.*/\([^./]*\)\.py[co]\{0,1\}$|\1|p' | sort -u
41+
)"
4042
}
4143

4244
_comp_cmd_yum()
@@ -105,16 +107,17 @@ _comp_cmd_yum()
105107
_comp_compgen_filedir -d
106108
;;
107109
--enablerepo)
108-
_comp_compgen_split -- "$(_yum_repolist disabled)"
110+
_comp_cmd_yum__compgen_repolist disabled
109111
;;
110112
--disablerepo)
111-
_comp_compgen_split -- "$(_yum_repolist enabled)"
113+
_comp_cmd_yum__compgen_repolist enabled
112114
;;
113115
--disableexcludes)
114-
_comp_compgen_split -- "$(_yum_repolist all) all main"
116+
_comp_cmd_yum__compgen_repolist all
117+
_comp_compgen -a -- -W "all main"
115118
;;
116119
--enableplugin | --disableplugin)
117-
_comp_compgen_split -- "$(_yum_plugins)"
120+
_comp_cmd_yum__compgen_plugins
118121
;;
119122
--color)
120123
_comp_compgen -- -W 'always auto never'

completions/a2x

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ _comp_cmd_a2x()
1717
return
1818
;;
1919
--doctype | -${noargopts}d)
20-
_comp_xfunc asciidoc doctype
20+
_comp_compgen -x asciidoc doctype
2121
return
2222
;;
2323
--stylesheet)

completions/apt-build

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ _comp_cmd_apt_build()
1616
if [[ $special ]]; then
1717
case $special in
1818
install | source | info)
19-
COMPREPLY=($(_comp_xfunc apt-cache packages))
19+
_comp_compgen -x apt-cache packages
2020
;;
2121
remove)
22-
_comp_xfunc dpkg installed_packages
22+
_comp_compgen -x dpkg installed_packages
2323
;;
2424
esac
2525
return

completions/apt-cache

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,60 @@
11
# Debian apt-cache(8) completion -*- shell-script -*-
22

33
# List APT binary packages
4-
# TODO:API: make it a generator
54
# @since 2.12
6-
_comp_xfunc_apt_cache_packages()
5+
_comp_xfunc_apt_cache_compgen_packages()
76
{
8-
_comp_cmd_apt_cache__packages apt-cache
7+
_comp_cmd_apt_cache__compgen_packages apt-cache
98
}
109

11-
# TODO:API: make it a generator
12-
_comp_cmd_apt_cache__packages()
10+
# List APT binary packages
11+
# @param $1 Name of executable
12+
_comp_cmd_apt_cache__compgen_packages()
1313
{
14-
"$1" --no-generate pkgnames "$cur" 2>/dev/null || :
14+
_comp_compgen_split -- "$("$1" --no-generate pkgnames "$cur" 2>/dev/null)"
1515
}
1616

1717
# List APT source packages
18-
# TODO:API: make it a generator
1918
# @since 2.12
20-
_comp_xfunc_apt_cache_sources()
19+
_comp_xfunc_apt_cache_compgen_sources()
20+
{
21+
_comp_cmd_apt_cache__compgen_sources apt-cache
22+
}
23+
24+
# List APT source packages
25+
# @param $1 Name of executable
26+
_comp_cmd_apt_cache__compgen_sources()
2127
{
22-
_comp_cmd_apt_cache__sources apt-cache "$1"
28+
_comp_compgen_split -- "$("$1" dumpavail |
29+
awk '$1 == "Source:" { print $2 }' | sort -u)"
2330
}
2431

25-
# TODO:API: make it a generator
26-
_comp_cmd_apt_cache__sources()
32+
# List APT binary packages
33+
# @deprecated 2.12
34+
_apt_cache_packages()
2735
{
28-
local ret
29-
_comp_compgen -c "$2" -v ret split -- "$("$1" dumpavail |
30-
awk '$1 == "Source:" { print $2 }' | sort -u)" &&
31-
printf '%s\n' "${ret[@]}"
36+
local packages
37+
_comp_compgen -v packages -i apt-cache packages apt-cache &&
38+
printf '%s\n' "${packages[@]}"
3239
}
3340

3441
# List APT source packages
35-
# TODO:API: make it a generator
36-
# @since 2.12
37-
_comp_xfunc_apt_cache_src_packages()
42+
# @deprecated 2.12
43+
_apt_cache_sources()
3844
{
39-
local ret
40-
_comp_compgen -v ret split -- \
41-
"$(_comp_cmd_apt_cache__sources apt-cache "$cur")" &&
42-
printf '%s\n' "${ret[@]}"
45+
local sources
46+
_comp_compgen -v sources -c "$1" -i apt-cache sources apt-cache &&
47+
printf '%s\n' "${sources[@]}"
4348
}
4449

45-
_comp_deprecate_func 2.12 _apt_cache_packages _comp_xfunc_apt_cache_packages
46-
_comp_deprecate_func 2.12 _apt_cache_sources _comp_xfunc_apt_cache_sources
47-
_comp_deprecate_func 2.12 _apt_cache_src_packages \
48-
_comp_xfunc_apt_cache_src_packages
50+
# List APT source packages
51+
# @deprecated 2.12
52+
_apt_cache_src_packages()
53+
{
54+
local sources
55+
_comp_compgen -v sources -i apt-cache sources apt-cache &&
56+
printf '%s\n' "${sources[@]}"
57+
}
4958

5059
_comp_cmd_apt_cache()
5160
{
@@ -69,11 +78,11 @@ _comp_cmd_apt_cache()
6978
;;
7079

7180
showsrc)
72-
COMPREPLY=($(_comp_cmd_apt_cache__sources "$1" "$cur"))
81+
_comp_cmd_apt_cache__compgen_sources "$1"
7382
;;
7483

7584
*)
76-
COMPREPLY=($(_comp_cmd_apt_cache__packages "$1"))
85+
_comp_cmd_apt_cache__compgen_packages "$1"
7786
;;
7887

7988
esac

completions/apt-get

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
# Debian apt-get(8) completion -*- shell-script -*-
22

33
# @since 2.12
4-
# TODO:API: make it a generator
5-
_comp_xfunc_apt_get_installed_packages()
4+
_comp_xfunc_apt_get_compgen_installed_packages()
65
{
76
if [[ -f /etc/debian_version ]]; then
87
# Debian system
9-
_comp_xfunc dpkg installed_packages
8+
_comp_compgen -x dpkg installed_packages
109
else
1110
# assume RPM based
12-
_comp_xfunc rpm installed_packages
11+
_comp_compgen -x rpm installed_packages
1312
fi
1413
}
1514

16-
_comp_deprecate_func 2.12 _comp_cmd_apt_get_installed_packages \
17-
_comp_xfunc_apt_get_installed_packages
18-
1915
_comp_cmd_apt_get()
2016
{
2117
local cur prev words cword comp_args package
@@ -32,13 +28,13 @@ _comp_cmd_apt_get()
3228
if [[ $special ]]; then
3329
case $special in
3430
remove | auto?(-)remove | purge)
35-
_comp_xfunc_apt_get_installed_packages
31+
_comp_xfunc_apt_get_compgen_installed_packages
3632
;;
3733
source)
3834
# Prefer `apt-cache` in the same dir as command
3935
local pathcmd
4036
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
41-
COMPREPLY=($(_comp_xfunc apt-cache packages))
37+
_comp_compgen -x apt-cache packages
4238
_comp_compgen -a split -- "$(apt-cache dumpavail |
4339
awk '$1 == "Source:" { print $2 }' | sort -u)"
4440
;;
@@ -64,7 +60,7 @@ _comp_cmd_apt_get()
6460
_comp_looks_like_path "$cur" && return
6561
;;&
6662
*)
67-
COMPREPLY+=($(_comp_xfunc apt-cache packages))
63+
_comp_compgen -ax apt-cache packages
6864
;;
6965
esac
7066
return

completions/apt-mark

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ _comp_cmd_apt_mark()
2525
return
2626
;;
2727
*)
28-
_comp_xfunc apt-get installed_packages
28+
_comp_compgen -x apt-get installed_packages
2929
;;
3030
esac
3131
return

completions/aptitude

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ _comp_cmd_aptitude()
1818
install | hold | markauto | unmarkauto | dist-upgrade | full-upgrade | \
1919
safe-upgrade | download | show | changelog | why | why-not | build-dep | \
2020
add-user-tag | remove-user-tag | versions)
21-
COMPREPLY=($(_comp_xfunc apt-cache packages))
21+
_comp_compgen -x apt-cache packages
2222
return
2323
;;
2424
purge | remove | reinstall | forbid-version)
25-
_comp_xfunc dpkg installed_packages
25+
_comp_compgen -x dpkg installed_packages
2626
return
2727
;;
2828
unhold)
29-
_comp_xfunc dpkg held_packages
29+
_comp_compgen -x dpkg held_packages
3030
return
3131
;;
3232
esac

completions/asciidoc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# asciidoc(1) completion -*- shell-script -*-
22

33
# @since 2.12
4-
# TODO:API: make it a default, replace by default
5-
_comp_xfunc_asciidoc_doctype()
4+
_comp_xfunc_asciidoc_compgen_doctype()
65
{
7-
_comp_compgen -a -- -W 'article book manpage'
6+
_comp_compgen -- -W 'article book manpage'
87
}
98

10-
_comp_deprecate_func 2.12 _asciidoc_doctype _comp_xfunc_asciidoc_doctype
9+
# @deprecated 2.12
10+
_asciidoc_doctype()
11+
{
12+
_comp_compgen -ax asciidoc doctype
13+
}
1114

1215
_comp_cmd_asciidoc()
1316
{
@@ -29,7 +32,7 @@ _comp_cmd_asciidoc()
2932
return
3033
;;
3134
--doctype | -${noargopts}d)
32-
_comp_xfunc_asciidoc_doctype
35+
_comp_xfunc_asciidoc_compgen_doctype
3336
return
3437
;;
3538
--help | -${noargopts}h)

completions/bts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ _comp_cmd_bts__compgen_cached_bugs()
1515
# Generate APT source packages prefixed with "src:"
1616
_comp_cmd_bts__compgen_src_packages_with_prefix()
1717
{
18-
local ppn=${cur:4} # partial package name, after stripping "src:"
19-
_comp_compgen -c "$ppn" -U ppn split -P "src:" -- \
20-
"$(_comp_xfunc apt-cache sources "$ppn")"
18+
local _ppn=${cur:4} # partial package name, after stripping "src:"
19+
local sources
20+
_comp_compgen -v sources -c "$_ppn" -x apt-cache sources &&
21+
_comp_compgen -U sources -- -P "src:" -W '"${sources[@]}"'
2122
}
2223

2324
_comp_cmd_bts()
@@ -62,17 +63,17 @@ _comp_cmd_bts()
6263
return
6364
;;
6465
package)
65-
COMPREPLY=($(_comp_xfunc apt-cache packages))
66+
_comp_compgen -x apt-cache packages
6667
return
6768
;;
6869
cache)
69-
COMPREPLY=($(_comp_xfunc apt-cache packages))
70+
_comp_compgen -x apt-cache packages
7071
_comp_compgen -ai bts src_packages_with_prefix
7172
_comp_compgen -a -- -W 'from: release-critical RC'
7273
return
7374
;;
7475
cleancache)
75-
COMPREPLY=($(_comp_xfunc apt-cache packages))
76+
_comp_compgen -x apt-cache packages
7677
_comp_compgen -ai bts src_packages_with_prefix
7778
_comp_compgen -a -- -W 'from: tag: usertag: ALL'
7879
return
@@ -86,7 +87,8 @@ _comp_cmd_bts()
8687
# COMP_WORDS would be: "bts cleancache src : <partial_pkg_name>"
8788
pos=$((COMP_CWORD - 2))
8889
if [[ $pos -gt 0 && ${COMP_WORDS[pos]} == "src" ]]; then
89-
COMPREPLY=($(_comp_xfunc apt-cache src_packages))
90+
_comp_compgen -x apt-cache sources
91+
9092
return
9193
fi
9294
;;

0 commit comments

Comments
 (0)