From cb3eea6208daa6ea47194ca40321fec46c5f7d07 Mon Sep 17 00:00:00 2001 From: Claus Beerta Date: Sun, 4 May 2025 09:15:02 +0200 Subject: [PATCH 1/5] feat: allow setting the walker --- yazi-plugin/preset/plugins/fzf.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/yazi-plugin/preset/plugins/fzf.lua b/yazi-plugin/preset/plugins/fzf.lua index 45fb5720b..e8c57b77c 100644 --- 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 = ya.hide() local cwd, selected = state() - local output, err = M.run_with(cwd, selected) + local output, err = M.run_with(cwd, selected, job) if not output then return ya.notify { title = "Fzf", content = tostring(err), timeout = 5, level = "error" } end @@ -29,9 +29,15 @@ function M:entry() end end -function M.run_with(cwd, selected) +function M.run_with(cwd, selected, job) + local args = {"-m"} + + if job.args.walker then + table.insert(args, "--walker="..job.args.walker) + end + local child, err = Command("fzf") - :arg("-m") + :args(args) :cwd(tostring(cwd)) :stdin(#selected > 0 and Command.PIPED or Command.INHERIT) :stdout(Command.PIPED) From 84d519e9733156bd83c77c92891136d2a81a563e Mon Sep 17 00:00:00 2001 From: Claus Beerta Date: Sun, 4 May 2025 09:27:40 +0200 Subject: [PATCH 2/5] fix stylechecks --- yazi-plugin/preset/plugins/fzf.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yazi-plugin/preset/plugins/fzf.lua b/yazi-plugin/preset/plugins/fzf.lua index e8c57b77c..f1dae418a 100644 --- a/yazi-plugin/preset/plugins/fzf.lua +++ b/yazi-plugin/preset/plugins/fzf.lua @@ -30,10 +30,10 @@ function M:entry(job) end function M.run_with(cwd, selected, job) - local args = {"-m"} + local args = { "-m" } if job.args.walker then - table.insert(args, "--walker="..job.args.walker) + table.insert(args, "--walker=" .. job.args.walker) end local child, err = Command("fzf") From 1d8eb59a03d45da7ba94b4bdff6937ece0a82469 Mon Sep 17 00:00:00 2001 From: Claus Beerta Date: Sun, 4 May 2025 18:51:03 +0200 Subject: [PATCH 3/5] allow any fzf option --- yazi-plugin/preset/plugins/fzf.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/yazi-plugin/preset/plugins/fzf.lua b/yazi-plugin/preset/plugins/fzf.lua index f1dae418a..55a6234d5 100644 --- a/yazi-plugin/preset/plugins/fzf.lua +++ b/yazi-plugin/preset/plugins/fzf.lua @@ -32,8 +32,13 @@ end function M.run_with(cwd, selected, job) local args = { "-m" } - if job.args.walker then - table.insert(args, "--walker=" .. job.args.walker) + for cmd, option in pairs(job.args) do + local c = cmd:gsub("_", "-") + if type(option) == "boolean" then + table.insert(args, "--" .. c) + else + table.insert(args, "--" .. c .. "=" .. option) + end end local child, err = Command("fzf") From 5dc4695e98425e5c0ff5d26e0bf676977a5e0941 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Mon, 12 May 2025 11:08:33 +0800 Subject: [PATCH 4/5] .. --- yazi-plugin/preset/plugins/fzf.lua | 34 +++++++++++++-------------- yazi-plugin/preset/plugins/magick.lua | 6 ++--- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/yazi-plugin/preset/plugins/fzf.lua b/yazi-plugin/preset/plugins/fzf.lua index 55a6234d5..09aa60daa 100644 --- a/yazi-plugin/preset/plugins/fzf.lua +++ b/yazi-plugin/preset/plugins/fzf.lua @@ -8,13 +8,20 @@ local state = ya.sync(function() return cx.active.current.cwd, selected end) -function M:entry(job) +function M:setup(tbl) + tbl = tbl or {} + if tbl.opts then + self.opts = table.concat(tbl.opts, " ") + end +end + +function M:entry() ya.emit("escape", { visual = true }) local _permit = ya.hide() local cwd, selected = state() - local output, err = M.run_with(cwd, selected, job) + local output, err = self:run_with(cwd, selected) if not output then return ya.notify { title = "Fzf", content = tostring(err), timeout = 5, level = "error" } end @@ -29,25 +36,18 @@ function M:entry(job) end end -function M.run_with(cwd, selected, job) - local args = { "-m" } - - for cmd, option in pairs(job.args) do - local c = cmd:gsub("_", "-") - if type(option) == "boolean" then - table.insert(args, "--" .. c) - else - table.insert(args, "--" .. c .. "=" .. option) - end - end - - local child, err = Command("fzf") - :args(args) +function M:run_with(cwd, selected) + local cmd = Command("fzf") + :arg("-m") :cwd(tostring(cwd)) :stdin(#selected > 0 and Command.PIPED or Command.INHERIT) :stdout(Command.PIPED) - :spawn() + if self.opts then + cmd:env("FZF_DEFAULT_OPTS", self.opts) + end + + local child, err = cmd:spawn() if not child then return nil, Err("Failed to start `fzf`, error: %s", err) end diff --git a/yazi-plugin/preset/plugins/magick.lua b/yazi-plugin/preset/plugins/magick.lua index 365d42d6b..291f1eb90 100644 --- a/yazi-plugin/preset/plugins/magick.lua +++ b/yazi-plugin/preset/plugins/magick.lua @@ -50,13 +50,13 @@ function M:spot(job) require("file"):spot(job) end function M.with_limit() local cmd = Command("magick"):args { "-limit", "thread", 1 } if rt.tasks.image_alloc > 0 then - cmd = cmd:args({ "-limit", "memory", rt.tasks.image_alloc }):args { "-limit", "disk", "1MiB" } + cmd:args({ "-limit", "memory", rt.tasks.image_alloc }):args { "-limit", "disk", "1MiB" } end if rt.tasks.image_bound[1] > 0 then - cmd = cmd:args { "-limit", "width", rt.tasks.image_bound[1] } + cmd:args { "-limit", "width", rt.tasks.image_bound[1] } end if rt.tasks.image_bound[2] > 0 then - cmd = cmd:args { "-limit", "height", rt.tasks.image_bound[2] } + cmd:args { "-limit", "height", rt.tasks.image_bound[2] } end return cmd end From e13a03ce4e8fecd061058d945295924a919a0903 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Mon, 12 May 2025 11:15:23 +0800 Subject: [PATCH 5/5] .. --- yazi-plugin/preset/plugins/fzf.lua | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/yazi-plugin/preset/plugins/fzf.lua b/yazi-plugin/preset/plugins/fzf.lua index 09aa60daa..665bdd2ce 100644 --- a/yazi-plugin/preset/plugins/fzf.lua +++ b/yazi-plugin/preset/plugins/fzf.lua @@ -8,11 +8,9 @@ local state = ya.sync(function() return cx.active.current.cwd, selected end) -function M:setup(tbl) - tbl = tbl or {} - if tbl.opts then - self.opts = table.concat(tbl.opts, " ") - end +function M:setup(opts) + opts = opts or {} + self.args = opts.args end function M:entry() @@ -37,17 +35,14 @@ function M:entry() end function M:run_with(cwd, selected) - local cmd = Command("fzf") + local child, err = Command("fzf") :arg("-m") + :args(self.args or {}) :cwd(tostring(cwd)) :stdin(#selected > 0 and Command.PIPED or Command.INHERIT) :stdout(Command.PIPED) + :spawn() - if self.opts then - cmd:env("FZF_DEFAULT_OPTS", self.opts) - end - - local child, err = cmd:spawn() if not child then return nil, Err("Failed to start `fzf`, error: %s", err) end