From 3d9b557be3327eeceb3a7054ae0316a8406fa357 Mon Sep 17 00:00:00 2001 From: tuzi3040 <28290621+tuzi3040@users.noreply.github.com> Date: Fri, 9 Oct 2026 07:45:21 +0800 Subject: [PATCH] fix(battery): make macOS regexes compatible with GNU grep (#14163) * fix(battery): remove unnecessary whitespace escapes in macOS battery parsing Remove unnecessary `\ ` escapes in the macOS battery plugin's `grep` and `sed` expressions. * fix(battery): replace \d with [0-9] for GNU grep compatibility --- plugins/battery/battery.plugin.zsh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh index c7618f6b3..dd8ab105f 100644 --- a/plugins/battery/battery.plugin.zsh +++ b/plugins/battery/battery.plugin.zsh @@ -25,10 +25,10 @@ if [[ "$OSTYPE" = darwin* ]]; then echo "$(ioreg -rc AppleSmartBattery | grep -o '"Watts"=[0-9]\+' | head -1 | grep -o '[0-9]\+')W " } function battery_is_charging() { - ioreg -rc AppleSmartBattery | command grep -q '^.*"ExternalConnected"\ =\ Yes' + ioreg -rc AppleSmartBattery | command grep -q '^.*"ExternalConnected" = Yes' } function battery_pct() { - pmset -g batt | grep -Eo "\d+%" | cut -d% -f1 + pmset -g batt | grep -Eo "[0-9]+%" | cut -d% -f1 } function battery_pct_remaining() { if battery_is_charging; then @@ -39,8 +39,8 @@ if [[ "$OSTYPE" = darwin* ]]; then } function battery_time_remaining() { local smart_battery_status="$(ioreg -rc "AppleSmartBattery")" - if [[ $(echo $smart_battery_status | command grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]]; then - timeremaining=$(echo $smart_battery_status | command grep '^.*"AvgTimeToEmpty"\ =\ ' | sed -e 's/^.*"AvgTimeToEmpty"\ =\ //') + if [[ $(echo $smart_battery_status | command grep -c '^.*"ExternalConnected" = No') -eq 1 ]]; then + timeremaining=$(echo $smart_battery_status | command grep '^.*"AvgTimeToEmpty" = ' | sed -e 's/^.*"AvgTimeToEmpty" = //') if [ $timeremaining -gt 720 ]; then echo "::" else @@ -52,7 +52,7 @@ if [[ "$OSTYPE" = darwin* ]]; then } function battery_pct_prompt () { local battery_pct color - if ioreg -rc AppleSmartBattery | command grep -q '^.*"ExternalConnected"\ =\ No'; then + if ioreg -rc AppleSmartBattery | command grep -q '^.*"ExternalConnected" = No'; then battery_pct=$(battery_pct_remaining) if [[ $battery_pct -gt 50 ]]; then color='green'