-
Notifications
You must be signed in to change notification settings - Fork 1
/
go.go
53 lines (46 loc) · 1.15 KB
/
go.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
46
47
48
49
50
51
52
53
package main
import (
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
)
func read(path string) string {
buf, _ := ioutil.ReadFile(path)
return string(buf)
}
func main() {
user := os.Getenv("USER")
host := read("/etc/hostname")
kernel := strings.Fields(read("/proc/version"))[2]
term := os.Getenv("TERM")
shell := os.Getenv("SHELL")
n := 0
files, _ := ioutil.ReadDir("/proc")
for _, file := range files {
_, err := strconv.Atoi(file.Name())
if err == nil {
n += 1
}
}
tasks := strconv.Itoa(n)
mem := strings.Split(read("/proc/meminfo"), "\n")
getSize := func(s string) string {
i, _ := strconv.Atoi(strings.Fields(s)[1])
return strconv.Itoa(i / 1000)
}
total := getSize(mem[0])
avail := getSize(mem[2])
uptime, _ := strconv.Atoi(strings.Split(read("/proc/uptime"), ".")[0])
d := strconv.Itoa(uptime / 60 / 60 / 24)
h := strconv.Itoa(uptime / 60 / 60 % 24)
m := strconv.Itoa(uptime / 60 / 60)
fmt.Printf(user + "@" + host +
"kernel\t" + kernel +
"\nterm\t" + term +
"\nshell\t" + shell +
"\ntasks\t" + tasks +
"\nmem\t" + avail + "m / " + total + "m" +
"\nuptime\t" + d + "d " + h + "h " + m + "m")
}