diff options
author | Dominik Ritter <dritter03@googlemail.com> | 2015-11-23 02:11:19 +0300 |
---|---|---|
committer | Dominik Ritter <dritter03@googlemail.com> | 2015-11-23 02:11:19 +0300 |
commit | c0efe9c342450b4d20488633a2e1bfd1e30ce7e0 (patch) | |
tree | 5c856296f797bf9a4061f5aa40339a4f48952a53 /powerlevel9k.zsh-theme | |
parent | 7774294113603e8fd4e3c6f1c1c6fb5aeae6cdb2 (diff) |
Performance improvement: Avoid aggregation of data over and over again by extracting a local variable.
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-x | powerlevel9k.zsh-theme | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 5b14647a..6fec74ca 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -220,23 +220,24 @@ prompt_battery() { [[ -z $POWERLEVEL9K_BATTERY_FOREGROUND ]] && local conn="$DEFAULT_COLOR_INVERTED" || local conn="$POWERLEVEL9K_BATTERY_FOREGROUND" if [[ $OS =~ OSX && -f /usr/sbin/ioreg && -x /usr/sbin/ioreg ]]; then + local raw_data=$(ioreg -n AppleSmartBattery) # return if there is no battery on system - [[ -z $(ioreg -n AppleSmartBattery | grep MaxCapacity) ]] && return + [[ -z $(echo $raw_data | grep MaxCapacity) ]] && return # get charge status - [[ $(ioreg -n AppleSmartBattery | grep ExternalConnected | awk '{ print $5 }') =~ "Yes" ]] && local connected=true - [[ $(ioreg -n AppleSmartBattery | grep IsCharging | awk '{ print $5 }') =~ "Yes" ]] && local charging=true + [[ $(echo $raw_data | grep ExternalConnected | awk '{ print $5 }') =~ "Yes" ]] && local connected=true + [[ $(echo $raw_data | grep IsCharging | awk '{ print $5 }') =~ "Yes" ]] && local charging=true # convert time remaining from minutes to hours:minutes date string - local time_remaining=$(ioreg -n AppleSmartBattery | grep TimeRemaining | awk '{ print $5 }') + local time_remaining=$(echo $raw_data | grep TimeRemaining | awk '{ print $5 }') if [[ ! -z $time_remaining ]]; then # this value is set to a very high number when the system is calculating [[ $time_remaining -gt 10000 ]] && local tstring="..." || local tstring=${(f)$(date -u -r $(($time_remaining * 60)) +%k:%M)} fi # get charge values - local max_capacity=$(ioreg -n AppleSmartBattery | grep MaxCapacity | awk '{ print $5 }') - local current_capacity=$(ioreg -n AppleSmartBattery | grep CurrentCapacity | awk '{ print $5 }') + local max_capacity=$(echo $raw_data | grep MaxCapacity | awk '{ print $5 }') + local current_capacity=$(echo $raw_data | grep CurrentCapacity | awk '{ print $5 }') if [[ -n "$max_capacity" && -n "$current_capacity" ]]; then typeset -F 2 current_capacity |