some light refactoring

master
Jordan Orelli 2 months ago
parent 0125349daf
commit 3f55f449b5

@ -4,22 +4,25 @@ local M = {}
local telescope = require("telescope.builtin")
-- cache directory checks for great speed
local is_inside_work_tree = {}
M.project_files = function()
local opts = {}
local work_tree_lookup_cache = {}
M.cwd_is_in_git_repo = function()
local cwd = vim.fn.getcwd()
if is_inside_work_tree[cwd] == nil then
if work_tree_lookup_cache[cwd] == nil then
-- The directory has not been checked
vim.fn.system("git rev-parse --is-inside-work-tree")
-- Add the result to our cache
is_inside_work_tree[cwd] = vim.v.shell_error == 0
work_tree_lookup_cache[cwd] = vim.v.shell_error == 0
end
if is_inside_work_tree[cwd] then
return work_tree_lookup_cache[cwd]
end
M.project_files = function()
local opts = {}
if M.cwd_is_in_git_repo() then
telescope.git_files(opts)
else
telescope.find_files(opts)

Loading…
Cancel
Save