-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
environment_unix.go
45 lines (36 loc) · 1.04 KB
/
environment_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//go:build !windows
package main
import (
"errors"
"os"
"time"
"github.com/shirou/gopsutil/host"
terminal "github.com/wayneashleyberry/terminal-dimensions"
)
func (env *environment) isRunningAsRoot() bool {
defer env.tracer.trace(time.Now(), "isRunningAsRoot")
return os.Geteuid() == 0
}
func (env *environment) homeDir() string {
return os.Getenv("HOME")
}
func (env *environment) getWindowTitle(imageName, windowTitleRegex string) (string, error) {
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
}
func (env *environment) getPlatform() string {
p, _, _, _ := host.PlatformInformation()
return p
}