Completions: Adjust apt-cache output limit

The limit has been reduced to 2500 to match the limit on what we actually
consume downstream in the actual `complete -c apt ...` rule, as discussed [0].

[0]: https://github.com/fish-shell/fish-shell/commit/b88b2577267c6837886c93c
This commit is contained in:
Mahmoud Al-Qudsi 2022-10-03 18:29:41 -05:00
parent 757c117591
commit cdfa76221e

View File

@ -18,20 +18,21 @@ function __fish_print_apt_packages
# Note: This can include "Description:" fields which we need to include, # Note: This can include "Description:" fields which we need to include,
# "Description-en_GB" (or another locale code) fields which we need to include # "Description-en_GB" (or another locale code) fields which we need to include
# as well as "Description-md5" fields which we absolutely do *not* want to include # as well as "Description-md5" fields which we absolutely do *not* want to include
# The regex doesn't allow numbers, so unless someone makes a hash algorithm without a number in the name, # The regex doesn't allow numbers, so unless someone makes a hash algorithm without a number
# we're safe. (yes, this should absolutely have a better format). # in the name, we're safe. (yes, this should absolutely have a better format).
# #
# aptitude has options that control the output formatting, but is orders of magnitude slower # aptitude has options that control the output formatting, but is orders of magnitude slower
# #
# sed could probably do all of the heavy lifting here, but would be even less readable # sed could probably do all of the heavy lifting here, but would be even less readable
# #
# The `head -n2500` causes us to stop once we have 2500 lines. We do it after the `sed` because # The `head -n 500` causes us to stop once we have 500 lines. We do it after the `sed` because
# Debian package descriptions can be extremely long - texlive-latex-extra has about 2700 lines in Debian 11. # Debian package descriptions can be extremely long and are hard-wrapped: texlive-latex-extra
apt-cache --no-generate show '.*'(commandline -ct)'.*' 2>/dev/null | sed -r '/^(Package|Description-?[a-zA-Z_]*):/!d;s/Package: (.*)/\1\t/g;s/Description-?[^:]*: (.*)/\1\x1a\n/g' | head -n 2500 | string join "" | string replace --all --regex \x1a+ \n | uniq # has about 2700 lines on Debian 11.
apt-cache --no-generate show '.*'(commandline -ct)'.*' 2>/dev/null | sed -r '/^(Package|Description-?[a-zA-Z_]*):/!d;s/Package: (.*)/\1\t/g;s/Description-?[^:]*: (.*)/\1\x1a\n/g' | head -n 500 | string join "" | string replace --all --regex \x1a+ \n | uniq
return 0 return 0
else else
set -l packages (dpkg --get-selections | string replace -fr '(\S+)\s+install' "\$1" | string match -e (commandline -ct)) set -l packages (dpkg --get-selections | string replace -fr '(\S+)\s+install' "\$1" | string match -e (commandline -ct))
apt-cache --no-generate show $packages 2>/dev/null | sed -r '/^(Package|Description-?[a-zA-Z_]*):/!d;s/Package: (.*)/\1\t/g;s/Description-?[^:]*: (.*)/\1\x1a\n/g' | head -n 2500 | string join "" | string replace --all --regex \x1a+ \n | uniq apt-cache --no-generate show $packages 2>/dev/null | sed -r '/^(Package|Description-?[a-zA-Z_]*):/!d;s/Package: (.*)/\1\t/g;s/Description-?[^:]*: (.*)/\1\x1a\n/g' | head -n 500 | string join "" | string replace --all --regex \x1a+ \n | uniq
return 0 return 0
end end
end end