From 8052f35b9b29d9d3624be1c161ad4f41ee26a533 Mon Sep 17 00:00:00 2001 From: Amin Bandali Date: Sat, 31 Aug 2024 00:54:31 -0400 Subject: Rewrite b-bar to use upower for battery info --- .local/bin/b-bar | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to '.local/bin') diff --git a/.local/bin/b-bar b/.local/bin/b-bar index 8f23563..8641238 100755 --- a/.local/bin/b-bar +++ b/.local/bin/b-bar @@ -1,29 +1,45 @@ #!/bin/sh while true do - h="$(hostname)" + host="$(hostname)" vols="$(b-pavols)" load="$(cat /proc/loadavg | cut -d' ' -f1)" - time="$(date +'%a, %d %b %Y %R %z')" + date="$(date +'%a, %d %b %Y %R %z')" - case $h in + bar="$vols | $load | $date" + + case $host in selene) sens="$(sensors -j w83795g-i2c-*-*)" - nrbr="$(echo $sens | jq -r '.[].temp1.temp1_input')" cpu1="$(echo $sens | jq -r '.[].temp7.temp7_input')" cpu2="$(echo $sens | jq -r '.[].temp8.temp8_input')" - printf "%s %s %s | %s | %s | %s\n" \ - "$nrbr" "$cpu1" "$cpu2" "$vols" "$load" "$time" + # KGPE-D16 northbridge temperature + nrbr="$(echo $sens | jq -r '.[].temp1.temp1_input')" + bar="$cpu1 $cpu2 $nrbr | $bar" + ;; + adelita|anahita) + [ "$host" = "anahita" ] && bdev="sbs_9_000b" || bdev="BAT0" + b0="$(upower -i /org/freedesktop/UPower/devices/battery_$bdev)" + batstat="$(echo "$b0" | awk '/state/{print $NF}')" + if [ "$batstat" = "discharging" ]; then + batstat='-' + elif [ "$batstat" = "charging" ]; then + batstat='+' + fi + batcap="$(echo "$b0" | awk '/percentage/ \ + {sub(/\%$/, "", $NF); \ + print $NF}')" + battime="$(echo "$b0" | awk -F: '/time to (full|empty)/ \ + {sub(/^[ \t]+/, "", $NF); \ + sub(/\ hours?$/, "h", $NF); \ + print $NF}')" + bat="${batcap}$batstat $battime" + bar="$bat | $bar" ;; *) - b0="/sys/class/power_supply/BAT0" - [ "$h" = "anahita" ] && b0="/sys/class/power_supply/sbs-9-000b" - bat="$(cat $b0/capacity)" - # batl="$(cat $b0/capacity_level)" - printf "%s%% | %s | %s | %s\n" \ - "$bat" "$vols" "$load" "$time" ;; esac + printf "$bar\n" sleep 5 done -- cgit v1.2.3-60-g2f50