-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.lua
51 lines (43 loc) · 1.19 KB
/
utils.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
M = {}
function M.quick_notification(msg) vim.notify(msg, "info", { title = "AstroNvim", timeout = 0 }) end
function M.vim_opt_toggle(opt, on, off, name)
local is_off = vim.opt[opt]:get() == off
vim.opt[opt] = is_off and on or off
M.quick_notification(name .. " " .. (is_off and "Enabled" or "Disabled"))
end
function M.async_run(cmd, on_finish)
local lines = { "" }
local function on_event(_, data, event)
if (event == "stdout" or event == "stderr") and data then vim.list_extend(lines, data) end
if event == "exit" then
vim.fn.setqflist({}, " ", {
title = table.concat(cmd, " "),
lines = lines,
efm = "%f:%l:%c: %t%n %m",
})
if on_finish then on_finish() end
end
end
vim.fn.jobstart(cmd, {
on_stdout = on_event,
on_stderr = on_event,
on_exit = on_event,
stdout_buffered = true,
stderr_buffered = true,
})
end
function M.toggle_qf()
local qf_exists = false
for _, win in pairs(vim.fn.getwininfo()) do
if win["quickfix"] == 1 then
qf_exists = true
break
end
end
if qf_exists then
vim.cmd "cclose"
elseif not vim.tbl_isempty(vim.fn.getqflist()) then
vim.cmd "copen"
end
end
return M