Repository: jesseduffield/lazygit (language: go)

Issue:
Process suspended after shell command execution
**Describe the bug**

When shell command executed with `:` hotkey lazygit process become suspended.

**To Reproduce**
Steps to reproduce the behavior:

1. Open lazygit
2. Type `:` to enter shell command menu
3. Type any command, ex.: `date`
4. Command output displayed and lazygit process suspended, your shell is open.

**Expected behavior**

Lazygit ask to press any key and after return to lazygit.

**Screenshots**

[demo.webm](https://github.com/user-attachments/assets/42fc45ca-b509-4dac-814e-48449a49bf00)

**Version info:**
_Run `lazygit --version` and paste the result here_

commit=2d0c7cb0fc85e3c262837eb9691813fa97e00e80, build date=2024-09-07T02:26:26Z, build source=binaryRelease, version=0.44.0, os=linux, arch=amd64, git version=2.39.2

_Run `git --version` and paste the result here_

git version 2.39.2

**Additional context**

Problem appears with version 0.44.0 and master.



Discussion / hints:
Reverting https://github.com/jesseduffield/lazygit/pull/3793 on master fix my issue. Maybe it is expected behavior now?
No, it's not the expected behavior, and it doesn't happen for me.

I can't explain why this happens to you, but I suspect it has something to do with what's in your `.zshrc` (or maybe `.zprofile`). Could you post those?
It is not related to my zsh config.  I also tested it on debian:latest docker image with default bash:

```shell
docker run -it debian:latest

# In container shell
apt update && apt install -y git wget
wget https://github.com/jesseduffield/lazygit/releases/download/v0.44.0/lazygit_0.44.0_Linux_x86_64.tar.gz
tar xf lazygit_0.44.0_Linux_x86_64.tar.gz
git init
./lazygit
```

Hm, ok. I can reproduce it on my Mac when doing `SHELL=bash lazygit` from my zsh prompt:
```
$ SHELL=bash lazygit

+ bash -i -c date

Di 10 Sep 2024 09:57:16 CEST
zsh: suspended (tty output)  SHELL=bash lazygit
$
```

Note that it is my zsh that suspends the lazygit process, not bash.

A bit of cursory googling finds [this](https://unix.stackexchange.com/a/600460), which sounds related. I'm still not sure what to make of this, I'm hoping somebody with more knowledge about this can suggest a fix. I'd hate to have to revert #3793, it's a useful feature.

Another data point: executing `:date </dev/null` in lazygit seems to work without suspending. Not that I'm suggesting this as a workaround, but maybe it can help shed some light.
i have the same issue, i am so confuse that i search everywhere. oh..
Just to add a bit more information, the behavior is reproducible also on WSL Ubuntu-24.04 with lazygit version 0.44.1_Linux_x86_64:
* It happens using either bash or fish - so does not seem to be shell (zsh) specific (?)
* It happens in windows conpty as well as alacritty as terminal emulator - so maybe not terminal specific either (?)
* The workaround of adding "</dev/null" as described above works in all tested cases

Fix patch:
diff --git a/pkg/commands/oscommands/cmd_obj_builder.go b/pkg/commands/oscommands/cmd_obj_builder.go
index 3e89ce10293..c96f2c5bf7d 100644
--- a/pkg/commands/oscommands/cmd_obj_builder.go
+++ b/pkg/commands/oscommands/cmd_obj_builder.go
@@ -52,7 +52,7 @@ func (self *CmdObjBuilder) NewShell(commandStr string) ICmdObj {
 }
 
 func (self *CmdObjBuilder) NewInteractiveShell(commandStr string) ICmdObj {
-	quotedCommand := self.quotedCommandString(commandStr)
+	quotedCommand := self.quotedCommandString(commandStr + self.platform.InteractiveShellExit)
 	cmdArgs := str.ToArgv(fmt.Sprintf("%s %s %s %s", self.platform.InteractiveShell, self.platform.InteractiveShellArg, self.platform.ShellArg, quotedCommand))
 
 	return self.New(cmdArgs)
diff --git a/pkg/commands/oscommands/dummies.go b/pkg/commands/oscommands/dummies.go
index ab528782fa6..1e015023842 100644
--- a/pkg/commands/oscommands/dummies.go
+++ b/pkg/commands/oscommands/dummies.go
@@ -51,13 +51,14 @@ func NewDummyCmdObjBuilder(runner ICmdObjRunner) *CmdObjBuilder {
 }
 
 var dummyPlatform = &Platform{
-	OS:                  "darwin",
-	Shell:               "bash",
-	InteractiveShell:    "bash",
-	ShellArg:            "-c",
-	InteractiveShellArg: "-i",
-	OpenCommand:         "open {{filename}}",
-	OpenLinkCommand:     "open {{link}}",
+	OS:                   "darwin",
+	Shell:                "bash",
+	InteractiveShell:     "bash",
+	ShellArg:             "-c",
+	InteractiveShellArg:  "-i",
+	InteractiveShellExit: "; exit $?",
+	OpenCommand:          "open {{filename}}",
+	OpenLinkCommand:      "open {{link}}",
 }
 
 func NewDummyOSCommandWithRunner(runner *FakeCmdObjRunner) *OSCommand {
diff --git a/pkg/commands/oscommands/os.go b/pkg/commands/oscommands/os.go
index cbeb99d4364..8da5572dcb2 100644
--- a/pkg/commands/oscommands/os.go
+++ b/pkg/commands/oscommands/os.go
@@ -35,13 +35,14 @@ type OSCommand struct {
 
 // Platform stores the os state
 type Platform struct {
-	OS                  string
-	Shell               string
-	InteractiveShell    string
-	ShellArg            string
-	InteractiveShellArg string
-	OpenCommand         string
-	OpenLinkCommand     string
+	OS                   string
+	Shell                string
+	InteractiveShell     string
+	ShellArg             string
+	InteractiveShellArg  string
+	InteractiveShellExit string
+	OpenCommand          string
+	OpenLinkCommand      string
 }
 
 // NewOSCommand os command runner
diff --git a/pkg/commands/oscommands/os_default_platform.go b/pkg/commands/oscommands/os_default_platform.go
index 196e4d9f634..f5ea96900f1 100644
--- a/pkg/commands/oscommands/os_default_platform.go
+++ b/pkg/commands/oscommands/os_default_platform.go
@@ -10,13 +10,14 @@ import (
 
 func GetPlatform() *Platform {
 	return &Platform{
-		OS:                  runtime.GOOS,
-		Shell:               "bash",
-		InteractiveShell:    getUserShell(),
-		ShellArg:            "-c",
-		InteractiveShellArg: "-i",
-		OpenCommand:         "open {{filename}}",
-		OpenLinkCommand:     "open {{link}}",
+		OS:                   runtime.GOOS,
+		Shell:                "bash",
+		InteractiveShell:     getUserShell(),
+		ShellArg:             "-c",
+		InteractiveShellArg:  "-i",
+		InteractiveShellExit: "; exit $?",
+		OpenCommand:          "open {{filename}}",
+		OpenLinkCommand:      "open {{link}}",
 	}
 }
 
diff --git a/pkg/commands/oscommands/os_windows.go b/pkg/commands/oscommands/os_windows.go
index 32cd59edb0a..a2088a40737 100644
--- a/pkg/commands/oscommands/os_windows.go
+++ b/pkg/commands/oscommands/os_windows.go
@@ -2,10 +2,11 @@ package oscommands
 
 func GetPlatform() *Platform {
 	return &Platform{
-		OS:                  "windows",
-		Shell:               "cmd",
-		InteractiveShell:    "cmd",
-		ShellArg:            "/c",
-		InteractiveShellArg: "",
+		OS:                   "windows",
+		Shell:                "cmd",
+		InteractiveShell:     "cmd",
+		ShellArg:             "/c",
+		InteractiveShellArg:  "",
+		InteractiveShellExit: "",
 	}
 }


Test patch: