-
Notifications
You must be signed in to change notification settings - Fork 0
/
batlevel
executable file
·32 lines (28 loc) · 916 Bytes
/
batlevel
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
#! /bin/bash
# If any batteries exist, enter loop
if compgen -G "/sys/class/power_supply/BAT*" > /dev/null; then
if ! [[ $1 == 'CLEAN' ]]; then
# Check if battery is on AC or not, then print a cute little power indicator
if [[ $(cat "/sys/class/power_supply/A"[CD]*"/online") -ge '1' ]]; then
printf '\xf0\x9f\x94\x8c'
else
printf '\xe2\x9a\xa1'
fi
fi
# Iterate over all of the batteries
for battery_path in "/sys/class/power_supply/BAT"*; do
# If this isn't the first run, add a separator
if [[ -v "${battery_index}" ]]; then
printf ', '
fi
# Get battery information
battery_index=$(basename "${battery_path}"|sed 's/^BAT//')
battery_level=$(cat "${battery_path}/capacity")
# Start printing information
if ! [[ $1 == 'CLEAN' ]]; then
printf ' %s%%' "${battery_level}"
else
printf '%s' "${battery_level}"
fi
done
fi