-
Notifications
You must be signed in to change notification settings - Fork 0
/
rundwm
executable file
·49 lines (44 loc) · 1.62 KB
/
rundwm
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
46
47
48
49
#! /bin/bash
/src/dwm/dwm &
pid=$!
# customize
# amount of time to show battery low warning
time_to_notify=100
percent_to_notify=30
do_bat_notif=1
time_var=0
# display percentage power and time at top of screen
# also says when battery is low in status bar
while kill -0 $pid 2> /dev/null; do
state_str="$(upower -d | grep state: | head -n 1)"
cur_power="$(upower -d | grep battery_BAT1 -A 30 | grep -i -m 1 'percentage' | sed 's/\([[:space:]]*.*:[[:space:]]*\)\([0-9]*\).*/\2/')"
if [[ $state_str == *fully-charged* ]]; then
power_str="I am charged!"
elif [[ $state_str == *discharging* ]]; then
power_str="Uber: $cur_power%"
else
power_str="Charging Uber: $cur_power%"
fi
cur_time="$(date +%s)"
# shows battery notif for (time_to_notify) seconds ONCE after cur_power is less than (percent_to_notify)
if [[ $do_bat_notif = 1 && $cur_power -lt $percent_to_notify ]]; then
if [ $time_var -eq 0 ]; then
time_var="$(date +%s)"
fi
let "doing_bat_notif=1"
xsetroot -name "+++ BATTERY LOW +++ | $(date)"
# if warning has displayed for 10 seconds, disable warning
let "diff=cur_time-time_var"
if [[ diff -gt $time_to_notify ]]; then
do_bat_notif=0
time_var=0
fi
else
#xsetroot -name "$(upower -d | grep battery_BAT1 -A 30 | grep -i -m 1 'percentage' | sed 's/.*:[[:blank:]]*/power: /') | $(date '+%a %b %d %r')"
xsetroot -name "$power_str | $(date '+%a %b %d %r')"
fi
if [[ $cur_power -gt $percent_to_notify ]]; then
do_bat_notif=1
fi
sleep 0.5s
done;