From e77b1c97445fcc1cc98ccdb0e06e0598f01cb06a Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 15 Nov 2025 08:34:13 +0100 Subject: [PATCH] __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 (5c2073135ef (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. --- share/functions/__fish_cached.fish | 10 ++++++++-- share/functions/__fish_print_port_packages.fish | 5 +++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/share/functions/__fish_cached.fish b/share/functions/__fish_cached.fish index 625b00b05..242ad3cc1 100644 --- a/share/functions/__fish_cached.fish +++ b/share/functions/__fish_cached.fish @@ -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 diff --git a/share/functions/__fish_print_port_packages.fish b/share/functions/__fish_print_port_packages.fish index 0cbae6eef..2515d4b93 100644 --- a/share/functions/__fish_print_port_packages.fish +++ b/share/functions/__fish_print_port_packages.fish @@ -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