mirror of
1
0
Fork 0

added support for multiple batteries, resolves #73

This commit is contained in:
Gregory Pakosz 2017-06-03 20:47:28 +02:00
parent a631d03b29
commit 680783c91b
1 changed files with 59 additions and 31 deletions

View File

@ -246,49 +246,77 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration'
# }
#
# _battery() {
# charge=0
# uname_s=$(uname -s)
# case "$uname_s" in
# *Darwin*)
# batt=$(pmset -g batt)
# percentage=$(echo "$batt" | grep -E -o [0-9]+%) || return
# discharging=$(echo "$batt" | grep -qi "discharging" && echo "true" || echo "false")
# charge="${percentage%%%} / 100"
# while IFS= read -r line; do
# if [ x"$discharging" != x"true" ]; then
# discharging=$(echo "$line" | grep -qi "discharging" && echo "true" || echo "false")
# fi
# percentage=$(echo "$line" | grep -E -o '[0-9]+%')
# charge=$(awk -v charge="$charge" -v percentage="${percentage%%%}" 'BEGIN { print charge + percentage / 100 }')
# count=$((count + 1))
# done << EOF
# $(pmset -g batt | grep 'Battery')
# EOF
# ;;
# *Linux*)
# batpath=/sys/class/power_supply/BAT0
# if [ ! -d $batpath ]; then
# batpath=/sys/class/power_supply/BAT1
# fi
# discharging=$(grep -qi "discharging" $batpath/status && echo "true" || echo "false")
# bat_capacity=$batpath/capacity
# bat_energy_full=$batpath/energy_full
# bat_energy_now=$batpath/energy_now
# if [ -r "$bat_capacity" ]; then
# charge="$(cat $bat_capacity) / 100"
# else
# if [ ! -r "$bat_energy_full" ] || [ ! -r "$bat_energy_now" ]; then
# return
# while IFS= read -r batpath; do
# if [ x"$discharging" != x"true" ]; then
# discharging=$(grep -qi "discharging" "$batpath/status" && echo "true" || echo "false")
# fi
# charge="$(cat $bat_energy_now) / $(cat $bat_energy_full)" || return
# fi
# bat_capacity="$batpath/capacity"
# if [ -r "$bat_capacity" ]; then
# charge=$(awk -v charge="$charge" -v capacity="$(cat "$bat_capacity")" 'BEGIN { print charge + capacity / 100 }')
# else
# bat_energy_full="$batpath/energy_full"
# bat_energy_now="$batpath/energy_now"
# if [ -r "$bat_energy_full" ] && [ -r "$bat_energy_now" ]; then
# charge=$(awk -v charge="$charge" -v energy_now="$(cat "$bat_energy_now")" -v energy_full="$(cat "$bat_energy_full")" 'BEGIN { print charge + energy_now / energy_full }')
# fi
# fi
# count=$((count + 1))
# done << EOF
# $(find /sys/class/power_supply -maxdepth 1 -iname '*bat*')
# EOF
# ;;
# *CYGWIN*)
# wmic path Win32_Battery 2>&1 | grep -q 'No Instance' && return
# discharging=$(wmic path Win32_Battery Get BatteryStatus 2>/dev/null | grep -q 1 && echo "true" || echo "false")
# percentage=$(wmic path Win32_Battery Get EstimatedChargeRemaining /format:list 2>/dev/null | grep '[^[:blank:]]' | cut -d= -f2)
# charge="${percentage} / 100"
# while IFS= read -r line; do
# [ -z "$line" ] && continue
# if [ x"$discharging" != x"true" ]; then
# discharging=$(echo "$line" | awk '{ s = ($1 == 1) ? "true" : "false"; print s }')
# fi
# charge=$(echo "$line" | awk -v charge="$charge" '{ print charge + $2 / 100 }')
# count=$((count + 1))
# done << EOF
# $(wmic path Win32_Battery get BatteryStatus, EstimatedChargeRemaining | tr -d '\r' | tail -n +2)
# EOF
# ;;
# *OpenBSD*)
# discharging=$(sysctl -n hw.sensors.acpibat0.raw0 | grep -q 1 && echo "true" || echo "false")
# if sysctl -n hw.sensors.acpibat0 | grep -q amphour; then
# charge="$(sysctl -n hw.sensors.acpibat0.amphour3 | cut -d' ' -f1) / $(sysctl -n hw.sensors.acpibat0.amphour0 | cut -d' ' -f1)"
# else
# charge="$(sysctl -n hw.sensors.acpibat0.watthour3 | cut -d' ' -f1) / $(sysctl -n hw.sensors.acpibat0.watthour0 | cut -d' ' -f1)"
# fi
# for batid in 0 1 2; do
# sysctl -n "hw.sensors.acpibat$batid.raw0" 2>&1 | grep -q 'not found' && continue
# if [ x"$discharging" != x"true" ]; then
# discharging=$(sysctl -n "hw.sensors.acpibat$batid.raw0" | grep -q 1 && echo "true" || echo "false")
# fi
# if sysctl -n "hw.sensors.acpibat$batid" | grep -q amphour; then
# charge=$(awk -v charge="$charge" -v remaining="$(sysctl -n hw.sensors.acpibat$batid.amphour3 | cut -d' ' -f1)" -v full="$(sysctl -n hw.sensors.acpibat$batid.amphour0 | cut -d' ' -f1)" 'BEGIN { print charge + remaining / full }')
# else
# charge=$(awk -v charge="$charge" -v remaining="$(sysctl -n hw.sensors.acpibat$batid.watthour3 | cut -d' ' -f1)" -v full="$(sysctl -n hw.sensors.acpibat$batid.watthour0 | cut -d' ' -f1)" 'BEGIN { print charge + remaining / full }')
# fi
# count=$((count + 1))
# done
# ;;
# *)
# return
# esac
# charge=$(awk -v charge="$charge" -v count="$count" 'BEGIN { print charge / count }')
# if [ "$charge" -eq 0 ]; then
# tmux set -ug '@battery_status' \;\
# set -ug '@battery_bar' \;\
# set -ug '@battery_hbar' \;\
# set -ug '@battery_vbar' \;\
# set -ug '@battery_percentage'
# return
# fi
#
# variables=$(tmux show -gqv '@battery_bar_symbol_full' \;\
# show -gqv '@battery_bar_symbol_empty' \;\