diff options
author | James Short <james.short@alumni.duke.edu> | 2017-01-19 01:50:00 +0300 |
---|---|---|
committer | James Short <james.short@alumni.duke.edu> | 2017-01-19 03:05:38 +0300 |
commit | 22540e04b83570ac77d903e918b14b17b42f38e0 (patch) | |
tree | 6d33143918522710211ba5e4feb074f82229dfda /powerlevel9k.zsh-theme | |
parent | c5909e71ea873542a053531012ee62a5af3a57b8 (diff) |
Fix MacOS specific battery segment logic.
The case statement was causing it to never display that it was charging
and some of the awk statements had an off-by-one bug to grab the correct
values.
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-x | powerlevel9k.zsh-theme | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 9e89f68d..8a6fe1c9 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -339,7 +339,7 @@ prompt_background_jobs() { prompt_battery() { # The battery can have four different states - default to 'unknown'. - local current_state="unknown" + local current_state='unknown' typeset -AH battery_states battery_states=( 'low' 'red' @@ -352,14 +352,14 @@ prompt_battery() { if [[ $OS =~ OSX && -f /usr/bin/pmset && -x /usr/bin/pmset ]]; then # obtain battery information from system - local raw_data="$(pmset -g batt)" + local raw_data="$(pmset -g batt | awk 'FNR==2{print}')" # return if there is no battery on system [[ -z $(echo $raw_data | grep "InternalBattery") ]] && return # Time remaining on battery operation (charging/discharging) - local tstring=$(echo $raw_data | awk 'FNR==2{print $5}') + local tstring=$(echo $raw_data | awk -F ';' '{print $3}' | awk '{print $1}') # If time has not been calculated by system yet - [[ $tstring =~ '\(no' ]] && tstring="..." + [[ $tstring =~ '(\(no|not)' ]] && tstring="..." # percent of battery charged typeset -i 10 bat_percent @@ -367,12 +367,13 @@ prompt_battery() { local remain="" # Logic for string output - case $(echo $raw_data | awk 'FNR==2{print $4}') in - 'charging;|finishing charge;') + case $(echo $raw_data | awk -F ';' '{print $2}' | awk '{$1=$1};1') in + # for a short time after attaching power, status will be 'AC attached;' + 'charging'|'finishing charge'|'AC attached') current_state="charging" remain=" ($tstring)" ;; - 'discharging;') + 'discharging') [[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && current_state="low" || current_state="disconnected" remain=" ($tstring)" ;; |