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") != "" {
|
|
|
|
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{
|
|
|
|
EditCommand: ``,
|
|
|
|
EditCommandTemplate: "",
|
|
|
|
OpenCommand: `powershell.exe start explorer.exe {{filename}} >/dev/null`,
|
2022-07-03 11:00:40 +02:00
|
|
|
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{
|
2021-08-04 11:43:34 +02:00
|
|
|
EditCommand: ``,
|
2022-04-22 14:54:03 +02:00
|
|
|
EditCommandTemplate: "",
|
2021-10-09 09:32:36 +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
|
|
|
}
|