mirror of
				https://github.com/jesseduffield/lazygit.git
				synced 2025-10-30 23:57:43 +02:00 
			
		
		
		
	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.
This commit is contained in:
		| @@ -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 { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user