telescope最小化应用
local pickers = require "telescope.pickers"
local finders = require("telescope.finders")
local themes = require("telescope.themes")
local actions = require("telescope.actions")
local action_state = require("telescope.actions.state")
local conf = require("telescope.config").values
function pp()
local function entry_maker(entry)
return {
value = entry,
display = string.format( "%s / * %s", entry.path, entry.ext),
ordinal = entry.path,
}
end
local theme = themes.get_ivy({
layout_config = {
prompt_position = "top",
height = 10,
},
})
local finder = finders.new_table({
results = {
{path = "~/wiki/cpp" , ext=".md"},
{path = "~/wiki/cpp" , ext=".tex"},
},
entry_maker = entry_maker,
})
local opts = {
finder = finder,
sorter = conf.generic_sorter(opts),
prompt_title = "Test Pickers",
attach_mappings = function(prompt_bufnr, _)
actions.select_default:replace(function()
actions._close(prompt_bufnr, true)
local selection = action_state.get_selected_entry().value
print("set note for " .. selection.ext .. '@' .. selection.path)
local path = selection.path
local ext = selection.ext
require('telekasten').setup({home = vim.fn.expand(path),extension=ext})
end)
return true
end,
}
local picker = pickers.new(opts, theme)
picker:find()
end