feat: added keybindings to update/install/clean/restore/... single plugins

This commit is contained in:
Folke Lemaitre 2022-11-29 10:56:17 +01:00
parent 54a82ad695
commit 08b7e42fb0
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
6 changed files with 43 additions and 22 deletions

View File

@ -23,6 +23,8 @@
## ✅ TODO ## ✅ TODO
- [ ] health checks: check merge conflicts async
- [ ] defaults for git log
- [ ] view keybindings for update/clean/... - [ ] view keybindings for update/clean/...
- [ ] add profiler to view - [ ] add profiler to view
- [ ] add buttons for actions - [ ] add buttons for actions

View File

@ -9,6 +9,7 @@ local M = {}
---@field clear? boolean ---@field clear? boolean
---@field interactive? boolean ---@field interactive? boolean
---@field mode? string ---@field mode? string
---@field plugins? LazyPlugin[]
---@param ropts RunnerOpts ---@param ropts RunnerOpts
---@param opts? ManagerOpts ---@param opts? ManagerOpts
@ -18,6 +19,10 @@ function M.run(ropts, opts)
opts.interactive = Config.options.interactive opts.interactive = Config.options.interactive
end end
if opts.plugins then
ropts.plugins = opts.plugins
end
if opts.clear then if opts.clear then
M.clear() M.clear()
end end

View File

@ -5,19 +5,20 @@ local Util = require("lazy.util")
local M = {} local M = {}
---@param cmd string ---@param cmd string
function M.cmd(cmd) ---@param plugins? LazyPlugin[]
function M.cmd(cmd, plugins)
cmd = cmd == "" and "show" or cmd cmd = cmd == "" and "show" or cmd
local command = M.commands[cmd] local command = M.commands[cmd]
if command == nil then if command == nil then
Util.error("Invalid lazy command '" .. cmd .. "'") Util.error("Invalid lazy command '" .. cmd .. "'")
else else
command() command(plugins)
end end
end end
M.commands = { M.commands = {
clean = function() clean = function(plugins)
Manage.clean({ clear = true, interactive = true, mode = "clean" }) Manage.clean({ clear = true, interactive = true, mode = "clean", plugins = plugins })
end, end,
clear = function() clear = function()
Manage.clear() Manage.clear()
@ -26,8 +27,8 @@ M.commands = {
install = function() install = function()
Manage.install({ clear = true, interactive = true, mode = "install" }) Manage.install({ clear = true, interactive = true, mode = "install" })
end, end,
log = function() log = function(plugins)
Manage.log({ clear = true, interactive = true, mode = "log" }) Manage.log({ clear = true, interactive = true, mode = "log", plugins = plugins })
end, end,
show = function() show = function()
View.show() View.show()
@ -40,14 +41,14 @@ M.commands = {
Manage.update({ interactive = true }) Manage.update({ interactive = true })
Manage.install({ interactive = true }) Manage.install({ interactive = true })
end, end,
update = function() update = function(plugins)
Manage.update({ clear = true, interactive = true, mode = "update" }) Manage.update({ clear = true, interactive = true, mode = "update", plugins = plugins })
end, end,
check = function() check = function(plugins)
Manage.check({ clear = true, interactive = true, mode = "check" }) Manage.check({ clear = true, interactive = true, mode = "check", plugins = plugins })
end, end,
restore = function() restore = function(plugins)
Manage.update({ clear = true, interactive = true, lockfile = true, mode = "restore" }) Manage.update({ clear = true, interactive = true, lockfile = true, mode = "restore", plugins = plugins })
end, end,
} }

View File

@ -13,6 +13,18 @@ M.modes = {
{ name = "log", key = "L", desc = "Show recent updates for all plugins" }, { name = "log", key = "L", desc = "Show recent updates for all plugins" },
{ name = "restore", key = "R", desc = "Updates all plugins to the state in the lockfile" }, { name = "restore", key = "R", desc = "Updates all plugins to the state in the lockfile" },
{ name = "help", key = "g?", hide = true, desc = "Toggle this help page" }, { name = "help", key = "g?", hide = true, desc = "Toggle this help page" },
{ plugin = true, name = "update", key = "u", desc = "Update this plugin. This will also update the lockfile" },
{
plugin = true,
name = "clean",
key = "x",
desc = "Delete this plugin. WARNING: this will delete the plugin even if it should be installed!",
},
{ plugin = true, name = "check", key = "c", desc = "Check for updates for this plugin and show the log (git fetch)" },
{ plugin = true, name = "install", key = "i", desc = "Install this plugin" },
{ plugin = true, name = "log", key = "gl", desc = "Show recent updates for this plugin" },
{ plugin = true, name = "restore", key = "r", desc = "Restore this plugin to the state in the lockfile" },
} }
---@type string? ---@type string?
@ -153,7 +165,14 @@ function M.show(mode)
for _, m in ipairs(M.modes) do for _, m in ipairs(M.modes) do
vim.keymap.set("n", m.key, function() vim.keymap.set("n", m.key, function()
local Commands = require("lazy.view.commands") local Commands = require("lazy.view.commands")
if m.plugin then
local plugin = get_plugin()
if plugin then
Commands.cmd(m.name, { plugin })
end
else
Commands.cmd(m.name) Commands.cmd(m.name)
end
end, { buffer = buf }) end, { buffer = buf })
end end

View File

@ -98,7 +98,7 @@ function M:title()
local View = require("lazy.view") local View = require("lazy.view")
for _, mode in ipairs(View.modes) do for _, mode in ipairs(View.modes) do
if not mode.hide then if not mode.hide and not mode.plugin then
local title = " " .. mode.name:sub(1, 1):upper() .. mode.name:sub(2) .. " (" .. mode.key .. ") " local title = " " .. mode.name:sub(1, 1):upper() .. mode.name:sub(2) .. " (" .. mode.key .. ") "
self:append(title, View.mode == mode.name and "LazyButtonActive" or "LazyButton"):append(" ") self:append(title, View.mode == mode.name and "LazyButtonActive" or "LazyButton"):append(" ")
end end

View File

@ -76,9 +76,9 @@ return {
}, },
{ {
filter = function(plugin) filter = function(plugin)
return not plugin._.installed and not plugin.uri return not plugin._.installed
end, end,
title = "Cleaned", title = "Not Installed",
}, },
{ {
filter = function(plugin) filter = function(plugin)
@ -92,10 +92,4 @@ return {
end, end,
title = "Installed", title = "Installed",
}, },
{
filter = function()
return true
end,
title = "Not Installed",
},
} }