From 18ad975573dce227f3d2a9dda03f6b22f6b35a64 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 3 Aug 2024 18:46:49 +0200 Subject: [PATCH] Make custom commands reload when switching repos Since onNewRepo calls resetKeybindings, which reinitializes the keybindings for custom commands, all we have to do for this is store a pointer to a config instead of storing the customCommands, so we get the up-to-date ones every time. --- pkg/gui/services/custom_commands/client.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pkg/gui/services/custom_commands/client.go b/pkg/gui/services/custom_commands/client.go index 4e49d0cf1..6cb1bf19c 100644 --- a/pkg/gui/services/custom_commands/client.go +++ b/pkg/gui/services/custom_commands/client.go @@ -1,7 +1,7 @@ package custom_commands import ( - "github.com/jesseduffield/lazygit/pkg/config" + "github.com/jesseduffield/lazygit/pkg/common" "github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -9,7 +9,7 @@ import ( // Client is the entry point to this package. It returns a list of keybindings based on the config's user-defined custom commands. // See https://github.com/jesseduffield/lazygit/blob/master/docs/Custom_Command_Keybindings.md for more info. type Client struct { - customCommands []config.CustomCommand + c *common.Common handlerCreator *HandlerCreator keybindingCreator *KeybindingCreator } @@ -26,10 +26,9 @@ func NewClient( helpers.MergeAndRebase, ) keybindingCreator := NewKeybindingCreator(c) - customCommands := c.UserConfig().CustomCommands return &Client{ - customCommands: customCommands, + c: c.Common, keybindingCreator: keybindingCreator, handlerCreator: handlerCreator, } @@ -37,7 +36,7 @@ func NewClient( func (self *Client) GetCustomCommandKeybindings() ([]*types.Binding, error) { bindings := []*types.Binding{} - for _, customCommand := range self.customCommands { + for _, customCommand := range self.c.UserConfig().CustomCommands { handler := self.handlerCreator.call(customCommand) compoundBindings, err := self.keybindingCreator.call(customCommand, handler) if err != nil {