telescope from git dir
This commit is contained in:
parent
fc404dcf07
commit
ef7bf74d4e
3 changed files with 18 additions and 9 deletions
.config/nvim
|
@ -5,3 +5,4 @@ require("config.autocmds")
|
||||||
require("config.filetypes")
|
require("config.filetypes")
|
||||||
require("funcs").set_title()
|
require("funcs").set_title()
|
||||||
require("funcs").set_maps(require("config.keymaps").maps())
|
require("funcs").set_maps(require("config.keymaps").maps())
|
||||||
|
require("funcs").set_cwd()
|
||||||
|
|
|
@ -405,7 +405,7 @@ M.maps = function()
|
||||||
}
|
}
|
||||||
maps.n["<Leader>fc"] = {
|
maps.n["<Leader>fc"] = {
|
||||||
function()
|
function()
|
||||||
require("telescope.builtin").grep_string()
|
require("telescope.builtin").grep_string({ cwd = f.get_gwd() })
|
||||||
end,
|
end,
|
||||||
desc = "Find word under cursor",
|
desc = "Find word under cursor",
|
||||||
}
|
}
|
||||||
|
@ -417,13 +417,13 @@ M.maps = function()
|
||||||
}
|
}
|
||||||
maps.n["<Leader>ff"] = {
|
maps.n["<Leader>ff"] = {
|
||||||
function()
|
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,
|
end,
|
||||||
desc = "Find files",
|
desc = "Find files",
|
||||||
}
|
}
|
||||||
maps.n["<Leader>fg"] = {
|
maps.n["<Leader>fg"] = {
|
||||||
function()
|
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,
|
end,
|
||||||
desc = "Find git files",
|
desc = "Find git files",
|
||||||
}
|
}
|
||||||
|
@ -439,12 +439,6 @@ M.maps = function()
|
||||||
end,
|
end,
|
||||||
desc = "Find keymaps",
|
desc = "Find keymaps",
|
||||||
}
|
}
|
||||||
maps.n["<Leader>fm"] = {
|
|
||||||
function()
|
|
||||||
require("telescope.builtin").man_pages()
|
|
||||||
end,
|
|
||||||
desc = "Find man",
|
|
||||||
}
|
|
||||||
maps.n["<Leader>fo"] = {
|
maps.n["<Leader>fo"] = {
|
||||||
function()
|
function()
|
||||||
require("telescope.builtin").oldfiles()
|
require("telescope.builtin").oldfiles()
|
||||||
|
@ -460,6 +454,7 @@ M.maps = function()
|
||||||
maps.n["<Leader>fw"] = {
|
maps.n["<Leader>fw"] = {
|
||||||
function()
|
function()
|
||||||
require("telescope.builtin").live_grep({
|
require("telescope.builtin").live_grep({
|
||||||
|
cwd = f.get_gwd(),
|
||||||
additional_args = function(args)
|
additional_args = function(args)
|
||||||
return vim.list_extend(args, { "--hidden", "--no-ignore" })
|
return vim.list_extend(args, { "--hidden", "--no-ignore" })
|
||||||
end,
|
end,
|
||||||
|
|
|
@ -564,4 +564,17 @@ function M.has_value(table, value)
|
||||||
return false
|
return false
|
||||||
end
|
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
|
return M
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue