2024-04-22 09:18:00 +03:00
|
|
|
local state = ya.sync(function() return cx.active.current.cwd end)
|
2024-04-07 14:28:09 +03:00
|
|
|
|
2024-04-08 03:29:21 +03:00
|
|
|
local function fail(s, ...) ya.notify { title = "Fzf", content = string.format(s, ...), timeout = 5, level = "error" } end
|
2024-04-07 14:28:09 +03:00
|
|
|
|
|
|
|
local function entry()
|
|
|
|
local _permit = ya.hide()
|
2024-04-22 09:18:00 +03:00
|
|
|
local cwd = tostring(state())
|
2024-04-07 14:28:09 +03:00
|
|
|
|
|
|
|
local child, err =
|
|
|
|
Command("fzf"):cwd(cwd):stdin(Command.INHERIT):stdout(Command.PIPED):stderr(Command.INHERIT):spawn()
|
|
|
|
|
|
|
|
if not child then
|
2024-04-08 03:29:21 +03:00
|
|
|
return fail("Spawn `fzf` failed with error code %s. Do you have it installed?", err)
|
2024-04-07 14:28:09 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local output, err = child:wait_with_output()
|
|
|
|
if not output then
|
2024-04-08 03:29:21 +03:00
|
|
|
return fail("Cannot read `fzf` output, error code %s", err)
|
2024-05-30 20:09:30 +03:00
|
|
|
elseif not output.status.success and output.status.code ~= 130 then
|
|
|
|
return fail("`fzf` exited with error code %s", output.status.code)
|
2024-04-07 14:28:09 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local target = output.stdout:gsub("\n$", "")
|
2024-04-08 03:29:21 +03:00
|
|
|
if target ~= "" then
|
2024-07-28 03:14:53 +03:00
|
|
|
ya.manager_emit(target:find("[/\\]$") and "cd" or "reveal", { target })
|
2024-04-08 03:29:21 +03:00
|
|
|
end
|
2024-04-07 14:28:09 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
return { entry = entry }
|