junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
61.96k stars 2.34k forks source link

preserve whitespace flag s not working? #3839

Closed malkomalko closed 1 month ago

malkomalko commented 1 month ago

Checklist

Output of fzf --version

0.52.1 (brew)

OS

Shell

Problem / Steps to reproduce

I have a binding that I'm trying to make work that selects all visible results and copies them to the clipboard: --bind "ctrl-y:select-all+execute-silent(echo -n {+s3..} | pbcopy)+abort"

It works, but the output is all one line. I was expecting the s flag to preserve the whitespace. Is this the intended outcome?

junegunn commented 1 month ago

Yes, s flags does not preserve record separators. They are removed right away when fzf reads the lines.

You can use printf instead or use for loop over the values.

ls -al | fzf --header-lines=1 --multi --bind 'ctrl-y:select-all+become(printf "%s\n" {+3..} | pbcopy)'
ls -al | fzf --header-lines=1 --multi --bind 'ctrl-y:select-all+become(for x in {+3..}; do echo "$x"; done | pbcopy)'