Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: apt autocompletion issue




On 30.07.19 01:53, 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.
Since in my workflow I often have to use apt, this feature is kinda
important to me.

Thanks for the report. I'm afraid the Debian specific completions aren't
as well maintained as they once were.

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.

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.

Oliver

diff --git a/Completion/Debian/Command/_apt b/Completion/Debian/Command/_apt
index 4486aa26d..d36d5240a 100644
--- a/Completion/Debian/Command/_apt
+++ b/Completion/Debian/Command/_apt
@@ -399,7 +399,10 @@ _apt-cmd () {
      -o,--option:arbitem \
      -t,--target-release:release \
      -- \
-    /$'list\0'/ /$'[^\0]#\0'/ ':packages::_deb_packages "$expl_packages[@]" avail' \# \| \
+    /$'list\0'/ \( \
+      \( // %-% /$'--[^\0]#\0'/ ':options:option:(--installed --upgradable --all-versions)' \| \) \
+      /$'[^\0]#\0'/ ':packages::_deb_packages "$expl_packages[@]" avail' \# \
+    \) \| \
      /$'search\0'/ /$'[^\0]#\0'/ ':strings:pattern:' \| \
      /$'showsrc\0'/ /$'[^\0]#\0'/ ':packages::_deb_packages "$expl_packages[@]" avail' \# \| \
      /$'show\0'/ /$'[^\0]#\0'/ ':packages::_deb_packages "$expl_packages[@]" avail' \# \| \



Well, I guess the Debian package sets should be:
--installed "installed"
--all-versions "avail"
--upgradeable Do not know the option for this one. Result should be a list of all packages that can be updated by "apt upgrade".

But the problem is not only with "apt list" but with all apt commands.
The apt package brings its own detailed completion file (not via the bash-completions package):
https://salsa.debian.org/apt-team/apt/blob/master/completions/bash/apt
This is the one used by bash and is located at "/usr/share/bash-completion/completions/apt" on my system. Maybe zsh can simply access the bash completion file and ignore its own?? Not sure if this can be done ...

I hesitated replacing "/usr/share/zsh/functions/Completion/Debian/_apt" with the bash file, because in the zsh completion file there are also the instructions for apt-get etc.

Felix



Messages sorted by: Reverse Date, Date, Thread, Author