1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/modules/power/source.go
Christopher Hall 51b4d42e8d add FreeBSD support to power module
uses the FreeBSD apm command to get charge status
and battery percentage

Signed-off-by: Christopher Hall <hsw@ms2.hinet.net>
2019-08-29 15:19:55 +08:00

29 lines
539 B
Go

// +build !linux
// +build !freebsd
package power
import (
"os/exec"
"regexp"
"strings"
"github.com/wtfutil/wtf/utils"
)
const SingleQuotesRegExp = "'(.*)'"
// powerSource returns the name of the current power source, probably one of
// "AC Power" or "Battery Power"
func powerSource() string {
cmd := exec.Command("pmset", []string{"-g", "ps"}...)
result := utils.ExecuteCommand(cmd)
r, _ := regexp.Compile(SingleQuotesRegExp)
source := r.FindString(result)
source = strings.Replace(source, "'", "", -1)
return source
}