Skip to content

Commit 1e11613

Browse files
committed
refactor(bts): {_ => _comp_cmd_bts__}{cached_bugs,src_packages_*}
1 parent 70a36d9 commit 1e11613

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

completions/bts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
# bts completion -*- shell-script -*-
22

3-
# List bug numbers from bugs cache in ~/.devscripts_cache/bts
4-
# TODO:API: rename per conventions, rework to use vars rather than outputting
5-
_cached_bugs()
3+
# Generate bug numbers from bugs cache in ~/.devscripts_cache/bts
4+
# TODO:API: generator
5+
_comp_cmd_bts__cached_bugs()
66
{
7-
[[ -d $HOME/.devscripts_cache/bts ]] &&
7+
[[ -d $HOME/.devscripts_cache/bts ]] || return 1
8+
local bugs=$(
89
find "$HOME/.devscripts_cache/bts" -maxdepth 1 \
910
-name "${cur}[0-9]*.html" \
1011
-printf "%f\n" | cut -d'.' -f1
12+
)
13+
_comp_compgen -aR -- -W '$bugs'
1114
}
1215

13-
# List APT source packages prefixed with "src:"
14-
# TODO:API: rename per conventions, rework to use vars rather than outputting
15-
_src_packages_with_prefix()
16+
# Generate APT source packages prefixed with "src:"
17+
# TODO:API: generator
18+
_comp_cmd_bts__src_packages_with_prefix()
1619
{
17-
ppn=${cur:4} # partial package name, after stripping "src:"
18-
compgen -P "src:" -W '$(_comp_xfunc apt-cache sources "$ppn")' \
19-
-- "$ppn"
20+
local ppn=${cur:4} # partial package name, after stripping "src:"
21+
_comp_compgen -ac "$ppn" -- -P "src:" -W '$(_comp_xfunc apt-cache sources "$ppn")'
2022
}
2123

2224
_comp_cmd_bts()
@@ -26,9 +28,9 @@ _comp_cmd_bts()
2628

2729
case $prev in
2830
show | bugs)
29-
COMPREPLY=($(compgen -W 'release-critical RC from: tag:
30-
usertag:' -- "$cur") $(_cached_bugs)
31-
$(_src_packages_with_prefix))
31+
_comp_compgen -- -W 'release-critical RC from: tag: usertag:'
32+
_comp_cmd_bts__cached_bugs
33+
_comp_cmd_bts__src_packages_with_prefix
3234
return
3335
;;
3436
select)
@@ -38,8 +40,8 @@ _comp_cmd_bts()
3840
return
3941
;;
4042
status)
41-
COMPREPLY=($(compgen -W 'file: fields: verbose' -- "$cur")
42-
$(_cached_bugs))
43+
_comp_compgen -- -W 'file: fields: verbose'
44+
_comp_cmd_bts__cached_bugs
4345
return
4446
;;
4547
block | unblock)
@@ -57,23 +59,24 @@ _comp_cmd_bts()
5759
return
5860
;;
5961
clone | "done" | reopen | archive | unarchive | retitle | summary | submitter | found | notfound | fixed | notfixed | merge | forcemerge | unmerge | claim | unclaim | forwarded | notforwarded | owner | noowner | subscribe | unsubscribe | reportspam | spamreport | affects | usertag | usertags | reassign | tag | tags)
60-
COMPREPLY=($(_cached_bugs))
62+
COMPREPLY=()
63+
_comp_cmd_bts__cached_bugs
6164
return
6265
;;
6366
package)
6467
COMPREPLY=($(_comp_xfunc apt-cache packages))
6568
return
6669
;;
6770
cache)
68-
COMPREPLY=($(_comp_xfunc apt-cache packages)
69-
$(_src_packages_with_prefix)
70-
$(compgen -W 'from: release-critical RC' -- "$cur"))
71+
COMPREPLY=($(_comp_xfunc apt-cache packages))
72+
_comp_cmd_bts__src_packages_with_prefix
73+
_comp_compgen -a -- -W 'from: release-critical RC'
7174
return
7275
;;
7376
cleancache)
74-
COMPREPLY=($(_comp_xfunc apt-cache packages)
75-
$(_src_packages_with_prefix)
76-
$(compgen -W 'from: tag: usertag: ALL' -- "$cur"))
77+
COMPREPLY=($(_comp_xfunc apt-cache packages))
78+
_comp_cmd_bts__src_packages_with_prefix
79+
_comp_compgen -a -- -W 'from: tag: usertag: ALL'
7780
return
7881
;;
7982
user)

0 commit comments

Comments
 (0)