This repository has been archived on 2023-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/.local/bin/statusbar/sb-battery
David JULIEN df6918e262 feat: remove deprecated scripts
BREAKING: remove bat_notify
-> notifications are sent through .local/bin/statusbar/sb-battery
BREAKING: remove AC_notify
BREAKING: remove backligt_notify
BREAKING: remove refbar
-> use dwmblocks
2021-02-16 00:33:55 +01:00

44 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env sh
######################################################################
# @author : swytch (adapted from Luke Smith - lukesmith.xyz)
# @file : sb-battery
# @license : MIT
# @created : Saturday Feb 13, 2021 17:19:04 CET
#
# @description : battery block dwmblocks
######################################################################
# Will show all batteries with approximate icon for remaining power.
# Or show that the computer is plugged to a power source
# In any case, show the remaining battery percentage
# Also sends a notification if battery running low
notify() { \
case "$(cat "$x")" in
1[0-9]) notify-send -u "normal" "Battery is $status and running low ($capacity%)" "Please plug your computer to a power source" ;;
[0-9]) notify-send -u "critical" "Battery is $status and dangerously low ($capacity%)" "Please plug your computer to a power source - <b>NOW!</b>" ;;
esac
}
for bat in /sys/class/power_supply/BAT?/
do
status="$(cat "$bat/status")"
capacity="$(cat "$bat/capacity")"
if [ "$status" = "Charging" ]; then
status=""
elif [ "$status" = "Full" ];
printf "%s FULL" "$status";
else
case "$capacity" in
100|9[0-9]|8[0-9]) status="" ;;
7[0-9]|6[0-9]) status="" ;;
5[0-9]|4[0-9]) status="" ;;
3[0-9]|2[0-9]) status="" ;;
*) status="" ; [ "$status" != "Charging" ] && notify;;
esac
fi
printf "%s %3d%%\n" "$status" "$capacity";
done && return 0