You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
658 B
Lua
32 lines
658 B
Lua
4 months ago
|
local M = {}
|
||
|
|
||
|
local telescope = require("telescope.builtin")
|
||
|
|
||
|
-- cache directory checks for great speed
|
||
4 months ago
|
local work_tree_lookup_cache = {}
|
||
4 months ago
|
|
||
4 months ago
|
M.cwd_is_in_git_repo = function()
|
||
4 months ago
|
local cwd = vim.fn.getcwd()
|
||
|
|
||
4 months ago
|
if work_tree_lookup_cache[cwd] == nil then
|
||
4 months ago
|
-- The directory has not been checked
|
||
|
vim.fn.system("git rev-parse --is-inside-work-tree")
|
||
|
-- Add the result to our cache
|
||
4 months ago
|
work_tree_lookup_cache[cwd] = vim.v.shell_error == 0
|
||
4 months ago
|
end
|
||
|
|
||
4 months ago
|
return work_tree_lookup_cache[cwd]
|
||
|
end
|
||
|
|
||
|
M.project_files = function()
|
||
|
local opts = {}
|
||
|
|
||
|
if M.cwd_is_in_git_repo() then
|
||
4 months ago
|
telescope.git_files(opts)
|
||
|
else
|
||
|
telescope.find_files(opts)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
return M
|