mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
This module displaysw which source is providing power (AC or battery) and for the battery displays the current charge capacity, how long it will last, and the battery state.
26 lines
506 B
Go
26 lines
506 B
Go
package power
|
|
|
|
import (
|
|
"os/exec"
|
|
"regexp"
|
|
"strings"
|
|
|
|
"github.com/senorprogrammer/wtf/wtf"
|
|
)
|
|
|
|
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 := wtf.ExecuteCommand(cmd)
|
|
|
|
r, _ := regexp.Compile(SingleQuotesRegExp)
|
|
|
|
source := r.FindString(result)
|
|
source = strings.Replace(source, "'", "", -1)
|
|
|
|
return source
|
|
}
|