···
1
1
+
package main
2
2
+
3
3
+
import (
4
4
+
"fmt"
5
5
+
"os"
6
6
+
"strings"
7
7
+
"golang.org/x/sys/unix"
8
8
+
"time"
9
9
+
)
10
10
+
11
11
+
func main() {
12
12
+
cwd, _ := os.Getwd()
13
13
+
host, _ := os.Hostname()
14
14
+
home := os.Getenv("HOME")
15
15
+
var parts []string
16
16
+
if strings.HasPrefix(cwd, home) {
17
17
+
cwd = "~" + cwd[len(home):]
18
18
+
}
19
19
+
// Maybe handle this and drop into failure if leenux
20
20
+
bootTime, _ := unix.SysctlTimeval("kern.boottime")
21
21
+
now := time.Now().Unix()
22
22
+
uptimeSeconds := now - bootTime.Sec
23
23
+
24
24
+
uptime := time.Duration(uptimeSeconds) * time.Second
25
25
+
fmt.Printf("\033[38;5;162m[%d:%02d:%02d] %s\033[0m ", int64(uptime.Hours()),
26
26
+
int64(uptime.Minutes()) % 60, int64(uptime.Seconds()) % 60,
27
27
+
host)
28
28
+
29
29
+
parts = strings.Split(cwd, "/")
30
30
+
for i, part := range parts {
31
31
+
if i == len(parts)-1 {
32
32
+
fmt.Printf("%s", part)
33
33
+
} else {
34
34
+
if len(part) != 0 {
35
35
+
fmt.Printf("%c/", part[0])
36
36
+
} else {
37
37
+
fmt.Printf("/")
38
38
+
}
39
39
+
}
40
40
+
}
41
41
+
}