Description
Describe the bug
I was trying to set up a custom command for the first time.
customCommands:
- key: '<c-m>'
context: 'localBranches'
command: 'git merge master'
Putting that in my config and launching lazygit on Windows causes it to just immediately terminate with no error message and a strange artifact at the edge of the window.
Only later did I learn that ctrl-m was not supported: docs/keybindings/Custom_Keybindings.md
lazygit/pkg/gui/keybindings/keybindings.go
Line 110 in 0fd7b9b
log.Fatal while the TUI has already started appears to cause this issue. I tried different shells and terminals on Windows to the same result. On WSL, it's better but multiline log.Fatal's still do not render quite correctly
(This log.Fatal happens when providing an invalid custom command context)
I think the ideal behavior would be for the custom command key/context validation to happen in
lazygit/pkg/config/app_config.go
Line 207 in 853a04d
Custom command misconfigurations would then behave consistently with how other user config errors are (gracefully) handled:
- If a config misconfiguration happens on startup, then lazygit cleanly prints the error and exits before starting the TUI.
- If a config misconfiguration happens during user config reload, an error popup will be shown and the old valid config will still be used instead of immediately crashing.
- If a config misconfiguration happens during repository switch, an error popup will be shown and the switch will be prevented instead of immediately crashing.
Actually making that fix is a bit of a refactor though...
Also, I noticed there are 3 disagreeing sources for what is a valid context value.
- The docs: https://github.com/jesseduffield/lazygit/blob/master/docs/Custom_Command_Keybindings.md#contexts
- What is actually allowed:
(basically any context key, for example
context: 'statusSpacer1'
is accepted...) - The context keys listed in the log fatal error message: Almost the same as 2 but missing some of the more recently added context keys.
To Reproduce
Steps to reproduce the behavior:
Add
customCommands:
- key: '<c-m>'
context: 'localBranches'
command: 'git merge master'
or
customCommands:
- key: '<c-n>'
context: 'localBranches2'
command: 'git merge master'
to your config and then launch lazygit
Expected behavior
See above
Screenshots
If applicable, add screenshots to help explain your problem.
Version info:
master branch
Additional context
Add any other context about the problem here.
Note: please try updating to the latest version or manually building the latest master
to see if the issue still occurs.