52 lines
1.1 KiB
Lua
52 lines
1.1 KiB
Lua
local M = {}
|
|
local uv = vim.loop
|
|
|
|
local function ensure_dir(path)
|
|
local st = uv.fs_stat(path)
|
|
if st and st.type == 'directory' then
|
|
return true
|
|
end
|
|
local parent = path:match("(.*)/")
|
|
if parent and parent ~= "" then
|
|
ensure_dir(parent)
|
|
end
|
|
uv.fs_mkdir(path, 511)
|
|
return true
|
|
end
|
|
|
|
function M.get_clipboard_content()
|
|
return vim.fn.getreg('+')
|
|
end
|
|
|
|
function M.write_file(filepath, content)
|
|
local dir = filepath:match("(.*)/")
|
|
if dir and dir ~= "" then
|
|
ensure_dir(dir)
|
|
end
|
|
local fd = uv.fs_open(filepath, "w", 438)
|
|
if not fd then
|
|
vim.api.nvim_err_writeln("Could not open file for writing: " .. filepath)
|
|
return
|
|
end
|
|
uv.fs_write(fd, content, -1)
|
|
uv.fs_close(fd)
|
|
end
|
|
|
|
function M.delete_file(filepath)
|
|
local st = uv.fs_stat(filepath)
|
|
if st then
|
|
local success, err = uv.fs_unlink(filepath)
|
|
if not success then
|
|
vim.api.nvim_err_writeln("Could not delete file: " .. filepath .. " - " .. (err or "unknown error"))
|
|
end
|
|
else
|
|
vim.api.nvim_err_writeln("File not found, cannot delete: " .. filepath)
|
|
end
|
|
end
|
|
|
|
function M.finish()
|
|
print("Finished processing files.")
|
|
end
|
|
|
|
return M
|