Skip to content

Instantly share code, notes, and snippets.

@mengwangk
Last active September 30, 2023 14:00
Show Gist options
  • Save mengwangk/f76fbe21569ac0760c9992f06ead4f0c to your computer and use it in GitHub Desktop.
Save mengwangk/f76fbe21569ac0760c9992f06ead4f0c to your computer and use it in GitHub Desktop.
Neovim Plugins and Configuration Recipes | 3
M.actions = transform_mod {
set_extension = function(prompt_bufnr)
local current_input = action_state.get_current_line()
vim.ui.input({ prompt = "*." }, function(input)
if input == nil then
return
end
live_grep_filters.extension = input
actions.close(prompt_bufnr)
run_live_grep(current_input)
end)
end,
set_folders = function(prompt_bufnr)
local current_input = action_state.get_current_line()
local data = {}
scan.scan_dir(vim.loop.cwd(), {
hidden = true,
only_dirs = true,
respect_gitignore = true,
on_insert = function(entry)
table.insert(data, entry .. os_sep)
end,
})
table.insert(data, 1, "." .. os_sep)
actions.close(prompt_bufnr)
pickers
.new({}, {
prompt_title = "Folders for Live Grep",
finder = finders.new_table { results = data, entry_maker = make_entry.gen_from_file {} },
previewer = conf.file_previewer {},
sorter = conf.file_sorter {},
attach_mappings = function(bufnr)
action_set.select:replace(function()
local current_picker = action_state.get_current_picker(bufnr)
local dirs = {}
local selections = current_picker:get_multi_selection()
if vim.tbl_isempty(selections) then
table.insert(dirs, action_state.get_selected_entry().value)
else
for _, selection in ipairs(selections) do
table.insert(dirs, selection.value)
end
end
live_grep_filters.directories = dirs
actions.close(bufnr)
run_live_grep(current_input)
end)
return true
end,
})
:find()
end,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment