mirror of
https://github.com/arkorty/Scripts.git
synced 2026-03-17 17:01:41 +00:00
58 lines
1.7 KiB
Bash
Executable File
58 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/sh
|
|
|
|
# Script: battery
|
|
# License: MIT
|
|
# Author: Arkaprabha Chakraborty
|
|
# Created: 07-08-23
|
|
# Dependencies: dunstify
|
|
#
|
|
# Copyright (C) 2023 Arkaprabha Chakraborty
|
|
|
|
PROG=dunstify
|
|
|
|
# icon paths
|
|
ICON_DIR=/usr/share/icons/<ICON_PACK>
|
|
BATTERY_FULL=$ICON_DIR/48x48/status/battery-full.svg
|
|
BATTERY_LOW=$ICON_DIR/48x48/status/battery-low.svg
|
|
BATTERY_CAUTION=$ICON_DIR/48x48/status/battery-caution.svg
|
|
AC_ADAPTER=$ICON_DIR/48x48/status/ac-adapter.svg
|
|
|
|
# capacity checkpoints
|
|
LOW=20
|
|
CRITICAL=10
|
|
|
|
# status flags
|
|
last_capacity=NONE
|
|
last_status=None
|
|
|
|
while true; do
|
|
BATTERY="/sys/class/power_supply/CMB0"
|
|
if [ -d $BATTERY ]; then
|
|
capacity=$(cat $BATTERY/capacity)
|
|
status=$(cat $BATTERY/status)
|
|
|
|
if [ $last_status = "None" ]; then
|
|
last_status=$status
|
|
elif [ $last_status != "Discharging" ] && [ $status = "Discharging" ]; then
|
|
$PROG "Power Unplugged" --replace 667 --icon $AC_ADAPTER --timeout 2000
|
|
last_status=$status
|
|
elif [ $last_status != "Charging" ] && [ $status = "Charging" ]; then
|
|
$PROG "Power Plugged" --replace 667 --icon $AC_ADAPTER --timeout 2000
|
|
last_status=$status
|
|
fi
|
|
|
|
if [ $last_capacity != "FULL" ] && [ $status = "Full" ]; then
|
|
$PROG "Battery Full" --replace 666 --icon $BATTERY_FULL
|
|
last_capacity="FULL"
|
|
elif [ $last_capacity != "LOW" ] && [ $status = "Discharging" ] &&
|
|
[ $capacity -le $LOW ] && [ $capacity -gt $CRITICAL ]; then
|
|
$PROG "Battery Low: $capacity%" --replace 666 --icon $BATTERY_LOW
|
|
last_capacity=LOW
|
|
elif [ $status = "Discharging" ] && [ $capacity -le $CRITICAL ]; then
|
|
$PROG --urgency critical "Battery Critical: $capacity%" --replace 666 --icon $BATTERY_CAUTION
|
|
last_capacity=CRITICAL
|
|
fi
|
|
fi
|
|
sleep 2
|
|
done
|