summaryrefslogtreecommitdiff
path: root/src/terminal.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2025-03-30 19:28:21 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2025-03-30 19:49:05 +0900
commit31fd207ba232cf419f55cbfede8a90490bd25c5d (patch)
treea6b21d989c2444a89beef0b9bcc47c66c514f509 /src/terminal.go
parentba6d1b8772ce5e75ff999dcca21c0fadb689d7bf (diff)
downloadfzf-31fd207ba232cf419f55cbfede8a90490bd25c5d.tar.gz
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
Diffstat (limited to 'src/terminal.go')
-rw-r--r--src/terminal.go11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/terminal.go b/src/terminal.go
index 8b4651c1..f3a7fe4d 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -38,7 +38,7 @@ As such it is not useful for validation, but rather to generate test
cases for example.
\\?(?: # escaped type
- {\+?s?f?RANGE(?:,RANGE)*} # token type
+ {\+?s?f?r?RANGE(?:,RANGE)*} # token type
{q[:s?RANGE]} # query type
|{\+?n?f?} # item type (notice no mandatory element inside brackets)
)
@@ -65,7 +65,7 @@ const maxFocusEvents = 10000
const blockDuration = 1 * time.Second
func init() {
- placeholder = regexp.MustCompile(`\\?(?:{[+sf]*[0-9,-.]*}|{q(?::s?[0-9,-.]+)?}|{fzf:(?:query|action|prompt)}|{\+?f?nf?})`)
+ placeholder = regexp.MustCompile(`\\?(?:{[+sfr]*[0-9,-.]*}|{q(?::s?[0-9,-.]+)?}|{fzf:(?:query|action|prompt)}|{\+?f?nf?})`)
whiteSuffix = regexp.MustCompile(`\s*$`)
offsetComponentRegex = regexp.MustCompile(`([+-][0-9]+)|(-?/[1-9][0-9]*)`)
offsetTrimCharsRegex = regexp.MustCompile(`[^0-9/+-]`)
@@ -628,6 +628,7 @@ type placeholderFlags struct {
number bool
forceUpdate bool
file bool
+ raw bool
}
type searchRequest struct {
@@ -3782,6 +3783,8 @@ func parsePlaceholder(match string) (bool, string, placeholderFlags) {
flags.number = true
case 'f':
flags.file = true
+ case 'r':
+ flags.raw = true
case 'q':
flags.forceUpdate = true
trimmed += string(char)
@@ -3933,7 +3936,7 @@ func replacePlaceholder(params replacePlaceholderParams) (string, []string) {
return "''"
}
return strconv.Itoa(int(n))
- case flags.file:
+ case flags.file || flags.raw:
return item.AsString(params.stripAnsi)
default:
return params.executor.QuoteEntry(item.AsString(params.stripAnsi))
@@ -3975,7 +3978,7 @@ func replacePlaceholder(params replacePlaceholderParams) (string, []string) {
if !flags.preserveSpace {
str = strings.TrimSpace(str)
}
- if !flags.file {
+ if !flags.file && !flags.raw {
str = params.executor.QuoteEntry(str)
}
return str