~tardypad/dotfiles

ref: 00c0c349a1b8960152233f11caa9ea1a40e395a3 dotfiles/files/scripts/shell/check-notify-low-battery -rwxr-xr-x 559 bytes
00c0c349 — Damien Tardy-Panis Add presentation mode to mako to hide notifications 4 months ago
                                                                                
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
#!/bin/sh

ALERT_THRESHOLD_PERCENT=10

BATTERY_STATUS=$( battery-status )

ADAPTER_STATUS=$(
  echo "${BATTERY_STATUS}" \
    | sed -n 's/^Adapter: \(.*\)$/\1/p'
)

[ "${ADAPTER_STATUS}" = 'on' ] && exit

TOTAL_ENERGY_PERCENT=$(
  echo "${BATTERY_STATUS}" \
    | sed -n 's/^Charge: \(.*\)%$/\1/p'
)

[ "${TOTAL_ENERGY_PERCENT}" -gt "${ALERT_THRESHOLD_PERCENT}" ] && exit

notify \
  -c 'alert' \
  -i 'low_battery' \
  'Low battery' \
  'Battery level is getting low'

aplay \
  "${XDG_DATA_HOME:-$HOME/.local/share}/sounds/low_battery.wav" \
  2> /dev/null