diff options
author | Eric Mrak <mail@ericmrak.info> | 2014-02-13 17:41:53 -0800 |
---|---|---|
committer | David Adam <zanchey@ucc.gu.uwa.edu.au> | 2014-02-16 18:09:55 +0800 |
commit | 64ca6c066c47a14fb1b1d05e5659a41cdc8f6f7c (patch) | |
tree | 3051831655ec7e8eec30e303764f87acd3f386b2 /share/functions/__fish_print_packages.fish | |
parent | d1cf5ab28608ff7135abd27d52949fbf4cd96ebd (diff) |
Caching for pacman packages.
Diffstat (limited to 'share/functions/__fish_print_packages.fish')
-rw-r--r-- | share/functions/__fish_print_packages.fish | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/share/functions/__fish_print_packages.fish b/share/functions/__fish_print_packages.fish index 351d88c4..ec812a64 100644 --- a/share/functions/__fish_print_packages.fish +++ b/share/functions/__fish_print_packages.fish @@ -29,6 +29,22 @@ function __fish_print_packages return end + # Caches for 5 minutes + if type -f pacman >/dev/null + set cache_file /tmp/.pac-cache.$USER + 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 # yum is slow, just like rpm, so go to the background if type -f /usr/share/yum-cli/completion-helper.py >/dev/null @@ -47,6 +63,7 @@ function __fish_print_packages # Remove package version information from output and pipe into cache file /usr/share/yum-cli/completion-helper.py list all -d 0 -C | sed "s/\..*/\t$package/" >$cache_file & + return end # Rpm is too slow for this job, so we set it up to do completions @@ -68,11 +85,6 @@ function __fish_print_packages # Remove package version information from output and pipe into cache file rpm -qa |sed -e 's/-[^-]*-[^-]*$/\t'$package'/' >$cache_file & - end - - # This completes pacman package names from pacman's cache - if type -f pacman >/dev/null - pacman -Sl | cut -d ' ' -f 2- | tr ' ' \t return end |