-
Notifications
You must be signed in to change notification settings - Fork 655
feat: allow configuring fzf options
#2716
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
base: main
Are you sure you want to change the base?
Conversation
|
So please consider a more general solution by forwarding any parameters provided by the user to fzf, not just |
|
Yeah, ofc. Is this better? I haven't actually ever really written any lua. Or would you rather use a |
fzf options
d1efbb8 to
a0ab614
Compare
35d9907 to
2768fd2
Compare
9f077f9 to
60a2382
Compare
|
I am writing a plugin that allows you to configure the search command fd, rg, etc., and all fzf options in one config file beside the main.lua so you can populate different fzf utilities in yazi. I will post it in a few days. |
Do you think this is acceptable? XYenon@1fd7338 |
|
The issue is trickier than expected because This means that something like Also, Furthermore, if plugin arguments are treated as |
then can't we just do the same as in the zoxide plugin - pass the arguments to fzf via an environment variable? yazi/yazi-plugin/preset/plugins/zoxide.lua Lines 44 to 48 in a3e9ea0
but use something like it's less flexible than the programmable way with the lua options, but at least still gives the freedom to the user to modify the arguments. and still probably covers 90% of use cases. edit: only after some thought i realized that's not easy as well, because in case of zoxide the environment variable is just assigned to pass the arguments, but in case of fzf these arguments need to be converted to the format that is accepted in still, i think it's possible to just get the environment variable, parse it to lua list and then pass it to the also, why this PR modifies the magick plugin? also, it's not specific to the current pull request, because it's related to the zoxide plugin, but a code block from this plugin was already mentioned above, so i want to write about it here (if it's approved, i can make a PR): i believe the usage of and i think the zoxide plugin should allow disabling the default options and/or allow disabling reassign of the
and even if i define my |
Yeah we can't easily do so, because that would be a global config. This PR is intended to solve #2715, which is to allow passing different fzf parameters for each key binding. The current problem is that the plugin API can only get key parameters as an unordered dictionary, not an ordered list, whereas fzf requires an ordered list.
Nope, once you pass Hence, Yazi must merge I might add some comments in the code later to clarify this behavior and the reasons for doing so |
oh. i see. i avoided this issue unintentionally by using
i forgot that if the code was written, there is always a reason for that. sorry, should have done my research.
then, does the yazi plugin api support passing quoted arguments? if so, then we can do a hack to pass the arguments to fzf as a single argument to the plugin. either positional or use a specific name ( though it's a hack, i think it's fine. support from the api level to get the arguments in order would be great, but as you mentioned, there should probably be a separation between fzf arguments and fzf plugin arguments, so i'm against "mapping" them directly. and then this string is passed as |
|
i played around a bit. yazi indeed supports quoted arguments. my implementation looks like this: --- a/yazi-plugin/preset/plugins/fzf.lua
+++ b/yazi-plugin/preset/plugins/fzf.lua
@@ -8,13 +8,13 @@ local state = ya.sync(function()
return cx.active.current.cwd, selected
end)
-function M:entry()
+function M:entry(job)
ya.emit("escape", { visual = true })
local _permit = ui.hide()
local cwd, selected = state()
- local output, err = M.run_with(cwd, selected)
+ local output, err = M.run_with(cwd, selected, job.args)
if not output then
return ya.notify { title = "Fzf", content = tostring(err), timeout = 5, level = "error" }
end
@@ -29,13 +29,26 @@ function M:entry()
end
end
-function M.run_with(cwd, selected)
- local child, err = Command("fzf")
- :arg("-m")
+function M.run_with(cwd, selected, args)
+ local fzf_args = (os.getenv("FZF_DEFAULT_OPTS") or "")
+ .. " "
+ .. table.concat({ "--multi" }, " ")
+ .. " "
+ .. (os.getenv("YAZI_FZF_OPTS") or "")
+ .. " "
+ .. (args.pass or "")
+
+ local cmd = Command("fzf")
+ :env("FZF_DEFAULT_OPTS", fzf_args)
:cwd(tostring(cwd))
:stdin(#selected > 0 and Command.PIPED or Command.INHERIT)
:stdout(Command.PIPED)
- :spawn()
+
+ if args.command then
+ cmd:env("FZF_DEFAULT_COMMAND", args.command)
+ end
+
+ local child, err = cmd:spawn()
if not child then
return nil, Err("Failed to start `fzf`, error: %s", err)and then it's used like this: run = '''
plugin fzf -- --pass='--black --preview="fzf-preview.bash {}" --no-multi'
'''i added the additional the author wanted to use so just using with the approach above, the wanted result can be achieved like this: run = "plugin fzf -- --pass='--walker=dir,follow' --command=''"blank aside from that, i still added support for configuring the plugin via environment variable edit: obviously, naming can be changed. maybe i like and an environment variable to set |
41034d0 to
449450d
Compare
Which issue does this PR close?
Closes #2715
Rationale of this PR