edkolev / promptline.vim

Generate a fast shell prompt with powerline symbols and airline colors
MIT License
623 stars 54 forks source link

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

Open errantepiphany opened 5 years ago

errantepiphany commented 5 years ago

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 commented 5 years ago

Here is the pull request that fixes the issue: https://github.com/edkolev/promptline.vim/pull/75

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

errantepiphany commented 5 years ago

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.