From 6cf46f13eb2f9449a6a750746a29749a66baaac7 Mon Sep 17 00:00:00 2001 From: rootiest Date: Sat, 23 Nov 2024 14:22:28 -0500 Subject: [PATCH] fix: improve grep command handling with egrepify support --- lua/data/func.lua | 29 ++++++++++++++++++++++------- lua/plugins/telescope.lua | 6 ++++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/lua/data/func.lua b/lua/data/func.lua index 0db9de6..d88183b 100644 --- a/lua/data/func.lua +++ b/lua/data/func.lua @@ -1707,6 +1707,14 @@ function M.pick(cmd, provider, options) -- Default the command to "files" if not provided cmd = cmd or 'files' + -- Helper function to check if a picker command exists for a given provider + local function has_picker(provide, commd) + local success, picker = pcall(function() + return require(provide)[commd] + end) + return success and type(picker) == 'function' + end + -- Determine the provider if one is not selected -- (defaults to fzf-lua if available, else telescope) -- Will use vim.g.lazyvim_picker if defined @@ -1725,7 +1733,9 @@ function M.pick(cmd, provider, options) end end - -- Handle special commands + -- ━━━━━━━━━━━━━━━━━━━━━━━ Handle special commands ━━━━━━━━━━━━━━━━━━━━━━━ + + -- Config files if cmd == 'config_files' then cmd = 'files' options = { cwd = vim.fn.stdpath('config') } @@ -1734,12 +1744,17 @@ function M.pick(cmd, provider, options) cmd = 'find_files' end - -- Helper function to check if a picker command exists for a given provider - local function has_picker(provide, commd) - local success, picker = pcall(function() - return require(provide)[commd] - end) - return success and type(picker) == 'function' + -- Grepping + if cmd == 'grep' then + if provider == 'telescope' then + local telescope = require('telescope') + if pcall(telescope.extensions.egrepify.egrepify, {}) then + cmd = 'egrepify' + telescope.extensions.egrepify.egrepify({}) + return true + end + end + cmd = 'live_grep' end -- Ensure options is always a table (to avoid errors if nil is passed) diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua index f22f5b9..4c694a5 100644 --- a/lua/plugins/telescope.lua +++ b/lua/plugins/telescope.lua @@ -182,6 +182,12 @@ local P = { -- Define Telescope Plugins Specs { 'nvim-telescope/telescope-fzy-native.nvim' }, }, }, + { -- Telescope Egrepify + 'fdschmidt93/telescope-egrepify.nvim', + lazy = false, + opts = {}, + dependencies = { 'nvim-telescope/telescope.nvim', 'nvim-lua/plenary.nvim' }, + }, } if require('data.func').check_global_var('use_telescope', false, true) then