bin/prompt.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
package main
import (
"fmt"
"os"
"strings"
"syscall"
"time"
)
func main() {
cwd, _ := os.Getwd()
host, _ := os.Hostname()
home := os.Getenv("HOME")
var parts []string
if strings.HasPrefix(cwd, home) {
cwd = "~" + cwd[len(home):]
}
var sysinfo syscall.Sysinfo_t
syscall.Sysinfo(&sysinfo)
uptime := time.Duration(sysinfo.Uptime) * time.Second
fmt.Printf("\033[38;5;162m[%d:%02d:%02d] %s\033[0m ", int64(uptime.Hours()),
int64(uptime.Minutes()) % 60, int64(uptime.Seconds()) % 60,
host)
parts = strings.Split(cwd, "/")
for i, part := range parts {
if i == len(parts)-1 {
fmt.Printf("%s", part)
} else {
if len(part) != 0 {
fmt.Printf("%c/", part[0])
} else {
fmt.Printf("/")
}
}
}
}