mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-14 00:47:30 +00:00
print_apt_packages: Go back to apt-cache for non-installed packages
Unfortunately, /var/lib/dpkg/status on recent-ish Debian versions at
least only contains the *installed* packages, rendering this solution
broken.
What we do instead is:
1. Remove a useless newline from each package, so our limit would now
let more full package data sets through
2. Increase the limit by 5x
This yields a completion that runs in ~800ms instead of ~700ms on a
raspberry pi, but gives ~10x the candidates, compared to the old
apt-cache version.
This partially reverts 96deaae7d8
This commit is contained in:
parent
36a7924fa8
commit
81cd035950
1 changed files with 22 additions and 17 deletions
|
@ -13,25 +13,30 @@ function __fish_print_apt_packages
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
# Do not not use `apt-cache` as it is sometimes inexplicably slow (by multiple orders of magnitude).
|
|
||||||
if not set -q _flag_installed
|
if not set -q _flag_installed
|
||||||
awk '
|
# Do not generate the cache as apparently sometimes this is slow.
|
||||||
BEGIN {
|
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=547550
|
||||||
FS=": "
|
# (It is safe to use `sed -r` here as we are guaranteed to be on a GNU platform
|
||||||
}
|
# if apt-cache was found.)
|
||||||
|
# Uses the UTF-8/ASCII record separator (0x1A) character.
|
||||||
/^Package/ {
|
#
|
||||||
pkg=$2
|
# Note: This can include "Description:" 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
|
||||||
/^Description(-[a-zA-Z]+)?:/ {
|
# The regex doesn't allow numbers, so unless someone makes a hash algorithm without a number
|
||||||
desc=$2
|
# in the name, we're safe. (yes, this should absolutely have a better format).
|
||||||
if (index(pkg, "'$search_term'") > 0) {
|
#
|
||||||
print pkg "\t" desc
|
# aptitude has options that control the output formatting, but is orders of magnitude slower
|
||||||
}
|
#
|
||||||
pkg="" # Prevent multiple description translations from being printed
|
# sed could probably do all of the heavy lifting here, but would be even less readable
|
||||||
}' </var/lib/dpkg/status
|
#
|
||||||
|
# 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 and are hard-wrapped: texlive-latex-extra
|
||||||
|
# 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/g' | head -n 2500 | string join "" | string replace --all --regex \x1a+ \n | uniq
|
||||||
|
return 0
|
||||||
else
|
else
|
||||||
|
# Do not not use `apt-cache` as it is sometimes inexplicably slow (by multiple orders of magnitude).
|
||||||
awk '
|
awk '
|
||||||
BEGIN {
|
BEGIN {
|
||||||
FS=": "
|
FS=": "
|
||||||
|
|
Loading…
Reference in a new issue