dotfiles/cli/vim/neovim/lua/plugins/searchinfolder.lua

30 lines
856 B
Lua
Raw Normal View History

2022-07-13 15:14:12 +00:00
local nvim_tree_lib_ok, nvim_tree_lib = pcall(require, "nvim-tree/lib")
if not nvim_tree_lib_ok then
return
end
local telescope_builtin_ok, telescope_builtin = pcall(require, "telescope/builtin")
if not telescope_builtin_ok then
return
end
2022-07-24 16:38:33 +00:00
function SearchInFolder(folder_path)
2022-07-13 15:14:12 +00:00
if folder_path == "" then
2022-07-24 16:38:33 +00:00
local folder = nvim_tree_lib.get_node_at_cursor()
if folder == nil then
folder_path = vim.fn.expand("%:p:h")
else
if assert(folder.fs_stat).type == "file" then
folder = folder.parent
end
folder_path = folder.absolute_path
2022-07-13 15:14:12 +00:00
end
end
telescope_builtin.live_grep{cwd = folder_path}
-- print(vim.inspect(folder_path))
end
vim.api.nvim_create_user_command("SearchInFolder", function(res)
2022-07-24 16:38:33 +00:00
SearchInFolder(res.args)
2022-07-13 15:14:12 +00:00
end, { nargs = "?" })