breto

A status bar written in Go.
Log | Files | Refs | README | LICENSE

commit 34c5462a7be90b8d6905f308581e769075d7ba54
parent 69e629efda408b4fcca4e6f409da9d9d73781e20
Author: J. R. Swab <jrswab@protonmail.com>
Date:   Wed, 22 May 2019 21:49:46 +0000

Merge branch 'memoryUsage' into 'master'

Total Gibs of free memory added

See merge request jrswab/dwm-status!1
Diffstat:
M.gitignore | 3+--
MdwmStatusBar | 0
Mstatus.go | 33++++++++++++++++++++++++++++-----
3 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1 +1 @@ -./dwmStatusBar -\ No newline at end of file +./dwmStatusBar diff --git a/dwmStatusBar b/dwmStatusBar Binary files differ. diff --git a/status.go b/status.go @@ -1,18 +1,41 @@ package main import ( - //"fmt" + "fmt" "os/exec" + "strings" "time" ) func main() { + i := 0 - for true { - hTime := time.Now().Format("2006-01-02 15:04:05") - //fmt.Print(hTime.String(), "\n") - cmd := exec.Command("xsetroot", "-name", hTime) + for i < 3700 { + hTime := time.Now().Format("Jan 02, 2006 15:04") + + // get free Ram using Posix compliant shell command + ramCmd := "free -h | gawk '/Mem:/ {print $4}'" + ramGib, err := exec.Command("sh", "-c", ramCmd).Output() + if err != nil { + fmt.Println(err) + } + ramFree := strings.TrimSpace(string(ramGib)) + + // storing desired items as strings + cat := []string{"RAM:", ramFree, + "free", "|", hTime} + + // concatinate all strings to one line for output + status := strings.Join(cat, " ") + + cmd := exec.Command("xsetroot", "-name", status) cmd.Run() time.Sleep(1 * time.Second) + + if i > 3600 { + i = 0 + } else { + i++ + } } }