From 5d8e1f82670e14b45a81e41e46467df51e193e77 Mon Sep 17 00:00:00 2001 From: aimuz Date: Wed, 11 Nov 2020 00:14:30 +0800 Subject: [PATCH] fix(battery): use `pmset` for battery percentage in macOS (#9364) Returns the battery charge consistent with the system battery manager --- plugins/battery/battery.plugin.zsh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh index 755ec8d64..a525fd7da 100644 --- a/plugins/battery/battery.plugin.zsh +++ b/plugins/battery/battery.plugin.zsh @@ -18,10 +18,7 @@ if [[ "$OSTYPE" = darwin* ]]; then } function battery_pct() { - local battery_status="$(ioreg -rc AppleSmartBattery)" - local -i capacity=$(sed -n -e '/MaxCapacity/s/^.*"MaxCapacity"\ =\ //p' <<< $battery_status) - local -i current=$(sed -n -e '/CurrentCapacity/s/^.*"CurrentCapacity"\ =\ //p' <<< $battery_status) - echo $(( current * 100 / capacity )) + pmset -g batt | grep -Eo "\d+%" | cut -d% -f1 } function battery_pct_remaining() {