From 4ee02ced07b2f3e02de81f63571f4b9c3b24193a Mon Sep 17 00:00:00 2001 From: aonemd Date: Sun, 18 Mar 2018 16:34:06 +0200 Subject: [PATCH] Add cmus player indicator --- components/cmus.go | 22 ++++++++++++++++++++++ onpar.go | 5 +++++ 2 files changed, 27 insertions(+) create mode 100644 components/cmus.go diff --git a/components/cmus.go b/components/cmus.go new file mode 100644 index 0000000..d064c71 --- /dev/null +++ b/components/cmus.go @@ -0,0 +1,22 @@ +package main + +import ( + "fmt" + "os/exec" + "regexp" + "strings" +) + +func main() { + response, _ := exec.Command("cmus-remote", "-Q").Output() + + artistPattern, _ := regexp.Compile("tag artist [a-zA-Z0-9_ ]+") + titlePattern, _ := regexp.Compile("tag title [a-zA-Z0-9_ ]+") + + artist := strings.Trim(artistPattern.FindString(string(response)), "tag artist") + title := strings.Trim(titlePattern.FindString(string(response)), "tag title") + + if artist != "" && title != "" { + fmt.Println(fmt.Sprintf("%s - %s", artist, title)) + } +} diff --git a/onpar.go b/onpar.go index 40a4dc3..92a623f 100644 --- a/onpar.go +++ b/onpar.go @@ -38,6 +38,7 @@ func main() { volumeLevel := NewComponent("components/volume_level", 1) darkSkyWeather := NewComponent("components/dark_sky_weather", 600) keyboardLayout := NewComponent("components/keyboard_layout", 1) + cmus := NewComponent("components/cmus", 1) // Initialize new components here ... go dateTime.Run() @@ -45,6 +46,7 @@ func main() { go volumeLevel.Run() go darkSkyWeather.Run() go keyboardLayout.Run() + go cmus.Run() // Call new components Run() here ... for { @@ -59,12 +61,15 @@ func main() { go batteryLevel.Run() case volumeLevel.Output = <-volumeLevel.Channel: go volumeLevel.Run() + case cmus.Output = <-cmus.Channel: + go cmus.Run() // Call new components Run() here ... } status = []string{ "", // Add new components here ... + cmus.Output, keyboardLayout.Output, darkSkyWeather.Output, volumeLevel.Output,