commit 2d5dea59cf77690d2311e2e4c5a99e620beb9515 Author: Micke Nordin Date: Fri Dec 20 15:14:49 2024 +0100 Initial diff --git a/lua/telescope/_extensions/telescope_knot.lua b/lua/telescope/_extensions/telescope_knot.lua new file mode 100644 index 0000000..40e3483 --- /dev/null +++ b/lua/telescope/_extensions/telescope_knot.lua @@ -0,0 +1,50 @@ +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, + }, +})