From 08b7e42fb0743da4fb4221f51d28bd8b108ee25f Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Tue, 29 Nov 2022 10:56:17 +0100 Subject: [PATCH] feat: added keybindings to update/install/clean/restore/... single plugins --- README.md | 2 ++ lua/lazy/manage/init.lua | 5 +++++ lua/lazy/view/commands.lua | 25 +++++++++++++------------ lua/lazy/view/init.lua | 21 ++++++++++++++++++++- lua/lazy/view/render.lua | 2 +- lua/lazy/view/sections.lua | 10 ++-------- 6 files changed, 43 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index fb3e782..2f93154 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lua/lazy/manage/init.lua b/lua/lazy/manage/init.lua index 11265f4..c478f1c 100644 --- a/lua/lazy/manage/init.lua +++ b/lua/lazy/manage/init.lua @@ -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 diff --git a/lua/lazy/view/commands.lua b/lua/lazy/view/commands.lua index 2279058..7c8d887 100644 --- a/lua/lazy/view/commands.lua +++ b/lua/lazy/view/commands.lua @@ -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, } diff --git a/lua/lazy/view/init.lua b/lua/lazy/view/init.lua index 8590b67..08095ee 100644 --- a/lua/lazy/view/init.lua +++ b/lua/lazy/view/init.lua @@ -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 diff --git a/lua/lazy/view/render.lua b/lua/lazy/view/render.lua index dd6e728..9cddb59 100644 --- a/lua/lazy/view/render.lua +++ b/lua/lazy/view/render.lua @@ -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 diff --git a/lua/lazy/view/sections.lua b/lua/lazy/view/sections.lua index bb4238f..6701e90 100644 --- a/lua/lazy/view/sections.lua +++ b/lua/lazy/view/sections.lua @@ -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", - }, }