Incorrect escape chars handling in bindings
- [x] I have read through the manual page (
man fzf) - [x] I have the latest version of fzf
- [x] I have searched through the existing issues
Info
- OS
- [x] Windows
- Shell
- [x] pwsh
Problem / Steps to reproduce
In the sample that does integration with ripgrep reload binding is defined as:
--bind "change:reload: $rg ""{q}"" || cd ." `
The problem though is that if one tries to find $ char in the files it is not possible to do that interactively.
It is possible to use $env:FZF_DEFAULT_COMMAND and correctly pass the "\$" regex that would really be used and correctly rendered via the --query.
But the moment the user types anything interactively (like search for S\$) fzf starts to pass "S\\$" to the ripgrep. And if query is interactively reverted back to the original \$ form that just used to work, then fzf would still pass "\\$" to ripgrep in the {q} value. This makes it impossible to interactively search for the $ char.
Can you check if this still is an issue with the latest version of fzf? I'm not a pwsh user, so I'm wondering if "" around {q} are required, because we don't do that in *nix systems.
In what version was it likely fixed? I see that the latest release is 0.55 but the latest one that I see in chocolaty repo is 0.53. Is the code that fixes it present in 0.53?
From my experience it takes several weeks before the chocolatey repo gets updated. Last time I asked the maintainer I was told that the chocolatey moderators are involved and the whole process just takes some time.
Just noticed that you publish win release as well. I thought that it was available for win only from the chocolatey package. Will test with the latest 0.55 version.
Same fzf behavior on 0.55. When fzf is started it can pass \$ to rg just fine. It uses --smart-case "\$"
rg --column --line-number --no-heading --color=always --colors "path:fg:0x3A,0x96,0xDD" --colors "line:fg:0x13,0xA1,0x0E" --colors "column:fg:0xF9,0xF1,0xA5" --colors "match:fg:0xE7,0x48,0x56" --colors "match:style:underline" --smart-case "\$"
But when I interactively change the \$ input to \ (char delete) and then \$ (add $) then rg receives something different and the end result is that it doesn't do the $ chars search in files. It passes --smart-case "^"\\"" then --smart-case "^"\$""
rg --column --line-number --no-heading --color=always --colors "path:fg:0x3A,0x96,0xDD" --colors "line:fg:0x13,0xA1,0x0E" --colors "column:fg:0xF9,0xF1,0xA5" --colors "match:fg:0xE7,0x48,0x56" --colors "match:style:underline" --smart-case "^"\\"" || cd .
rg --column --line-number --no-heading --color=always --colors "path:fg:0x3A,0x96,0xDD" --colors "line:fg:0x13,0xA1,0x0E" --colors "column:fg:0xF9,0xF1,0xA5" --colors "match:fg:0xE7,0x48,0x56" --colors "match:style:underline" --smart-case "^"\$"" || cd .
For the repro completeness here is the full fzf call:
"C:\ProgramData\chocolatey\bin\fzf.exe" --ansi --color hl:-1:bold,hl+:-1:bold:reverse --disabled --query \$ --bind "change:reload: rg --column --line-number --no-heading --color=always --colors \"path:fg:0x3A,0x96,0xDD\" --colors \"line:fg:0x13,0xA1,0x0E\" --colors \"column:fg:0xF9,0xF1,0xA5\" --colors \"match:fg:0xE7,0x48,0x56\" --colors \"match:style:underline\" --smart-case \"{q}\" || cd ." --bind "alt-f:unbind(change,alt-f)+change-prompt(rg|fzf> )+enable-search+clear-query+rebind(alt-r)" --bind "alt-r:unbind(alt-r)+change-prompt(rg> )+disable-search+reload(rg --column --line-number --no-heading --color=always --colors \"path:fg:0x3A,0x96,0xDD\" --colors \"line:fg:0x13,0xA1,0x0E\" --colors \"column:fg:0xF9,0xF1,0xA5\" --colors \"match:fg:0xE7,0x48,0x56\" --colors \"match:style:underline\" --smart-case \"{q}\" || cd .)+rebind(change,alt-f)" --prompt "rg> " --delimiter : --tiebreak begin,length --header "<ALT-R: rg> <ALT-F: fzf>" --preview "bat --color=always {1} --highlight-line {2}" --preview-window up,72%,border-bottom,+{2}/3,~3
And the version:
» C:\ProgramData\chocolatey\bin\fzf.exe --version
0.55.0 (fc69308)
Is $SHELL environment variable defined? If not, fzf will use cmd to execute external processes.
https://github.com/junegunn/fzf/blob/2286edb3296a5d50f048bf950163ef4c3a0651fa/src/util/util_windows.go#L46-L48
And it uses this code to escape shell arguments.
https://github.com/junegunn/fzf/blob/2286edb3296a5d50f048bf950163ef4c3a0651fa/src/util/util_windows.go#L114-L165
I'm not a Windows user, so I don't how we can address the issue you're experiencing.
It looks like fzf shouldn't escape regex chars in this kind of situation. If a user types in regex in the interactive mode it should be passed as is to the rg, not escaped char by char. Otherwise as shown in the example --smart-case "$" that is accepted by rg invoked from cmd becomes its escaped version --smart-case "^"$"" that is not a valid input to rg.
On Tue, Sep 10, 2024 at 7:51 PM Junegunn Choi @.***> wrote:
Is $SHELL environment variable defined? If not, fzf will use cmd to execute external processes.
https://github.com/junegunn/fzf/blob/2286edb3296a5d50f048bf950163ef4c3a0651fa/src/util/util_windows.go#L46-L48
And it uses this code to escape shell arguments.
https://github.com/junegunn/fzf/blob/2286edb3296a5d50f048bf950163ef4c3a0651fa/src/util/util_windows.go#L114-L165
I'm not a Windows user, so I don't how we can address the issue you're experiencing.
— Reply to this email directly, view it on GitHub https://github.com/junegunn/fzf/issues/2947#issuecomment-2342508395 or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFNU74OWQY7MSA5KKTWOT3ZV6V2HBFKMF2HI4TJMJ2XIZLTSOBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDUOJ2WLJDOMFWWLLTXMF2GG2C7MFRXI2LWNF2HTAVFOZQWY5LFUVUXG43VMWSG4YLNMWVXI2DSMVQWIX3UPFYGLLDTOVRGUZLDORPXI6LQMWWES43TOVSUG33NNVSW45FGORXXA2LDOOJIFJDUPFYGLKTSMVYG643JORXXE6NFOZQWY5LFVAYTGOBQG43DANUCUR2HS4DFUVUXG43VMWSXMYLMOVS2UMJTGU2DSNBTGEYDJJ3UOJUWOZ3FOKTGG4TFMF2GK . You are receiving this email because you authored the thread.
Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub .