__fish_cached: tolerate trailing newline

In POSIX sh, ";" is not a valid statement, leading to errors when the
__fish_cached callback argument has a trailing newline (5c2073135e
(Fix syntax error in __fish_print_port_packages.fish, 2025-11-14)).

Use a newline instead of ";", to avoid this error.

While at it, replace rogue tab characters.
This commit is contained in:
Johannes Altmanninger
2025-11-15 08:34:13 +01:00
parent 5c2073135e
commit e77b1c9744
2 changed files with 11 additions and 4 deletions

View File

@@ -23,9 +23,15 @@ function __fish_cached --description "Cache the command output for a given amoun
set -l cache_file (path normalize $cache_dir/$cache_key)
set -l cache_age (path mtime --relative $cache_file)
set -l populate_cache sh -c "
{
$argv
} >$cache_file || rm $cache_file 2>/dev/null
"
if not test -f $cache_file
__fish_cache_put $cache_file
sh -c "{ $argv; } >$cache_file || rm $cache_file 2>/dev/null" &
$populate_cache &
if test -n "$last_pid"
# wait for at most 1 second if supported
@@ -39,7 +45,7 @@ function __fish_cached --description "Cache the command output for a given amoun
if test $cache_age -gt $max_age
__fish_cache_put $cache_file
sh -c "{ $argv; } >$cache_file || rm $cache_file 2>/dev/null" &
$populate_cache &
end
end
end

View File

@@ -3,7 +3,8 @@ function __fish_print_port_packages
type -q -f port || return 1
__fish_cached -t 250 -k port '
printf "all\ncurrent\nactive\ninactive\ninstalled\nuninstalled\noutdated\n"
port echo all | awk \'{$1=$1};1\''
printf "all\ncurrent\nactive\ninactive\ninstalled\nuninstalled\noutdated\n"
port echo all | awk \'{$1=$1};1\'
'
return 0
end