diff --git a/README.md b/README.md index 0bdbc4d..cd35584 100644 --- a/README.md +++ b/README.md @@ -176,6 +176,7 @@ nnoremap lua require('fzf-lua').files() |`spell_suggest`|spelling suggestions| |`tags`|project tags| |`btags`|buffer tags| +|`packadd`|:packadd | ## Customization diff --git a/lua/fzf-lua/actions.lua b/lua/fzf-lua/actions.lua index 5f2409c..858b683 100644 --- a/lua/fzf-lua/actions.lua +++ b/lua/fzf-lua/actions.lua @@ -25,7 +25,8 @@ M.act = function(actions, selected) -- the table will contain the results directly -- otherwise 'selected[1]` will contain the keybind -- empty string in selected[1] represents default - if #selected>1 and #selected[1]>0 then action = selected[1] end + if actions and utils.tbl_length(actions) > 1 and + #selected>1 and #selected[1]>0 then action = selected[1] end if actions[action] then actions[action](selected) end @@ -167,6 +168,13 @@ M.spell_apply = function(selected) vim.cmd("stopinsert") end +M.packadd = function(selected) + if not selected then return end + for i = 1, #selected do + vim.cmd("packadd " .. selected[i]) + end +end + M.help = function(selected) local vimcmd = "help" M.vimcmd(vimcmd, selected) diff --git a/lua/fzf-lua/config.lua b/lua/fzf-lua/config.lua index f225884..ebdf8a2 100644 --- a/lua/fzf-lua/config.lua +++ b/lua/fzf-lua/config.lua @@ -417,6 +417,12 @@ M.globals.nvim = { ["default"] = actions.spell_apply, }, }, + packadd = { + prompt = 'packadd> ', + actions = { + ["default"] = actions.packadd, + }, + }, } M.globals.file_icon_colors = { ["lua"] = "blue", diff --git a/lua/fzf-lua/init.lua b/lua/fzf-lua/init.lua index e80416b..c48cc3e 100644 --- a/lua/fzf-lua/init.lua +++ b/lua/fzf-lua/init.lua @@ -78,6 +78,7 @@ M.commands = require'fzf-lua.providers.nvim'.commands M.command_history = require'fzf-lua.providers.nvim'.command_history M.search_history = require'fzf-lua.providers.nvim'.search_history M.spell_suggest = require'fzf-lua.providers.nvim'.spell_suggest +M.packadd = require'fzf-lua.providers.nvim'.packadd M.lsp_typedefs = require'fzf-lua.providers.lsp'.typedefs M.lsp_references = require'fzf-lua.providers.lsp'.references diff --git a/lua/fzf-lua/providers/nvim.lua b/lua/fzf-lua/providers/nvim.lua index 4ca59f8..d2f1ad5 100644 --- a/lua/fzf-lua/providers/nvim.lua +++ b/lua/fzf-lua/providers/nvim.lua @@ -252,4 +252,28 @@ M.spell_suggest = function(opts) end + +M.packadd = function(opts) + + opts = config.normalize_opts(opts, config.globals.nvim.packadd) + + coroutine.wrap(function () + + local entries = vim.fn.getcompletion('', 'packadd') + + if vim.tbl_isempty(entries) then return end + + opts.nomulti = false + opts.preview = nil + opts.preview_window = 'hidden:down:0' + + local selected = core.fzf(opts, entries) + + if not selected then return end + actions.act(opts.actions, selected) + + end)() + +end + return M