Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fzf adding a ^ character on Windows when an @ symbol exists in selected line/field #3764

Closed
4 of 10 tasks
amreus opened this issue May 2, 2024 · 5 comments
Closed
4 of 10 tasks
Labels

Comments

@amreus
Copy link

amreus commented May 2, 2024

Checklist

  • I have read through the manual page (man fzf)
  • I have searched through the existing issues
  • For bug reports, I have checked if the bug is reproducible in the latest version of fzf

Output of fzf --version

0.51.0 (260a65b)

OS

  • Linux
  • macOS
  • Windows
  • Etc.

Shell

  • bash
  • zsh
  • fish

Problem / Steps to reproduce

Using Windows Terminal:

Command line entered:

>echo one @two three @four five s@ix |fzf  --bind "enter:execute(echo {})+abort"

Result displayed:

"one ^@two three ^@four five s^@ix "

So it appears wherever the is a @ symbol, fzf has added a ^ symbol?

@junegunn
Copy link
Owner

junegunn commented May 6, 2024

I recently revised the argument escaping for cmd.exe to fix some of the long-standing problems on Windows.

func escapeArg(s string) string {
b := make([]byte, 0, len(s)+2)
b = append(b, '"')
slashes := 0
for i := 0; i < len(s); i++ {
c := s[i]
switch c {
default:
slashes = 0
case '\\':
slashes++
case '&', '|', '<', '>', '(', ')', '@', '^', '%', '!':
b = append(b, '^')
case '"':
for ; slashes > 0; slashes-- {
b = append(b, '\\')
}
b = append(b, '\\')
}
b = append(b, c)
}
for ; slashes > 0; slashes-- {
b = append(b, '\\')
}
b = append(b, '"')
return string(b)
}

And it escapes @ with ^. Is this a problem for you?

@junegunn
Copy link
Owner

junegunn commented May 6, 2024

Maybe escaping @ is not really required. I'll look into it.

https://ss64.com/nt/syntax-esc.html

@amreus
Copy link
Author

amreus commented May 6, 2024

I'm using fzf as a front-end for youtube subscriptions - fetching xml and parsing using a Ruby script and displaying the results in fzf. One of the columns is the channel "handle" which start with the @ symbol. I am sending the handle to an executable:

--bind "delete:execute-silent(exec\mark-handle-read.exe {3})"

In this case, the .exe handles any strings passed - no escaping required. I think because fzf already quotes the result on Windows?

On the Windows cmd.exe:

prog.exe ^| tee is the same as prog.exe "|" tee

The example does not pipe - it passes the | as an argument to the program.

@junegunn
Copy link
Owner

junegunn commented May 6, 2024

Can you check if the problem is fixed on the latest source? In case you can't build the binary, I'm attaching the one I just built.

fzf.exe.zip

@amreus
Copy link
Author

amreus commented May 6, 2024

I tried the binary you built - it works, thank you. I had reverted to the previous version for the short term.

Is there a discussion of the need for the escaping? If fzf returns double-quoted strings in Windows, I am not sure why escaping would be needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants