oh-my-posh/src/environment_unix.go

66 lines
1.6 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"
"github.com/shirou/gopsutil/v3/host"
terminal "github.com/wayneashleyberry/terminal-dimensions"
2019-03-13 04:14:30 -07:00
)
func (env *environment) isRunningAsRoot() bool {
2021-11-16 22:16:43 -08:00
defer env.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 {
2021-11-16 22:16:43 -08:00
defer env.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) {
2021-11-16 22:16:43 -08:00
defer env.trace(time.Now(), "getTerminalWidth")
width, err := terminal.Width()
if err != nil {
2021-11-16 22:16:43 -08:00
env.log(Error, "runCommand", err.Error())
}
return int(width), err
}
2021-09-09 22:25:12 -07:00
func (env *environment) getPlatform() string {
p, _, _, _ := host.PlatformInformation()
return p
}
func (env *environment) getCachePath() string {
2021-11-16 22:16:43 -08:00
defer env.trace(time.Now(), "getCachePath")
// get XDG_CACHE_HOME if present
if cachePath := returnOrBuildCachePath(env.getenv("XDG_CACHE_HOME")); len(cachePath) != 0 {
return cachePath
}
// HOME cache folder
if cachePath := returnOrBuildCachePath(env.homeDir() + "/.cache"); len(cachePath) != 0 {
return cachePath
}
return env.homeDir()
}
2021-11-24 04:47:30 -08:00
func (env *environment) getWindowsRegistryKeyValue(path string) (*windowsRegistryValue, error) {
return nil, errors.New("not implemented")
2021-11-24 04:47:30 -08:00
}