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
- [ ] health checks: check merge conflicts async
- [ ] defaults for git log
- [ ] view keybindings for update/clean/...
- [ ] add profiler to view
- [ ] add buttons for actions

View File

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

View File

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

View File

@ -13,6 +13,18 @@ M.modes = {
{ 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 = "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?
@ -153,7 +165,14 @@ function M.show(mode)
for _, m in ipairs(M.modes) do
vim.keymap.set("n", m.key, function()
local Commands = require("lazy.view.commands")
Commands.cmd(m.name)
if m.plugin then
local plugin = get_plugin()
if plugin then
Commands.cmd(m.name, { plugin })
end
else
Commands.cmd(m.name)
end
end, { buffer = buf })
end

View File

@ -98,7 +98,7 @@ function M:title()
local View = require("lazy.view")
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 .. ") "
self:append(title, View.mode == mode.name and "LazyButtonActive" or "LazyButton"):append(" ")
end

View File

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