zk-nvim icon indicating copy to clipboard operation
zk-nvim copied to clipboard

How can i search content using telescope ui?

Open zsmatrix62 opened this issue 3 years ago • 1 comments

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?

zsmatrix62 avatar Aug 03 '22 06:08 zsmatrix62

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

kylo252 avatar Aug 12 '22 11:08 kylo252

Thanks! this totally works!!

zsmatrix62 avatar Aug 17 '22 18:08 zsmatrix62