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/AC_notify
David JULIEN 28dfdd5ae5 feat: change shebang to /usr/bin/env sh
this setting is more user-config compliant
2021-02-12 23:20:57 +01:00

40 lines
914 B
Bash
Executable File

#!/usr/bin/env sh
######################################################################
# @author : swytch
# @file : AC_notify
# @license : MIT
# @created : Wednesday May 20, 2020 17:51:45 CEST
#
# @description : send a notification when AC status change
# refresh statusbar
######################################################################
new_state="$(cat /sys/class/power_supply/AC/online)"
prev_state="$new_state"
notify() { \
# $1 is $new_state
if [ "$1" = 1 ]; then
notify-send -u "normal" "AC plugged in - CHARGING"
else
notify-send -u "critical" "AC unplugged ! - DISCHARGING"
fi
}
update(){ \
new_state="$(cat /sys/class/power_supply/AC/online)"
if [ "$prev_state" != "$new_state" ]; then
notify "$new_state" && refbar
fi
prev_state="$new_state"
}
while :; do
update
# Sleep for 5s seconds before checking again
sleep 5 &
wait
done