Skip to content

Commit

Permalink
Merge pull request #11 from nwg-piotr/dev
Browse files Browse the repository at this point in the history
Added `-ts` argument to specify which (t)emperature (s)sensor to show the value for. Closes #8.
  • Loading branch information
nwg-piotr authored Nov 6, 2024
2 parents 7977f44 + 4b8b012 commit 9ce93f6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ Add all the components you need to this way. Sample output with monochrome icons
![image](https://user-images.githubusercontent.com/20579136/171515322-f469d580-72e7-4950-9857-28746e380d6a.png)

```
$ gopsuinfo -h
gopsuinfo -h
Use gopsuinfo list_mountpoints to see available mount points.
Usage of bin/gopsuinfo:
Usage of gopsuinfo:
-c string
Output (c)omponents: (a)vg CPU load, (g)rahical CPU bar,
disk usage by mou(n)tpoints, (t)emperatures,
Expand All @@ -41,9 +41,13 @@ Usage of bin/gopsuinfo:
use (dark) icon set
-i string
returns (i)con path and a single component (a, n, t, m, u) value
-ls
(l)ist temperature (s)ensors
-p string
quotation-delimited, space-separated list of mount(p)oints (default "/")
-t Just (t)ext, no glyphs
-ts string
show temperature for a certain (t)emperature (s)ensor (-ls to list available sensors)
-v display (v)ersion information
```

Expand Down
37 changes: 33 additions & 4 deletions gopsuinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/shirou/gopsutil/net"
)

const version = "0.1.8"
const version = "0.1.9"

var g glyphs
var path string
Expand All @@ -51,14 +51,37 @@ func cpuAvSpeed(asIcon bool, delay *string) string {
return output
}

func temperatures(asIcon bool) string {
func listSensors() {
temps, _ := host.SensorsTemperatures()
for _, temp := range temps {
if strings.HasSuffix(temp.SensorKey, "_input") {
fmt.Printf("%s (%v°C)\n", temp.SensorKey, temp.Temperature)
}
}
os.Exit(0)
}

func temperatures(asIcon bool, sensorName string) string {
output := ""
if !asIcon {
output += g.glyphTemp
}
vals := make(map[string]float64)

temps, _ := host.SensorsTemperatures()

// temp sensor name given with the -ts flag
sensorName = strings.TrimSpace(sensorName)
if sensorName != "" {
for _, temp := range temps {
if temp.SensorKey == sensorName {
return fmt.Sprintf("%v℃", int(math.Round(temp.Temperature)))
}
}
return fmt.Sprintf("No such sensor as '%s', try the -ls flag", sensorName)
}

// temp sensor name not given
for _, temp := range temps {
// Some machines may return multiple sensors of the same name. Let's accept the 1st non-zero temp value.
if vals["acpitz"] == 0 && temp.SensorKey == "acpitz_input" {
Expand Down Expand Up @@ -213,6 +236,8 @@ func main() {
setPtr := flag.Bool("dark", false, "use (dark) icon set")
textPtr := flag.Bool("t", false, "Just (t)ext, no glyphs")
displayVersion := flag.Bool("v", false, "display (v)ersion information")
listTempSensors := flag.Bool("ls", false, "(l)ist temperature (s)ensors")
tempSensor := flag.String("ts", "", "show temperature for a certain (t)emperature (s)ensor (-ls to list available sensors)")

flag.Parse()

Expand All @@ -221,6 +246,10 @@ func main() {
os.Exit(0)
}

if *listTempSensors {
listSensors()
}

if *textPtr {
g = glyphs{graphCPU: []rune("_▁▂▃▄▅▆▇███"), glyphCPU: "", glyphMem: "", glyphTemp: "", glyphUptime: ""}
} else {
Expand All @@ -244,7 +273,7 @@ func main() {
output += cpuAvSpeed(true, cpuDelayPtr)
} else if *iconPtr == "t" {
output += path + "/temp.svg\n"
output += temperatures(true)
output += temperatures(true, *tempSensor)
} else if *iconPtr == "n" {
output += path + "/hdd.svg\n"
output += diskUsage(pathsPtr)
Expand All @@ -266,7 +295,7 @@ func main() {
output += cpuAvSpeed(false, cpuDelayPtr) + " "
}
if string(char) == "t" {
output += temperatures(false) + " "
output += temperatures(false, *tempSensor) + " "
}
if string(char) == "u" {
output += uptime(false) + " "
Expand Down

0 comments on commit 9ce93f6

Please sign in to comment.