mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-10-20 04:12:06 +08:00
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:
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user