Skip to content

Commit

Permalink
feat: added keybindings to update/install/clean/restore/... single pl…
Browse files Browse the repository at this point in the history
…ugins
  • Loading branch information
folke committed Nov 29, 2022
1 parent 54a82ad commit 08b7e42
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 22 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lua/lazy/manage/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local M = {}
---@field clear? boolean
---@field interactive? boolean
---@field mode? string
---@field plugins? LazyPlugin[]

---@param ropts RunnerOpts
---@param opts? ManagerOpts
Expand All @@ -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
Expand Down
25 changes: 13 additions & 12 deletions lua/lazy/view/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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,
}

Expand Down
21 changes: 20 additions & 1 deletion lua/lazy/view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lua/lazy/view/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions lua/lazy/view/sections.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -92,10 +92,4 @@ return {
end,
title = "Installed",
},
{
filter = function()
return true
end,
title = "Not Installed",
},
}

0 comments on commit 08b7e42

Please sign in to comment.