-
Notifications
You must be signed in to change notification settings - Fork 1
/
battery
executable file
·42 lines (40 loc) · 1.05 KB
/
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
#! /bin/bash
shopt -s extglob
if [[ -d /proc/acpi/battery ]] ; then
max=$(
grep -h 'last full capacity' /proc/acpi/battery/BAT*/info |
cut -f2 -d: | tr -d '\n' | sed 's/m[AW]h/+/g'
)
current=$(
grep -h 'remaining capacity' /proc/acpi/battery/BAT*/state |
cut -f2 -d: | tr -d '\n' | sed 's/m[AW]h/+/g'
)
else
max=$(cat /sys/class/power_supply/BAT*/?(charge|energy)_full | tr '\n' +)
current=$(cat /sys/class/power_supply/BAT*/?(charge|energy)_now | tr '\n' +)
fi
percent=$( bc -l <<< "100 * ($current 0) / ($max 0)" )
if [[ $1 ]] ; then
cols=$(stty --all | grep -o 'columns [0-9]*')
cols=${cols#* }
rmax=cols
rperc=$(( ${percent%.*} * cols / 100 ))
for (( i=1; i<rmax; i++ )) ; do
printf -
done
echo
for (( i=1; i<rmax; i++ )) ; do
if ((i<rperc)) ; then
printf $'\e[0;32mX'
else
printf $'\e[1;31m|'
fi
done
echo $'\e[0m'
for (( i=1; i<rmax; i++ )) ; do
printf -
done
echo
else
echo $percent
fi