Fix battery-notify.sh
This commit is contained in:
parent
4067e215fe
commit
d2a2c0fd58
@ -1,6 +1,8 @@
|
|||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
if [[ "$(uname)" = 'Linux' ]]; then
|
local system_uname="$(uname)"
|
||||||
|
|
||||||
|
if [[ "${system_uname}" = 'Linux' ]]; then
|
||||||
let charge_full="$(cat '/sys/class/power_supply/BAT0/charge_full')."
|
let charge_full="$(cat '/sys/class/power_supply/BAT0/charge_full')."
|
||||||
function get_battery_percent {
|
function get_battery_percent {
|
||||||
let charge_now="$(cat '/sys/class/power_supply/BAT0/charge_now')."
|
let charge_now="$(cat '/sys/class/power_supply/BAT0/charge_now')."
|
||||||
@ -13,23 +15,28 @@ if [[ "$(uname)" = 'Linux' ]]; then
|
|||||||
}
|
}
|
||||||
# Linux ends here
|
# Linux ends here
|
||||||
else
|
else
|
||||||
echo "${0}: error: unknown os: \"$(uname)\"" >&2
|
echo "${0}: error: unknown os: \"${system_uname}\"" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function send_battery_warning {
|
function send_battery_warning {
|
||||||
notify-send -t 0 "Low Battery" "Battery is at ${1}%!"
|
dunstify -p -t 0 "Low Battery" "Battery is at ${1}%!"
|
||||||
}
|
}
|
||||||
|
|
||||||
local did_notify=false
|
local did_notify=false
|
||||||
|
let notify_id=-1
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
let battery_percent="$(get_battery_percent)"
|
let battery_percent="$(get_battery_percent)"
|
||||||
if ((${battery_percent} > 10)) || is_adapted_connected; then
|
if ((${battery_percent} > 10)) || is_adapted_connected; then
|
||||||
did_notify=false
|
did_notify=false
|
||||||
|
if ((${notify_id} > 0)); then
|
||||||
|
dunstify -C ${notify_id}
|
||||||
|
notify_id=-1
|
||||||
|
fi
|
||||||
elif ! ${did_notify}; then
|
elif ! ${did_notify}; then
|
||||||
did_notify=true
|
did_notify=true
|
||||||
send_battery_warning ${battery_percent}
|
notify_id="$(send_battery_warning ${battery_percent})"
|
||||||
fi
|
fi
|
||||||
sleep 10
|
sleep 10
|
||||||
done
|
done
|
||||||
|
Loading…
Reference in New Issue
Block a user