mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
1d8eb59a03
commit
5dc4695e98
2 changed files with 20 additions and 20 deletions
|
|
@ -8,13 +8,20 @@ local state = ya.sync(function()
|
||||||
return cx.active.current.cwd, selected
|
return cx.active.current.cwd, selected
|
||||||
end)
|
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 })
|
ya.emit("escape", { visual = true })
|
||||||
|
|
||||||
local _permit = ya.hide()
|
local _permit = ya.hide()
|
||||||
local cwd, selected = state()
|
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
|
if not output then
|
||||||
return ya.notify { title = "Fzf", content = tostring(err), timeout = 5, level = "error" }
|
return ya.notify { title = "Fzf", content = tostring(err), timeout = 5, level = "error" }
|
||||||
end
|
end
|
||||||
|
|
@ -29,25 +36,18 @@ function M:entry(job)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.run_with(cwd, selected, job)
|
function M:run_with(cwd, selected)
|
||||||
local args = { "-m" }
|
local cmd = Command("fzf")
|
||||||
|
:arg("-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)
|
|
||||||
:cwd(tostring(cwd))
|
:cwd(tostring(cwd))
|
||||||
:stdin(#selected > 0 and Command.PIPED or Command.INHERIT)
|
:stdin(#selected > 0 and Command.PIPED or Command.INHERIT)
|
||||||
:stdout(Command.PIPED)
|
: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
|
if not child then
|
||||||
return nil, Err("Failed to start `fzf`, error: %s", err)
|
return nil, Err("Failed to start `fzf`, error: %s", err)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -50,13 +50,13 @@ function M:spot(job) require("file"):spot(job) end
|
||||||
function M.with_limit()
|
function M.with_limit()
|
||||||
local cmd = Command("magick"):args { "-limit", "thread", 1 }
|
local cmd = Command("magick"):args { "-limit", "thread", 1 }
|
||||||
if rt.tasks.image_alloc > 0 then
|
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
|
end
|
||||||
if rt.tasks.image_bound[1] > 0 then
|
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
|
end
|
||||||
if rt.tasks.image_bound[2] > 0 then
|
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
|
end
|
||||||
return cmd
|
return cmd
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue