From 2a4f74cd9bd7429ee48e428a0fa93253182e44e0 Mon Sep 17 00:00:00 2001 From: pml68 Date: Sun, 23 Mar 2025 02:21:22 +0100 Subject: feat: update TODO finder fn --- lua/pml68/remap.lua | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'lua/pml68') diff --git a/lua/pml68/remap.lua b/lua/pml68/remap.lua index 3846493..950140d 100644 --- a/lua/pml68/remap.lua +++ b/lua/pml68/remap.lua @@ -64,22 +64,28 @@ vim.keymap.set('n', 'fg', "Telescope git_files", {}) vim.keymap.set('n', 'fd', "Telescope diagnostics", {}) vim.keymap.set('n', 'ft', function() local telescope = require("telescope.builtin") - local todo_files = {} - - local handle = io.popen("rg --files -g 'TODO.{md,txt}'") + local handle = io.popen("rg 'TODO'") local result = handle:read("*a") handle:close() - for file in result:gmatch("[^\r\n]+") do - table.insert(todo_files, file) - end + if result:match("[^\r\n]+") == nil then + local todo_files = {} + + local files_handle = io.popen("rg --files -g 'TODO.{md,txt}'") + local files_result = files_handle:read("*a") + files_handle:close() + + for file in files_result:gmatch("[^\r\n]+") do + table.insert(todo_files, file) + end - if #todo_files > 0 then - telescope.find_files({ - prompt_title = "Choose TODO file", - cwd = vim.fn.getcwd(), - search_dirs = todo_files - }) + if #todo_files > 0 then + telescope.find_files({ + prompt_title = "Choose TODO file", + cwd = vim.fn.getcwd(), + search_dirs = todo_files + }) + end else telescope.grep_string({ search = "TODO" }) end -- cgit v1.2.3