|
| 1 | +return { |
| 2 | + "nvim-telescope/telescope.nvim", |
| 3 | + specs = { |
| 4 | + { "nvim-lua/plenary.nvim", lazy = true }, |
| 5 | + { "folke/snacks.nvim", opts = { picker = { enabled = false } } }, |
| 6 | + { |
| 7 | + "AstroNvim/astrocore", |
| 8 | + opts = function(_, opts) |
| 9 | + local maps = opts.mappings |
| 10 | + local astro = require "astrocore" |
| 11 | + local is_available = astro.is_available |
| 12 | + maps.n["<Leader>f"] = vim.tbl_get(opts, "_map_sections", "f") |
| 13 | + if vim.fn.executable "git" == 1 then |
| 14 | + maps.n["<Leader>g"] = vim.tbl_get(opts, "_map_sections", "g") |
| 15 | + maps.n["<Leader>gb"] = { |
| 16 | + function() require("telescope.builtin").git_branches { use_file_path = true } end, |
| 17 | + desc = "Git branches", |
| 18 | + } |
| 19 | + maps.n["<Leader>gc"] = { |
| 20 | + function() require("telescope.builtin").git_commits { use_file_path = true } end, |
| 21 | + desc = "Git commits (repository)", |
| 22 | + } |
| 23 | + maps.n["<Leader>gC"] = { |
| 24 | + function() require("telescope.builtin").git_bcommits { use_file_path = true } end, |
| 25 | + desc = "Git commits (current file)", |
| 26 | + } |
| 27 | + maps.n["<Leader>gt"] = |
| 28 | + { function() require("telescope.builtin").git_status { use_file_path = true } end, desc = "Git status" } |
| 29 | + end |
| 30 | + maps.n["<Leader>f<CR>"] = |
| 31 | + { function() require("telescope.builtin").resume() end, desc = "Resume previous search" } |
| 32 | + maps.n["<Leader>f'"] = { function() require("telescope.builtin").marks() end, desc = "Find marks" } |
| 33 | + maps.n["<Leader>f/"] = { |
| 34 | + function() require("telescope.builtin").current_buffer_fuzzy_find() end, |
| 35 | + desc = "Find words in current buffer", |
| 36 | + } |
| 37 | + maps.n["<Leader>fa"] = { |
| 38 | + function() |
| 39 | + require("telescope.builtin").find_files { |
| 40 | + prompt_title = "Config Files", |
| 41 | + cwd = vim.fn.stdpath "config", |
| 42 | + follow = true, |
| 43 | + } |
| 44 | + end, |
| 45 | + desc = "Find AstroNvim config files", |
| 46 | + } |
| 47 | + maps.n["<Leader>fb"] = { function() require("telescope.builtin").buffers() end, desc = "Find buffers" } |
| 48 | + maps.n["<Leader>fc"] = |
| 49 | + { function() require("telescope.builtin").grep_string() end, desc = "Find word under cursor" } |
| 50 | + maps.n["<Leader>fC"] = { function() require("telescope.builtin").commands() end, desc = "Find commands" } |
| 51 | + maps.n["<Leader>ff"] = { function() require("telescope.builtin").find_files() end, desc = "Find files" } |
| 52 | + maps.n["<Leader>fF"] = { |
| 53 | + function() require("telescope.builtin").find_files { hidden = true, no_ignore = true } end, |
| 54 | + desc = "Find all files", |
| 55 | + } |
| 56 | + maps.n["<Leader>fg"] = { function() require("telescope.builtin").git_files() end, desc = "Find git files" } |
| 57 | + maps.n["<Leader>fh"] = { function() require("telescope.builtin").help_tags() end, desc = "Find help" } |
| 58 | + maps.n["<Leader>fk"] = { function() require("telescope.builtin").keymaps() end, desc = "Find keymaps" } |
| 59 | + maps.n["<Leader>fm"] = { function() require("telescope.builtin").man_pages() end, desc = "Find man" } |
| 60 | + if is_available "nvim-notify" then |
| 61 | + maps.n["<Leader>fn"] = |
| 62 | + { function() require("telescope").extensions.notify.notify() end, desc = "Find notifications" } |
| 63 | + end |
| 64 | + maps.n["<Leader>fo"] = { function() require("telescope.builtin").oldfiles() end, desc = "Find history" } |
| 65 | + maps.n["<Leader>fr"] = { function() require("telescope.builtin").registers() end, desc = "Find registers" } |
| 66 | + maps.n["<Leader>ft"] = { |
| 67 | + function() require("telescope.builtin").colorscheme { enable_preview = true, ignore_builtins = true } end, |
| 68 | + desc = "Find themes", |
| 69 | + } |
| 70 | + if vim.fn.executable "rg" == 1 then |
| 71 | + maps.n["<Leader>fw"] = { function() require("telescope.builtin").live_grep() end, desc = "Find words" } |
| 72 | + maps.n["<Leader>fW"] = { |
| 73 | + function() |
| 74 | + require("telescope.builtin").live_grep { |
| 75 | + additional_args = function(args) return vim.list_extend(args, { "--hidden", "--no-ignore" }) end, |
| 76 | + } |
| 77 | + end, |
| 78 | + desc = "Find words in all files", |
| 79 | + } |
| 80 | + end |
| 81 | + maps.n["<Leader>lD"] = |
| 82 | + { function() require("telescope.builtin").diagnostics() end, desc = "Search diagnostics" } |
| 83 | + maps.n["<Leader>ls"] = { |
| 84 | + function() |
| 85 | + if is_available "aerial.nvim" then |
| 86 | + require("telescope").extensions.aerial.aerial() |
| 87 | + else |
| 88 | + require("telescope.builtin").lsp_document_symbols() |
| 89 | + end |
| 90 | + end, |
| 91 | + desc = "Search symbols", |
| 92 | + } |
| 93 | + end, |
| 94 | + }, |
| 95 | + }, |
| 96 | + dependencies = { |
| 97 | + "nvim-treesitter/nvim-treesitter", |
| 98 | + { |
| 99 | + "nvim-telescope/telescope-fzf-native.nvim", |
| 100 | + lazy = true, |
| 101 | + enabled = vim.fn.executable "make" == 1 or vim.fn.executable "cmake" == 1, |
| 102 | + build = vim.fn.executable "make" == 1 and "make" |
| 103 | + or "cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build", |
| 104 | + config = function(plugin) |
| 105 | + local astrocore = require "astrocore" |
| 106 | + astrocore.on_load("telescope.nvim", function() |
| 107 | + local ok, err = pcall(require("telescope").load_extension, "fzf") |
| 108 | + if not ok then |
| 109 | + local lib = plugin.dir .. "/build/libfzf." .. (vim.fn.has "win32" == 1 and "dll" or "so") |
| 110 | + if not (vim.uv or vim.loop).fs_stat(lib) then |
| 111 | + astrocore.notify("`telescope-fzf-native.nvim` not built. Rebuilding...", vim.log.levels.WARN) |
| 112 | + require("lazy").build({ plugins = { plugin }, show = false }):wait( |
| 113 | + function() astrocore.notify "Rebuilding `telescope-fzf-native.nvim` done.\nPlease restart Neovim." end |
| 114 | + ) |
| 115 | + else |
| 116 | + astrocore.notify("Failed to load `telescope-fzf-native.nvim`:\n" .. err, vim.log.levels.ERROR) |
| 117 | + end |
| 118 | + end |
| 119 | + end) |
| 120 | + end, |
| 121 | + }, |
| 122 | + }, |
| 123 | + cmd = "Telescope", |
| 124 | + opts = function(_, opts) |
| 125 | + local actions, get_icon = require "telescope.actions", require("astroui").get_icon |
| 126 | + local function open_selected(prompt_bufnr) |
| 127 | + local picker = require("telescope.actions.state").get_current_picker(prompt_bufnr) |
| 128 | + local selected = picker:get_multi_selection() |
| 129 | + if vim.tbl_isempty(selected) then |
| 130 | + actions.select_default(prompt_bufnr) |
| 131 | + else |
| 132 | + actions.close(prompt_bufnr) |
| 133 | + for _, file in pairs(selected) do |
| 134 | + if file.path then vim.cmd("edit" .. (file.lnum and " +" .. file.lnum or "") .. " " .. file.path) end |
| 135 | + end |
| 136 | + end |
| 137 | + end |
| 138 | + local function open_all(prompt_bufnr) |
| 139 | + actions.select_all(prompt_bufnr) |
| 140 | + open_selected(prompt_bufnr) |
| 141 | + end |
| 142 | + |
| 143 | + local is_available = require("astrocore").is_available |
| 144 | + local telescope = require "telescope" |
| 145 | + if is_available "nvim-notify" then telescope.load_extension "notify" end |
| 146 | + if is_available "aerial.nvim" then telescope.load_extension "aerial" end |
| 147 | + return require("astrocore").extend_tbl(opts, { |
| 148 | + defaults = { |
| 149 | + file_ignore_patterns = { "^%.git[/\\]", "[/\\]%.git[/\\]" }, |
| 150 | + git_worktrees = require("astrocore").config.git_worktrees, |
| 151 | + prompt_prefix = get_icon("Selected", 1), |
| 152 | + selection_caret = get_icon("Selected", 1), |
| 153 | + multi_icon = get_icon("Selected", 1), |
| 154 | + path_display = { "truncate" }, |
| 155 | + sorting_strategy = "ascending", |
| 156 | + layout_config = { |
| 157 | + horizontal = { prompt_position = "top", preview_width = 0.55 }, |
| 158 | + vertical = { mirror = false }, |
| 159 | + width = 0.87, |
| 160 | + height = 0.80, |
| 161 | + preview_cutoff = 120, |
| 162 | + }, |
| 163 | + mappings = { |
| 164 | + i = { |
| 165 | + ["<C-J>"] = actions.move_selection_next, |
| 166 | + ["<C-K>"] = actions.move_selection_previous, |
| 167 | + ["<CR>"] = open_selected, |
| 168 | + ["<M-CR>"] = open_all, |
| 169 | + }, |
| 170 | + n = { |
| 171 | + q = actions.close, |
| 172 | + ["<CR>"] = open_selected, |
| 173 | + ["<M-CR>"] = open_all, |
| 174 | + }, |
| 175 | + }, |
| 176 | + }, |
| 177 | + }) |
| 178 | + end, |
| 179 | +} |
0 commit comments