1
0
Fork 0

telescope from git dir

This commit is contained in:
Luca Bilke 2024-03-06 18:46:17 +01:00
parent fc404dcf07
commit ef7bf74d4e
3 changed files with 18 additions and 9 deletions

View File

@ -5,3 +5,4 @@ require("config.autocmds")
require("config.filetypes")
require("funcs").set_title()
require("funcs").set_maps(require("config.keymaps").maps())
require("funcs").set_cwd()

View File

@ -405,7 +405,7 @@ M.maps = function()
}
maps.n["<Leader>fc"] = {
function()
require("telescope.builtin").grep_string()
require("telescope.builtin").grep_string({ cwd = f.get_gwd() })
end,
desc = "Find word under cursor",
}
@ -417,13 +417,13 @@ M.maps = function()
}
maps.n["<Leader>ff"] = {
function()
require("telescope.builtin").find_files({ hidden = true, no_ignore = true })
require("telescope.builtin").find_files({ hidden = true, no_ignore = true, cwd = f.get_gwd() })
end,
desc = "Find files",
}
maps.n["<Leader>fg"] = {
function()
require("telescope.builtin").git_files({ hidden = true, no_ignore = true })
require("telescope.builtin").git_files({ hidden = true, no_ignore = true, cwd = f.get_gwd() })
end,
desc = "Find git files",
}
@ -439,12 +439,6 @@ M.maps = function()
end,
desc = "Find keymaps",
}
maps.n["<Leader>fm"] = {
function()
require("telescope.builtin").man_pages()
end,
desc = "Find man",
}
maps.n["<Leader>fo"] = {
function()
require("telescope.builtin").oldfiles()
@ -460,6 +454,7 @@ M.maps = function()
maps.n["<Leader>fw"] = {
function()
require("telescope.builtin").live_grep({
cwd = f.get_gwd(),
additional_args = function(args)
return vim.list_extend(args, { "--hidden", "--no-ignore" })
end,

View File

@ -564,4 +564,17 @@ function M.has_value(table, value)
return false
end
function M.get_gwd(path)
local find = { ".git" }
local opts = { stop = os.getenv("HOME"), upward = true, limit = 1, path = path }
local found = vim.fs.find(find, opts)
if found ~= nil then
return vim.fs.dirname(found[1])
end
end
function M.set_cwd()
vim.fn.chdir(M.get_gwd())
end
return M