From c57b3c3fe6caad89fdd2140d892cbb435f5682e0 Mon Sep 17 00:00:00 2001 From: Tovi Jaeschke-Rogers Date: Sun, 15 Dec 2024 21:20:07 +1030 Subject: [PATCH] feat: add multigrep to telescope --- .config/nvim/lua/plugins/telescope.lua | 2 +- .../nvim/lua/plugins/telescope/multigrep.lua | 59 +++++++++++++++++++ .config/zsh/.zshrc | 3 +- 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 .config/nvim/lua/plugins/telescope/multigrep.lua diff --git a/.config/nvim/lua/plugins/telescope.lua b/.config/nvim/lua/plugins/telescope.lua index e6d828a..d358067 100644 --- a/.config/nvim/lua/plugins/telescope.lua +++ b/.config/nvim/lua/plugins/telescope.lua @@ -119,7 +119,7 @@ return { local keymap = vim.keymap keymap.set("n", "ff", function() - builtin.live_grep({ hidden = true }) + require("plugins.telescope.multigrep").live_multgrep() end, {}) keymap.set("n", "p", project_files, {}) diff --git a/.config/nvim/lua/plugins/telescope/multigrep.lua b/.config/nvim/lua/plugins/telescope/multigrep.lua new file mode 100644 index 0000000..7e945dc --- /dev/null +++ b/.config/nvim/lua/plugins/telescope/multigrep.lua @@ -0,0 +1,59 @@ +local pickers = require("telescope.pickers") +local finders = require("telescope.finders") +local make_entry = require("telescope.make_entry") +local conf = require("telescope.config").values + +local M = {} + +M.live_multgrep = function (opts) + opts = opts or {} + opts.cwd = opts.cwd or vim.uv.cwd() + + local finder = finders.new_async_job({ + command_generator = function (prompt) + print(prompt) + if not prompt or prompt == "" then + return nil + end + + local pieces = vim.split(prompt, " ") + + local args = { "rg" } + if pieces[1] then + table.insert(args, "-e") + table.insert(args, pieces[1]) + end + + if pieces[2] then + table.insert(args, "-g") + table.insert(args, pieces[2]) + end + + ---@diagnostic disable-next-line: deprecated + return vim.tbl_flatten({ + args, + { + "--color=never", + "--no-heading", + "--with-filename", + "--line-number", + "--column", + "--smart-case", + "--hidden", + } + }) + end, + entry_maker = make_entry.gen_from_vimgrep(opts), + cwd = opts.cwd + }) + + pickers.new(opts, { + debounce = 100, + prompt_title = "Multi Grep", + finder = finder, + previewer = conf.grep_previewer(opts), + sorter = require("telescope.sorters").empty(), + }):find() +end + +return M diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index 02e4cf1..21c0d32 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -42,7 +42,8 @@ if [[ $(uname) == 'Darwin' ]]; then export PATH="/opt/homebrew/lib/ruby/gems/3.3.0:$PATH" export PATH="/opt/homebrew/Cellar/ruby/3.3.0/lib/ruby/gems/3.3.0:$PATH" - eval "$(rbenv init - zsh)" + + eval "$(/opt/homebrew/bin/brew shellenv)" fi autoload -Uz compinit