[Bash-completion-devel] merging related completions into a file for dynamic loading?

Peter Cordes peter at cordes.ca
Sat Dec 13 00:42:27 UTC 2014


 apt-cache and apt-get completions use very similar commands, but
slightly different.  This is silly.  apt-get should just be a symlink
to apt-cache, with the contents in apt-cache.

e.g.
_apt_cache_sources() {
    apt-cache dumpavail | command grep "^Source: $1" | cut -f2 -d" " | sort -u
}

vs. apt-get's:

     source)
         COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \
 	     2> /dev/null ) $( apt-cache dumpavail | \
	     command grep "^Source: $cur" | sort -u | cut -f2 -d" " ) )
	 return 0
	 ;;

 Note that in apt-get's case, sort -u happens before stripping off the
optional (ver-number) after the package name, which is silly.  bash
sorts and uniques COMPREPLY before using it, anyway.  (Is this a new
feature, or can we go around stripping sort out of pipelines all over
the place?  I'm inclined to leave it in, in this case, to reduce the
amount of memory bash has to allocate.  I'm also thinking it wouldn't
be a bad idea to rearrange things so the sort -u happened on the
combined output of the available binary packages and the available
source packages.  (Since apt-get source will accept binary-package
names, and get the source for them.)

 So, thoughts on replacing some of the many files in completions/*
with symlinks to groups of related commands?

 And, thoughts on performance of bash with very large arrays to sort?
I did manage to get Ubuntu's  GNU bash, version 4.3.11(1)-release
(x86_64-pc-linux-gnu) to print an error and exit once, while testing
apt-get completions.  I don't have the exact message, or details of
what I completed, because my screen(1) window only stayed open showing
the error message for about a second.  And I didn't try to write it
down while I still remembered it, unfortunately.  So I guess my
thinking is that when we can bring COMPREPLY down from 100k to 50k
items with sort -u, it's not a bad idea.

-- 
#define X(x,y) x##y
Peter Cordes ;  e-mail: X(peter at cor , des.ca)

"The gods confound the man who first found out how to distinguish the hours!
 Confound him, too, who in this place set up a sundial, to cut and hack
 my day so wretchedly into small pieces!" -- Plautus, 200 BC
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 359 bytes
Desc: Digital signature
URL: <http://lists.alioth.debian.org/pipermail/bash-completion-devel/attachments/20141212/dd77020d/attachment.sig>


More information about the Bash-completion-devel mailing list