diff options
| author | Julian Hurst <ark@mansus.space> | 2022-01-13 11:31:15 +0100 |
|---|---|---|
| committer | Julian Hurst <ark@mansus.space> | 2022-01-13 11:31:15 +0100 |
| commit | ac6db6c9c392bc35fceb9b8123a3619c18a9b242 (patch) | |
| tree | ccbb36b594cba6c19dce7c94d45c9c8e68be4c7a | |
| parent | 310b4d5330dade970581a0ea9d11a22cc03e1a5e (diff) | |
| download | statusbar-ac6db6c9c392bc35fceb9b8123a3619c18a9b242.tar.gz | |
Add support for specifying the batteries to display
| -rw-r--r-- | statusbar.go | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/statusbar.go b/statusbar.go index 8480995..e5cf559 100644 --- a/statusbar.go +++ b/statusbar.go @@ -13,6 +13,7 @@ import ( "time" "flag" "errors" + "path/filepath" "github.com/BurntSushi/toml" "github.com/google/shlex" @@ -79,6 +80,7 @@ type ClockConfig struct { type BatteryConfig struct { Label string SubLabel string `toml:"sublabel"` + Batteries []string `toml:"batteries"` } type HostnameConfig struct { @@ -272,15 +274,26 @@ func (mocp MOCP) status() int { func battery(config BatteryConfig) string { var b strings.Builder const batteryPath = "/sys/class/power_supply" - files, err := ioutil.ReadDir(batteryPath) - if err != nil { - panic(err) + var batteries []string + if config.Batteries == nil { + files, err := ioutil.ReadDir(batteryPath) + if err != nil { + panic(err) + } + for _, file := range files { + path := filepath.Join(batteryPath, file.Name(), "capacity") + batteries = append(batteries, path) + } + } else { + for _, battery := range config.Batteries { + path := filepath.Join(batteryPath, battery, "capacity") + batteries = append(batteries, path) + } } batteryNb := 0 separator := "" - for _, file := range files { + for _, filePath := range batteries { b.WriteString(separator) - filePath := fmt.Sprintf("%v/%v/%v", batteryPath, file.Name(), "capacity") var capacity string content, err := ioutil.ReadFile(filePath) if err != nil { |
