Use interactive shell for running shell commands only if shell is bash or zsh

We use an interactive shell so that users can use their custom shell aliases in
lazygit's shell prompt, which is convenient; however, this only really works for
shells like bash or zsh. We know it doesn't work for fish or nushell (because
these use different names for the $? variable); so use an interactive shell only
if the user's shell is either bash or zsh.
This commit is contained in:
Stefan Haller 2025-01-09 09:29:31 +01:00
parent b8d5e481bb
commit dbd407c01d

View file

@ -6,16 +6,29 @@ package oscommands
import ( import (
"os" "os"
"runtime" "runtime"
"strings"
) )
func GetPlatform() *Platform { func GetPlatform() *Platform {
shell := getUserShell()
interactiveShell := shell
interactiveShellArg := "-i"
interactiveShellExit := "; exit $?"
if !(strings.HasSuffix(shell, "bash") || strings.HasSuffix(shell, "zsh")) {
interactiveShell = "bash"
interactiveShellArg = ""
interactiveShellExit = ""
}
return &Platform{ return &Platform{
OS: runtime.GOOS, OS: runtime.GOOS,
Shell: "bash", Shell: "bash",
InteractiveShell: getUserShell(), InteractiveShell: interactiveShell,
ShellArg: "-c", ShellArg: "-c",
InteractiveShellArg: "-i", InteractiveShellArg: interactiveShellArg,
InteractiveShellExit: "; exit $?", InteractiveShellExit: interactiveShellExit,
OpenCommand: "open {{filename}}", OpenCommand: "open {{filename}}",
OpenLinkCommand: "open {{link}}", OpenLinkCommand: "open {{link}}",
} }