From ccdbc64be5e3efd80cb6b6782cbd3da9c2757e4f Mon Sep 17 00:00:00 2001 From: Yuan Chiu Date: Thu, 1 May 2025 18:34:05 +0800 Subject: [PATCH] =?UTF-8?q?nvim:=20telescope=20=E5=A2=9E=E5=8A=A0=E8=A8=AD?= =?UTF-8?q?=E5=AE=9A=EF=BC=8C=E4=B8=A6=E9=A1=AF=E7=A4=BA=E9=9A=B1=E8=97=8F?= =?UTF-8?q?=E6=AA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exact_components/telescope.lua | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/dot_config/nvim/exact_lua/exact_plugins/exact_components/telescope.lua b/dot_config/nvim/exact_lua/exact_plugins/exact_components/telescope.lua index e83b93c..e748029 100644 --- a/dot_config/nvim/exact_lua/exact_plugins/exact_components/telescope.lua +++ b/dot_config/nvim/exact_lua/exact_plugins/exact_components/telescope.lua @@ -14,4 +14,76 @@ return { { "fh", "Telescope help_tags", desc = "Help tags" }, { "fk", "Telescope keymaps", desc = "Keymaps" }, }, + opts = function() + local actions = require("telescope.actions") + + local open_with_trouble = function(...) + return require("trouble.sources.telescope").open(...) + end + local find_files_no_ignore = function() + local action_state = require("telescope.actions.state") + local line = action_state.get_current_line() + LazyVim.pick("find_files", { no_ignore = true, default_text = line })() + end + local find_files_with_hidden = function() + local action_state = require("telescope.actions.state") + local line = action_state.get_current_line() + LazyVim.pick("find_files", { hidden = true, default_text = line })() + end + + local function find_command() + if 1 == vim.fn.executable("rg") then + return { "rg", "--files", "--color", "never", "-g", "!.git" } + elseif 1 == vim.fn.executable("fd") then + return { "fd", "--type", "f", "--color", "never", "-E", ".git" } + elseif 1 == vim.fn.executable("fdfind") then + return { "fdfind", "--type", "f", "--color", "never", "-E", ".git" } + elseif 1 == vim.fn.executable("find") and vim.fn.has("win32") == 0 then + return { "find", ".", "-type", "f" } + elseif 1 == vim.fn.executable("where") then + return { "where", "/r", ".", "*" } + end + end + + return { + defaults = { + prompt_prefix = " ", + selection_caret = " ", + -- open files in the first window that is an actual file. + -- use the current window if no other window is available. + get_selection_window = function() + local wins = vim.api.nvim_list_wins() + table.insert(wins, 1, vim.api.nvim_get_current_win()) + for _, win in ipairs(wins) do + local buf = vim.api.nvim_win_get_buf(win) + if vim.bo[buf].buftype == "" then + return win + end + end + return 0 + end, + mappings = { + i = { + [""] = open_with_trouble, + [""] = open_with_trouble, + [""] = find_files_no_ignore, + [""] = find_files_with_hidden, + [""] = actions.cycle_history_next, + [""] = actions.cycle_history_prev, + [""] = actions.preview_scrolling_down, + [""] = actions.preview_scrolling_up, + }, + n = { + ["q"] = actions.close, + }, + }, + }, + pickers = { + find_files = { + find_command = find_command, + hidden = true, + }, + }, + } + end, }