oh-my-posh/src/environment_unix.go

46 lines
1 KiB
Go
Raw Normal View History

//go:build !windows
2019-03-13 04:14:30 -07:00
package main
import (
2020-11-04 23:56:12 -08:00
"errors"
2019-03-13 04:14:30 -07:00
"os"
"time"
2021-09-09 22:25:12 -07:00
"github.com/shirou/gopsutil/host"
terminal "github.com/wayneashleyberry/terminal-dimensions"
2019-03-13 04:14:30 -07:00
)
func (env *environment) isRunningAsRoot() bool {
defer env.tracer.trace(time.Now(), "isRunningAsRoot")
2019-03-13 04:14:30 -07:00
return os.Geteuid() == 0
}
func (env *environment) homeDir() string {
return os.Getenv("HOME")
}
2020-11-04 23:56:12 -08:00
func (env *environment) getWindowTitle(imageName, windowTitleRegex string) (string, error) {
2020-11-04 23:56:12 -08:00
return "", errors.New("not implemented")
}
func (env *environment) isWsl() bool {
defer env.tracer.trace(time.Now(), "isWsl")
// one way to check
// version := env.getFileContent("/proc/version")
// return strings.Contains(version, "microsoft")
// using env variable
return env.getenv("WSL_DISTRO_NAME") != ""
}
func (env *environment) getTerminalWidth() (int, error) {
defer env.tracer.trace(time.Now(), "getTerminalWidth")
width, err := terminal.Width()
return int(width), err
}
2021-09-09 22:25:12 -07:00
func (env *environment) getPlatform() string {
p, _, _, _ := host.PlatformInformation()
return p
}