From f90e997da8e4689680835c97907eb9ff2a3029c1 Mon Sep 17 00:00:00 2001 From: Marty Sluijtman Date: Mon, 16 Dec 2024 23:50:43 +0100 Subject: [PATCH] Fixed dfr usage --- src/bin/status-notification | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/bin/status-notification b/src/bin/status-notification index 3027249..c357a6d 100755 --- a/src/bin/status-notification +++ b/src/bin/status-notification @@ -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