-
Notifications
You must be signed in to change notification settings - Fork 423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed battery reporting #536
Conversation
#476 was requested over a year ago and never got pulled. Good luck with this one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 1317 should "return 2 + ..."
@@ -1301,7 +1301,7 @@ case "$LP_OS" in | |||
{ | |||
(( LP_ENABLE_BATT )) || return 4 | |||
local percent batt_status | |||
eval "$(pmset -g batt | sed -n 's/^ -InternalBattery[^ ]*[ ]\([0-9]*[0-9]\)%; \([^;]*\).*$/percent=\1 batt_status='\'\\2\'/p)" | |||
eval "$(pmset -g batt | awk '/InternalBattery/{gsub(/[^0-9]/,"",$3);gsub(/[;]/,"",$4);printf "percent=%d batt_status=%s", $3, $4}')" | |||
case "$batt_status" in | |||
charged | "") | |||
return 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 1317 should "return 2 + ..."
return $(( 2 + ( percent > LP_BATTERY_THRESHOLD ) ))
This change is more robust than the change in #476, because it doesn't depend on the specific formatting of numbers and whitespace of the |
Resolves liquidprompt#476 and partially addresses liquidprompt#481
If you're going to fix this, the same off-by-one error also exists in line 1295 (on the Linux code for this same battery check). |
@overhacked I disagree that this change is more robust. dolmen has said before that using Your point that "it doesn't depend on the specific formatting of numbers and whitespace of the InternalBattery line" is false, since your usage of
The other PR has solved this in the same way, using the POSIX
The real issue is exactly how many fields there are, since that is what broke before. We don't have a record of what
Based on what the old
and they added the ID field, which changed what number the percent and status fields were. If they add another field again, your Of course there are a multitude of things that Apple could change in the output, and they are hard to prepare for. A simple one (that could already be possible) would be for them to output a line for each physical battery:
The
But will only show the stats for the last listed battery. The
Still kinda works, but will show the percent of the first battery and the status of the last battery. I would of course love for this feature to become more robust, but that is difficult, and I'm not sure it's worth anyone's time, since we don't know what changes will or could be coming. |
The sed script was having some issues with the way
pmset -g batt
output looks on macOS 10.12 Sierra and later. I rewrote the sed commands to an awk script, which is a bit more resistant to any future format changes.