diff options
| author | Christine Dodrill <xena@yolo-swag.com> | 2015-03-10 22:01:41 -0700 |
|---|---|---|
| committer | Christine Dodrill <xena@yolo-swag.com> | 2015-03-10 22:01:41 -0700 |
| commit | 3e08f9090b89373273609b123c0baaeb4c73ad20 (patch) | |
| tree | e377267845458bf45b98b80acf89f4e12a86014a | |
| parent | e309bb69d427955d8ce84ae317fdffe92c721048 (diff) | |
| download | x-3e08f9090b89373273609b123c0baaeb4c73ad20.tar.xz x-3e08f9090b89373273609b123c0baaeb4c73ad20.zip | |
add draft of logo command
| -rw-r--r-- | logo/.gitignore | 1 | ||||
| -rw-r--r-- | logo/Makefile | 2 | ||||
| -rw-r--r-- | logo/logo.go | 35 | ||||
| -rw-r--r-- | logo/logo_openbsd.go | 48 |
4 files changed, 86 insertions, 0 deletions
diff --git a/logo/.gitignore b/logo/.gitignore new file mode 100644 index 0000000..98a0152 --- /dev/null +++ b/logo/.gitignore @@ -0,0 +1 @@ +logo diff --git a/logo/Makefile b/logo/Makefile new file mode 100644 index 0000000..5f03483 --- /dev/null +++ b/logo/Makefile @@ -0,0 +1,2 @@ +all: + go build diff --git a/logo/logo.go b/logo/logo.go new file mode 100644 index 0000000..b688075 --- /dev/null +++ b/logo/logo.go @@ -0,0 +1,35 @@ +package main + +import ( + "fmt" + "os" + "os/user" + + "github.com/mgutz/ansi" +) + +func main() { + color := ansi.ColorCode("white+b:green") + + fmt.Print(color) + fmt.Printf(logo, 0, 0, 0, "Fast", getUptime(), getUsername(), getHostname()) + fmt.Println(ansi.ColorCode("reset")) +} + +func getUsername() string { + u, err := user.Current() + if err != nil { + panic(err) + } + + return u.Username +} + +func getHostname() string { + name, err := os.Hostname() + if err != nil { + panic(err) + } + + return name +} diff --git a/logo/logo_openbsd.go b/logo/logo_openbsd.go new file mode 100644 index 0000000..a465fcf --- /dev/null +++ b/logo/logo_openbsd.go @@ -0,0 +1,48 @@ +package main + +import ( + "fmt" + "os/exec" + "strconv" + "time" + + "github.com/mgutz/ansi" +) + +var ( + color = ansi.ColorCode("white+b:green") + reset = ansi.ColorCode("reset") +) + +var logo string = ` ____ + /____\ ` + reset + " Ram: %dM/%dM" + color + ` + |\ | __________.__ __ .__ ` + reset + " Pacakges: %d" + color + ` + | \ | \______ \__|/ |________|__| ____ ` + reset + " CPU: %s" + color + ` + | \ | | | _/ \ __\_ __ \ |/ ___\ ` + reset + " Uptime: %s" + color + ` + |___\| | | \ || | | | \/ / /_/ > ` + reset + " User: %s" + color + ` + | /| |______ /__||__| |__| |__\___ / ` + reset + " Hostname: %s" + color + ` + | / | \/ /_____/ + | / | + |/ __| Version 1.0 + | |___________________________________________` + +func getUptime() string { + out, err := exec.Command("sysctl", "-n", "kern.boottime").Output() + if err != nil { + panic(err) + } + + boottimeint, err := strconv.ParseInt(string(out[:len(out)-1]), 10, 64) + if err != nil { + panic(err) + } + + boottime := time.Unix(boottimeint, 0) + dur := time.Since(boottime) + + days := int(dur.Hours() / 24) + hours := int(dur.Hours()) % 24 + minutes := int(dur.Minutes()) % 60 + + return fmt.Sprintf("%d days, %d hours, %d minutes", days, hours, minutes) +} |
