summaryrefslogtreecommitdiff
path: root/powerlevel9k.zsh-theme
diff options
context:
space:
mode:
authorDominik Ritter <dritter03@googlemail.com>2015-11-24 04:36:37 +0300
committerDominik Ritter <dritter03@googlemail.com>2015-11-24 04:36:37 +0300
commitdad38b0592141fc4243fb8c67659a3a499f6cc4c (patch)
tree21ecd8c3413b9273efba4cc09ae75d75a214f2ed /powerlevel9k.zsh-theme
parentda2b8e342efa952dea4b664fac6179d75804a2b9 (diff)
Better code structure.
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-xpowerlevel9k.zsh-theme23
1 files changed, 14 insertions, 9 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index c1d1abf0..989f04ce 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -224,10 +224,6 @@ prompt_battery() {
# return if there is no battery on system
[[ -z $(echo $raw_data | grep MaxCapacity) ]] && return
- # get charge status
- [[ $(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=$(echo $raw_data | grep TimeRemaining | awk '{ print $5 }')
if [[ -n $time_remaining ]]; then
@@ -244,12 +240,20 @@ prompt_battery() {
bat_percent=$(( (current_capacity * 100) / max_capacity ))
fi
- # logic for string output
- [[ $charging =~ true && $connected =~ true ]] && local icon_color="$POWERLEVEL9K_BATTERY_CHARGING" && local remain=" ($tstring)"
- [[ ! $charging =~ true && $connected =~ true ]] && local icon_color="$POWERLEVEL9K_BATTERY_CHARGED" && local remain=""
- if [[ ! $connected =~ true ]]; then
+ local remain=""
+ ## logic for string output
+ # Powerplug connected
+ if [[ $(echo $raw_data | grep ExternalConnected | awk '{ print $5 }') =~ "Yes" ]]; then
+ # Battery is charging
+ if [[ $(echo $raw_data | grep IsCharging | awk '{ print $5 }') =~ "Yes" ]]; then
+ icon_color="$POWERLEVEL9K_BATTERY_CHARGING"
+ remain=" ($tstring)"
+ else
+ icon_color="$POWERLEVEL9K_BATTERY_CHARGED"
+ fi
+ else
[[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && local icon_color="$POWERLEVEL9K_BATTERY_LOW_COLOR" || local icon_color="$POWERLEVEL9K_BATTERY_DISCONNECTED"
- local remain=" ($tstring)"
+ remain=" ($tstring)"
fi
fi
@@ -261,6 +265,7 @@ prompt_battery() {
# return if no battery found
[[ -z $bat ]] && return
+
[[ $(cat $bat/capacity) -gt 100 ]] && local bat_percent=100 || local bat_percent=$(cat $bat/capacity)
[[ $(cat $bat/status) =~ Charging ]] && local connected=true
[[ $(cat $bat/status) =~ Charging && $bat_percent =~ 100 ]] && local icon_color="$POWERLEVEL9K_BATTERY_CHARGED"