2018-07-02 16:40:01 +00:00
|
|
|
# Use --installed to limit to installed packages only
|
2006-02-08 09:20:05 +00:00
|
|
|
function __fish_print_packages
|
2020-03-09 18:36:12 +00:00
|
|
|
argparse --name=__fish_print_packages i/installed -- $argv
|
2019-05-05 10:09:25 +00:00
|
|
|
or return
|
|
|
|
|
2018-07-02 16:40:01 +00:00
|
|
|
set -l only_installed 1
|
|
|
|
if not set -q _flag_installed
|
|
|
|
set -e only_installed
|
|
|
|
end
|
2006-02-08 09:20:05 +00:00
|
|
|
|
2016-11-28 05:27:22 +00:00
|
|
|
# apt-cache is much, much faster than rpm, and can do this in real
|
|
|
|
# time. We use it if available.
|
|
|
|
|
2017-04-16 04:49:08 +00:00
|
|
|
switch (commandline -ct)
|
2016-11-28 05:27:22 +00:00
|
|
|
case '-**'
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if type -q -f apt-cache
|
2018-07-28 22:41:39 +00:00
|
|
|
if not set -q only_installed
|
2018-07-02 16:40:01 +00:00
|
|
|
# Do not generate the cache as apparently sometimes this is slow.
|
|
|
|
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=547550
|
2018-07-28 22:41:39 +00:00
|
|
|
# (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.)
|
2020-12-04 15:43:15 +00:00
|
|
|
#
|
|
|
|
# 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
|
2018-07-28 22:41:39 +00:00
|
|
|
return
|
|
|
|
else
|
|
|
|
set -l packages (dpkg --get-selections | string replace -fr '(\S+)\s+install' "\$1" | string match -e (commandline -ct))
|
2020-12-04 15:43:15 +00:00
|
|
|
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
|
2018-07-28 22:41:39 +00:00
|
|
|
|
2018-07-02 16:40:01 +00:00
|
|
|
return
|
|
|
|
end
|
2016-11-28 05:27:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Pkg is fast on FreeBSD and provides versioning info which we want for
|
|
|
|
# installed packages
|
2017-12-11 14:19:45 +00:00
|
|
|
if type -q -f pkg
|
2016-11-28 05:27:22 +00:00
|
|
|
pkg query "%n-%v"
|
|
|
|
return
|
|
|
|
end
|
2013-06-04 12:56:37 +00:00
|
|
|
|
2017-12-11 14:19:45 +00:00
|
|
|
# pkg_info on OpenBSD provides versioning info which we want for
|
|
|
|
# installed packages but, calling it directly can cause delays in
|
|
|
|
# returning information if another pkg_* tool have a lock.
|
|
|
|
# Listing /var/db/pkg is a clean alternative.
|
|
|
|
if type -q -f pkg_add
|
2017-12-21 15:43:21 +00:00
|
|
|
set -l files /var/db/pkg/*
|
2020-03-09 18:36:12 +00:00
|
|
|
string replace /var/db/pkg/ '' -- $files
|
2017-12-11 14:19:45 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-05-18 03:21:19 +00:00
|
|
|
### BEGIN CACHED RESULTS ###
|
|
|
|
|
|
|
|
# Set up cache directory
|
2020-05-15 05:56:06 +00:00
|
|
|
set -l xdg_cache_home $XDG_CACHE_HOME
|
|
|
|
if test -z "$xdg_cache_home"
|
|
|
|
set xdg_cache_home $HOME/.cache
|
2018-05-18 03:21:19 +00:00
|
|
|
end
|
2020-05-15 05:56:06 +00:00
|
|
|
mkdir -m 700 -p $xdg_cache_home
|
2018-05-18 03:21:19 +00:00
|
|
|
|
2014-02-14 01:41:53 +00:00
|
|
|
# Caches for 5 minutes
|
2016-11-28 05:27:22 +00:00
|
|
|
if type -q -f pacman
|
2020-03-14 14:11:33 +00:00
|
|
|
if not set -q only_installed
|
2020-05-15 05:56:06 +00:00
|
|
|
set -l cache_file $xdg_cache_home/.pac-cache.$USER
|
2020-03-14 14:11:33 +00:00
|
|
|
if test -f $cache_file
|
|
|
|
cat $cache_file
|
2020-05-15 05:56:06 +00:00
|
|
|
set -l age (math (date +%s) - (stat -c '%Y' $cache_file))
|
|
|
|
set -l max_age 250
|
2020-03-14 14:11:33 +00:00
|
|
|
if test $age -lt $max_age
|
|
|
|
return
|
|
|
|
end
|
2016-11-28 05:27:22 +00:00
|
|
|
end
|
2020-03-14 14:11:33 +00:00
|
|
|
# prints: <package name> Package
|
|
|
|
pacman -Ssq | sed -e 's/$/\t'Package'/' >$cache_file &
|
|
|
|
return
|
|
|
|
else
|
|
|
|
pacman -Q | string replace ' ' \t
|
|
|
|
return
|
2016-11-28 05:27:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Zypper needs caching as it is slow
|
|
|
|
if type -q -f zypper
|
|
|
|
# Use libzypp cache file if available
|
|
|
|
if test -f /var/cache/zypp/solv/@System/solv.idx
|
2020-02-28 12:37:14 +00:00
|
|
|
awk '!/application:|srcpackage:|product:|pattern:|patch:/ {print $1'\tPackage'}' /var/cache/zypp/solv/*/solv.idx
|
2016-11-28 05:27:22 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
# If the cache is less than five minutes old, we do not recalculate it
|
|
|
|
|
2020-05-15 05:56:06 +00:00
|
|
|
set -l cache_file $xdg_cache_home/.zypper-cache.$USER
|
2016-11-28 05:27:22 +00:00
|
|
|
if test -f $cache_file
|
|
|
|
cat $cache_file
|
2017-09-10 06:35:47 +00:00
|
|
|
set -l age (math (date +%s) - (stat -c '%Y' $cache_file))
|
2016-11-28 05:27:22 +00:00
|
|
|
set -l max_age 300
|
|
|
|
if test $age -lt $max_age
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Remove package version information from output and pipe into cache file
|
2020-02-28 12:37:14 +00:00
|
|
|
zypper --quiet --non-interactive search --type=package | tail -n +4 | sed -r 's/^. \| ((\w|[-_.])+).*/\1\t'Package'/g' >$cache_file &
|
2016-11-28 05:27:22 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
# yum is slow, just like rpm, so go to the background
|
|
|
|
if type -q -f /usr/share/yum-cli/completion-helper.py
|
|
|
|
|
|
|
|
# If the cache is less than six hours old, we do not recalculate it
|
|
|
|
|
2020-05-15 05:56:06 +00:00
|
|
|
set -l cache_file $xdg_cache_home/.yum-cache.$USER
|
2016-11-28 05:27:22 +00:00
|
|
|
if test -f $cache_file
|
|
|
|
cat $cache_file
|
2020-05-15 19:34:48 +00:00
|
|
|
set -l age (math (date +%s) - (stat -c '%Y' $cache_file))
|
|
|
|
set -l max_age 21600
|
2016-11-28 05:27:22 +00:00
|
|
|
if test $age -lt $max_age
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Remove package version information from output and pipe into cache file
|
2020-02-28 12:37:14 +00:00
|
|
|
/usr/share/yum-cli/completion-helper.py list all -d 0 -C | sed "s/\..*/\tPackage/" >$cache_file &
|
2016-11-28 05:27:22 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
# Rpm is too slow for this job, so we set it up to do completions
|
|
|
|
# as a background job and cache the results.
|
|
|
|
|
|
|
|
if type -q -f rpm
|
|
|
|
|
|
|
|
# If the cache is less than five minutes old, we do not recalculate it
|
|
|
|
|
2020-05-15 05:56:06 +00:00
|
|
|
set -l cache_file $xdg_cache_home/.rpm-cache.$USER
|
2016-11-28 05:27:22 +00:00
|
|
|
if test -f $cache_file
|
|
|
|
cat $cache_file
|
2020-05-15 19:34:48 +00:00
|
|
|
set -l age (math (date +%s) - (stat -c '%Y' $cache_file))
|
|
|
|
set -l max_age 250
|
2016-11-28 05:27:22 +00:00
|
|
|
if test $age -lt $max_age
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Remove package version information from output and pipe into cache file
|
2020-02-28 12:37:14 +00:00
|
|
|
rpm -qa | sed -e 's/-[^-]*-[^-]*$/\t'Package'/' >$cache_file &
|
2016-11-28 05:27:22 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-12-21 15:43:21 +00:00
|
|
|
# Eopkg is slow in showing list of available packages
|
|
|
|
|
|
|
|
if type -q -f eopkg
|
|
|
|
|
|
|
|
# If the cache is less than max_age, we do not recalculate it
|
2018-07-10 06:21:44 +00:00
|
|
|
# Determine whether to print installed/available packages
|
2017-12-21 15:43:21 +00:00
|
|
|
|
2018-07-10 06:21:44 +00:00
|
|
|
if set -q only_installed
|
2020-05-15 05:56:06 +00:00
|
|
|
set -l cache_file $xdg_cache_home/.eopkg-installed-cache.$USER
|
2018-07-10 06:21:44 +00:00
|
|
|
if test -f $cache_file
|
|
|
|
cat $cache_file
|
2020-05-15 19:34:48 +00:00
|
|
|
set -l age (math (date +%s) - (stat -c '%Y' $cache_file))
|
|
|
|
set -l max_age 500
|
2018-07-10 06:21:44 +00:00
|
|
|
if test $age -lt $max_age
|
|
|
|
return
|
|
|
|
end
|
2017-12-21 15:43:21 +00:00
|
|
|
end
|
|
|
|
|
2018-07-10 06:21:44 +00:00
|
|
|
# Remove package version information from output and pipe into cache file
|
|
|
|
eopkg list-installed -N | cut -d ' ' -f 1 >$cache_file &
|
|
|
|
return
|
|
|
|
else
|
2020-05-15 05:56:06 +00:00
|
|
|
set -l cache_file $xdg_cache_home/.eopkg-available-cache.$USER
|
2018-07-10 06:21:44 +00:00
|
|
|
if test -f $cache_file
|
|
|
|
cat $cache_file
|
2020-05-15 19:34:48 +00:00
|
|
|
set -l age (math (date +%s) - (stat -c '%Y' $cache_file))
|
|
|
|
set -l max_age 500
|
2018-07-10 06:21:44 +00:00
|
|
|
if test $age -lt $max_age
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Remove package version information from output and pipe into cache file
|
|
|
|
eopkg list-available -N | cut -d ' ' -f 1 >$cache_file &
|
|
|
|
return
|
|
|
|
end
|
2017-12-21 15:43:21 +00:00
|
|
|
end
|
|
|
|
|
2016-11-28 05:27:22 +00:00
|
|
|
# This completes the package name from the portage tree.
|
|
|
|
# True for installing new packages. Function for printing
|
|
|
|
# installed on the system packages is in completions/emerge.fish
|
|
|
|
|
|
|
|
# eix is MUCH faster than emerge so use it if it is available
|
|
|
|
if type -q -f eix
|
2017-04-16 04:49:08 +00:00
|
|
|
eix --only-names "^"(commandline -ct) | cut -d/ -f2
|
2016-11-28 05:27:22 +00:00
|
|
|
return
|
|
|
|
else
|
|
|
|
# FIXME? Seems to be broken
|
|
|
|
if type -q -f emerge
|
2017-04-16 04:49:08 +00:00
|
|
|
emerge -s \^(commandline -ct) | string match -r "^\*.*" | cut -d' ' -f3 | cut -d/ -f2
|
2016-11-28 05:27:22 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
2006-02-08 09:20:05 +00:00
|
|
|
|
2018-02-19 20:46:03 +00:00
|
|
|
# port needs caching, as it tends to be slow
|
|
|
|
# BSD find is used for determining file age because HFS+ and APFS
|
|
|
|
# don't save unix time, but the actual date. Also BSD stat is vastly
|
|
|
|
# different from linux stat and converting its time format is tedious
|
|
|
|
if type -q -f port
|
2020-05-15 05:56:06 +00:00
|
|
|
set -l cache_file $xdg_cache_home/.port-cache.$USER
|
2018-02-19 20:46:03 +00:00
|
|
|
if test -e $cache_file
|
|
|
|
# Delete if cache is older than 15 minutes
|
|
|
|
find "$cache_file" -ctime +15m | awk '{$1=$1;print}' | xargs rm
|
|
|
|
if test -f $cache_file
|
|
|
|
cat $cache_file
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
# Remove trailing whitespace and pipe into cache file
|
|
|
|
printf "all\ncurrent\nactive\ninactive\ninstalled\nuninstalled\noutdated" >$cache_file
|
|
|
|
port echo all | awk '{$1=$1};1' >>$cache_file &
|
|
|
|
cat $cache_file
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-09-04 02:48:54 +00:00
|
|
|
if type -q -f opkg
|
2018-12-31 15:48:03 +00:00
|
|
|
if set -q only_installed
|
2018-09-04 02:48:54 +00:00
|
|
|
opkg list-installed 2>/dev/null | sed -r 's/^([a-zA-Z0-9\-]+) - ([a-zA-Z0-9\-]+)/\1\t\2/g'
|
|
|
|
return
|
|
|
|
else
|
|
|
|
opkg list 2>/dev/null | sed -r 's/^([a-zA-Z0-9\-]+) - ([a-zA-Z0-9\-]+)/\1\t\2/g'
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-11 10:12:15 +00:00
|
|
|
if type -q -f apk
|
|
|
|
if set -q only_installed
|
2020-07-05 23:22:36 +00:00
|
|
|
apk info -q
|
2020-06-11 10:12:15 +00:00
|
|
|
return
|
|
|
|
else
|
|
|
|
apk search -q
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-05 18:01:19 +00:00
|
|
|
# Caches for 5 minutes
|
|
|
|
if type -q -f xbps-query
|
|
|
|
if not set -q only_installed
|
|
|
|
set -l cache_file $xdg_cache_home/.xbps-cache.$USER
|
|
|
|
if test -f $cache_file
|
|
|
|
set -l age (math (date +%s) - (stat -c '%Y' $cache_file))
|
|
|
|
set -l max_age 300
|
|
|
|
if test $age -lt $max_age
|
2020-12-08 19:59:56 +00:00
|
|
|
cat $cache_file
|
2020-08-05 18:01:19 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
# prints: <package name> Package
|
2020-12-08 19:59:56 +00:00
|
|
|
xbps-query -Rsl | sed 's/^... \([^ ]*\)-.* .*/\1/; s/$/\t'Package'/' | tee $cache_file
|
2020-08-05 18:01:19 +00:00
|
|
|
return
|
|
|
|
else
|
|
|
|
xbps-query -l | sed 's/^.. \([^ ]*\)-.* .*/\1/' # TODO: actually put package versions in tab for locally installed packages
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-02-08 09:20:05 +00:00
|
|
|
end
|