2024-03-28 21:40:01 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# ***This script was made by Clay Gomera (Drake)***
|
|
|
|
# - Description: A dwmblocks script to print the current power profile and battery status
|
|
|
|
# - Dependencies: dwm, dwmblocks, power-profiles-daemon
|
|
|
|
|
|
|
|
# this variable will store the current power profile
|
|
|
|
currntpwr=$(powerprofilesctl get)
|
|
|
|
if [ "${currntpwr}" = "performance" ]; then
|
2024-07-15 19:11:54 +00:00
|
|
|
pwr=" | "
|
2024-03-28 21:40:01 +00:00
|
|
|
elif [ "${currntpwr}" = "balanced" ]; then
|
2024-07-15 19:11:54 +00:00
|
|
|
pwr=" | "
|
2024-03-28 21:40:01 +00:00
|
|
|
elif [ "${currntpwr}" = "power-saver" ]; then
|
2024-07-15 19:11:54 +00:00
|
|
|
pwr=" | "
|
2024-03-28 21:40:01 +00:00
|
|
|
fi
|
|
|
|
|
2024-07-15 19:11:54 +00:00
|
|
|
# loop through all the available batteries and get its current capacity
|
2024-03-28 21:40:01 +00:00
|
|
|
for battery in /sys/class/power_supply/BAT?*; do
|
2024-07-15 19:11:54 +00:00
|
|
|
# if non-first battery, print a space separator.
|
|
|
|
[ -n "${capacity+x}" ] && printf " "
|
|
|
|
percentage="$(cat "$battery/capacity" 2>&1)"
|
2024-03-28 21:40:01 +00:00
|
|
|
|
2024-07-15 19:11:54 +00:00
|
|
|
# sets up the status and capacity
|
|
|
|
case "$(cat "$battery/status" 2>&1)" in
|
|
|
|
"Full")
|
|
|
|
status=" "
|
|
|
|
;;
|
|
|
|
"Discharging")
|
|
|
|
# updates the status icon based on the battery percentage
|
|
|
|
if [ "$percentage" -le 20 ]; then
|
|
|
|
status=" "
|
|
|
|
elif [ "$percentage" -le 30 ]; then
|
|
|
|
status=" "
|
|
|
|
elif [ "$percentage" -le 40 ]; then
|
|
|
|
status=" "
|
|
|
|
elif [ "$percentage" -le 50 ]; then
|
|
|
|
status=" "
|
|
|
|
elif [ "$percentage" -le 60 ]; then
|
|
|
|
status=" "
|
|
|
|
elif [ "$percentage" -le 70 ]; then
|
|
|
|
status=" "
|
|
|
|
elif [ "$percentage" -le 80 ]; then
|
|
|
|
status=" "
|
|
|
|
elif [ "$percentage" -le 90 ]; then
|
|
|
|
status=" "
|
|
|
|
else
|
|
|
|
status=" "
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
"Charging")
|
|
|
|
# updates the status icon based on the battery percentage while charging
|
|
|
|
if [ "$percentage" -le 10 ]; then
|
|
|
|
status=" "
|
|
|
|
elif [ "$percentage" -le 20 ]; then
|
|
|
|
status=" "
|
|
|
|
elif [ "$percentage" -le 30 ]; then
|
|
|
|
status=" "
|
|
|
|
elif [ "$percentage" -le 40 ]; then
|
|
|
|
status=" "
|
|
|
|
elif [ "$percentage" -le 50 ]; then
|
|
|
|
status=" "
|
|
|
|
elif [ "$percentage" -le 60 ]; then
|
|
|
|
status=" "
|
|
|
|
elif [ "$percentage" -le 70 ]; then
|
|
|
|
status=" "
|
|
|
|
elif [ "$percentage" -le 80 ]; then
|
|
|
|
status=" "
|
|
|
|
elif [ "$percentage" -le 90 ]; then
|
|
|
|
status=" "
|
|
|
|
else
|
|
|
|
status=" "
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
"Not charging")
|
|
|
|
# updates the status icon based on the battery percentage
|
|
|
|
if [ "$percentage" -le 20 ]; then
|
|
|
|
status=" "
|
|
|
|
elif [ "$percentage" -le 30 ]; then
|
|
|
|
status=" "
|
|
|
|
elif [ "$percentage" -le 40 ]; then
|
|
|
|
status=" "
|
|
|
|
elif [ "$percentage" -le 50 ]; then
|
|
|
|
status=" "
|
|
|
|
elif [ "$percentage" -le 60 ]; then
|
|
|
|
status=" "
|
|
|
|
elif [ "$percentage" -le 70 ]; then
|
|
|
|
status=" "
|
|
|
|
elif [ "$percentage" -le 80 ]; then
|
|
|
|
status=" "
|
|
|
|
elif [ "$percentage" -le 90 ]; then
|
|
|
|
status=" "
|
|
|
|
else
|
|
|
|
status=" "
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
"Unknown")
|
|
|
|
echo " " && exit 0 # just in case
|
|
|
|
;;
|
|
|
|
*) exit 1 ;; # just exit if there isn't a battery on the system
|
|
|
|
esac
|
2024-03-28 21:40:01 +00:00
|
|
|
|
2024-07-15 19:11:54 +00:00
|
|
|
# will make a warning variable if percentage is low
|
|
|
|
if [ "$status" = " " ] && [ "$percentage" -le 10 ]; then
|
|
|
|
warn=""
|
|
|
|
fi
|
2024-03-28 21:40:01 +00:00
|
|
|
|
2024-07-15 19:11:54 +00:00
|
|
|
# print everything
|
|
|
|
printf "%s%s%d%%" "$status" "${warn:- }" "$percentage"; unset warn
|
2024-07-14 11:38:44 +00:00
|
|
|
done && printf "$pwr\\n"
|