[Pkg-zsh-devel] apt autocompletion issue

Axel Beckert abe at debian.org
Tue Jul 30 15:53:54 BST 2019


Hi,

TL;DR: I recommend to just complete all packages upon
"apt list --upgradable <Tab>".

Oliver Kiddle wrote:
> On 26 Jul, "Hauser, Felix (MRT)" wrote:
> > just discovered the Z-shell and so far it really makes my life a little 
> > bit easier! The only issue I have with it is the completion of options 
> > for the apt command. So e.g.:
> >
> > apt list --u<tab>
> >
> > won't autocomplete to
> >
> > apt list --upgradeable
> >
> > which is easily done in the normal bash file.

Should be easy in zsh, too, as the number of long options behind "apt
list" isn't that big IIRC.

> It's not clear from the man page whether the three options can be
> combined with the glob(7) patterns for matching packages (as per the
> patch below) or whether they need to be standalone.

Indeed. Just from testing, there are additional filters possible:

→ apt list --installed 'z*'
Listing... Done
zathura-cb/stable,now 0.1.8-2 amd64 [installed,automatic]
zathura-djvu/stable,now 0.2.8-1 amd64 [installed,automatic]
[…]
zsh/stable,now 5.7.1-1 amd64 [installed,automatic]
zutils/stable,now 1.8-3+b10 amd64 [installed,automatic]
zziplib-bin/stable,now 0.13.62-3.2 amd64 [installed]
zzuf/stable,now 0.15-1+b1 amd64 [installed]
→ 

But I think the primary issue of Felix is that not even the (rather
unambiguous) options are completed.

> The option should probably modify whether it is calling _deb_packages
> with "avail", "installed", "uninstalled" or some other package set. If
> you let me know what the relevant package set argument should be for
> each option, then it is easy to do that.

It makes sense that "apt list --installed <Tab>" only completes
installed packages as it will only list these anyway.

It makes sense that "apt list --upgradable <Tab>" (and "apt list
--upgradeable <Tab>") only completes packages as it will only list
these anyway.

And "apt list --all-versions <Tab>" should probably complete all
packages.

Daniel Shahaf wrote:
> Hauser, Felix (MRT) wrote on Tue, 30 Jul 2019 11:50 +00:00:
> > --upgradeable Do not know the option for this one. Result should be a 
> > list of all packages that can be updated by "apt upgrade".
> 
> «aptitude search -F %p '?upgradable'» would print the right set of
> packages, I think, but aptitude isn't part of a minimal installation so
> can't be assumed available.

Correct. Don't expect it to be there, it's no more installed by
default. (Saying that with my "apt+aptitude team" member hat on,
although I'm mostly only working on aptitude. :-)

It seems obvious that "apt list --installed <Tab>" should be completed
with what "apt list --installed" outputs and "apt list --upgradable
<Tab>" and "apt list --upgradeable <Tab>" with what "apt list
--upgradeable" outputs.

But: "apt" output is not yet considered to be stable and hence emits
the following warning on STDERR when used inside a pipe or similar:

  WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

> I'm not sure what's the best way to answer this question on a minimal
> installation.  One _could_ parse the output of «apt-cache policy \*»,
> but I hope there's a better way...

Currently I don't know any efficient _and_ scriptable method to do
that. (Calling "apt-cache policy \*" to see if it's installed or
upgradeable is the only method which comes to my mind, too, but also
rather slow and inefficient.

> Cc += Debian zsh packagers.

Thanks. I read Felix initial mail, but just adding three hard coded
long options seemed rather trivial...

> tl;dr: What apt(7) command generates the right set of packages to be
> completed after «apt list --upgradable <TAB>»?

"apt list --upgradable", but see above.

Officially, there is currently no scriptable interface which offers
that. aptitude-like pattern matching is planned for
apt/apt-get/apt-cache as well, but not yet there.

And parsing /var/lib/apt/lists/* is explicitly discouraged as the
format might change without notice. (Zsh seems to do that somewhere
else already and I get according warnings when in building the zsh
package for Debian:
https://lintian.debian.org/tags/uses-dpkg-database-directly.html)

So we basically have these options:

* Use "apt list --<something>" and have to adapt quickly when the
  output format changes.

* Parse the output of "apt-cache policy \*". (Probably the best way if
  we want to really only list upgradable packages there.)

* Parse /var/lib/apt/archives/*.packages (format might change over
  time, too), /etc/apt/preferences and /etc/apt/preferences.d/*.

* Completely ignore any "apt list" option and just complete all known
  packages. This seems to be a easily done solution and I consider it
  valid, because it is a valid call to pass not upgradable or
  installed packages even with --installed or --upgradable:

  → apt list --installed systemd zsh
  Listing... Done
  zsh/stable,now 5.7.1-1 amd64 [installed,automatic]
  →

  (i.e. in this example, systemd is not installed and zsh is
  installed.)

Installed packages are easier to generated as they can be queried with
dpkg-query which has options for machine-readable formatting.

		Regards, Axel
-- 
 ,''`.  |  Axel Beckert <abe at debian.org>, https://people.debian.org/~abe/
: :' :  |  Debian Developer, ftp.ch.debian.org Admin
`. `'   |  4096R: 2517 B724 C5F6 CA99 5329  6E61 2FF9 CD59 6126 16B5
  `-    |  1024D: F067 EA27 26B9 C3FC 1486  202E C09E 1D89 9593 0EDE



More information about the Pkg-zsh-devel mailing list