Repository: junegunn/fzf (language: go)

Issue:
Fish shell integration broken in fzf 0.58.0
### Checklist

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

### Output of `fzf --version`

0.58.0 (brew)

### OS

- [x] Linux
- [ ] macOS
- [ ] Windows
- [ ] Etc.

### Shell

- [ ] bash
- [ ] zsh
- [x] fish

### Problem / Steps to reproduce

Running `fzf --fish | source` to set up fzf integration in the fish shell no longer works as it did in earlier versions but fails with an error due to the use of an `$(` construct:

```
 $ fzf --fish | source
- (line 79): $(...) is not supported. In fish, please use '(__fzfcmd)'.
      set -l result (eval "$FZF_DEFAULT_COMMAND | $(__fzfcmd) --read0 --print0 -q (commandline) --bind='enter:become:string replace -a -- \n\t \n {2..} | string collect'")
                                                  ^
from sourcing file -
source: Error while reading file “<stdin>”
```

I suspect that this change came in in v0.58.0


Discussion / hints:
`fish --version`?

/cc @bitraid 
This might be a regression of fish v3.4.0. Are you using that version?
I'm using fish version 3.3.1 - system package from Ubuntu 22.04 LTS

I hadn't realised, but `$(` is supported in addition to just `(` as of fish 3.4.0
> I hadn't realised, but `$(` is supported in addition to just `(` as of fish 3.4.0

Yes, you're right. I was under the impression that this syntax support was older.
We better fix this then. @junegunn Should I open a PR?

@skilleter Meanwhile, you can use:
```fish
fzf --fish | string replace '"$FZF_DEFAULT_COMMAND | $(__fzfcmd) --read0 --print0 -q (commandline) --bind=\'enter:become:string replace -a -- \n\t \n {2..} | string collect\'"' '$FZF_DEFAULT_COMMAND \| (__fzfcmd) --read0 --print0 -q \'(commandline)\' "--bind=enter:become:\'string replace -a -- \n\t \n {2..} | string collect\'"' | source
``` 
@bitraid thanks for the help, I came up something rather simpler (but probably more error-prone) using sed: `fzf --fish | sed 's^ $(^ (^g' | source` that seems to work.
> [@bitraid](https://github.com/bitraid) thanks for the help, I came up something rather simpler (but probably more error-prone) using sed: `fzf --fish | sed 's^ $(^ (^g' | source` that seems to work.

Just have in mind that this doesn't work in more recent versions.


> @bitraid We better fix this then. [@junegunn](https://github.com/junegunn) Should I open a PR?

Could you do it? Thanks.

Fix patch:
diff --git a/shell/key-bindings.fish b/shell/key-bindings.fish
index f343bd15819..15c53ef21a9 100644
--- a/shell/key-bindings.fish
+++ b/shell/key-bindings.fish
@@ -75,7 +75,7 @@ function fzf_key_bindings
           'string join0 -- $i\t(string replace -a -- \n \n\t $h[$i] | string collect);' \
           'end'
       end
-      set -l result (eval "$FZF_DEFAULT_COMMAND | $(__fzfcmd) --read0 --print0 -q (commandline) --bind='enter:become:string replace -a -- \n\t \n {2..} | string collect'")
+      set -l result (eval $FZF_DEFAULT_COMMAND \| (__fzfcmd) --read0 --print0 -q (commandline | string escape) "--bind=enter:become:'string replace -a -- \n\t \n {2..} | string collect'")
       and commandline -- $result
     end
     commandline -f repaint


Test patch: