From: Axel Beckert <abe@debian.org>
To: zsh-workers@zsh.org, pkg-zsh-devel@alioth-lists.debian.net
Subject: Re: apt autocompletion issue
Date: Tue, 30 Jul 2019 16:53:54 +0200 [thread overview]
Message-ID: <20190730145353.k2eonyy6w2z7luau@sym.noone.org> (raw)
In-Reply-To: <325f29f5-fc1c-46fb-94eb-5c6589536652@www.fastmail.com> <79188-1564444425.709181@h-V7.a7lO.lIR7>
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@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
next prev parent reply other threads:[~2019-07-30 14:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-26 16:20 Hauser, Felix (MRT)
2019-07-29 23:53 ` Oliver Kiddle
2019-07-30 11:49 ` Hauser, Felix (MRT)
2019-07-30 13:02 ` Daniel Shahaf
2019-07-30 14:53 ` Axel Beckert [this message]
2019-07-30 22:13 ` Oliver Kiddle
2019-07-30 23:21 ` aptitude vs apt vs apt-get (was: Re: [Pkg-zsh-devel] apt autocompletion issue) Axel Beckert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190730145353.k2eonyy6w2z7luau@sym.noone.org \
--to=abe@debian.org \
--cc=pkg-zsh-devel@alioth-lists.debian.net \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).