-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
44 lines (34 loc) · 1.14 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
local function fail(s, ...)
ya.notify({ title = "cdhist", content = s:format(...), timeout = 5, level = "error" })
end
local function entry(_, job)
ya.hide()
local args = { "--" }
-- Yazi plugins only support long options at present
for k, v in pairs(job.args or {}) do
if type(k) == "string" then
if v and v ~= "" then
table.insert(args, 1, v)
end
table.insert(args, 1, "--" .. k)
end
end
local child, err_run =
Command("cdhist"):args(args):stdin(Command.INHERIT):stdout(Command.PIPED):stderr(Command.PIPED):spawn()
if not child or err_run then
return fail("Failed to start `cdhist`, error: " .. err_run)
end
local output, err_out = child:wait_with_output()
if err_out then
return fail("Cannot read `cdhist` output, error: " .. err_out)
end
if output.stderr ~= "" then
return fail("Error from `cdhist`:" .. output.stderr)
end
local dir = output.stdout:gsub("\n$", "")
if dir ~= "" then
ya.manager_emit("cd", { dir })
end
end
return { entry = entry }
-- vim: sw=4:ts=4:sts=4:et