52 lines
1.6 KiB
Lua
52 lines
1.6 KiB
Lua
function vim.find_files_from_project_git_root()
|
|
local function is_git_repo()
|
|
vim.fn.system("git rev-parse --is-inside-work-tree")
|
|
return vim.v.shell_error == 0
|
|
end
|
|
local function is_svn_repo()
|
|
vim.fn.system("svn info")
|
|
return vim.v.shell_error == 0
|
|
end
|
|
local function get_git_root()
|
|
local dot_git_path = vim.fn.finddir(".git", ".;")
|
|
return vim.fn.fnamemodify(dot_git_path, ":h")
|
|
end
|
|
local function get_svn_root()
|
|
local dot_svn_path = vim.fn.system("svn info --show-item wc-root")
|
|
return vim.trim(dot_svn_path)
|
|
end
|
|
local opts = {}
|
|
if is_git_repo() then
|
|
opts = {
|
|
cwd = get_git_root(),
|
|
}
|
|
elseif is_svn_repo() then
|
|
opts = {
|
|
cwd = get_svn_root(),
|
|
}
|
|
end
|
|
require("telescope.builtin").find_files(opts)
|
|
end
|
|
|
|
return {
|
|
{
|
|
"nvim-telescope/telescope.nvim",
|
|
branch = "0.1.x",
|
|
event = "VimEnter",
|
|
dependencies = { "nvim-lua/plenary.nvim"},
|
|
opts = {
|
|
defaults = {
|
|
layout_config = {
|
|
horizontal = { width = 0.9 }
|
|
},
|
|
},
|
|
},
|
|
keys = {
|
|
{ "<leader>ff", "<cmd>Telescope find_files<cr>", desc = "Find files" },
|
|
{ "<leader>F", vim.find_files_from_project_git_root, desc = "Find project files" },
|
|
{ "<leader>fg", require("telescope.builtin").live_grep, desc = "Find inside files" },
|
|
{ "<leader>s", "<cmd>Telescope spell_suggest<cr>", desc = "Spelling suggestions" },
|
|
},
|
|
}
|
|
}
|