浏览代码

fix(battery): use `pmset` for battery percentage in macOS (#9364)

Returns the battery charge consistent with the system battery manager
aimuz 3 年之前
父节点
当前提交
5d8e1f8267
共有 1 个文件被更改,包括 1 次插入4 次删除
  1. 1 4
      plugins/battery/battery.plugin.zsh

+ 1 - 4
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() {