1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-14 11:23:09 +02:00
lazygit/pkg/config/config_linux.go

42 lines
996 B
Go
Raw Normal View History

2018-09-01 06:33:01 +02:00
package config
2022-06-12 08:18:29 +02:00
import (
2022-06-12 08:23:22 +02:00
"io/ioutil"
2023-03-05 03:47:21 +02:00
"os"
2022-06-12 08:23:22 +02:00
"strings"
2022-06-12 08:18:29 +02:00
)
func isWSL() bool {
2022-06-12 08:23:22 +02:00
data, err := ioutil.ReadFile("/proc/sys/kernel/osrelease")
return err == nil && strings.Contains(string(data), "microsoft")
2022-06-12 08:18:29 +02:00
}
2023-03-05 03:47:21 +02: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 03:47:21 +02:00
return err == nil && true
}
return err == nil && false
}
2018-09-01 06:33:01 +02:00
// GetPlatformDefaultConfig gets the defaults for the platform
2020-10-03 06:54:55 +02:00
func GetPlatformDefaultConfig() OSConfig {
2023-03-05 03:47:21 +02:00
if isWSL() && !isContainer() {
2022-06-12 08:23:22 +02:00
return OSConfig{
2023-03-26 14:04:09 +02:00
OpenCommand: `powershell.exe start explorer.exe {{filename}} >/dev/null`,
OpenLinkCommand: `powershell.exe start {{link}} >/dev/null`,
2022-06-12 08:23:22 +02:00
}
}
2022-06-12 08:18:29 +02:00
2020-10-03 06:54:55 +02:00
return OSConfig{
2023-03-26 14:04:09 +02:00
OpenCommand: `xdg-open {{filename}} >/dev/null`,
OpenLinkCommand: `xdg-open {{link}} >/dev/null`,
2020-10-03 06:54:55 +02:00
}
2018-09-01 06:33:01 +02:00
}