breto

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

commit b80ed5fc025f19ff8a3419f443cf206835bffc28
parent 5f46f2f8e4c780084011b4f15c8c8ae4f517b331
Author: Jaron Swab <jrswab@gmail.com>
Date:   Wed,  5 Jun 2019 20:40:19 -0400

Added icon for Syncthing.

When syncthing is running now a cloud icon will appear if called by the
user.

Diffstat:
Mblocks/icons.go | 15+++++++++++++++
Mblocks/icons_test.go | 8++++++++
Mmain.go | 20+++++++++++---------
3 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/blocks/icons.go b/blocks/icons.go @@ -35,6 +35,20 @@ func RedshiftIcon() (string, error) { return "", nil } +func SyncthingIcon() (string, error) { + syncIcon := "" + syncCmd := "ps ux | gawk '/syncthing/ {print $11}' | grep syncthing" + runSyncCmd, err := exec.Command("sh", "-c", syncCmd).Output() + + if err != nil && err.Error() != "exit status 1" { + return "", err + } + if string(runSyncCmd) != "" { + return fmt.Sprintf("%s", syncIcon), nil + } + return "", nil +} + func VolumeIcon() (string, error) { volIconMute := " " volIconLow := " " @@ -62,6 +76,7 @@ func VolumeIcon() (string, error) { } } +// The following have no checks that need to be made func DirIcon() string { return " " } diff --git a/blocks/icons_test.go b/blocks/icons_test.go @@ -28,3 +28,11 @@ func TestVolumeIcon(t *testing.T) { } fmt.Println(vi) } + +func TestSyncthingIcon(t *testing.T) { + sync, err := SyncthingIcon() + if err != nil { + t.Error(err) //.Error()) + } + fmt.Println(sync, err) +} diff --git a/main.go b/main.go @@ -11,9 +11,13 @@ import ( func main() { // Other Blocks: var status, hTime string - var weather, ramFree, homeSpace string // Go Routine Blocks - var tempIco, memIco, rShift, dropbox, volIcon, volText, homeDir string // Icon Blocks - var wttrErr, ramErr, homeErr error // Go routine errors + var weather, ramFree, homeSpace string // Go routine blocks + var wttrErr, ramErr, homeErr error // Go routine errors + var rShift, dropbox, volIcon, volText, syncthing string // Icon blocks + + homeDir := blocks.DirIcon() // These icons are static and + memIco := blocks.MemIcon() // only need defined once + tempIco := blocks.TempIcon() cWttr := make(chan string) // start weather data routine eWttr := make(chan error) @@ -50,14 +54,12 @@ func main() { dropbox, _ = blocks.DropboxIcon() volText, _ = blocks.VolumeText() volIcon, _ = blocks.VolumeIcon() - homeDir = blocks.DirIcon() - memIco = blocks.MemIcon() - tempIco = blocks.TempIcon() + syncthing, _ = blocks.SyncthingIcon() // Change by editing variables & `%s` - status = fmt.Sprintf(" %s%s %s%s %s%s %s%s %s %s%s", + status = fmt.Sprintf(" %s%s %s%s %s%s %s%s %s %s%s%s", tempIco, weather, homeDir, homeSpace, memIco, ramFree, volIcon, volText, - hTime, dropbox, rShift) - ui.Dwm(status) // change this to the UI of choice + hTime, dropbox, syncthing, rShift) + ui.Tmux(status) // change this to the UI of choice } }