telescope from git dir
This commit is contained in:
parent
fc404dcf07
commit
ef7bf74d4e
|
@ -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()
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue