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
This commit is contained in:
tuzi3040
2026-10-08 16:45:21 -07:00
committed by GitHub
parent 60c9a7a839
commit 3d9b557be3
+5 -5
View File
@@ -25,10 +25,10 @@ if [[ "$OSTYPE" = darwin* ]]; then
echo "$(ioreg -rc AppleSmartBattery | grep -o '"Watts"=[0-9]\+' | head -1 | grep -o '[0-9]\+')W " echo "$(ioreg -rc AppleSmartBattery | grep -o '"Watts"=[0-9]\+' | head -1 | grep -o '[0-9]\+')W "
} }
function battery_is_charging() { function battery_is_charging() {
ioreg -rc AppleSmartBattery | command grep -q '^.*"ExternalConnected"\ =\ Yes' ioreg -rc AppleSmartBattery | command grep -q '^.*"ExternalConnected" = Yes'
} }
function battery_pct() { 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() { function battery_pct_remaining() {
if battery_is_charging; then if battery_is_charging; then
@@ -39,8 +39,8 @@ if [[ "$OSTYPE" = darwin* ]]; then
} }
function battery_time_remaining() { function battery_time_remaining() {
local smart_battery_status="$(ioreg -rc "AppleSmartBattery")" local smart_battery_status="$(ioreg -rc "AppleSmartBattery")"
if [[ $(echo $smart_battery_status | command grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]]; then 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"\ =\ //') timeremaining=$(echo $smart_battery_status | command grep '^.*"AvgTimeToEmpty" = ' | sed -e 's/^.*"AvgTimeToEmpty" = //')
if [ $timeremaining -gt 720 ]; then if [ $timeremaining -gt 720 ]; then
echo "::" echo "::"
else else
@@ -52,7 +52,7 @@ if [[ "$OSTYPE" = darwin* ]]; then
} }
function battery_pct_prompt () { function battery_pct_prompt () {
local battery_pct color 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) battery_pct=$(battery_pct_remaining)
if [[ $battery_pct -gt 50 ]]; then if [[ $battery_pct -gt 50 ]]; then
color='green' color='green'