38 lines
1.2 KiB
Nix
38 lines
1.2 KiB
Nix
{ pkgs, ... }:
|
|
{
|
|
home.packages = with pkgs; [
|
|
(writeShellScriptBin "sb-battery" ''
|
|
BAT=/sys/class/power_supply/BAT0/capacity
|
|
|
|
# Exit script if no battery detected
|
|
[ ! -f "$BAT" ] && exit
|
|
|
|
STATUS=$(cat /sys/class/power_supply/BAT0/uevent | grep "POWER_SUPPLY_STATUS" | sed "s/^.*=//")
|
|
capacity=$(cat "$BAT")
|
|
|
|
if [ "$STATUS" == "Charging" ] || [ "$STATUS" == "Not charging" ]; then
|
|
echo "[ $capacity%] "
|
|
else
|
|
case $capacity in
|
|
100) echo "[ $capacity%] ";;
|
|
9[0-9]) echo "[ $capacity%] ";;
|
|
8[0-9]) echo "[ $capacity%] ";;
|
|
7[0-9]) echo "[ $capacity%] ";;
|
|
6[0-9]) echo "[ $capacity%] ";;
|
|
5[0-9]) echo "[ $capacity%] ";;
|
|
4[0-9]) echo "[ $capacity%] ";;
|
|
3[0-9]) echo "[ $capacity%] ";;
|
|
2[0-9]) echo "[ $capacity%] ";;
|
|
1[0-9]) echo "[ $capacity%] ";;
|
|
[6-9]) echo "[ $capacity%] ";;
|
|
[0-5]) echo "[ $capacity%] ";;
|
|
esac
|
|
fi
|
|
|
|
if [[ $capacity -le 20 && $STATUS != "Charging" ]]; then
|
|
dunstify-battery-notification
|
|
fi
|
|
'')
|
|
];
|
|
}
|