2006-02-08 17:20:05 +08:00
|
|
|
|
|
|
|
function __fish_print_packages
|
|
|
|
|
|
|
|
# apt-cache is much, much faster than rpm, and can do this in real
|
2013-09-17 22:20:16 +08:00
|
|
|
# time. We use it if available.
|
2006-02-08 17:20:05 +08:00
|
|
|
|
|
|
|
switch (commandline -tc)
|
|
|
|
case '-**'
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
#Get the word 'Package' in the current language
|
|
|
|
set -l package (_ Package)
|
|
|
|
|
2006-03-14 08:21:27 +08:00
|
|
|
if type -f apt-cache >/dev/null
|
2013-09-17 22:27:15 +08: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 17:20:05 +08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-09-17 22:20:16 +08:00
|
|
|
# Pkg is fast on FreeBSD and provides versioning info which we want for
|
|
|
|
# installed packages
|
|
|
|
if begin
|
|
|
|
type -f pkg > /dev/null
|
|
|
|
and test (uname) = "FreeBSD"
|
|
|
|
end
|
|
|
|
pkg query "%n-%v"
|
|
|
|
return
|
|
|
|
end
|
2013-06-04 20:56:37 +08:00
|
|
|
|
|
|
|
|
2013-09-17 22:20:16 +08:00
|
|
|
# yum is slow, just like rpm, so go to the background
|
2013-03-02 03:57:03 +08:00
|
|
|
if type -f /usr/share/yum-cli/completion-helper.py >/dev/null
|
|
|
|
|
2013-03-02 06:18:56 +08:00
|
|
|
# If the cache is less than six hours old, we do not recalculate it
|
2013-03-02 03:57:03 +08:00
|
|
|
|
|
|
|
set cache_file /tmp/.yum-cache.$USER
|
|
|
|
if test -f $cache_file
|
|
|
|
cat $cache_file
|
|
|
|
set age (math (date +%s) - (stat -c '%Y' $cache_file))
|
2013-03-02 06:18:56 +08:00
|
|
|
set max_age 21600
|
2013-03-02 03:57:03 +08:00
|
|
|
if test $age -lt $max_age
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Remove package version information from output and pipe into cache file
|
2013-09-17 22:20:16 +08:00
|
|
|
/usr/share/yum-cli/completion-helper.py list all -d 0 -C >$cache_file | cut -d '.' -f 1 | sed '1d' | sed '/^\s/d' | sed -e 's/$/'\t$package'/' &
|
2013-03-02 03:57:03 +08:00
|
|
|
end
|
|
|
|
|
2006-02-08 17:20:05 +08:00
|
|
|
# Rpm is too slow for this job, so we set it up to do completions
|
2013-09-17 22:20:16 +08:00
|
|
|
# as a background job and cache the results.
|
2006-02-08 17:20:05 +08:00
|
|
|
|
2010-09-18 10:18:26 +08:00
|
|
|
if type -f rpm >/dev/null
|
2006-02-08 17:20:05 +08:00
|
|
|
|
|
|
|
# If the cache is less than five minutes old, we do not recalculate it
|
|
|
|
|
|
|
|
set cache_file /tmp/.rpm-cache.$USER
|
2010-09-18 10:18:26 +08:00
|
|
|
if test -f $cache_file
|
2006-02-08 17:20:05 +08:00
|
|
|
cat $cache_file
|
2006-12-13 01:11:18 +08:00
|
|
|
set age (math (date +%s) - (stat -c '%Y' $cache_file))
|
2006-02-08 17:20:05 +08: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
|
2006-03-02 19:28:08 +08:00
|
|
|
rpm -qa >$cache_file |sed -e 's/-[^-]*-[^-]*$//' | sed -e 's/$/'\t$package'/' &
|
2006-02-08 17:20:05 +08:00
|
|
|
end
|
|
|
|
|
2010-09-18 10:18:26 +08:00
|
|
|
# This completes the package name from the portage tree.
|
|
|
|
# True for installing new packages. Function for printing
|
2006-02-08 17:20:05 +08:00
|
|
|
# installed on the system packages is in completions/emerge.fish
|
2010-12-02 01:33:56 +08:00
|
|
|
|
|
|
|
# eix is MUCH faster than emerge so use it if it is available
|
|
|
|
if type -f eix > /dev/null
|
|
|
|
eix --only-names "^"(commandline -tc) | cut -d/ -f2
|
2006-02-08 17:20:05 +08:00
|
|
|
return
|
2010-12-02 01:33:56 +08:00
|
|
|
else
|
|
|
|
# FIXME? Seems to be broken
|
|
|
|
if type -f emerge >/dev/null
|
|
|
|
emerge -s \^(commandline -tc) |sgrep "^*" |cut -d\ -f3 |cut -d/ -f2
|
|
|
|
return
|
|
|
|
end
|
2006-02-08 17:20:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|