58 lines
1.8 KiB
Lua
58 lines
1.8 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", require("telescope.builtin").find_files, 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", require("telescope.builtin").spell_suggest, desc = "Spelling suggestions" },
|
|
{ "<leader>s", function()
|
|
require("telescope.builtin").current_buffer_fuzzy_find({
|
|
fuzzy = false,
|
|
case_mode = "smart_case",
|
|
})
|
|
end, desc = "Search within a file"},
|
|
},
|
|
}
|
|
}
|