From dbd407c01d406ddfdf4e1929042fd607ae97ebd1 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 9 Jan 2025 09:29:31 +0100 Subject: [PATCH] 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. --- .../oscommands/os_default_platform.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/pkg/commands/oscommands/os_default_platform.go b/pkg/commands/oscommands/os_default_platform.go index f5ea96900..beb767723 100644 --- a/pkg/commands/oscommands/os_default_platform.go +++ b/pkg/commands/oscommands/os_default_platform.go @@ -6,16 +6,29 @@ package oscommands import ( "os" "runtime" + "strings" ) 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{ OS: runtime.GOOS, Shell: "bash", - InteractiveShell: getUserShell(), + InteractiveShell: interactiveShell, ShellArg: "-c", - InteractiveShellArg: "-i", - InteractiveShellExit: "; exit $?", + InteractiveShellArg: interactiveShellArg, + InteractiveShellExit: interactiveShellExit, OpenCommand: "open {{filename}}", OpenLinkCommand: "open {{link}}", }