diff --git a/po/de.po b/po/de.po index 28df63a9f..e54002510 100644 --- a/po/de.po +++ b/po/de.po @@ -8131,6 +8131,9 @@ msgstr "Testergebnisse in Datei config.cache zwischenspeichern" msgid "Cache test results in specified file" msgstr "Testergebnisse in angegebener Datei zwischenspeichern" +msgid "Cache the command output for a given amount of time" +msgstr "" + msgid "Caddyfile to load" msgstr "" diff --git a/po/en.po b/po/en.po index 2f570a166..679c205e6 100644 --- a/po/en.po +++ b/po/en.po @@ -8127,6 +8127,9 @@ msgstr "Cache test results in file config.cache" msgid "Cache test results in specified file" msgstr "Cache test results in specified file" +msgid "Cache the command output for a given amount of time" +msgstr "" + msgid "Caddyfile to load" msgstr "" diff --git a/po/fr.po b/po/fr.po index 5381e6d7b..b52fd2017 100644 --- a/po/fr.po +++ b/po/fr.po @@ -8228,6 +8228,9 @@ msgstr "Mettre en cache les résultats des tests dans le fichier config.cache" msgid "Cache test results in specified file" msgstr "Mettre en cache les résultats des tests dans le fichier spécifié" +msgid "Cache the command output for a given amount of time" +msgstr "" + msgid "Caddyfile to load" msgstr "" diff --git a/po/pl.po b/po/pl.po index b34766aed..bb9077060 100644 --- a/po/pl.po +++ b/po/pl.po @@ -8123,6 +8123,9 @@ msgstr "" msgid "Cache test results in specified file" msgstr "" +msgid "Cache the command output for a given amount of time" +msgstr "" + msgid "Caddyfile to load" msgstr "" diff --git a/po/pt_BR.po b/po/pt_BR.po index adf6f7fcc..605a79ada 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -8128,6 +8128,9 @@ msgstr "Cache test results in file config.cache" msgid "Cache test results in specified file" msgstr "" +msgid "Cache the command output for a given amount of time" +msgstr "" + msgid "Caddyfile to load" msgstr "" diff --git a/po/sv.po b/po/sv.po index ea8a974ae..2387b9804 100644 --- a/po/sv.po +++ b/po/sv.po @@ -8126,6 +8126,9 @@ msgstr "Cachea test resultat i filen config.cache" msgid "Cache test results in specified file" msgstr "Cache:a resultat i angiven fil" +msgid "Cache the command output for a given amount of time" +msgstr "" + msgid "Caddyfile to load" msgstr "" diff --git a/po/zh_CN.po b/po/zh_CN.po index fd7ab7855..29cdcad93 100644 --- a/po/zh_CN.po +++ b/po/zh_CN.po @@ -8126,6 +8126,9 @@ msgstr "文件配置中的缓存测试结果 . 缓存" msgid "Cache test results in specified file" msgstr "指定文件中的缓存测试结果" +msgid "Cache the command output for a given amount of time" +msgstr "" + msgid "Caddyfile to load" msgstr "要装入的卡迪文件" diff --git a/share/completions/flatpak.fish b/share/completions/flatpak.fish index 688a80055..6d0d12d1b 100644 --- a/share/completions/flatpak.fish +++ b/share/completions/flatpak.fish @@ -58,29 +58,12 @@ function __fish_flatpak flatpak $argv | string replace -rf '^([^A-Z].*?)(?: +|\t)(.*?)\s*$' '$1\t$2' end -function __fish_print_flatpak_packages - set -l xdg_cache_home (__fish_make_cache_dir) - or return - set -l cache_file $xdg_cache_home/flatpak - if test -f $cache_file - cat $cache_file - set -l age (path mtime -R -- $cache_file) - set -l max_age 250 - if test $age -lt $max_age - return - end - end - __fish_cache_put $cache_file - __fish_flatpak remote-ls --columns=application,name >$cache_file & - return 0 -end - complete -f -c flatpak -n "__fish_seen_subcommand_from run" -a "(__fish_flatpak list --app --columns=application,name)" complete -f -c flatpak -n "__fish_seen_subcommand_from info uninstall" -a "(__fish_flatpak list --columns=application,name)" complete -f -c flatpak -n "__fish_seen_subcommand_from enter kill" -a "(__fish_flatpak ps --columns=instance,application)" complete -f -c flatpak -n "__fish_seen_subcommand_from remote-info remote-ls remote-modify remote-delete" -a "(__fish_flatpak remotes --columns=name,title)" -complete -c flatpak -n '__fish_seen_subcommand_from install' -xa "(__fish_print_flatpak_packages)" +complete -c flatpak -n '__fish_seen_subcommand_from install' -xa "(__fish_cached -t 250 -- '__fish_flatpak remote-ls --columns=application,name')" # Plenty of the other stuff is too free-form to complete (e.g. remote-add). complete -f -c flatpak -s h -l help diff --git a/share/completions/winetricks.fish b/share/completions/winetricks.fish index 7e4b30609..2f8df4db3 100644 --- a/share/completions/winetricks.fish +++ b/share/completions/winetricks.fish @@ -1,5 +1,5 @@ function __fish_winetricks__complete_verbs - winetricks list-all 2>/dev/null | + __fish_cached -t 3600 -- 'winetricks list-all 2>/dev/null' | string match --invert --regex '^==' | string match --invert --regex '^(apps|dlls|fonts|games|settings)$' | string replace --regex '(\S+)\s+(.+)' '$1\t$2' diff --git a/share/functions/__fish_cached.fish b/share/functions/__fish_cached.fish new file mode 100644 index 000000000..5dc2b8cfc --- /dev/null +++ b/share/functions/__fish_cached.fish @@ -0,0 +1,44 @@ +function __fish_cached --description "Cache the command output for a given amount of time" + + argparse --min-args 1 --max-args 1 --stop-nonopt 't/max-age=!_validate_int --min 0' 'k/cache-key=' -- $argv + or return + + if set -q _flag_cache_key + set -f cache_key $_flag_cache_key + else + set -f cache_key (string trim "$argv" | string split ' ')[1] + end + if not string match -q --regex '^[\w+-]+$' -- "$cache_key" + return 1 + end + + if set -q _flag_max_age + set -f max_age $_flag_max_age + else + set -f max_age -1 + end + set -l cache_dir (__fish_make_cache_dir) + or return + set -l cache_file (path normalize $cache_dir/$cache_key) + set -l cache_age (path mtime --relative $cache_file) + + if not test -f $cache_file + __fish_cache_put $cache_file + sh -c "{ $argv; } >$cache_file || rm $cache_file 2>/dev/null" & + + if test -n "$last_pid" + # wait for at most 1 second if supported + command --search waitpid &>/dev/null + and waitpid --exited --timeout 1 $last_pid + and test -f $cache_file + and cat $cache_file + end + else + cat $cache_file + + if test $cache_age -gt $max_age + __fish_cache_put $cache_file + sh -c "{ $argv; } >$cache_file || rm $cache_file 2>/dev/null" & + end + end +end diff --git a/share/functions/__fish_print_eopkg_packages.fish b/share/functions/__fish_print_eopkg_packages.fish index d303ece8e..c749ecd35 100644 --- a/share/functions/__fish_print_eopkg_packages.fish +++ b/share/functions/__fish_print_eopkg_packages.fish @@ -4,41 +4,16 @@ function __fish_print_eopkg_packages argparse i/installed -- $argv or return 1 - set -l xdg_cache_home (__fish_make_cache_dir) - or return - # If the cache is less than max_age, we do not recalculate it # Determine whether to print installed/available packages if set -q _flag_installed - set -l cache_file $xdg_cache_home/eopkg-installed - if test -f $cache_file - cat $cache_file - set -l age (path mtime -R -- $cache_file) - set -l max_age 500 - if test $age -lt $max_age - return 0 - end - end - - __fish_cache_put $cache_file # Remove package version information from output and pipe into cache file - eopkg list-installed -N | cut -d ' ' -f 1 >$cache_file & + __fish_cached -t 500 -k eopkg-installed -- "eopkg list-installed -N | cut -d ' ' -f 1" return 0 else - set -l cache_file $xdg_cache_home/eopkg-available - if test -f $cache_file - cat $cache_file - set -l age (path mtime -R -- $cache_file) - set -l max_age 500 - if test $age -lt $max_age - return 0 - end - end - - __fish_cache_put $cache_file # Remove package version information from output and pipe into cache file - eopkg list-available -N | cut -d ' ' -f 1 >$cache_file & + __fish_cached -t 500 -k eopkg-available -- "eopkg list-available -N | cut -d ' ' -f 1" return 0 end return 1 diff --git a/share/functions/__fish_print_pacman_packages.fish b/share/functions/__fish_print_pacman_packages.fish index 242dc496a..01e23747c 100644 --- a/share/functions/__fish_print_pacman_packages.fish +++ b/share/functions/__fish_print_pacman_packages.fish @@ -5,22 +5,8 @@ function __fish_print_pacman_packages argparse i/installed -- $argv or return 1 - set -l xdg_cache_home (__fish_make_cache_dir) - or return - if not set -q _flag_installed - set -l cache_file $xdg_cache_home/pacman - if test -f $cache_file - cat $cache_file - set -l age (path mtime -R -- $cache_file) - set -l max_age 250 - if test $age -lt $max_age - return - end - end - __fish_cache_put $cache_file - # prints: Package - pacman -Ssq | sed -e 's/$/\t'Package'/' >$cache_file & + __fish_cached -t 250 -- "pacman -Ssq | sed -e 's/\$/\\tPackage/'" return 0 else pacman -Q | string replace ' ' \t diff --git a/share/functions/__fish_print_port_packages.fish b/share/functions/__fish_print_port_packages.fish index eb2cb42cb..440901d4e 100644 --- a/share/functions/__fish_print_port_packages.fish +++ b/share/functions/__fish_print_port_packages.fish @@ -1,24 +1,9 @@ function __fish_print_port_packages type -q -f port || return 1 - # port needs caching, as it tends to be slow - set -l xdg_cache_home (__fish_make_cache_dir) - or return - - set -l cache_file $xdg_cache_home/port - if test -f $cache_file - cat $cache_file - set -l age (path mtime -R -- $cache_file) - set -l max_age 250 - if test $age -lt $max_age - return - end - end - - __fish_cache_put $cache_file - # Remove trailing whitespace and pipe into cache file - printf "all\ncurrent\nactive\ninactive\ninstalled\nuninstalled\noutdated" >$cache_file - port echo all | awk '{$1=$1};1' >>$cache_file & - cat $cache_file + __fish_cached -t 250 -k port ' + printf "all\ncurrent\nactive\ninactive\ninstalled\nuninstalled\noutdated\n" + port echo all | awk \'{$1=$1};1\' + ' return 0 end diff --git a/share/functions/__fish_print_rpm_packages.fish b/share/functions/__fish_print_rpm_packages.fish index 5f343a2a1..d27c22143 100644 --- a/share/functions/__fish_print_rpm_packages.fish +++ b/share/functions/__fish_print_rpm_packages.fish @@ -5,44 +5,17 @@ function __fish_print_rpm_packages argparse i/installed -- $argv or return 1 - set -l xdg_cache_home (__fish_make_cache_dir) - or return - if type -q -f /usr/share/yum-cli/completion-helper.py - # If the cache is less than six hours old, we do not recalculate it - set -l cache_file $xdg_cache_home/yum - if test -f $cache_file - cat $cache_file - set -l age (path mtime -R -- $cache_file) - set -l max_age 21600 - if test $age -lt $max_age - return - end - end - - __fish_cache_put $cache_file # 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/\..*/\tPackage/" >$cache_file & + __fish_cached -t 21600 -k yum-completion-helper -- '/usr/share/yum-cli/completion-helper.py list all -d 0 -C | sed "s/\\..*/\\tPackage/"' return end # Rpm is too slow for this job, so we set it up to do completions # as a background job and cache the results. if type -q -f rpm - # If the cache is less than five minutes old, we do not recalculate it - set -l cache_file $xdg_cache_home/rpm - if test -f $cache_file - cat $cache_file - set -l age (path mtime -R -- $cache_file) - set -l max_age 250 - if test $age -lt $max_age - return - end - end - # Remove package version information from output and pipe into cache file - __fish_cache_put $cache_file - rpm -qa | sed -e 's/-[^-]*-[^-]*$/\t'Package'/' >$cache_file & + __fish_cached -t 250 -- "rpm -qa | sed -e 's/-[^-]*-[^-]*\$/\\t'Package'/'" return end end diff --git a/share/functions/__fish_print_xbps_packages.fish b/share/functions/__fish_print_xbps_packages.fish index 7a3bd9b1e..ee1ac21ab 100644 --- a/share/functions/__fish_print_xbps_packages.fish +++ b/share/functions/__fish_print_xbps_packages.fish @@ -5,22 +5,9 @@ function __fish_print_xbps_packages argparse i/installed -- $argv or return 1 - set -l xdg_cache_home (__fish_make_cache_dir) - or return - if not set -q _flag_installed - set -l cache_file $xdg_cache_home/xbps - if test -f $cache_file - set -l age (path mtime -R -- $cache_file) - set -l max_age 300 - if test $age -lt $max_age - cat $cache_file - return - end - end - __fish_cache_put $cache_file # prints: Package - xbps-query -Rs "" | sed 's/^... \([^ ]*\)-.* .*/\1/; s/$/\t'Package'/' | tee $cache_file + __fish_cached -t 250 -- "xbps-query -Rs '' | sed 's/^... \\([^ ]*\\)-.* .*/\\1/; s/\$/\\t'Package'/'" return 0 else xbps-query -l | sed 's/^.. \([^ ]*\)-.* .*/\1/' # TODO: actually put package versions in tab for locally installed packages