[download]

local/bin/battery

   1 #!/bin/bash
   2 
   3 exec > >(sort -k 2 -k 1n | column -ts $'\t')
   4 
   5 get(){ # {{{
   6     busctl get-property org.freedesktop.UPower \
   7     $1 org.freedesktop.UPower.Device $2 |
   8     cut -d ' ' -f 2- | sed 's/^"//; s/"$//'
   9 } # }}}
  10 map=( # {{{
  11     'Unknown'
  12     'Charging'
  13     'Discharging'
  14     'Empty'
  15     'Full'
  16     'Pending'
  17     'Pending'
  18 ) # }}}
  19 
  20 upower -e | while read i; do
  21     m=$(get $i Model)
  22     p=$(get $i Percentage)
  23     s=$(get $i State)
  24 
  25     [[ $m ]] && printf '%3d%%\t%s\t%s\n' $p ${map[$s]} "$m"
  26 done
  27 
  28 # adb devices | sed '1d; /^$/d' | while read i _; do
  29 #     m=$(adb -s $i shell getprop ro.product.model | tr -d '\r\n')
  30 #     p=$(adb -s $i shell cat /sys/class/power_supply/battery/capacity | tr -d \\r)
  31 #     s=$(adb -s $i shell cat /sys/class/power_supply/battery/status   | tr -d \\r)
  32 #
  33 #     [[ $m ]] && printf '%3d%%\t%s\t%s\n' $p $s "$m"
  34 # done