Long time, no commit, big ol' changes though
This commit is contained in:
parent
3c9e2c3279
commit
501f1f4066
19 changed files with 271 additions and 352 deletions
55
config/i3/batteryNotify
Executable file
55
config/i3/batteryNotify
Executable file
|
@ -0,0 +1,55 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
BATT="/sys/class/power_supply/BAT0"
|
||||
LOW=10
|
||||
CRIT=3
|
||||
LASTSTATE="$HOME/.cache/batteryState"
|
||||
|
||||
function setState() { # state [...notify-send arguments]
|
||||
state="$1"
|
||||
last="$(cat "$LASTSTATE" 2> /dev/null)"
|
||||
shift
|
||||
|
||||
echo "Battery state: $state"
|
||||
|
||||
if [ "$state" != "$last" ]
|
||||
then
|
||||
notify-send "$@"
|
||||
echo "$state" > "$LASTSTATE"
|
||||
fi
|
||||
}
|
||||
|
||||
function computeState() {
|
||||
acpiStatus="$(cat "$BATT/status")"
|
||||
acpiCapacity="$(cat "$BATT/capacity")"
|
||||
|
||||
if [ "$acpiStatus" == "Discharging" ]
|
||||
then
|
||||
if [ $acpiCapacity -le $CRIT ]
|
||||
then
|
||||
setState "CRIT" -u critical -i battery-caution "Battery level is critical" "$acpiCapacity %"
|
||||
elif [ $acpiCapacity -le $LOW ]
|
||||
then
|
||||
setState "LOW" -u critical -i battery-low "Battery level is low" "$acpiCapacity %"
|
||||
else
|
||||
setState "DISCHARGING" -i battery-good "Battery is discharging" "$acpiCapacity %"
|
||||
fi
|
||||
elif [ "$acpiStatus" == "Charging" ]
|
||||
then
|
||||
setState "CHARGING" -u normal -i battery-good-charging "Battery is charging" "$acpiCapacity %"
|
||||
elif [ "$acpiStatus" == "Full" ]
|
||||
then
|
||||
setState "FULL" -u low -i battery-full-charged "Battery is full" "$acpiCapacity %"
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$1" == "-d" ]
|
||||
then
|
||||
while true
|
||||
do
|
||||
computeState
|
||||
sleep 10
|
||||
done
|
||||
else
|
||||
computeState
|
||||
fi
|
Loading…
Add table
Add a link
Reference in a new issue