Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: apt autocompletion issue
- X-seq: zsh-workers 44591
- From: Axel Beckert <abe@xxxxxxxxxx>
- To: zsh-workers@xxxxxxx, pkg-zsh-devel@xxxxxxxxxxxxxxxxxxxxxxx
- Subject: Re: apt autocompletion issue
- Date: Tue, 30 Jul 2019 16:53:54 +0200
- Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAAAAAC3mUtaAAAABGdBTUEAALGPC/xhBQAAADh0RVh0U29mdHdhcmUAWFYgVmVyc2lvbiAzLjEwYSAgUmV2OiAxMi8yOS85NCAoUE5HIHBhdGNoIDEuMindFS5JAAACGElEQVQ4jXXQMU8UYRDG8f8shNjdDH4AbpfGDjAWlKiJiZ0ajL1aGCvsNCbGaCGG1koLaztaTYz6ATy+gOyehYmF3MxVxgg3FnDsHcTpJr/M+8w7Rf6nCsaVTTDqxbg9hoOXmw83H71+Eyfg4E1d7/Z2fG9rGkZbTQiu+K+3U/C+76lmkvAhJuDndnoAiftou4V84okAGclop4U/jYACZDTxrYWP0gkxVfAm/W//GLZpxIzwIN0Hn8dw0B+IWkZmQmRsj2HfhwokEklHfNCCiQCRgAR7YyhQVRVTCKCzP4Y5zBBE0t0zY3Q8oQaBqqAMlVEcgVQd9706zGirAFium8HXumlMIeMwqQCInju+2+uB6MRENupdpMt8pRlHZyuAW0F+Mb6XSIVqtxjD+iVmVqqystLEzFTGT92YqRaXpNT5eTVjeJhbALPnrTxLUZUKZsgxcNm64hAOYisT/xhF+oKTGU5RegtC3Rt6eEDi/QnIevdTx9Md2EMmYBRmCQR1026FCGQQJJExsRUqgkMGaWSbwYLnoO4T6VgpbQbdELPMBAHWWrhYrcxXnYgAsatPWygkFCBD4K62MAsOTqA6szYRPpsu6e6Y8mPiVrBMNuGIMrgwBUu4p2DgG1Ownu6hpuTv7hScefHAzAC/yRRw5U5pALMbJ4AUALvHSZhxgHPXTsHcdWD1GadAHr9avP+c0wCr7263Df8ASLwXWHWs+KIAAAAHdElNRQfYBQEBODPr
- In-reply-to: <325f29f5-fc1c-46fb-94eb-5c6589536652@www.fastmail.com> <79188-1564444425.709181@h-V7.a7lO.lIR7>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mail-followup-to: zsh-workers@xxxxxxx, pkg-zsh-devel@xxxxxxxxxxxxxxxxxxxxxxx
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- Organization: The Debian Project
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@xxxxxxxxxx>, 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author