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")
|
|
|
|
|
2023-03-05 07:06:34 +05:00
|
|
|
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{
|
2023-03-28 18:00:40 +02:00
|
|
|
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{
|
2023-03-28 18:00:40 +02:00
|
|
|
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
|
|
|
}
|