Skip to content
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

battery checking errors on mac desktops (fix provided!) #74

Open
errantepiphany opened this issue Feb 14, 2019 · 2 comments
Open

battery checking errors on mac desktops (fix provided!) #74

errantepiphany opened this issue Feb 14, 2019 · 2 comments

Comments

@errantepiphany
Copy link

In the"__promptline_battery" function of the battery slice, a math error occurs on Mac desktops:

The problem code is here:

if ioreg_output=$(ioreg -rc AppleSmartBattery 2>/dev/null); then
...
local battery_level=$(($current_capacity * 100 / $battery_capacity))

, which upon execution errors out the script with this message:

-bash: * 100 / : syntax error: operand expected (error token is "* 100 / ")

The reason it fails on Mac desktops via Mac laptops (MacBooks) is because desktops don't have batteries! Thus the value of $current_capacity is empty, so the multiplying an empty string by 100 fails.

The fix is to only enter the code block if $ioreg_output is not empty. I will submit a Pull Request that fixes this.

@errantepiphany
Copy link
Author

errantepiphany commented Feb 14, 2019

Here is the pull request that fixes the issue: #75

I would be grateful if you would consider merging it in. Thank you!

@errantepiphany errantepiphany changed the title battery slice fails on mac desktops battery slice fails on mac desktops (fix provided!) Feb 14, 2019
@errantepiphany errantepiphany changed the title battery slice fails on mac desktops (fix provided!) battery checking errors on mac desktops (fix provided!) Feb 16, 2019
@errantepiphany
Copy link
Author

errantepiphany commented Feb 16, 2019

The second fix on this PR is the same chunk of code (battery checking). In the linux block, the original code simply iterates over "/sys/class/power_supply/BAT*" . However, the "/sys/class/power_supply" directory doesn't exist on some systems. Thus, the fix is to check for that directory's existence before attempting to iterate over subdirectories. Without this fix, the script errors out on some systems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant