fix(platform): detect WSL via /proc/version

This commit is contained in:
L. Yeung 2023-03-31 00:18:38 +08:00 committed by Jan De Dobbeleer
parent 4e19379e19
commit ea19410f23

View file

@ -5,6 +5,7 @@ package platform
import ( import (
"errors" "errors"
"os" "os"
"strconv"
"strings" "strings"
"time" "time"
@ -29,11 +30,19 @@ func (env *Shell) QueryWindowTitles(_, _ string) (string, error) {
func (env *Shell) IsWsl() bool { func (env *Shell) IsWsl() bool {
defer env.Trace(time.Now()) defer env.Trace(time.Now())
// one way to check const key = "is_wsl"
// version := env.FileContent("/proc/version") if val, found := env.Cache().Get(key); found {
// return strings.Contains(version, "microsoft") env.Debug(val)
// using env variable return val == "true"
return env.Getenv("WSL_DISTRO_NAME") != "" }
var val bool
defer func() {
env.Cache().Set(key, strconv.FormatBool(val), -1)
}()
version := env.FileContent("/proc/version")
val = strings.Contains(version, "microsoft")
env.Debug(strconv.FormatBool(val))
return val
} }
func (env *Shell) IsWsl2() bool { func (env *Shell) IsWsl2() bool {