2020-09-22 17:12:40 +00:00
|
|
|
function __fish_print_apt_packages
|
|
|
|
argparse --name=__fish_print_packages i/installed -- $argv
|
|
|
|
or return
|
|
|
|
|
|
|
|
switch (commandline -ct)
|
|
|
|
case '-**'
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2023-02-05 22:17:08 +00:00
|
|
|
set -l search_term (commandline -ct | string replace -ar '[\'"\\\\]' '' | string lower)
|
|
|
|
|
|
|
|
if ! test -f /var/lib/dpkg/status
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
|
|
|
# Do not not use `apt-cache` as it is sometimes inexplicably slow (by multiple orders of magnitude).
|
2020-09-22 17:24:04 +00:00
|
|
|
if not set -q _flag_installed
|
2023-05-04 02:27:46 +00:00
|
|
|
awk '
|
2023-02-05 22:17:08 +00:00
|
|
|
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
|
2023-06-01 16:20:19 +00:00
|
|
|
}' </var/lib/dpkg/status
|
2020-09-22 17:12:40 +00:00
|
|
|
else
|
2023-05-04 02:27:46 +00:00
|
|
|
awk '
|
2023-02-05 22:17:08 +00:00
|
|
|
BEGIN {
|
|
|
|
FS=": "
|
|
|
|
}
|
|
|
|
|
|
|
|
/^Package/ {
|
|
|
|
pkg=$2
|
|
|
|
}
|
|
|
|
|
|
|
|
/^Status/ {
|
|
|
|
installed=0
|
|
|
|
if ($2 ~ /(^|\s)installed/) {
|
|
|
|
installed=1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/^Description(-[a-zA-Z]+)?:/ {
|
|
|
|
desc=$2
|
|
|
|
if (installed == 1 && index(pkg, "'$search_term'") > 0) {
|
|
|
|
print pkg "\t" desc
|
|
|
|
installed=0 # Prevent multiple description translations from being printed
|
|
|
|
}
|
2023-06-01 16:20:19 +00:00
|
|
|
}' </var/lib/dpkg/status
|
2020-09-22 17:12:40 +00:00
|
|
|
end
|
|
|
|
end
|