-
Notifications
You must be signed in to change notification settings - Fork 0
/
battery.sh
executable file
·41 lines (35 loc) · 1.04 KB
/
battery.sh
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
#!/usr/bin/env bash
LIGHTNING="<span color='#7780a1' font='FontAwesome'></span>"
PLUG="<span font='FontAwesome' color='#7780a1'></span>"
function handleFull {
printf "100%%"
}
function handleDischarging {
ROW=$(echo "$1" | grep Discharging)
if [ $? = 0 ]; then
PERCENTAGE=$(echo "$ROW" | grep -o '.[0-9]%')
printf "$PERCENTAGE%"
REMAINING=$(echo "$ROW" | grep -o '[0-9][0-9]:[0-9][0-9]:[0-9][0-9]')
if [ $? = 0 ]; then
printf " (${REMAINING:1:4})"
fi
exit 0
fi
}
function handleCharging {
ROW=$(echo "$1" | grep Charging)
if [ $? = 0 ]; then
PERCENTAGE=$(echo "$ROW" | grep -o '.[0-9]%')
printf "$PLUG $PERCENTAGE%"
REMAINING=$(echo "$ROW" | grep -o '[0-9][0-9]:[0-9][0-9]:[0-9][0-9]')
if [ $? = 0 ]; then
printf " (${REMAINING:1:4})"
fi
exit 0
fi
}
ACPI_OUTPUT=$(acpi)
printf "$LIGHTNING "
handleDischarging "$ACPI_OUTPUT"
handleCharging "$ACPI_OUTPUT"
handleFull "$ACPI_OUTPUT"