From 87aca05e7f254a65e22d49293e1ce6893af9a5e2 Mon Sep 17 00:00:00 2001 From: aliva Date: Fri, 1 Mar 2013 23:27:03 +0330 Subject: [PATCH 1/2] autocomplete 'yum install' using yum cache --- share/completions/yum.fish | 2 +- share/functions/__fish_print_packages.fish | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/share/completions/yum.fish b/share/completions/yum.fish index 7ffec2cb0..35f878d0c 100644 --- a/share/completions/yum.fish +++ b/share/completions/yum.fish @@ -7,7 +7,7 @@ # Test if completing using package names is appropriate function __fish_yum_package_ok for i in (commandline -poc) - if contains $i update upgrade remove erase + if contains $i update upgrade remove erase install reinstall return 0 end end diff --git a/share/functions/__fish_print_packages.fish b/share/functions/__fish_print_packages.fish index 1991bd6d7..6573ce8ed 100644 --- a/share/functions/__fish_print_packages.fish +++ b/share/functions/__fish_print_packages.fish @@ -22,6 +22,25 @@ function __fish_print_packages 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 + + # If the cache is less than five minutes old, we do not recalculate it + + 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)) + set max_age 250 + if test $age -lt $max_age + return + end + end + + # Remove package version information from output and pipe into cache file + /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'/' & + end + # Rpm is too slow for this job, so we set it up to do completions # as a background job and cache the results. From 3bfcd5e1052c5840a23e7a5f3c91ac9d927289d6 Mon Sep 17 00:00:00 2001 From: aliva Date: Sat, 2 Mar 2013 01:48:56 +0330 Subject: [PATCH 2/2] recreate yum-cache file every six hours. --- share/functions/__fish_print_packages.fish | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/share/functions/__fish_print_packages.fish b/share/functions/__fish_print_packages.fish index 6573ce8ed..6ee76c555 100644 --- a/share/functions/__fish_print_packages.fish +++ b/share/functions/__fish_print_packages.fish @@ -25,13 +25,13 @@ function __fish_print_packages # yum is slow, just like rpm, so go to the background if type -f /usr/share/yum-cli/completion-helper.py >/dev/null - # If the cache is less than five minutes old, we do not recalculate it + # If the cache is less than six hours old, we do not recalculate it 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)) - set max_age 250 + set max_age 21600 if test $age -lt $max_age return end