Skip to content

Commit be3909c

Browse files
committed
feat(ui): added custom commands for lazygit and opening a terminal for a plugin
1 parent 7d02da2 commit be3909c

File tree

4 files changed

+61
-7
lines changed

4 files changed

+61
-7
lines changed

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,31 @@ return {
327327
task = "",
328328
},
329329
throttle = 20, -- how frequently should the ui process render events
330+
custom_keys = {
331+
-- you can define custom key maps here.
332+
-- To disable one of the defaults, set it to false
333+
334+
-- open lazygit log
335+
["<localleader>l"] = function(plugin)
336+
require("lazy.util").open_cmd({ "lazygit", "log" }, {
337+
cwd = plugin.dir,
338+
terminal = true,
339+
close_on_exit = true,
340+
enter = true,
341+
})
342+
end,
343+
344+
-- open a terminal for the plugin dir
345+
["<localleader>t"] = function(plugin)
346+
require("lazy.util").open_cmd({ vim.go.shell }, {
347+
cwd = plugin.dir,
348+
terminal = true,
349+
close_on_exit = true,
350+
enter = true,
351+
})
352+
end,
353+
},
354+
},
330355
diff = {
331356
-- diff command <d> can be one of:
332357
-- * browser: opens the github compare view. Note that this is always mapped to <K> as well,

TODO.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## ✅ TODO
1+
# ✅ TODO
22

33
- [x] fancy UI to manage all your Neovim plugins
44
- [x] auto lazy-loading of lua modules
@@ -46,6 +46,8 @@
4646

4747
- [ ] document highlight groups
4848
- [ ] document user events
49+
- [ ] document API, like lazy.plugins()
50+
- [ ] icons
4951

5052
- [x] check in cache if rtp files match
5153
- [x] I think the installation section, specifically the loading part, could use an

lua/lazy/core/config.lua

+25
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,31 @@ M.defaults = {
5050
task = "",
5151
},
5252
throttle = 20, -- how frequently should the ui process render events
53+
custom_keys = {
54+
-- you can define custom key maps here.
55+
-- To disable one of the defaults, set it to false
56+
57+
-- open lazygit log
58+
["<localleader>l"] = function(plugin)
59+
require("lazy.util").open_cmd({ "lazygit", "log" }, {
60+
cwd = plugin.dir,
61+
terminal = true,
62+
close_on_exit = true,
63+
enter = true,
64+
})
65+
end,
66+
67+
-- open a terminal for the plugin dir
68+
["<localleader>t"] = function(plugin)
69+
require("lazy.util").open_cmd({ vim.go.shell }, {
70+
cwd = plugin.dir,
71+
terminal = true,
72+
close_on_exit = true,
73+
enter = true,
74+
})
75+
end,
76+
},
77+
},
5378
diff = {
5479
-- diff command <d> can be one of:
5580
-- * browser: opens the github compare view. Note that this is always mapped to <K> as well,

lua/lazy/view/init.lua

+8-6
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,14 @@ function M.create(opts)
9696
end)
9797

9898
for key, handler in pairs(Config.options.ui.custom_keys) do
99-
self:on_key(key, function()
100-
local plugin = self.render:get_plugin()
101-
if plugin then
102-
handler(plugin)
103-
end
104-
end)
99+
if handler then
100+
self:on_key(key, function()
101+
local plugin = self.render:get_plugin()
102+
if plugin then
103+
handler(plugin)
104+
end
105+
end)
106+
end
105107
end
106108

107109
self:setup_patterns()

0 commit comments

Comments
 (0)