From a6a41d159cd4e34d5db7db8c6e29629c7db91d15 Mon Sep 17 00:00:00 2001 From: David Adam Date: Thu, 13 Nov 2014 18:15:35 +0800 Subject: [PATCH] __fish_print_packages: add support for zypper Closes #1787. --- share/functions/__fish_print_packages.fish | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/share/functions/__fish_print_packages.fish b/share/functions/__fish_print_packages.fish index 050fcac28..eb8470f46 100644 --- a/share/functions/__fish_print_packages.fish +++ b/share/functions/__fish_print_packages.fish @@ -52,6 +52,25 @@ function __fish_print_packages return end + # 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 + # yum is slow, just like rpm, so go to the background if type -q -f /usr/share/yum-cli/completion-helper.py