Optimize and slightly refactor the setup for telescope. We now only
setup our theme and the picker options once instead of each time we call to open one.
This commit is contained in:
parent
77eab724c6
commit
77b61eaf59
1 changed files with 56 additions and 42 deletions
|
|
@ -5,16 +5,6 @@ return {
|
|||
"nvim-telescope/telescope-fzf-native.nvim",
|
||||
},
|
||||
config = function()
|
||||
local dropdown = require("telescope.themes").get_dropdown({
|
||||
borderchars = {
|
||||
prompt = { "─", "│", "─", "│", "┌", "┐", "┘", "└" },
|
||||
results = { "─", "│", "─", "│", "├", "┤", "┘", "└" },
|
||||
preview = { "─", "│", "─", "│", "┌", "┐", "┘", "└" },
|
||||
},
|
||||
prompt_title = "",
|
||||
winblend = 20
|
||||
})
|
||||
|
||||
require("telescope").setup({
|
||||
extensions = {
|
||||
fzf = {
|
||||
|
|
@ -28,38 +18,62 @@ return {
|
|||
|
||||
require("telescope").load_extension("fzf")
|
||||
local builtin = require("telescope.builtin")
|
||||
require("utils").add_keymaps({
|
||||
n = {
|
||||
["<leader>to"] = {
|
||||
cmd = function()
|
||||
builtin.find_files(vim.tbl_extend("force", dropdown, {
|
||||
prompt_prefix = "Files> ",
|
||||
previewer = false,
|
||||
}))
|
||||
end
|
||||
},
|
||||
["<leader>tf"] = {
|
||||
cmd = function()
|
||||
builtin.current_buffer_fuzzy_find(vim.tbl_extend("force", dropdown, {
|
||||
prompt_prefix = "Find> "
|
||||
}))
|
||||
end
|
||||
},
|
||||
["<leader>ta"] = {
|
||||
cmd = function()
|
||||
builtin.live_grep(vim.tbl_extend("force", dropdown, {
|
||||
prompt_prefix = "Grep> "
|
||||
}))
|
||||
end
|
||||
},
|
||||
["<leader>tb"] = {
|
||||
cmd = function()
|
||||
builtin.marks(vim.tbl_extend("force", dropdown, {
|
||||
prompt_prefix = "Marks> "
|
||||
}))
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
local dropdown = require("telescope.themes").get_dropdown({
|
||||
borderchars = {
|
||||
prompt = { "─", "│", "─", "│", "┌", "┐", "┘", "└" },
|
||||
results = { "─", "│", "─", "│", "├", "┤", "┘", "└" },
|
||||
preview = { "─", "│", "─", "│", "┌", "┐", "┘", "└" },
|
||||
},
|
||||
prompt_title = "",
|
||||
winblend = 20
|
||||
})
|
||||
|
||||
local pickers = {
|
||||
{
|
||||
fn = builtin.find_files,
|
||||
key = "o",
|
||||
picker_opts = {
|
||||
prompt_prefix = "Files> ",
|
||||
previewer = false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fn = builtin.current_buffer_fuzzy_find,
|
||||
key = "f",
|
||||
picker_opts = {
|
||||
prompt_prefix = "Find> "
|
||||
},
|
||||
},
|
||||
{
|
||||
fn = builtin.live_grep,
|
||||
key = "a",
|
||||
picker_opts = {
|
||||
prompt_prefix = "Grep> "
|
||||
},
|
||||
},
|
||||
{
|
||||
fn = builtin.marks,
|
||||
key = "b",
|
||||
picker_opts = {
|
||||
prompt_prefix = "Marks> "
|
||||
},
|
||||
},
|
||||
}
|
||||
-- Cache the options with the dropdown theme for each picker so we don't
|
||||
-- recalculate it every time we open a picker
|
||||
for _, v in ipairs(pickers) do
|
||||
v.picker_opts = vim.tbl_extend("force", dropdown, v.picker_opts)
|
||||
end
|
||||
|
||||
local keymaps = { n = {} }
|
||||
for _, v in ipairs(pickers) do
|
||||
keymaps.n["<leader>t" .. v.key] = {
|
||||
cmd = function()
|
||||
v.fn(v.picker_opts)
|
||||
end
|
||||
}
|
||||
end
|
||||
require("utils").add_keymaps(keymaps)
|
||||
end,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue