some light refactoring

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

@ -4,22 +4,25 @@ local M = {}
local telescope = require("telescope.builtin") local telescope = require("telescope.builtin")
-- cache directory checks for great speed -- cache directory checks for great speed
local is_inside_work_tree = {} local work_tree_lookup_cache = {}
M.project_files = function()
local opts = {}
M.cwd_is_in_git_repo = function()
local cwd = vim.fn.getcwd() 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 -- The directory has not been checked
vim.fn.system("git rev-parse --is-inside-work-tree") vim.fn.system("git rev-parse --is-inside-work-tree")
-- Add the result to our cache -- 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 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) telescope.git_files(opts)
else else
telescope.find_files(opts) telescope.find_files(opts)

Loading…
Cancel
Save