Merge branch 'kawaiiamber-battery'
This commit is contained in:
commit
f76e9c4e93
1 changed files with 18 additions and 14 deletions
|
@ -16,19 +16,23 @@ case $BLOCK_BUTTON in
|
||||||
6) "$TERMINAL" -e "$EDITOR" "$0" ;;
|
6) "$TERMINAL" -e "$EDITOR" "$0" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# acpi alternative
|
# Check if battery directories are detected
|
||||||
# acpi | sed "s/Battery [0-9]: //;s/[Dd]ischarging, /🔋/;s/[Nn]ot charging, /🛑/;s/[Cc]harging, /🔌/;s/[Uu]nknown, /♻️/;s/[Ff]ull, /⚡/;s/ \(remaining\|until charged\)//"; exit
|
[ ! -e /sys/class/power_supply/BAT?* ] && echo "No battery found" && exit 1
|
||||||
|
|
||||||
# Loop through all attached batteries.
|
# Loop through all attached batteries and format the info
|
||||||
for battery in /sys/class/power_supply/BAT?
|
for battery in /sys/class/power_supply/BAT?*
|
||||||
do
|
do
|
||||||
# Get its remaining capacity and charge status.
|
# Sets up the status and capacity
|
||||||
capacity=$(cat "$battery"/capacity 2>/dev/null) || break
|
status=$(cat "$battery/status")
|
||||||
status=$(sed "s/[Dd]ischarging/🔋/;s/[Nn]ot charging/🛑/;s/[Cc]harging/🔌/;s/[Uu]nknown/♻️/;s/[Ff]ull/⚡/" "$battery"/status)
|
case "$status" in
|
||||||
|
"Full") status="⚡" ;;
|
||||||
# If it is discharging and 25% or less, we will add a ❗ as a warning.
|
"Discharging") status="🔋" ;;
|
||||||
[ "$capacity" -le 25 ] && [ "$status" = "🔋" ] && warn="❗"
|
"Not charging") status="🛑" ;;
|
||||||
|
"Unknown") status="♻️" ;;
|
||||||
printf "%s%s%s%% " "$status" "$warn" "$capacity"
|
esac
|
||||||
unset warn
|
capacity=$(cat "$battery/capacity")
|
||||||
done | sed 's/ *$//'
|
# Will make a warn variable if discharging and low
|
||||||
|
[ "$status" = "🔋" ] && [ "$capacity" -le 25 ] && local warn="❗"
|
||||||
|
# Prints the info
|
||||||
|
printf "%s%s%d%%\n" "$status" "$warn" "$capacity"
|
||||||
|
done && return 0
|
||||||
|
|
Loading…
Reference in a new issue