-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-battery
executable file
·45 lines (35 loc) · 1.18 KB
/
check-battery
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env fish
# check-battery - Check the battery and notify if it's low.
# May be useful as a cron job.
# settings:
# Show a notification when any devices have less than this percent battery remaining.
set low_percent 25
# Play a sound if the battery is getting too low.
set sound
# code:
set -- script "$(path basename (status filename))"
argparse -n "$script" 'h/help' -- $argv
if set -q _flag_h
echo "$script - Check the battery and pop up a message on the OSD if it's low."
echo "Usage: $script [arguments]"
echo
echo " -h/--help - Print help and exit."
exit
end
set -x DBUS_SESSION_BUS_ADDRESS "unix:path=/run/user/$(id --user)/bus"
if not set -q DISPLAY
set -x DISPLAY :0.0
end
set acpi (acpi)
for battery in $acpi
echo "$battery" | string match --quiet --regex '^Battery (?<id>[0-9]+): (?<state>[^,]+), (?<percent>[0-9]+)%,?'
if contains "$state" 'Full' 'Charging'; or test "$percent" = 0
continue
end
if test "$percent" -lt "$low_percent"
notify-send -u critical -h string:x-dunst-stack-tag:check-battery "Battery $id low" "$state ($percent%)."
if test -n "$sound"
mpv $sound &
end
end
end