mirror of
https://github.com/robbyrussell/oh-my-zsh.git
synced 2025-12-06 07:20:40 +01:00
fix(battery): use pmset for battery percentage in macOS (#9364)
Returns the battery charge consistent with the system battery manager
This commit is contained in:
@@ -18,10 +18,7 @@ if [[ "$OSTYPE" = darwin* ]]; then
|
|||||||
}
|
}
|
||||||
|
|
||||||
function battery_pct() {
|
function battery_pct() {
|
||||||
local battery_status="$(ioreg -rc AppleSmartBattery)"
|
pmset -g batt | grep -Eo "\d+%" | cut -d% -f1
|
||||||
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 ))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function battery_pct_remaining() {
|
function battery_pct_remaining() {
|
||||||
|
|||||||
Reference in New Issue
Block a user