battery status in terminal ubuntu 17.10 artful. upower


Поскольку у меня ubuntu artful 17.10 стоит на ноутбуке, то хорошо бы иметь возможность посмотреть данные заряда батареи из терминала.
(или написать очередной супер-алерт, чтобы мазолил глаза, когда увлекся и не заметил разряда батареи…)
В общем, поле для полёта фантазии на тему аккумулятора ноутбука.

upower -d

$ upower -d
Device: /org/freedesktop/UPower/devices/line_power_ADP1
  native-path:          ADP1
  power supply:         yes
  updated:              Вс 15 окт 2017 03:31:42 (3151 seconds ago)
  has history:          no
  has statistics:       no
  line-power
    warning-level:       none
    online:              no
    icon-name:          'ac-adapter-symbolic'

Device: /org/freedesktop/UPower/devices/battery_BAT0
  native-path:          BAT0
  vendor:               LGC
  model:                AC14B18J
  serial:               5339
  power supply:         yes
  updated:              Вс 15 окт 2017 04:23:47 (26 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               discharging
    warning-level:       none
    energy:              18,5936 Wh
    energy-empty:        0 Wh
    energy-full:         34,3032 Wh
    energy-full-design:  36,7123 Wh
    energy-rate:         6,76338 W
    voltage:             11,289 V
    time to empty:       2,7 hours
    percentage:          54%
    capacity:            93,4381%
    technology:          lithium-ion
    icon-name:          'battery-good-symbolic'
  History (rate):
    1508030627	6,763	discharging

Device: /org/freedesktop/UPower/devices/DisplayDevice
  power supply:         yes
  updated:              Вс 15 окт 2017 04:23:47 (26 seconds ago)
  has history:          no
  has statistics:       no
  battery
    present:             yes
    state:               discharging
    warning-level:       none
    energy:              18,5936 Wh
    energy-full:         34,3032 Wh
    energy-rate:         6,76338 W
    time to empty:       2,7 hours
    percentage:          54%
    icon-name:          'battery-good-symbolic'

Daemon:
  daemon-version:  0.99.6
  on-battery:      yes
  lid-is-closed:   no
  lid-is-present:  yes
  critical-action: PowerOff

Теперь, отфильтруем данные батарейки.
Удобочитаемый статус.

$ upower -i /org/freedesktop/UPower/devices/battery_BAT0| grep -E "state|to\ full|percentage"
    state:               discharging
    percentage:          53%

Или так.

$ upower -i $(upower -e | grep BAT) | grep --color=never -E "state|to\ full|to\ empty|percentage"
    state:               discharging
    time to empty:       2,6 hours
    percentage:          52%

теперь можно засунуть это в алиас или в скрипт.

$ alias bat="upower -i $(upower -e | grep BAT) | grep --color=never -E 'state|to\ full|to\ empty|percentage'"
$ bat
    state:               discharging
    time to empty:       2,6 hours
    percentage:          50%

Можно зайти и с другого бока. Например через /sys/

$ find /sys/class/power_supply/BAT0/* -type f -exec cat {} \;
0
39
Normal
3033000
3246000
1209000
641000
0
LGC
AC14B18J
0
0
cat: /sys/class/power_supply/BAT0/power/autosuspend_delay_ms: Input/output error
disabled
0
auto
disabled
0
unsupported
1
 5339
Discharging
Li-ion
Battery
POWER_SUPPLY_NAME=BAT0
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_PRESENT=1
POWER_SUPPLY_TECHNOLOGY=Li-ion
POWER_SUPPLY_CYCLE_COUNT=0
POWER_SUPPLY_VOLTAGE_MIN_DESIGN=11310000
POWER_SUPPLY_VOLTAGE_NOW=11100000
POWER_SUPPLY_CURRENT_NOW=641000
POWER_SUPPLY_CHARGE_FULL_DESIGN=3246000
POWER_SUPPLY_CHARGE_FULL=3033000
POWER_SUPPLY_CHARGE_NOW=1209000
POWER_SUPPLY_CAPACITY=39
POWER_SUPPLY_CAPACITY_LEVEL=Normal
POWER_SUPPLY_MODEL_NAME=AC14B18J
POWER_SUPPLY_MANUFACTURER=LGC
POWER_SUPPLY_SERIAL_NUMBER= 5339
11310000
11100000