mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 12:29:40 -08:00
fix(platform): detect WSL via /proc/version
This commit is contained in:
parent
4e19379e19
commit
ea19410f23
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue