github.com/wtfutil/wtf@v0.43.0/modules/power/source.go (about)

     1  //go:build !linux && !freebsd
     2  
     3  package power
     4  
     5  import (
     6  	"os/exec"
     7  	"regexp"
     8  	"strings"
     9  
    10  	"github.com/wtfutil/wtf/utils"
    11  )
    12  
    13  const SingleQuotesRegExp = "'(.*)'"
    14  
    15  // powerSource returns the name of the current power source, probably one of
    16  // "AC Power" or "Battery Power"
    17  func powerSource() string {
    18  	cmd := exec.Command("pmset", []string{"-g", "ps"}...)
    19  	result := utils.ExecuteCommand(cmd)
    20  
    21  	r, _ := regexp.Compile(SingleQuotesRegExp)
    22  
    23  	source := r.FindString(result)
    24  	source = strings.Replace(source, "'", "", -1)
    25  
    26  	return source
    27  }