Skip to content

Commit

Permalink
Fix "bad math expression" for battery with UPS
Browse files Browse the repository at this point in the history
Fixes spaceship-prompt#245 `spaceship_battery:56: bad math expression: operator expected at '100'` if
multiple battery statuses are reported (on macOS, at least).
Happens when pmset reports secondary charge due to UPS.
  • Loading branch information
nomaed committed Nov 5, 2018
1 parent 0f4f684 commit f97d6f0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sections/battery.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ spaceship_battery() {
local battery_data battery_percent battery_status battery_color

if spaceship::exists pmset; then
battery_data=$(pmset -g batt)
battery_data=$(pmset -g batt | grep "InternalBattery")

# Return if no internal battery
[[ -z $(echo $battery_data | grep "InternalBattery") ]] && return
[[ -z "$battery_data" ]] && return

battery_percent="$( echo $battery_data | grep -oE '[0-9]{1,3}%' )"
battery_status="$( echo $battery_data | awk -F '; *' 'NR==2 { print $2 }' )"
Expand Down

0 comments on commit f97d6f0

Please sign in to comment.