respect the git root for telescope
This commit is contained in:
parent
9ce533eac0
commit
636c0562b3
@ -1,3 +1,18 @@
|
||||
function git_root()
|
||||
return string.gsub(vim.fn.system("git rev-parse --show-toplevel"), "\n", "")
|
||||
end
|
||||
|
||||
function get_opts()
|
||||
local opts = {}
|
||||
|
||||
local root = git_root()
|
||||
if vim.v.shell_error == 0 then
|
||||
opts.cwd = root
|
||||
end
|
||||
|
||||
return opts
|
||||
end
|
||||
|
||||
-- Telescope
|
||||
return {
|
||||
"nvim-telescope/telescope.nvim",
|
||||
@ -7,19 +22,27 @@ return {
|
||||
keys = {
|
||||
{
|
||||
"<leader>fp",
|
||||
function() require("telescope.builtin").find_files({ cwd = require("lazy.core.config").options.root }) end,
|
||||
function()
|
||||
require("telescope.builtin").find_files(get_opts())
|
||||
end,
|
||||
},
|
||||
{
|
||||
"<leader>ff",
|
||||
function() require('telescope.builtin').live_grep() end,
|
||||
function()
|
||||
require('telescope.builtin').live_grep(get_opts())
|
||||
end,
|
||||
},
|
||||
{
|
||||
"<leader>fb",
|
||||
function() require('telescope.builtin').buffers() end,
|
||||
function()
|
||||
require('telescope.builtin').buffers(get_opts())
|
||||
end,
|
||||
},
|
||||
{
|
||||
"<leader>fh",
|
||||
function() require('telescope.builtin').help_tags() end,
|
||||
function()
|
||||
require('telescope.builtin').help_tags(get_opts())
|
||||
end,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user