sxmo: conky: include battery estimate

This commit is contained in:
Colin 2023-07-13 00:40:52 +00:00
parent 29bf9d410f
commit 67a52eca86
3 changed files with 43 additions and 5 deletions

View File

@ -0,0 +1,31 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash
full=$(cat /sys/class/power_supply/axp20x-battery/charge_full_design)
rate=$(cat /sys/class/power_supply/axp20x-battery/current_now)
perc=$(cat /sys/class/power_supply/axp20x-battery/capacity)
perc_left=$((100 - $perc))
# these icons come from sxmo; they only render in nerdfonts
bat_dis="󱊢"
bat_chg="󱊥"
fmt_minutes() {
if [[ $2 -gt 1440 ]]; then
echo "∞" # more than 1d
else
hr=$(($2 / 60))
hr_in_min=$(($hr * 60))
min=$(($2 - $hr_in_min))
echo "$1 ${hr}h${min}m"
fi
}
if [[ $rate -lt 0 ]]; then
# discharging
fmt_minutes "$bat_dis" $(($full * 60 * $perc / (-100 * $rate)))
elif [[ $rate -gt 0 ]]; then
# charging
fmt_minutes "$bat_chg" $(($full * 60 * $perc_left / (100 * $rate)))
else
echo "󱊢 N/A"
fi

View File

@ -17,7 +17,7 @@ ${alignc}${font Sxmo:size=50:style=Bold}${exec date +"%H"}${font Sxmo:size=50}:$
${font Sxmo:size=20}${exec date +"%a %d %b %Y"}${font}
${alignc}${font Sxmo:size=15}${color lightgrey}☵ $memperc%${font}
${alignc}${font Sxmo:size=15}${color lightgrey} $cpu%${font}
${alignc}${font Sxmo:size=15}${color lightgrey} $cpu%${font}
${alignc}${font Sxmo:size=15}${color lightgrey}⇅ ${downspeedf wlan0}K/s${font}
${alignc}${font Sxmo:size=15}${color lightgrey} ${exec echo $(( $(cat /sys/class/power_supply/axp20x-battery/charge_full_design) * -60 / $(cat /sys/class/power_supply/axp20x-battery/current_now) )) }m${font}
${alignc}${font Sxmo:size=15}${color lightgrey}${exec @bat@ }${font}
]]

View File

@ -43,7 +43,7 @@
# - gestures: lisgd
# - on-screen keyboard: wvkbd (if wayland), svkbd (if X)
#
{ lib, config, pkgs, sane-lib, ... }:
{ config, lib, pkgs, sane-lib, ... }:
let
cfg = config.sane.gui.sxmo;
@ -217,8 +217,15 @@ in
# sane.user.fs.".config/waybar/style.css".symlink.text =
# builtins.readFile ./waybar-style.css;
sane.user.fs.".config/sxmo/conky.conf".symlink.target =
builtins.readFile ./conky-config;
sane.user.fs.".config/sxmo/conky.conf".symlink.target = let
battery_estimate = pkgs.static-nix-shell.mkBash {
pname = "battery_estimate";
src = ./.;
};
in pkgs.substituteAll {
src = ./conky-config;
bat = "${battery_estimate}/bin/battery_estimate";
};
## greeter