Skip to content

Commit 15f97bd

Browse files
authored
feat(recipes): Add telescope + snacks plugin (#1440)
1 parent 699fbdd commit 15f97bd

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# telescope.nvim with snacks
2+
3+
Find, Filter, Preview, Pick. All lua, all the time.
4+
5+
This adds the telescope.nvim plugin without removing snacks. Use this if another plugin depends on a telescope but you wish to continue using snacks as your picker.
6+
7+
**Repository:** <https://github.com/nvim-telescope/telescope.nvim>
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
return {
2+
"nvim-telescope/telescope.nvim",
3+
specs = {
4+
{ "nvim-lua/plenary.nvim", lazy = true },
5+
},
6+
dependencies = {
7+
"nvim-treesitter/nvim-treesitter",
8+
{
9+
"nvim-telescope/telescope-fzf-native.nvim",
10+
lazy = true,
11+
enabled = vim.fn.executable "make" == 1 or vim.fn.executable "cmake" == 1,
12+
build = vim.fn.executable "make" == 1 and "make"
13+
or "cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build",
14+
config = function(plugin)
15+
local astrocore = require "astrocore"
16+
astrocore.on_load("telescope.nvim", function()
17+
local ok, err = pcall(require("telescope").load_extension, "fzf")
18+
if not ok then
19+
local lib = plugin.dir .. "/build/libfzf." .. (vim.fn.has "win32" == 1 and "dll" or "so")
20+
if not (vim.uv or vim.loop).fs_stat(lib) then
21+
astrocore.notify("`telescope-fzf-native.nvim` not built. Rebuilding...", vim.log.levels.WARN)
22+
require("lazy").build({ plugins = { plugin }, show = false }):wait(
23+
function() astrocore.notify "Rebuilding `telescope-fzf-native.nvim` done.\nPlease restart Neovim." end
24+
)
25+
else
26+
astrocore.notify("Failed to load `telescope-fzf-native.nvim`:\n" .. err, vim.log.levels.ERROR)
27+
end
28+
end
29+
end)
30+
end,
31+
},
32+
},
33+
cmd = "Telescope",
34+
opts = function(_, opts)
35+
local actions, get_icon = require "telescope.actions", require("astroui").get_icon
36+
local function open_selected(prompt_bufnr)
37+
local picker = require("telescope.actions.state").get_current_picker(prompt_bufnr)
38+
local selected = picker:get_multi_selection()
39+
if vim.tbl_isempty(selected) then
40+
actions.select_default(prompt_bufnr)
41+
else
42+
actions.close(prompt_bufnr)
43+
for _, file in pairs(selected) do
44+
if file.path then vim.cmd("edit" .. (file.lnum and " +" .. file.lnum or "") .. " " .. file.path) end
45+
end
46+
end
47+
end
48+
local function open_all(prompt_bufnr)
49+
actions.select_all(prompt_bufnr)
50+
open_selected(prompt_bufnr)
51+
end
52+
53+
local is_available = require("astrocore").is_available
54+
local telescope = require "telescope"
55+
if is_available "nvim-notify" then telescope.load_extension "notify" end
56+
if is_available "aerial.nvim" then telescope.load_extension "aerial" end
57+
return require("astrocore").extend_tbl(opts, {
58+
defaults = {
59+
file_ignore_patterns = { "^%.git[/\\]", "[/\\]%.git[/\\]" },
60+
git_worktrees = require("astrocore").config.git_worktrees,
61+
prompt_prefix = get_icon("Selected", 1),
62+
selection_caret = get_icon("Selected", 1),
63+
multi_icon = get_icon("Selected", 1),
64+
path_display = { "truncate" },
65+
sorting_strategy = "ascending",
66+
layout_config = {
67+
horizontal = { prompt_position = "top", preview_width = 0.55 },
68+
vertical = { mirror = false },
69+
width = 0.87,
70+
height = 0.80,
71+
preview_cutoff = 120,
72+
},
73+
mappings = {
74+
i = {
75+
["<C-J>"] = actions.move_selection_next,
76+
["<C-K>"] = actions.move_selection_previous,
77+
["<CR>"] = open_selected,
78+
["<M-CR>"] = open_all,
79+
},
80+
n = {
81+
q = actions.close,
82+
["<CR>"] = open_selected,
83+
["<M-CR>"] = open_all,
84+
},
85+
},
86+
},
87+
})
88+
end,
89+
}

0 commit comments

Comments
 (0)