jesseduffield / lazygit

simple terminal UI for git commands
MIT License
47.94k stars 1.72k forks source link

Allow replacing close event to custom commands #3699

Closed xzbdmw closed 16 hours ago

xzbdmw commented 4 days ago

Is your feature request related to a problem? Please describe. In neovim, I use floating terminal to open lazygit, and it makes perfect sense if close event is translated into a custom command such as `nvim --remote --send-keys "close"' which hide the terminal window, so next time lazygit does not need to restart.

Describe the solution you'd like Adds a new keymap to trigger custom commands everytime layzgit is about to close itself, and keep a keymap to actually close lazygit when needed.

Describe alternatives you've considered I can bind a key in neovim to toggle terminal, but it is not intuitive to use because return at top level is very useful but can not be achieved in neovim side(I'm so used to press esc so many time I just unexpected close lazygit). Additional context Add any other context or screenshots about the feature request here.

stefanhaller commented 3 days ago

You should be able to do this already using a config like this:

customCommands:
  - key: "q"
    command: 'nvim --remote --send-keys "close"'
    context: "global"
    description: "Quit"
keybinding:
  universal:
    quit: <disabled>

Let me know if this works!

xzbdmw commented 3 days ago

But esc to return at top level will have to close lazygit, so can we permit a way to specify a custom command be triggered at that time?

stefanhaller commented 3 days ago

When quitOnTopLevelReturn is true, you mean? Hm, I very much dislike that option, so it's off for me and I don't have this problem. Maybe you can just train yourself to hit q instead of esc? 😄

If not, then yes, we'll have to add a new config key to support this. I was trying to avoid this if possible...

(For a moment I was considering changing the top-level esc handler to send a q keystroke down the event queue, so that it goes through the normal keybinding dispatching and the above solution would work, but that's probably too hacky.)

xzbdmw commented 3 days ago

I very much dislike that option

Yeah if it accidentally closes lazygit that's bad, but quitOnTopLevelReturn would be convenient to hide lazygit, kinda like customCommandOnTopLevelReturn. Maybe the usecase is too special, feel free to close this.

xzbdmw commented 16 hours ago

closing as I'm now only use q to close