Skip to content

Commit 43c284a

Browse files
authored
feat(keys): include custom keys in help menu (#1105)
1 parent 906ff8e commit 43c284a

File tree

5 files changed

+73
-49
lines changed

5 files changed

+73
-49
lines changed

README.md

+21-16
Original file line numberDiff line numberDiff line change
@@ -371,22 +371,27 @@ return {
371371
browser = nil, ---@type string?
372372
throttle = 20, -- how frequently should the ui process render events
373373
custom_keys = {
374-
-- you can define custom key maps here.
375-
-- To disable one of the defaults, set it to false
376-
377-
-- open lazygit log
378-
["<localleader>l"] = function(plugin)
379-
require("lazy.util").float_term({ "lazygit", "log" }, {
380-
cwd = plugin.dir,
381-
})
382-
end,
383-
384-
-- open a terminal for the plugin dir
385-
["<localleader>t"] = function(plugin)
386-
require("lazy.util").float_term(nil, {
387-
cwd = plugin.dir,
388-
})
389-
end,
374+
-- You can define custom key maps here. If present, the description will
375+
-- be shown in the help menu.
376+
-- To disable one of the defaults, set it to false.
377+
378+
["<localleader>l"] = {
379+
function(plugin)
380+
require("lazy.util").float_term({ "lazygit", "log" }, {
381+
cwd = plugin.dir,
382+
})
383+
end,
384+
desc = "Open lazygit log",
385+
},
386+
387+
["<localleader>t"] = {
388+
function(plugin)
389+
require("lazy.util").float_term(nil, {
390+
cwd = plugin.dir,
391+
})
392+
end,
393+
desc = "Open terminal in plugin dir",
394+
},
390395
},
391396
},
392397
diff = {

doc/lazy.nvim.txt

+21-16
Original file line numberDiff line numberDiff line change
@@ -473,22 +473,27 @@ CONFIGURATION *lazy.nvim-lazy.nvim-configuration*
473473
browser = nil, ---@type string?
474474
throttle = 20, -- how frequently should the ui process render events
475475
custom_keys = {
476-
-- you can define custom key maps here.
477-
-- To disable one of the defaults, set it to false
478-
479-
-- open lazygit log
480-
["<localleader>l"] = function(plugin)
481-
require("lazy.util").float_term({ "lazygit", "log" }, {
482-
cwd = plugin.dir,
483-
})
484-
end,
485-
486-
-- open a terminal for the plugin dir
487-
["<localleader>t"] = function(plugin)
488-
require("lazy.util").float_term(nil, {
489-
cwd = plugin.dir,
490-
})
491-
end,
476+
-- You can define custom key maps here. If present, the description will
477+
-- be shown in the help menu.
478+
-- To disable one of the defaults, set it to false.
479+
480+
["<localleader>l"] = {
481+
function(plugin)
482+
require("lazy.util").float_term({ "lazygit", "log" }, {
483+
cwd = plugin.dir,
484+
})
485+
end,
486+
desc = "Open lazygit log",
487+
},
488+
489+
["<localleader>t"] = {
490+
function(plugin)
491+
require("lazy.util").float_term(nil, {
492+
cwd = plugin.dir,
493+
})
494+
end,
495+
desc = "Open terminal in plugin dir",
496+
},
492497
},
493498
},
494499
diff = {

lua/lazy/core/config.lua

+19-14
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,27 @@ M.defaults = {
8181
browser = nil, ---@type string?
8282
throttle = 20, -- how frequently should the ui process render events
8383
custom_keys = {
84-
-- you can define custom key maps here.
85-
-- To disable one of the defaults, set it to false
84+
-- You can define custom key maps here. If present, the description will
85+
-- be shown in the help menu.
86+
-- To disable one of the defaults, set it to false.
8687

87-
-- open lazygit log
88-
["<localleader>l"] = function(plugin)
89-
require("lazy.util").float_term({ "lazygit", "log" }, {
90-
cwd = plugin.dir,
91-
})
92-
end,
88+
["<localleader>l"] = {
89+
function(plugin)
90+
require("lazy.util").float_term({ "lazygit", "log" }, {
91+
cwd = plugin.dir,
92+
})
93+
end,
94+
desc = "Open lazygit log",
95+
},
9396

94-
-- open a terminal for the plugin dir
95-
["<localleader>t"] = function(plugin)
96-
require("lazy.util").float_term(nil, {
97-
cwd = plugin.dir,
98-
})
99-
end,
97+
["<localleader>t"] = {
98+
function(plugin)
99+
require("lazy.util").float_term(nil, {
100+
cwd = plugin.dir,
101+
})
102+
end,
103+
desc = "Open terminal in plugin dir",
104+
},
100105
},
101106
},
102107
diff = {

lua/lazy/view/init.lua

+4-3
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,10 @@ function M.create()
121121
end
122122
end)
123123

124-
for key, handler in pairs(Config.options.ui.custom_keys) do
125-
if handler then
126-
self:on_key(key, function()
124+
for lhs, rhs in pairs(Config.options.ui.custom_keys) do
125+
if rhs then
126+
local handler = type(rhs) == "table" and rhs[1] or rhs
127+
self:on_key(lhs, function()
127128
local plugin = self.render:get_plugin()
128129
if plugin then
129130
handler(plugin)

lua/lazy/view/render.lua

+8
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,14 @@ function M:help()
209209
self:append(" " .. (mode.desc_plugin or mode.desc)):nl()
210210
end
211211
end
212+
for lhs, rhs in pairs(Config.options.ui.custom_keys) do
213+
if type(rhs) == "table" and rhs.desc then
214+
self:append("- ", "LazySpecial", { indent = 2 })
215+
self:append("Custom key ", "Title")
216+
self:append(lhs, "LazyProp")
217+
self:append(" " .. rhs.desc):nl()
218+
end
219+
end
212220
end
213221

214222
function M:progressbar()

0 commit comments

Comments
 (0)