mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-28 13:53:10 +00:00
__fish_print_apt_packages: stringify
GNU tr is not Unicode-aware, and was corrupting descriptions that had non-ASCII characters. Additionally, rather than using the Unicode private use characters, use the ASCII/UTF-8 record separator character as it was intended. The sed command could probably be rewritten to do all the heavy lifting here, but would be even less readable. Closes #8575.
This commit is contained in:
parent
41da16408a
commit
b4e8e5abff
1 changed files with 8 additions and 5 deletions
|
@ -12,20 +12,23 @@ function __fish_print_apt_packages
|
||||||
# Do not generate the cache as apparently sometimes this is slow.
|
# Do not generate the cache as apparently sometimes this is slow.
|
||||||
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=547550
|
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=547550
|
||||||
# (It is safe to use `sed -r` here as we are guaranteed to be on a GNU platform
|
# (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
|
# if apt-cache was found.)
|
||||||
# little-endian bytecode equivalent in `sed`. Supports localization.)
|
# Uses the UTF-8/ASCII record separator (0x1A) character.
|
||||||
#
|
#
|
||||||
# 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 in the name,
|
||||||
# we're safe. (yes, this should absolutely have a better format).
|
# 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
|
#
|
||||||
|
# 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
|
||||||
|
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' | 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\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\x1a\n/g' | string join "" | string replace --all --regex \x1a+ \n | uniq
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue