-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
47 lines (39 loc) · 1.52 KB
/
main.lua
File metadata and controls
47 lines (39 loc) · 1.52 KB
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
local get_hovered_url = ya.sync(function()
local hovered = cx.active.current.hovered
if hovered then
return tostring(hovered.url)
end
end)
return {
entry = function(_, _)
local path = get_hovered_url()
if not path then
ya.notify({ title = "wsl-path", content = "No file hovered", level = "warn", timeout = 3 })
return
end
local wslpath_child, err = Command("wslpath"):arg("-w"):arg(path):stdout(Command.PIPED):stderr(Command.PIPED):spawn()
if not wslpath_child then
ya.notify({ title = "wsl-path", content = "Failed to spawn wslpath: " .. tostring(err), level = "error", timeout = 5 })
return
end
local wslpath_output = wslpath_child:wait_with_output()
if not wslpath_output.status.success then
ya.notify({ title = "wsl-path", content = "wslpath failed: " .. wslpath_output.stderr, level = "error", timeout = 5 })
return
end
local win_path = wslpath_output.stdout:gsub("%s+$", "")
local clip_child, clip_err = Command("win32yank.exe"):arg("-i"):stdin(Command.PIPED):spawn()
if not clip_child then
ya.notify({ title = "wsl-path", content = "Failed to spawn win32yank.exe: " .. tostring(clip_err), level = "error", timeout = 5 })
return
end
clip_child:write_all(win_path)
clip_child:flush()
local clip_status = clip_child:wait()
if not clip_status or not clip_status.success then
ya.notify({ title = "wsl-path", content = "win32yank.exe failed", level = "error", timeout = 5 })
return
end
ya.notify({ title = "wsl-path", content = win_path, level = "info", timeout = 4 })
end,
}