So what I was looking for was simply print -z…
This new version appears to work just the way I want. Thanks!
function pacs {
cmd=$(yay -Slq | fzf --prompt 'yay> ' \
--header 'Install packages. CTRL+(Pacman/Aur/Installed)' \
--bind 'ctrl-p:change-prompt(pacman> )+reload(pacman -Slq)' \
--bind 'ctrl-a:change-prompt(yay> )+reload(yay -Slq)' \
--bind 'ctrl-i:change-prompt(inst> )+reload(yay -Qq)' \
--multi --height=80% --preview 'sleep 2; yay -Si {1}' \
--preview-window bottom) #| xargs -ro yay -S
cmd=${cmd//$'\n'/ } # newline -> space
if ! [ -z "$cmd" ];
then print -z yay -S $cmd ;
fi
}
edit: add test to avoid writing empty yay -S if no package selected