From 81cd0359509621bd8fb11556bdfd65462ede54a9 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Tue, 22 Aug 2023 22:17:22 +0200 Subject: [PATCH] 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 96deaae7d86edfbc16e411bdb73bf54ced7fb447 --- .../functions/__fish_print_apt_packages.fish | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/share/functions/__fish_print_apt_packages.fish b/share/functions/__fish_print_apt_packages.fish index 76c05ef5f..102895b1b 100644 --- a/share/functions/__fish_print_apt_packages.fish +++ b/share/functions/__fish_print_apt_packages.fish @@ -13,25 +13,30 @@ function __fish_print_apt_packages return 1 end - # Do not not use `apt-cache` as it is sometimes inexplicably slow (by multiple orders of magnitude). if not set -q _flag_installed - awk ' -BEGIN { - FS=": " -} - -/^Package/ { - pkg=$2 -} - -/^Description(-[a-zA-Z]+)?:/ { - desc=$2 - if (index(pkg, "'$search_term'") > 0) { - print pkg "\t" desc - } - pkg="" # Prevent multiple description translations from being printed -}' /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 + # Do not not use `apt-cache` as it is sometimes inexplicably slow (by multiple orders of magnitude). awk ' BEGIN { FS=": "