mirror of
https://forge.katzen.cafe/schrottkatze/nix-configs.git
synced 2024-11-06 15:46:24 +01:00
56 lines
1.1 KiB
Plaintext
56 lines
1.1 KiB
Plaintext
|
#!/usr/bin/env nu
|
||
|
|
||
|
const ICONS = [
|
||
|
[ normal charging];
|
||
|
[ ]
|
||
|
[ ]
|
||
|
[ ]
|
||
|
[ ]
|
||
|
[ ]
|
||
|
[ ]
|
||
|
[ ]
|
||
|
[ ]
|
||
|
[ ]
|
||
|
[ ]
|
||
|
[ ]
|
||
|
];
|
||
|
|
||
|
def main [ path: string ] {
|
||
|
loop {
|
||
|
let fract = get_bat_charge_fraction $path;
|
||
|
let is_charging = get_bat_charging_status $path;
|
||
|
let percent = ($fract * 100) | math round;
|
||
|
|
||
|
print $"<span foreground=\"#d65d0e\">(get_bat_icon $fract $is_charging)</span> ($percent)<span foreground=\"#7c6f64\">%</span>";
|
||
|
sleep 2sec;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
def get_bat_charge_fraction [
|
||
|
path: string
|
||
|
] {
|
||
|
let energy_full = open $"/sys/class/power_supply/($path)/energy_full" | into float;
|
||
|
let energy_now = open $"/sys/class/power_supply/($path)/energy_now" | into float;
|
||
|
|
||
|
$energy_now / $energy_full
|
||
|
}
|
||
|
|
||
|
def get_bat_charging_status [
|
||
|
path: string
|
||
|
] {
|
||
|
let status = open $"/sys/class/power_supply/($path)/status";
|
||
|
|
||
|
if ($status == Charging) {
|
||
|
true
|
||
|
} else {
|
||
|
false
|
||
|
}
|
||
|
}
|
||
|
|
||
|
def get_bat_icon [
|
||
|
frac: float
|
||
|
is_charging = false
|
||
|
] {
|
||
|
$ICONS | get (($frac * 10) | math round) | get (if ($is_charging) { "charging" } else { "normal" })
|
||
|
}
|