Closed letuanhai closed 1 month ago
- evironment variable
$FZF_QUERY
in the event binding (i.e.--bind "start:reload:$RG_PREFIX $FZF_QUERY"
), but it does not get replaced with the query string.
The FZF_QUERY
is an environment variable exported by fzf
that you must escape when used with double quotes; otherwise, it will expand immediately.
--bind "start:reload:$RG_PREFIX \$FZF_QUERY"
[!NOTE] fzf runs the command with
$SHELL -c
ifSHELL
is set, otherwise withsh -c
essentially doing shell word splitting.
Try the (z)
[^1][^2] and (Q)
[^3] parameter expansion flags on FZF_QUERY
.
export test_string='--glob !*.go "immediately after"'
zsh -fxc 'print -- ${(Q)${(z)test_string}}'
# +zsh:1> print -- --glob '!*.go' 'immediately after'
# --glob !*.go immediately after
TEST: Search for the string immediately after
in the fzf
repo with the option --glob !*.go
passed along.
SHELL=$(which zsh) fzf \
--bind "start:become:rg --column --line-number --no-heading \${(Q)\${(z)FZF_QUERY}}" \
--disabled \
--query '--glob !*.go "immediately after"'
# CHANGELOG.md:2132:33:- Fixed to update "inline-info" immediately after terminal resize
Instead of SHELL=$(which zsh)
, one can also use the --with-shell "$(which zsh) -c"
flag. The latter allows passing additional options. This feature was added in version 0.51.0
[^4].
[^1]: zsh: 14 Expansion [^2]: Zsh Parameter Expansion z [^3]: Zsh Parameter Expansion Q [^4]: fzf/CHANGELOG.md - 0.51.0
Wow, it works like a charm 😀 Thank you for your reply.
The caveat is that the parameter options (z)
and (Q)
are specific to zsh
, though I'm fine with that since I'm using zsh
.
The
FZF_QUERY
is an environment variable exported byfzf
that you must escape when used with double quotes; otherwise, it will expand immediately.
I think this note should be added to the documentation somewhere, since I didn't find example about the use of the environment variable FZF_QUERY
in my research, and someone who is not so familiar with shell script, like myself, would miss this point.
I think this note should be added to the documentation somewhere, since I didn't find example about the use of the environment variable
FZF_QUERY
in my research
You can find it in the man page.
Hi, thanks for checking the issue again.
You can find it in the man page.
Yes I've found out about the environment variable from the man page. That's why I've mentioned it in my original post. However, I didn't find any example of its usage, and was failed to use it correctly.
What I think should be documented is the following note about its usage, as it's not very straightforward, and someone who is inexperienced with shell scripting may encounter trouble:
The FZF_QUERY is an environment variable exported by fzf that you must escape when used with double quotes; otherwise, it will expand immediately.
--bind "start:reload:$RG_PREFIX \$FZF_QUERY"
Checklist
man fzf
)Output of
fzf --version
0.55.0
OS
Shell
Problem / Steps to reproduce
Use case: Building on the example in ADVANCED.md to use
fzf
as interactiverg
launcher, I also want to pass additional options torg
. Currently, the whole query string{q}
is replaced as a single-quoted string.I want to have a placeholder expression that will be replaced by a list of single-quoted strings by separating the query string by space characters, essentially doing shell word splitting. For the previous example, I expect the query string to be replaced with:
'--glob=!*.go' 'one'
.What I have tried so far: I've tried replacing
{q}
with the evironment variable$FZF_QUERY
in the event binding (i.e.--bind "start:reload:$RG_PREFIX $FZF_QUERY"
), but it does not get replaced with the query string.Any other suggestions without the need for the additonal placeholder expression would also be great.