From 3f55f449b5bea43acb8919ce8dbf7ebf7562d3c7 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sun, 21 Jul 2024 18:32:54 -0500 Subject: [PATCH] some light refactoring --- nvim/lua/etc.lua | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/nvim/lua/etc.lua b/nvim/lua/etc.lua index c8badcb..9ae61d5 100644 --- a/nvim/lua/etc.lua +++ b/nvim/lua/etc.lua @@ -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)