no bash-completion for pull-lp-source (and probably others)

Bug #1797290 reported by Rolf Leggewie
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
ubuntu-dev-tools (Ubuntu)
New
Low
Dan Streetman

Bug Description

It would be nice if the package offered bash-completion for pull-lp-source and other binaries or CLI tools where appropriate. I just tried "pull-lp-source wmcTAB" and expected it to complete to wmctrl.

Tags: bioinic
Revision history for this message
Dan Streetman (ddstreet) wrote :

This has bugged me too, unless someone else gets to this first I'll take a look at adding it.

Revision history for this message
Mattia Rizzolo (mapreri) wrote :

I recommend you look at python3-argcomplete for this :)

Revision history for this message
Dan Streetman (ddstreet) wrote :

python3-argcomplete does seem quite useful for complex pythonic autocompletion, but it seems to have downside as well - users will need to run a script to set it up first:
https://pypi.org/project/argcomplete/#activating-global-completion

am I misunderstanding that? Seems like a fairly big ask for users to have to know to 'set up' their global argcomplete before it works at all. Maybe the debian/ubuntu python[3]-argcomplete pkg should invoke the global activation script on deb install?

plus, for this use case, it really does seem like just a good-old bash completion function is easier, at least to start with.

First, I think the "best" way to generate the list of autocomplete pkgs would be to get the current list of all source and binary package names from lp. However, that's basically a non-starter as it would take way, way too long for autocomplete purposes. Caching it all would be good, but (assuming we don't want to create a background cache update just for this) it would prevent autocomplete until the cache was up to date.

As a compromise, I think using apt's package cache will be "good enough", at least to start with. It's actually rather trivial to do that; for quick testing:

$ _pullpkg() { local cur; _init_completion || return; COMPREPLY=($( apt-cache --no-generate pkgnames "$cur" 2> /dev/null )); return 0; }
$ complete -F _pullpkg pull-lp-source

After that, in the bash shell where you ran those cmds, pull-lp-source should autocomplete any/all package names. Those 2 lines can be dropped into ~/.bash_completion (or a file in /usr/share/bash-completion/completions/ or /etc/bash_completions.d/) and all new shells will pick up the autocompletion.

Unfortunately that still isn't quite perfect; for example there are lots and lots (and lots and LOTS) of different kernel package names. If I'm running bionic but I want to pull a specific kernel from trusty, the apt autocompletion won't provide those package names (because each kernel package has version-specific naming). It might be worth trying to use the apt cache for the first 3 (or so) letters of a package name, but after that switch to real LP querying (hopefully with caching). Or, maybe we could use a LP package local cache, but if that's not populated yet fall back to apt caching.

Changed in ubuntu-dev-tools (Ubuntu):
assignee: nobody → Dan Streetman (ddstreet)
importance: Undecided → Low
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.