mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-30 11:21:15 -03:00
Extract __fish_cached function (#11526)
- extract __fish_cached function - add cache for winetricks verb completion
This commit is contained in:
committed by
GitHub
parent
06578bd03d
commit
43fbfa9a0f
3
po/de.po
3
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 ""
|
||||
|
||||
|
||||
3
po/en.po
3
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 ""
|
||||
|
||||
|
||||
3
po/fr.po
3
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 ""
|
||||
|
||||
|
||||
3
po/pl.po
3
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 ""
|
||||
|
||||
|
||||
@@ -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 ""
|
||||
|
||||
|
||||
3
po/sv.po
3
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 ""
|
||||
|
||||
|
||||
@@ -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 "要装入的卡迪文件"
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
44
share/functions/__fish_cached.fish
Normal file
44
share/functions/__fish_cached.fish
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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 name> 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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 name> 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
|
||||
|
||||
Reference in New Issue
Block a user