From be3909c54420c734e32cb045a387990a6fb51bd4 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Sat, 24 Dec 2022 11:28:19 +0100 Subject: [PATCH] feat(ui): added custom commands for lazygit and opening a terminal for a plugin --- README.md | 25 +++++++++++++++++++++++++ TODO.md | 4 +++- lua/lazy/core/config.lua | 25 +++++++++++++++++++++++++ lua/lazy/view/init.lua | 14 ++++++++------ 4 files changed, 61 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 25cace6..8ac8921 100644 --- a/README.md +++ b/README.md @@ -327,6 +327,31 @@ return { task = "✔ ", }, throttle = 20, -- how frequently should the ui process render events + custom_keys = { + -- you can define custom key maps here. + -- To disable one of the defaults, set it to false + + -- open lazygit log + ["l"] = function(plugin) + require("lazy.util").open_cmd({ "lazygit", "log" }, { + cwd = plugin.dir, + terminal = true, + close_on_exit = true, + enter = true, + }) + end, + + -- open a terminal for the plugin dir + ["t"] = function(plugin) + require("lazy.util").open_cmd({ vim.go.shell }, { + cwd = plugin.dir, + terminal = true, + close_on_exit = true, + enter = true, + }) + end, + }, + }, diff = { -- diff command can be one of: -- * browser: opens the github compare view. Note that this is always mapped to as well, diff --git a/TODO.md b/TODO.md index dc33bc0..a0b7600 100644 --- a/TODO.md +++ b/TODO.md @@ -1,4 +1,4 @@ -## ✅ TODO +# ✅ TODO - [x] fancy UI to manage all your Neovim plugins - [x] auto lazy-loading of lua modules @@ -46,6 +46,8 @@ - [ ] document highlight groups - [ ] document user events +- [ ] document API, like lazy.plugins() +- [ ] icons - [x] check in cache if rtp files match - [x] I think the installation section, specifically the loading part, could use an diff --git a/lua/lazy/core/config.lua b/lua/lazy/core/config.lua index c061ea9..1cb90dc 100644 --- a/lua/lazy/core/config.lua +++ b/lua/lazy/core/config.lua @@ -50,6 +50,31 @@ M.defaults = { task = "✔ ", }, throttle = 20, -- how frequently should the ui process render events + custom_keys = { + -- you can define custom key maps here. + -- To disable one of the defaults, set it to false + + -- open lazygit log + ["l"] = function(plugin) + require("lazy.util").open_cmd({ "lazygit", "log" }, { + cwd = plugin.dir, + terminal = true, + close_on_exit = true, + enter = true, + }) + end, + + -- open a terminal for the plugin dir + ["t"] = function(plugin) + require("lazy.util").open_cmd({ vim.go.shell }, { + cwd = plugin.dir, + terminal = true, + close_on_exit = true, + enter = true, + }) + end, + }, + }, diff = { -- diff command can be one of: -- * browser: opens the github compare view. Note that this is always mapped to as well, diff --git a/lua/lazy/view/init.lua b/lua/lazy/view/init.lua index 73a3091..e2d39c0 100644 --- a/lua/lazy/view/init.lua +++ b/lua/lazy/view/init.lua @@ -96,12 +96,14 @@ function M.create(opts) end) for key, handler in pairs(Config.options.ui.custom_keys) do - self:on_key(key, function() - local plugin = self.render:get_plugin() - if plugin then - handler(plugin) - end - end) + if handler then + self:on_key(key, function() + local plugin = self.render:get_plugin() + if plugin then + handler(plugin) + end + end) + end end self:setup_patterns()