Fix hang when returning from shell command

In 5a3049485c we changed the execution of shell commands to use an interactive
shell (-i), because this allows users to use aliases or shell functions, which
is a nice convenience.

Since then, however, many users have reported problems with lazygit not coming
back to the foreground after executing a shell command. Some users report that
appending "; exit" to the end of the command line solves this. I don't really
understand what the cause of this problem was, or why appending "; exit" solves
it, but if it helps, let's do it.
This commit is contained in:
Stefan Haller 2024-12-23 13:53:28 +01:00
parent ec410b2ae6
commit 5fac40c129
5 changed files with 31 additions and 27 deletions

View file

@ -52,7 +52,7 @@ func (self *CmdObjBuilder) NewShell(commandStr string) ICmdObj {
} }
func (self *CmdObjBuilder) NewInteractiveShell(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)) cmdArgs := str.ToArgv(fmt.Sprintf("%s %s %s %s", self.platform.InteractiveShell, self.platform.InteractiveShellArg, self.platform.ShellArg, quotedCommand))
return self.New(cmdArgs) return self.New(cmdArgs)

View file

@ -51,13 +51,14 @@ func NewDummyCmdObjBuilder(runner ICmdObjRunner) *CmdObjBuilder {
} }
var dummyPlatform = &Platform{ var dummyPlatform = &Platform{
OS: "darwin", OS: "darwin",
Shell: "bash", Shell: "bash",
InteractiveShell: "bash", InteractiveShell: "bash",
ShellArg: "-c", ShellArg: "-c",
InteractiveShellArg: "-i", InteractiveShellArg: "-i",
OpenCommand: "open {{filename}}", InteractiveShellExit: "; exit $?",
OpenLinkCommand: "open {{link}}", OpenCommand: "open {{filename}}",
OpenLinkCommand: "open {{link}}",
} }
func NewDummyOSCommandWithRunner(runner *FakeCmdObjRunner) *OSCommand { func NewDummyOSCommandWithRunner(runner *FakeCmdObjRunner) *OSCommand {

View file

@ -35,13 +35,14 @@ type OSCommand struct {
// Platform stores the os state // Platform stores the os state
type Platform struct { type Platform struct {
OS string OS string
Shell string Shell string
InteractiveShell string InteractiveShell string
ShellArg string ShellArg string
InteractiveShellArg string InteractiveShellArg string
OpenCommand string InteractiveShellExit string
OpenLinkCommand string OpenCommand string
OpenLinkCommand string
} }
// NewOSCommand os command runner // NewOSCommand os command runner

View file

@ -10,13 +10,14 @@ import (
func GetPlatform() *Platform { func GetPlatform() *Platform {
return &Platform{ return &Platform{
OS: runtime.GOOS, OS: runtime.GOOS,
Shell: "bash", Shell: "bash",
InteractiveShell: getUserShell(), InteractiveShell: getUserShell(),
ShellArg: "-c", ShellArg: "-c",
InteractiveShellArg: "-i", InteractiveShellArg: "-i",
OpenCommand: "open {{filename}}", InteractiveShellExit: "; exit $?",
OpenLinkCommand: "open {{link}}", OpenCommand: "open {{filename}}",
OpenLinkCommand: "open {{link}}",
} }
} }

View file

@ -2,10 +2,11 @@ package oscommands
func GetPlatform() *Platform { func GetPlatform() *Platform {
return &Platform{ return &Platform{
OS: "windows", OS: "windows",
Shell: "cmd", Shell: "cmd",
InteractiveShell: "cmd", InteractiveShell: "cmd",
ShellArg: "/c", ShellArg: "/c",
InteractiveShellArg: "", InteractiveShellArg: "",
InteractiveShellExit: "",
} }
} }