fix time to charge display on mac, closes #28 (#68)

* fix time to charge display on mac, closes #28
* add charging colour to battery_status_fg
* fix incorrect colours when discharging
* change charging colour default to green
* add text to show charged when applicable instead of 0:00
This commit is contained in:
hulkk 2018-08-03 11:03:23 +03:00 committed by Martin Beentjes
parent 8d5adf92fd
commit c2cd5c8687
2 changed files with 22 additions and 5 deletions

View file

@ -15,6 +15,11 @@ battery_discharging() {
[[ $status =~ (discharging) ]]
}
battery_charged() {
local status="$(battery_status)"
[[ $status =~ (charged) ]]
}
pmset_battery_remaining_time() {
local status="$(pmset -g batt)"
if echo $status | grep 'no estimate' >/dev/null 2>&1; then
@ -31,8 +36,16 @@ pmset_battery_remaining_time() {
else
echo $remaining_time | awk '{printf "- %s left", $1}'
fi
elif battery_charged; then
if $short; then
echo $remaining_time | awk '{printf "charged", $1}'
else
echo $remaining_time | awk '{printf "fully charged", $1}'
fi
else
if !$short; then
if $short; then
echo $remaining_time | awk '{printf "~%s", $1}'
else
echo $remaining_time | awk '{printf "- %s till full", $1}'
fi
fi
@ -76,9 +89,7 @@ main() {
if battery_discharging; then
print_battery_remain
else
if !$short; then
print_battery_full
fi
print_battery_full
fi
}
main

View file

@ -8,23 +8,29 @@ color_full_charge_default="#[fg=green]"
color_high_charge_default="#[fg=yellow]"
color_medium_charge_default="#[fg=colour208]" # orange
color_low_charge_default="#[fg=red]"
color_charging_default="#[fg=green]"
color_full_charge=""
color_high_charge=""
color_medium_charge=""
color_low_charge=""
color_charging=""
get_charge_color_settings() {
color_full_charge=$(get_tmux_option "@batt_color_full_charge" "$color_full_charge_default")
color_high_charge=$(get_tmux_option "@batt_color_high_charge" "$color_high_charge_default")
color_medium_charge=$(get_tmux_option "@batt_color_medium_charge" "$color_medium_charge_default")
color_low_charge=$(get_tmux_option "@batt_color_low_charge" "$color_low_charge_default")
color_charging=$(get_tmux_option "@batt_color_charging" "$color_charging_default")
}
print_battery_status_fg() {
# Call `battery_percentage.sh`.
percentage=$($CURRENT_DIR/battery_percentage.sh | sed -e 's/%//')
if [ $percentage -eq 100 ]; then
status=$(battery_status | awk '{print $1;}')
if [ $status == 'charging' ]; then
printf $color_charging
elif [ $percentage -eq 100 ]; then
printf $color_full_charge
elif [ $percentage -le 99 -a $percentage -ge 51 ];then
printf $color_high_charge