aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Ritter <dritter03@googlemail.com>2015-11-23 02:09:37 +0300
committerDominik Ritter <dritter03@googlemail.com>2015-11-23 02:09:37 +0300
commit7774294113603e8fd4e3c6f1c1c6fb5aeae6cdb2 (patch)
tree0d01fa17c765d25bf107b57c4bf719fdac7b5691
parent1eadf5ad76d0d9a9a5c4f6e6b2cde47c018363c0 (diff)
Performance improvement by calculating the battery percentage with zsh.
-rwxr-xr-xpowerlevel9k.zsh-theme7
1 files changed, 6 insertions, 1 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index 002267f4..5b14647a 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -238,7 +238,12 @@ prompt_battery() {
local max_capacity=$(ioreg -n AppleSmartBattery | grep MaxCapacity | awk '{ print $5 }')
local current_capacity=$(ioreg -n AppleSmartBattery | grep CurrentCapacity | awk '{ print $5 }')
- [[ ! -z $max_capacity && ! -z $current_capacity ]] && local bat_percent=$(ruby -e "puts ($current_capacity.to_f / $max_capacity.to_f * 100).round.to_i")
+ if [[ -n "$max_capacity" && -n "$current_capacity" ]]; then
+ typeset -F 2 current_capacity
+ current_capacity="$current_capacity"+0.00001
+ typeset -i 10 bat_percent
+ bat_percent=$(( (current_capacity / max_capacity) * 100 ))
+ fi
# logic for string output
[[ $charging =~ true && $connected =~ true ]] && local conn="$POWERLEVEL9K_BATTERY_CHARGING" && local remain=" ($tstring)"