-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinit.lua
51 lines (44 loc) · 1.15 KB
/
init.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
45
46
47
48
49
50
51
local save = ya.sync(function(st, cwd, output)
if cx.active.current.cwd == Url(cwd) then
st.output = output
ya.render()
end
end)
local default_config = "https://raw.githubusercontent.com/saumyajyoti/omp.yazi/main/yazi-prompt.omp.json"
local get_config = ya.sync(function(st)
return st.config
end)
return {
setup = function(st, args)
Header:children_remove(1, Header.LEFT)
Header:children_add(function() return ui.Line.parse(st.output or "") end, 1000, Header.LEFT)
st.config = default_config
if args ~= nil and args.config ~= nil then
st.config = args.config
end
local callback = function()
local cwd = cx.active.current.cwd
if st.cwd ~= cwd then
st.cwd = cwd
ya.manager_emit("plugin", { st._id, args = ya.quote(tostring(cwd), true) })
end
end
ps.sub("cd", callback)
ps.sub("tab", callback)
end,
entry = function(_, job)
local output = Command("oh-my-posh")
:args({
"print",
"primary",
"--no-status",
"-c",
get_config(),
})
:cwd(job.args[1])
:output()
if output then
save(job.args[1], output.stdout:gsub("^%s+", ""))
end
end,
}