summaryrefslogtreecommitdiff
path: root/plugins/battery/battery.plugin.zsh
diff options
context:
space:
mode:
authoraimuz <mr.imuz@gmail.com>2020-11-11 00:14:30 +0800
committerGitHub <noreply@github.com>2020-11-10 17:14:30 +0100
commit5d8e1f82670e14b45a81e41e46467df51e193e77 (patch)
tree77a13828e93ca0aa97809c9728ac9938bda22f48 /plugins/battery/battery.plugin.zsh
parenteef04c62c2dfbd81f9fee6752e3b7e0b9c3bf617 (diff)
downloadzsh-5d8e1f82670e14b45a81e41e46467df51e193e77.tar.gz
zsh-5d8e1f82670e14b45a81e41e46467df51e193e77.tar.bz2
zsh-5d8e1f82670e14b45a81e41e46467df51e193e77.zip
fix(battery): use `pmset` for battery percentage in macOS (#9364)
Returns the battery charge consistent with the system battery manager
Diffstat (limited to 'plugins/battery/battery.plugin.zsh')
-rw-r--r--plugins/battery/battery.plugin.zsh5
1 files changed, 1 insertions, 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() {