[Pkg-zsh-devel] debbugs bug number completion += bug subjects

Daniel Shahaf danielsh at apache.org
Sat Aug 20 23:10:23 UTC 2016


zsh master has bug number completion:

    % bts tag 82<TAB>
    > bug number
     …0510   …0947   …0951

I've patched that completion to show bug subjects:

    % bts close type<TAB>
    > bug number
    778512  - mr: "unknown repository type" if config file is a symlink - Debian 
    796872  - vim: E676 saving a buftype=nofile buffer - Debian Bug report logs
    814753  - scummvm-tools: FTBFS on non-Linux: #error No system type defined - 

I wonder what to do with this patch: on the one hand, I'm not sure the
extraction of <title>s into $descs is robust enough to be accepted by
upstream; on the other hand, the patch works, and I suspect I'm not the
only one who would find it useful.

WDYT?

Cheers,

Daniel

P.S. The patch is against master; to try it with 5.2 or 5.0.7, just drop
the _debbugs_bugnumber and _bts functions from upstream master into your
$fpath.

commit 6968e3186850fdb9f5892786b2be18a394be20ae
Author: Daniel Shahaf <d.s at daniel.shahaf.name>
Date:   Sat 20 Aug 2016 22:55:56 +0000

    WIP: _debbugs_bugnumber: Complete bug title to bug number

    TODO: review behaviour when there's a single match
    TODO: let user specify case-insensitive matching?

diff --git a/Completion/Debian/Type/_debbugs_bugnumber b/Completion/Debian/Type/_debbugs_bugnumber
index f7b0905..7db96e5 100644
--- a/Completion/Debian/Type/_debbugs_bugnumber
+++ b/Completion/Debian/Type/_debbugs_bugnumber
@@ -1,9 +1,22 @@
 #autoload
-# TODO: use _describe with some basic metadata (e.g., bug title/package/version)
-
-[[ $PREFIX$SUFFIX == [0-9]# ]] || return 1
-
 # The cache directory moved; try both locations.
 # ### TODO: Use 'bts listcachedbugs'?
-local -a cachedirs=( ~/.devscripts_cache/bts ~/.cache/devscripts/bts )
+local -a cachedirs; cachedirs=( ~/.devscripts_cache/bts ~/.cache/devscripts/bts )
-_wanted -x bugnum expl 'bug number' compadd -- $^cachedirs/<->.(html|mbox)(N:t:r)
+
+local -a descs; descs=(
+  ${(f)"$(<$^cachedirs/*html(N) grep -o '<title>.*</title>' | tr \> \< | cut -d \< -f3 | perl -MHTML::Entities -lnE 'say decode_entities s/^#(\d+) - /\1:/r')"}
+)
+
+if (( $+descs[1] )); then
+  if [[ $PREFIX$SUFFIX == [0-9]# ]]; then
+    _describe -t bugnum 'bug number' descs
+  else
+    descs=( ${(M)descs:#*${~words[CURRENT]}*} )
+    # This bit borrowed from _pids
+    _describe -t bugnum 'bug number' descs -P "$IPREFIX" -S "$ISUFFIX" -U
+    compstate[insert]=menu
+    compstate[list]='list force' # for confirmation
+  fi
+else
+  _message 'bug number'
+fi

P.P.S. HTML::Entities is a dependency of libwww-perl which is
a dependency of 'bts cache' — by which I mean, 'bts cache' will fail to
run if libwww-perl is not installed.



More information about the Pkg-zsh-devel mailing list