@@ -104,18 +104,6 @@ __battery_macos() {
104
104
__battery_linux () {
105
105
case " $SHELL_PLATFORM " in
106
106
" linux" )
107
- BATPATH=/sys/class/power_supply/BAT0
108
- if [ ! -d $BATPATH ]; then
109
- BATPATH=/sys/class/power_supply/BAT1
110
- fi
111
- BAT_FULL=$BATPATH /charge_full
112
- if [ ! -r $BAT_FULL ]; then
113
- BAT_FULL=$BATPATH /energy_full
114
- fi
115
- BAT_NOW=$BATPATH /charge_now
116
- if [ ! -r $BAT_NOW ]; then
117
- BAT_NOW=$BATPATH /energy_now
118
- fi
119
107
__linux_get_bat
120
108
;;
121
109
" bsd" )
@@ -158,28 +146,26 @@ __linux_get_bat() {
158
146
local total_full=0
159
147
local total_now=0
160
148
161
- for bat in /sys/class/power_supply/BAT* ; do
162
- if [ -d " $bat " ]; then
163
- local full=" $bat /charge_full"
164
- local now=" $bat /charge_now"
149
+ while read -r bat; do
150
+ local full=" $bat /charge_full"
151
+ local now=" $bat /charge_now"
165
152
166
- if [ ! -r " $full " ]; then
167
- full=" $bat /energy_full"
168
- fi
169
- if [ ! -r " $now " ]; then
170
- now=" $bat /energy_now"
171
- fi
153
+ if [ ! -r " $full " ]; then
154
+ full=" $bat /energy_full"
155
+ fi
156
+ if [ ! -r " $now " ]; then
157
+ now=" $bat /energy_now"
158
+ fi
172
159
173
- if [ -r " $full " ] && [ -r " $now " ]; then
174
- local bf
175
- local bn
176
- bf=$( cat " $full " )
177
- bn=$( cat " $now " )
178
- total_full=$(( total_full + bf))
179
- total_now=$(( total_now + bn))
180
- fi
160
+ if [ -r " $full " ] && [ -r " $now " ]; then
161
+ local bf
162
+ local bn
163
+ bf=$( cat " $full " )
164
+ bn=$( cat " $now " )
165
+ total_full=$(( total_full + bf))
166
+ total_now=$(( total_now + bn))
181
167
fi
182
- done
168
+ done <<< " $(grep -l " Battery " /sys/class/power_supply/*/type | sed -e 's,/type$,,') "
183
169
184
170
if [ " $total_full " -gt 0 ]; then
185
171
if [ " $total_now " -gt " $total_full " ]; then
0 commit comments