Update swaybar status to show the power consumption instead of the status

This commit is contained in:
Martin Larsson 2024-06-01 21:22:31 +02:00
parent faf33261de
commit e9b22de610

View file

@ -12,12 +12,13 @@ while true; do
# Date and time # Date and time
date_time=$(date +"%Y-%m-%d %H:%M") date_time=$(date +"%Y-%m-%d %H:%M")
# Battery status # Battery status and power consumption
battery_path="/sys/class/power_supply/macsmc-battery" battery_path="/sys/class/power_supply/macsmc-battery"
if [ -d "$battery_path" ]; then if [ -d "$battery_path" ]; then
battery_capacity=$(cat $battery_path/capacity) battery_capacity=$(cat $battery_path/capacity)
battery_status=$(cat $battery_path/status) power_consumption=$(cat $battery_path/power_now) # in microwatts
battery="Battery: $battery_capacity% ($battery_status)" power_consumption_watts=$(echo "scale=2; $power_consumption / 1000000" | bc)
battery="Battery: $battery_capacity% ($power_consumption_watts W)"
else else
battery="Battery: N/A" battery="Battery: N/A"
fi fi