5d8e1f82670e14b45a81e41e46467df51e193e77
- Author
- aimuz <mr.imuz@gmail.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
fix(battery): use `pmset` for battery percentage in macOS (#9364)
Returns the battery charge consistent with the system battery manager
Diff
1diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh
2index 755ec8d6483f7a90467d74c69f71802fb7b237b2..a525fd7da03a4539ea5090b12f4c424815ec947d 100644
3--- a/plugins/battery/battery.plugin.zsh
4+++ b/plugins/battery/battery.plugin.zsh
5@@ -18,10 +18,7 @@ if [[ "$OSTYPE" = darwin* ]]; then
6 }
7
8 function battery_pct() {
9- local battery_status="$(ioreg -rc AppleSmartBattery)"
10- local -i capacity=$(sed -n -e '/MaxCapacity/s/^.*"MaxCapacity"\ =\ //p' <<< $battery_status)
11- local -i current=$(sed -n -e '/CurrentCapacity/s/^.*"CurrentCapacity"\ =\ //p' <<< $battery_status)
12- echo $(( current * 100 / capacity ))
13+ pmset -g batt | grep -Eo "\d+%" | cut -d% -f1
14 }
15
16 function battery_pct_remaining() {