From 672fdde1f07883e45728ea19bcc2bae2e66e5a97 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 4 Dec 2020 16:43:15 +0100 Subject: [PATCH] __fish_print_packages: Better parse apt-cache's weird format Fixes #7521. --- share/functions/__fish_print_packages.fish | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/share/functions/__fish_print_packages.fish b/share/functions/__fish_print_packages.fish index 09ab9b958..0572b553a 100644 --- a/share/functions/__fish_print_packages.fish +++ b/share/functions/__fish_print_packages.fish @@ -23,11 +23,17 @@ function __fish_print_packages # (It is safe to use `sed -r` here as we are guaranteed to be on a GNU platform # if apt-cache was found. Using unicode reserved range in `fish/tr` and the # little-endian bytecode equivalent in `sed`. Supports localization.) - apt-cache --no-generate show '.*'(commandline -ct)'.*' 2>/dev/null | sed -r '/^(Package|Description-?[a-z]{0,2}):/!d;s/Package: (.*)/\1\t/g;s/Description-?[^:]*: (.*)/\1\xee\x80\x80\x0a/g' | tr -d \n | tr -s \uE000 \n | uniq + # + # 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 + # The regex doesn't allow numbers, so unless someone makes a hash algorithm without a number in the name, + # we're safe. (yes, this should absolutely have a better format). + 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\xee\x80\x80\x0a/g' | tr -d \n | tr -s \uE000 \n | uniq return else 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-z]{0,2}):/!d;s/Package: (.*)/\1\t/g;s/Description-?[^:]*: (.*)/\1\xee\x80\x80\x0a/g' | tr -d \n | tr -s \uE000 \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\xee\x80\x80\x0a/g' | tr -d \n | tr -s \uE000 \n | uniq return end