ms-jpq / sad

CLI search and replace | Space Age seD
MIT License
1.68k stars 22 forks source link

How do you pass arguments to fzf #308

Closed KiLLeRRaT closed 1 month ago

KiLLeRRaT commented 4 months ago

Hi,

I see in the manual you can use --fzf to pass params to fzf.

I can't get this to work.

These are the commands I've been trying to run:

With double quotes

❯ rg smrc --files-with-matches | sad 'smrc' 'smc' --fzf "--bind ctrl-a:select-all"
error: unexpected argument '--bind ctrl-a:select-all' found

  tip: to pass '--bind ctrl-a:select-all' as a value, use '-- --bind ctrl-a:select-all'

Usage: sad <PATTERN|REPLACE|--read0|--commit|--exact|--flags <FLAGS>|--pager <PAGER>|--fzf <FZF>|--unified <UNIFIED>>

For more information, try '--help'.

No dashes before bind

 rg smrc --files-with-matches | sad 'smrc' 'smc' --fzf "bind ctrl-a:select-all"
unknown option: bind
Error:
IO(
    "/usr/bin/fzf",
    BrokenPipe,
)
Error:
BadExit(
    "/usr/bin/fzf",
    2,
)

No double quotes

❯ rg smrc --files-with-matches | sad 'smrc' 'smc' --fzf --bind=ctrl-a:select-all
error: unexpected argument '--bind' found

  tip: to pass '--bind' as a value, use '-- --bind'

Usage: sad <PATTERN|REPLACE|--read0|--commit|--exact|--flags <FLAGS>|--pager <PAGER>|--fzf <FZF>|--unified <UNIFIED>>

For more information, try '--help'.

Any ideas what's going on?

Looks like it should work reading the source code. Something that has me worrying about bind specifically is the function you run around the --bind args in the code though. https://github.com/ms-jpq/sad/blob/a0dc8b31de8f321a195e8cc74238be378f6d209e/src/fzf.rs#L142

Thanks!

jiangyinzuo commented 1 month ago

@KiLLeRRaT Adding a backslash \ works well for me.

fd | sad Duck Chicken --fzf '\--bind ctrl-a:select-all'
KiLLeRRaT commented 1 month ago

That seems to do the trick! Thanks :)