1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-18 05:17:55 +02:00
lazygit/pkg/config/config_linux.go

42 lines
968 B
Go
Raw Normal View History

2018-09-01 14:33:01 +10:00
package config
2022-06-11 23:18:29 -07:00
import (
2022-06-11 23:23:22 -07:00
"io/ioutil"
2023-03-05 06:47:21 +05:00
"os"
2022-06-11 23:23:22 -07:00
"strings"
2022-06-11 23:18:29 -07:00
)
func isWSL() bool {
2022-06-11 23:23:22 -07:00
data, err := ioutil.ReadFile("/proc/sys/kernel/osrelease")
return err == nil && strings.Contains(string(data), "microsoft")
2022-06-11 23:18:29 -07:00
}
2023-03-05 06:47:21 +05:00
func isContainer() bool {
data, err := ioutil.ReadFile("/proc/1/cgroup")
if strings.Contains(string(data), "docker") ||
strings.Contains(string(data), "/lxc/") ||
[]string{string(data)}[0] != "systemd" &&
[]string{string(data)}[0] != "init" ||
os.Getenv("container") != "" {
2023-03-05 06:47:21 +05:00
return err == nil && true
}
return err == nil && false
}
2018-09-01 14:33:01 +10:00
// GetPlatformDefaultConfig gets the defaults for the platform
2020-10-03 14:54:55 +10:00
func GetPlatformDefaultConfig() OSConfig {
2023-03-05 06:47:21 +05:00
if isWSL() && !isContainer() {
2022-06-11 23:23:22 -07:00
return OSConfig{
Open: `powershell.exe start explorer.exe {{filename}} >/dev/null`,
OpenLink: `powershell.exe start {{link}} >/dev/null`,
2022-06-11 23:23:22 -07:00
}
}
2022-06-11 23:18:29 -07:00
2020-10-03 14:54:55 +10:00
return OSConfig{
Open: `xdg-open {{filename}} >/dev/null`,
OpenLink: `xdg-open {{link}} >/dev/null`,
2020-10-03 14:54:55 +10:00
}
2018-09-01 14:33:01 +10:00
}