fish-shell/share/functions/__fish_print_eopkg_packages.fish
Fabian Boehm 5dfb64b547
Add path mtime (#9057)
This can be used to print the modification time, like `stat` with some
options.

The reason is that `stat` has caused us a number of portability
headaches:

1. It's not available everywhere by default
2. The versions are quite different

For instance, with GNU stat it's `stat -c '%Y'`, with macOS it's `stat
-f %m`.

So now checking a cache file can be done just with builtins.
2022-07-18 20:39:01 +02:00

43 lines
1.3 KiB
Fish

function __fish_print_eopkg_packages
type -q -f eopkg || return 1
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-cache.$USER
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
# Remove package version information from output and pipe into cache file
eopkg list-installed -N | cut -d ' ' -f 1 >$cache_file &
return 0
else
set -l cache_file $xdg_cache_home/.eopkg-available-cache.$USER
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
# Remove package version information from output and pipe into cache file
eopkg list-available -N | cut -d ' ' -f 1 >$cache_file &
return 0
end
return 1
end