2006-02-08 09:20:05 +00:00
|
|
|
|
|
|
|
function __fish_print_packages
|
|
|
|
|
|
|
|
# apt-cache is much, much faster than rpm, and can do this in real
|
2013-09-17 14:20:16 +00:00
|
|
|
# time. We use it if available.
|
2006-02-08 09:20:05 +00:00
|
|
|
|
|
|
|
switch (commandline -tc)
|
|
|
|
case '-**'
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
#Get the word 'Package' in the current language
|
|
|
|
set -l package (_ Package)
|
|
|
|
|
2014-04-28 15:37:02 +00:00
|
|
|
# Set up cache directory
|
|
|
|
if test -z "$XDG_CACHE_HOME"
|
|
|
|
set XDG_CACHE_HOME $HOME/.cache
|
|
|
|
end
|
|
|
|
mkdir -m 700 -p $XDG_CACHE_HOME
|
|
|
|
|
2014-07-10 07:26:58 +00:00
|
|
|
if type -q -f apt-cache
|
2013-09-17 14:27:15 +00:00
|
|
|
# Do not generate the cache as apparently sometimes this is slow.
|
|
|
|
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=547550
|
|
|
|
apt-cache --no-generate pkgnames (commandline -tc) ^/dev/null | sed -e 's/$/'\t$package'/'
|
2006-02-08 09:20:05 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-09-17 14:20:16 +00:00
|
|
|
# Pkg is fast on FreeBSD and provides versioning info which we want for
|
|
|
|
# installed packages
|
|
|
|
if begin
|
2014-07-10 07:26:58 +00:00
|
|
|
type -q -f pkg
|
2013-09-17 14:20:16 +00:00
|
|
|
and test (uname) = "FreeBSD"
|
|
|
|
end
|
|
|
|
pkg query "%n-%v"
|
|
|
|
return
|
|
|
|
end
|
2013-06-04 12:56:37 +00:00
|
|
|
|
2014-02-14 01:41:53 +00:00
|
|
|
# Caches for 5 minutes
|
2014-07-10 07:26:58 +00:00
|
|
|
if type -q -f pacman
|
2014-04-28 15:37:02 +00:00
|
|
|
set cache_file $XDG_CACHE_HOME/.pac-cache.$USER
|
2014-02-14 01:41:53 +00:00
|
|
|
if test -f $cache_file
|
|
|
|
cat $cache_file
|
|
|
|
set age (math (date +%s) - (stat -c '%Y' $cache_file))
|
|
|
|
set max_age 250
|
|
|
|
if test $age -lt $max_age
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# prints: <package name> Package
|
|
|
|
pacman -Ssq | sed -e 's/$/\t'$package'/' >$cache_file &
|
|
|
|
return
|
|
|
|
end
|
2013-06-04 12:56:37 +00:00
|
|
|
|
2014-11-13 10:15:35 +00:00
|
|
|
# Zypper needs caching as it is slow
|
|
|
|
if type -q -f zypper
|
|
|
|
# If the cache is less than five minutes old, we do not recalculate it
|
|
|
|
|
|
|
|
set -l cache_file $XDG_CACHE_HOME/.zypper-cache.$USER
|
|
|
|
if test -f $cache_file
|
|
|
|
cat $cache_file
|
|
|
|
set -l age (math (date +%s) - (stat -c '%Y' $cache_file))
|
|
|
|
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
|
|
|
|
zypper --quiet --non-interactive search --type=package | tail -n +4 | sed -E 's/^. \| ((\w|[-_.])+).*/\1\t'$package'/g' > $cache_file &
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-09-17 14:20:16 +00:00
|
|
|
# yum is slow, just like rpm, so go to the background
|
2014-07-10 07:26:58 +00:00
|
|
|
if type -q -f /usr/share/yum-cli/completion-helper.py
|
2013-03-01 19:57:03 +00:00
|
|
|
|
2013-03-01 22:18:56 +00:00
|
|
|
# If the cache is less than six hours old, we do not recalculate it
|
2013-03-01 19:57:03 +00:00
|
|
|
|
2014-04-28 15:37:02 +00:00
|
|
|
set cache_file $XDG_CACHE_HOME/.yum-cache.$USER
|
2013-03-01 19:57:03 +00:00
|
|
|
if test -f $cache_file
|
|
|
|
cat $cache_file
|
|
|
|
set age (math (date +%s) - (stat -c '%Y' $cache_file))
|
2013-03-01 22:18:56 +00:00
|
|
|
set max_age 21600
|
2013-03-01 19:57:03 +00:00
|
|
|
if test $age -lt $max_age
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Remove package version information from output and pipe into cache file
|
2014-01-29 04:47:56 +00:00
|
|
|
/usr/share/yum-cli/completion-helper.py list all -d 0 -C | sed "s/\..*/\t$package/" >$cache_file &
|
2014-02-14 01:41:53 +00:00
|
|
|
return
|
2013-03-01 19:57:03 +00:00
|
|
|
end
|
|
|
|
|
2006-02-08 09:20:05 +00:00
|
|
|
# Rpm is too slow for this job, so we set it up to do completions
|
2013-09-17 14:20:16 +00:00
|
|
|
# as a background job and cache the results.
|
2006-02-08 09:20:05 +00:00
|
|
|
|
2014-07-10 07:26:58 +00:00
|
|
|
if type -q -f rpm
|
2006-02-08 09:20:05 +00:00
|
|
|
|
|
|
|
# If the cache is less than five minutes old, we do not recalculate it
|
|
|
|
|
2014-04-28 15:37:02 +00:00
|
|
|
set cache_file $XDG_CACHE_HOME/.rpm-cache.$USER
|
2010-09-18 02:18:26 +00:00
|
|
|
if test -f $cache_file
|
2006-02-08 09:20:05 +00:00
|
|
|
cat $cache_file
|
2006-12-12 17:11:18 +00:00
|
|
|
set age (math (date +%s) - (stat -c '%Y' $cache_file))
|
2006-02-08 09:20:05 +00:00
|
|
|
set max_age 250
|
|
|
|
if test $age -lt $max_age
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Remove package version information from output and pipe into cache file
|
2014-01-29 04:47:56 +00:00
|
|
|
rpm -qa |sed -e 's/-[^-]*-[^-]*$/\t'$package'/' >$cache_file &
|
2014-02-07 05:55:53 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2010-09-18 02:18:26 +00:00
|
|
|
# This completes the package name from the portage tree.
|
|
|
|
# True for installing new packages. Function for printing
|
2006-02-08 09:20:05 +00:00
|
|
|
# installed on the system packages is in completions/emerge.fish
|
2010-12-01 17:33:56 +00:00
|
|
|
|
|
|
|
# eix is MUCH faster than emerge so use it if it is available
|
2014-07-10 07:26:58 +00:00
|
|
|
if type -q -f eix
|
2010-12-01 17:33:56 +00:00
|
|
|
eix --only-names "^"(commandline -tc) | cut -d/ -f2
|
2006-02-08 09:20:05 +00:00
|
|
|
return
|
2010-12-01 17:33:56 +00:00
|
|
|
else
|
|
|
|
# FIXME? Seems to be broken
|
2014-07-10 07:26:58 +00:00
|
|
|
if type -q -f emerge
|
2010-12-01 17:33:56 +00:00
|
|
|
emerge -s \^(commandline -tc) |sgrep "^*" |cut -d\ -f3 |cut -d/ -f2
|
|
|
|
return
|
|
|
|
end
|
2006-02-08 09:20:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|