mirror of
https://github.com/sxyazi/yazi.git
synced 2024-12-20 23:31:44 +03:00
30 lines
959 B
Lua
30 lines
959 B
Lua
local state = ya.sync(function() return cx.active.current.cwd end)
|
|
|
|
local function fail(s, ...) ya.notify { title = "Fzf", content = string.format(s, ...), timeout = 5, level = "error" } end
|
|
|
|
local function entry()
|
|
local _permit = ya.hide()
|
|
local cwd = tostring(state())
|
|
|
|
local child, err =
|
|
Command("fzf"):cwd(cwd):stdin(Command.INHERIT):stdout(Command.PIPED):stderr(Command.INHERIT):spawn()
|
|
|
|
if not child then
|
|
return fail("Spawn `fzf` failed with error code %s. Do you have it installed?", err)
|
|
end
|
|
|
|
local output, err = child:wait_with_output()
|
|
if not output then
|
|
return fail("Cannot read `fzf` output, error code %s", err)
|
|
elseif not output.status.success and output.status.code ~= 130 then
|
|
return fail("`fzf` exited with error code %s", output.status.code)
|
|
end
|
|
|
|
local target = output.stdout:gsub("\n$", "")
|
|
if target ~= "" then
|
|
ya.manager_emit(target:find("[/\\]$") and "cd" or "reveal", { target })
|
|
end
|
|
end
|
|
|
|
return { entry = entry }
|