small pixel drawing of a pufferfish dotfiles

add osx prompt
j3s j3s@c3f.net
Fri, 23 Oct 2020 01:37:47 -0500
commit

ecd9de72b47efda39b307235fbcdfa1f86288155

parent

c35e04421377326b5f1c81829426e66b5d27cf49

1 files changed, 41 insertions(+), 0 deletions(-)

jump to
A bin/prompt_osx.go

@@ -0,0 +1,41 @@

+package main + +import ( + "fmt" + "os" + "strings" + "golang.org/x/sys/unix" + "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):] + } + // Maybe handle this and drop into failure if leenux + bootTime, _ := unix.SysctlTimeval("kern.boottime") + now := time.Now().Unix() + uptimeSeconds := now - bootTime.Sec + + uptime := time.Duration(uptimeSeconds) * 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("/") + } + } + } +}