Skip to content

Add support for suspending LazyGit with Ctrl+Z on Unix systems #4757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

cowboy8625
Copy link

@cowboy8625 cowboy8625 commented Jul 19, 2025

  • PR Description

✨ Add Ctrl+Z suspend support for LazyGit on Unix-like systems

📝 Summary

This PR adds support for suspending LazyGit when the user presses Ctrl+Z, making it behave like common CLI tools (e.g., Vim, less, htop):

  • Pressing Ctrl+Z sends a SIGTSTP signal to suspend LazyGit.
  • After resuming with fg, LazyGit redraws and continues working without hanging.
  • During suspension, background routines are paused to avoid running while LazyGit is stopped.

⚙ Implementation details

  • Added a new suspendApp function triggered by a Ctrl+Z keybinding.

  • Inside suspendApp, we do a runtime OS check (runtime.GOOS == "windows") and return early (effectively no-op) on Windows.
    This way, the keybinding itself is always defined cross-platform, but the suspend logic only runs on Unix-like systems.

  • Integrated with the background routine manager:

    • Calls PauseBackgroundRefreshes(true) before sending the suspend signal.
    • Calls PauseBackgroundRefreshes(false) on resume (handled via SIGCONT).
  • After resuming, LazyGit keeps running smoothly without hanging.

🧠 Design notes

  • Considered using build tags / OS-specific Go files to fully exclude the suspend logic on Windows.
  • Opted for a runtime check instead for simplicity, but happy to refactor to build-specific files if that’s the preferred approach.

✅ Motivation

Make LazyGit feel more native on Unix-like systems by supporting standard terminal suspend/resume (Ctrl+Z / fg) behavior.

  • Please check if the PR fulfills these requirements
  • Cheatsheets are up-to-date (run go generate ./...)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • If a new UserConfig entry was added, make sure it can be hot-reloaded (see here)
  • Docs have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

Closes #3906

@cowboy8625 cowboy8625 changed the title Allow ctrl-z to suspend lazygit Add support for suspending LazyGit with Ctrl+Z on Unix systems Jul 19, 2025
@cowboy8625
Copy link
Author

@stefanhaller I’ve addressed the earlier issues you pointed out. I’m not sure if a test is needed for this change, or if there are any other steps you’d expect before merging. Let me know! 🙂

@stefanhaller
Copy link
Collaborator

@cowboy8625 The behavior is still the same for me, as described in #3906 (comment). After typing bg, I get the "+ suspended (tty output)" error, and then fg hangs.

(We had a similar problem back when we used $SHELL -i for running custom shell commands; see #3903 (comment) for some discussion. Not sure how much of a connection there is between the two cases; just mentioning it.)

And finally, when I use make run to start lazygit, then ctrl-z doesn't work at all; lazygit does suspend, but the shell prompt doesn't appear. This may be only relevant for developers, not users, but the same could happen for users if they launch lazygit through a wrapper script. I suppose in this case we'd have to send the SIGTSTP to the wrapper script (or to the make process in my case), not to lazygit; but I'm not sure what the criterion for that is. Walk the chain of parent processes until we find one whose name matches $SHELL?

Until these problems are solved I don't feel we can merge this. But I'm also not sure how much time is justified for putting into this, to be honest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow ctrl-z to suspend lazygit
2 participants