Fixed dfr usage

This commit is contained in:
Nox Sluijtman 2024-12-16 23:50:43 +01:00
parent ec550c42b0
commit f90e997da8
Signed by: Egg
SSH key fingerprint: SHA256:2sG9X3C7Xvq2svGumz1/k7cm8l4G9+qAtAeugqB4J9M

View file

@ -6,31 +6,22 @@ let discordianDate = ^ddate
def get_batteries [] {
let power_supplies = (
(ls /sys/class/power_supply).name
| each {|item|
open $"($item)/uevent"
}
| each {|item|
$item | lines | parse "{key}={value}"
})
| each { open $"($in)/uevent" }
| each { $in | lines | parse "{key}={value}"}
)
let batteries = $power_supplies | each {||
$in | dfr into-df | dfr get key | dfr contains POWER_SUPPLY_CAPACITY | dfr into-nu | get key | any {|| $in == true }
} | into record | items {|k,v|
if $v == true {
($power_supplies | get ($k | into int) | transpose -r)
}
} | each {|| $in}
let batteries = $power_supplies
| each { where key == "POWER_SUPPLY_CAPACITY" | get value | is-not-empty }
| enumerate | where item == true | get index
| each {|index| $power_supplies | get $index | transpose -r}
$batteries | each {|i|
[ $i.POWER_SUPPLY_MANUFACTURER $i.POWER_SUPPLY_MODEL_NAME $i.POWER_SUPPLY_STATUS $i.POWER_SUPPLY_CAPACITY ]
| each {|j|
$j | first
$batteries
| each {|i| [ $i.POWER_SUPPLY_MANUFACTURER $i.POWER_SUPPLY_MODEL_NAME $i.POWER_SUPPLY_STATUS $i.POWER_SUPPLY_CAPACITY ]
| each { first }
}
} | each {|str|
$str | str join " "
} | each {|str|
$str | str replace -r '$' '%'
} | str join "\n"
| each {|str| $str | str join " " }
| each {|str| $str | str replace -r '$' '%' }
| str join "\n"
}
# Documentation for notify