1
0
Fork 0
mirror of synced 2024-11-03 01:08:59 -04:00

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

View file

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