zk-nvim
zk-nvim copied to clipboard
How can i search content using telescope ui?
Hi,
Im quite new to lua development, so wondering how can i do a live-searching in telescope ui? jus tlike the one in searching ZKNotes?
Here's a simple implementation for ZkGrep
function M.grep_notes(opts)
local collection = {}
local list_opts = { select = { "title", "path", "absPath" } }
require("zk.api").list(vim.env.ZK_NOTEBOOK_DIR, list_opts, function(_, notes)
for _, note in ipairs(notes) do
collection[note.absPath] = note.title or note.path
end
end)
local options = vim.tbl_deep_extend("force", {
prompt_title = "Notes",
search_dirs = { vim.env.ZK_NOTEBOOK_DIR },
disable_coordinates = true,
path_display = function(_, path)
return collection[path]
end,
}, opts or {})
require("telescope.builtin").live_grep(options)
end
vim.api.nvim_create_user_command("ZkGrep", M.grep_notes, {})
Note: it's possible to make the display closer to zk edit, but that requires re-writing a complex entry_maker.gen_from_vimgrep
Thanks! this totally works!!