breto

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

commit f874e41ff00d06dfa8dc93e5ebcd559cffa84e14
parent 4479ced73d3b51a6756c1fd3a0e6af3bfddbbc41
Author: J. R. Swab <jrswab@protonmail.com>
Date:   Mon,  3 Jun 2019 21:28:30 +0000

Merge branch 'statusIcons' into 'master'

Status icons

See merge request jrswab/go-status!12
Diffstat:
MREADME.md | 21++++++++++++++++++---
Ablocks/icons.go | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ablocks/icons_test.go | 30++++++++++++++++++++++++++++++
Mblocks/wttr.go | 8+++++++-
Mmain.go | 8+++++++-
5 files changed, 125 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md @@ -1,5 +1,6 @@ # Go Status Bar -This is a script written with Go to display information. Currently tested with DWM, i3wm, and tmux. +This is a script written with Go to display information. +Currently tested with DWM, i3wm, and tmux. ## Current Features: ### Master Branch: @@ -7,16 +8,27 @@ This is a script written with Go to display information. Currently tested with D - Date & Time - Weather via wttr.in - Total RAM not used +- Icons #### Current UIs: - DWM - i3wm - tmux +### Icons: +To display icons in DWM. +1. Install FontAwesome v4 +2. Set FontAwesome as the second font in `dwm/config.h` + - eg. `static const char *fonts[] = { "Source Code Pro:size=13", "FontAwesome:size=14" };` + - Relaunch DWM + +Currently, the icons are much too small to be usefull in Tmux or i3wm without further configuration. +If you have an easy way to display FontAwesome icons at the same scale as the terminal text please submit a pull request. + ## How To Use: 1. Open main.go in a text editor. 1. If cloned from Github change the custom package directories from Gitlab to Github. 2. Edit the last `status` variable to contain the blocks you wish to use. -3. Change the laste line to match your UI (eg, `ui.Dwm(status)`). +3. Change the last line to match your UI (eg, `ui.Dwm(status)`). 4. Build the binary. 5. Edit your config file to use the new binary. @@ -35,7 +47,7 @@ This is a script written with Go to display information. Currently tested with D - If you notice the status getting cut off just increase the number and reload tmux. ### Adding to i3wm: -- Change `status_command ...` to `status_command PATH/TO/go-status` +- In the i3wm confige file, change `status_command ...` to `status_command PATH/TO/go-status` ## Wttr.in Options: 1. Add your area to the weather function @@ -44,3 +56,6 @@ This is a script written with Go to display information. Currently tested with D - More information can be found at [wttr.in/:help](https://wttr.in/:help) 2. Add tweaks to `blocks/wttr.go` +## To-Do: +1. Get a proper name +2. Scale icons in tmux and i3wm diff --git a/blocks/icons.go b/blocks/icons.go @@ -0,0 +1,63 @@ +package blocks + +import ( + "encoding/binary" + "fmt" + "os/exec" +) + +func DropboxIcon() (string, error) { + // ps ux | awk '/dropbox/ {print $11}' | grep dropbox + dbIcon := "" + dbCmd := "ps ux | gawk '/dropbox/ {print $11}' | grep dropbox" + runDbCmd, err := exec.Command("sh", "-c", dbCmd).Output() + + if err != nil && err.Error() != "exit status 1" { + return "", err + } + if string(runDbCmd) != "" { + return fmt.Sprintf("%s ", dbIcon), nil + } + return "", nil +} + +func RedshiftIcon() (string, error) { + rsIcon := "" + rsCmd := "ps ux | gawk '/redshift/ {print $11}' | grep redshift" + runRsCmd, err := exec.Command("sh", "-c", rsCmd).Output() + + if err != nil && err.Error() != "exit status 1" { + return "", err + } + if string(runRsCmd) != "" { + return fmt.Sprintf("%s ", rsIcon), nil + } + return "", nil +} + +func VolumeIcon() (string, error) { + volIconMute := "" + volIconLow := "" + volIconMid := "" + volIconHigh := "" + volCmd := "amixer -D pulse sget Master | awk '/Front Right:/ {print $5}' | grep -o '[0-9]*'" + runVolCmd, err := exec.Command("sh", "-c", volCmd).Output() + volValue := binary.LittleEndian.Uint16(runVolCmd) + + if err != nil && err.Error() != "exit status 1" { + return "", err + } + + switch { + case volValue == 0: + return fmt.Sprintf("%s ", volIconMute), nil + case volValue < 50: + return fmt.Sprintf("%s ", volIconLow), nil + case volValue >= 50 && volValue <= 74: + return fmt.Sprintf("%s ", volIconMid), nil + case volValue >= 75: + return fmt.Sprintf("%s ", volIconHigh), nil + default: + return "", nil + } +} diff --git a/blocks/icons_test.go b/blocks/icons_test.go @@ -0,0 +1,30 @@ +package blocks + +import ( + "fmt" + "testing" +) + +func TestDropboxIcon(t *testing.T) { + db, err := DropboxIcon() + if err != nil { + t.Error(err) //.Error()) + } + fmt.Println(db, err) +} + +func TestRedshiftIcon(t *testing.T) { + rs, err := RedshiftIcon() + if err != nil { + t.Error(err) + } + fmt.Println(rs, err) +} + +func TestVolumeIcon(t *testing.T) { + vi, err := VolumeIcon() + if err != nil { + t.Error(err) + } + fmt.Println(vi) +} diff --git a/blocks/wttr.go b/blocks/wttr.go @@ -11,6 +11,8 @@ import ( func Wttr(cWttr chan string, eWttr chan error) { var passed, hour float64 + var data string + start := time.Now() // to determine seconds passed ticker := time.NewTicker(time.Second) @@ -26,9 +28,13 @@ func Wttr(cWttr chan string, eWttr chan error) { } bodyData, _ := ioutil.ReadAll(resp.Body) + if len(bodyData) > 100 { // wttr.in displays a webpage on server error + data = "wttr.in overloaded" // display this on wttr.in server error + } // convert responce to string for go channel + data = string(bodyData) weather := fmt.Sprintf("%s | ", - strings.TrimSpace(string(bodyData))) + strings.TrimSpace(data)) resp.Body.Close() cWttr <- weather } diff --git a/main.go b/main.go @@ -11,6 +11,9 @@ import ( func main() { var status, hTime, weather, ramFree string var wttrErr, ramErr error + volume, _ := blocks.VolumeIcon() + redshift, _ := blocks.RedshiftIcon() + dropbox, _ := blocks.DropboxIcon() cWttr := make(chan string) // start weather data routine eWttr := make(chan error) @@ -35,8 +38,11 @@ func main() { default: } + volume, _ = blocks.VolumeIcon() + redshift, _ = blocks.RedshiftIcon() + dropbox, _ = blocks.DropboxIcon() // Change by editing variables & `%s` - status = fmt.Sprintf(" %s%s%s ", ramFree, weather, hTime) + status = fmt.Sprintf(" %s%s%s %s%s%s ", ramFree, weather, hTime, dropbox, redshift, volume) ui.Dwm(status) // change this to the UI of choice } }