mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-23 12:18:51 +02:00
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.
44 lines
871 B
Go
44 lines
871 B
Go
//go:build !windows
|
|
// +build !windows
|
|
|
|
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: interactiveShell,
|
|
ShellArg: "-c",
|
|
InteractiveShellArg: interactiveShellArg,
|
|
InteractiveShellExit: interactiveShellExit,
|
|
OpenCommand: "open {{filename}}",
|
|
OpenLinkCommand: "open {{link}}",
|
|
}
|
|
}
|
|
|
|
func getUserShell() string {
|
|
if shell := os.Getenv("SHELL"); shell != "" {
|
|
return shell
|
|
}
|
|
|
|
return "bash"
|
|
}
|