Fix events
This commit is contained in:
parent
2afce0278e
commit
a72f85ce15
1 changed files with 38 additions and 34 deletions
|
@ -66,47 +66,51 @@ telescope_knot.zones = function(opts)
|
||||||
local record = _filter_records(entry, records)
|
local record = _filter_records(entry, records)
|
||||||
actions.close(prompt_bufnr)
|
actions.close(prompt_bufnr)
|
||||||
local buffer = vim.api.nvim_create_buf(false, true)
|
local buffer = vim.api.nvim_create_buf(false, true)
|
||||||
vim.api.nvim_buf_set_name(buffer, entry.value)
|
|
||||||
vim.api.nvim_buf_set_lines(buffer, 0, 0, false, record)
|
vim.api.nvim_buf_set_lines(buffer, 0, 0, false, record)
|
||||||
local width = vim.api.nvim_win_get_width(0)
|
local width = vim.api.nvim_win_get_width(0)
|
||||||
local height = vim.api.nvim_win_get_height(0) - 10
|
local height = vim.api.nvim_win_get_height(0) - 10
|
||||||
local _ = vim.api.nvim_open_win(buffer, true,
|
local win = vim.api.nvim_open_win(buffer, true,
|
||||||
{ relative = 'win', bufpos = { 0, 0 }, width = width, height = height, border = 'rounded' })
|
{ relative = 'win', bufpos = { 0, 0 }, width = width, height = height, border = 'rounded' })
|
||||||
vim.api.nvim_set_keymap("n", "q", "<cmd>bd<CR>", {})
|
vim.api.nvim_buf_set_keymap(buffer, "c", "w",
|
||||||
vim.api.nvim_buf_set_keymap(buffer, "c", "w", "<NOP>", {})
|
"lua vim.api.nvim_exec_autocmds('User', { pattern = 'KnotWrite' })<CR>", {})
|
||||||
vim.api.nvim_create_autocmd({ "BufWinLeave" }, {
|
vim.api.nvim_create_autocmd({ "User" }, {
|
||||||
buffer = buffer,
|
buffer = buffer,
|
||||||
callback = function(_)
|
callback = function(event)
|
||||||
local new = vim.api.nvim_buf_get_lines(buffer, 0, -1, false)
|
if event.match == "KnotWrite" then
|
||||||
if new ~= record then
|
local new = vim.api.nvim_buf_get_lines(buffer, 0, -1, false)
|
||||||
local cleanold = {}
|
if new ~= record then
|
||||||
local changed = {}
|
local cleanold = {}
|
||||||
for _, v in ipairs(record) do
|
local updated = {}
|
||||||
if v ~= nil and v ~= "" then
|
local did_update = false
|
||||||
local key = v:match("%w+"):lower()
|
for _, v in ipairs(record) do
|
||||||
cleanold[key] = v:gsub("%w+%:%s", "")
|
if v ~= nil and v ~= "" then
|
||||||
end
|
local key = v:match("%w+"):lower()
|
||||||
end
|
cleanold[key] = v:gsub("%w+%:%s", "")
|
||||||
local cleannew = {}
|
|
||||||
for _, v in ipairs(new) do
|
|
||||||
if v ~= nil and v ~= "" then
|
|
||||||
local key = v:match("%w+"):lower()
|
|
||||||
cleannew[key] = v:gsub("%w+%:%s", "")
|
|
||||||
if cleanold[key] ~= cleannew[key] and (key ~= "url" or key ~= "zone") then
|
|
||||||
table.insert(changed, " -a " .. key .. "=" .. cleannew[key])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
local cleannew = {}
|
||||||
if changed ~= {} then
|
for _, v in ipairs(new) do
|
||||||
local command = "knotctl update -z" .. cleanold.zone ..
|
if v ~= nil and v ~= "" then
|
||||||
" -t" .. cleanold.ttl ..
|
local key = v:match("%w+"):lower()
|
||||||
" -n" .. cleanold.name ..
|
cleannew[key] = v:gsub("%w+%:%s", "")
|
||||||
" -r" .. cleanold.rtype ..
|
if cleanold[key] ~= cleannew[key] and (key ~= "url" or key ~= "zone") then
|
||||||
" -d" .. cleanold.data ..
|
table.insert(updated, " -a " .. key .. "=" .. cleannew[key])
|
||||||
table.concat(changed, " ")
|
did_update = true
|
||||||
local choice = vim.fn.confirm("Update record?", "&Yes\n&No", 2)
|
end
|
||||||
if choice == 1 then
|
end
|
||||||
log.info(vim.fn.system(command))
|
end
|
||||||
|
if did_update then
|
||||||
|
local command = "knotctl update -z" .. cleanold.zone ..
|
||||||
|
" -t" .. cleanold.ttl ..
|
||||||
|
" -n" .. cleanold.name ..
|
||||||
|
" -r" .. cleanold.rtype ..
|
||||||
|
" -d" .. cleanold.data ..
|
||||||
|
table.concat(updated, " ")
|
||||||
|
local choice = vim.fn.confirm("Update record and close buffer?", "&Yes\n&No", 2)
|
||||||
|
if choice == 1 then
|
||||||
|
log.info(vim.fn.system(command))
|
||||||
|
vim.api.nvim_buf_delete(buffer, {})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue