From 31fd207ba232cf419f55cbfede8a90490bd25c5d Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sun, 30 Mar 2025 19:28:21 +0900 Subject: Add 'r' flag (raw) for unquoted output By default, placeholder expressions are automatically quoted to ensure they are safely passed as arguments to external programs. The r flag ({r}, {r1}, etc.) disables this behavior, outputting the evaluated value without quotes. For example, echo 'foo bar' | fzf --preview 'echo {} {r}' The preview command becomes: echo 'foo bar' foo bar Since `{r}` expands to unquoted "foo bar", 'foo' and 'bar' are passed as separate arguments. **Use with caution** Unquoted output can lead to broken commands. echo "let's go" | fzf --preview 'echo {r}' Close #4330 --- src/terminal_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/terminal_test.go') diff --git a/src/terminal_test.go b/src/terminal_test.go index 1d50767b..380e40d1 100644 --- a/src/terminal_test.go +++ b/src/terminal_test.go @@ -75,6 +75,14 @@ func TestReplacePlaceholder(t *testing.T) { result = replacePlaceholderTest("echo {}", true, Delimiter{}, printsep, false, "query", items1) checkFormat("echo {{.O}} foo{{.I}}bar baz{{.O}}") + // {r}, strip ansi + result = replacePlaceholderTest("echo {r}", true, Delimiter{}, printsep, false, "query", items1) + checkFormat("echo foo'bar baz") + + // {r..}, strip ansi + result = replacePlaceholderTest("echo {r..}", true, Delimiter{}, printsep, false, "query", items1) + checkFormat("echo foo'bar baz") + // {}, with multiple items result = replacePlaceholderTest("echo {}", true, Delimiter{}, printsep, false, "query", items2) checkFormat("echo {{.O}}foo{{.I}}bar baz{{.O}}") -- cgit v1.2.3