You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB

6 days ago
local pickers = require("telescope.pickers")
local finders = require("telescope.finders")
local conf = require("telescope.config").values
local previewers = require("telescope.previewers")
local log = require('plenary.log').new {
plugin = 'telescope_knot',
level = 'info',
}
local telescope_knot = {}
telescope_knot.zones = function(opts)
local results = vim.json.decode(vim.fn.system("knotctl --json list"))
local entries = vim.tbl_map(function(zone)
return zone.name
end, results)
pickers.new(opts, {
dropdown = true,
prompt_title = "Zones",
sorter = conf.generic_sorter(opts),
finder = finders.new_table(entries),
previewer = previewers.new_buffer_previewer({
title = "Zone",
define_preview = function(self, entry)
local zone = {}
for _, z in ipairs(results) do
if z.name == entry.display then
zone = z
break
end
end
if zone then
local formatted_zone = vim.tbl_map(
function(record)
return record.rtype .. " " .. record.name .. " " .. record.data
end,
zone["records"])
vim.api.nvim_buf_set_lines(self.state.bufnr, 0, 0, false, formatted_zone)
end
end
}),
}):find()
end
return require('telescope').register_extension({
exports = {
telescope_knot = telescope_knot.zones,
},
})