1
0
mirror of https://github.com/artizirk/dotfiles.git synced 2024-12-22 11:30:15 +02:00

Add battery indicator via upower dbus api

This commit is contained in:
Arti Zirk 2019-06-20 13:00:40 +03:00
parent 28b1472005
commit 3b49e24724
2 changed files with 54 additions and 3 deletions

50
.config/i3blocks/battery Executable file
View File

@ -0,0 +1,50 @@
#!/bin/bash
#cd "/sys/class/power_supply/$BLOCK_INSTANCE/"
status=$(busctl get-property org.freedesktop.UPower /org/freedesktop/UPower/devices/DisplayDevice org.freedesktop.UPower.Device State | cut -d' ' -f2)
charge_f=$(busctl get-property org.freedesktop.UPower /org/freedesktop/UPower/devices/DisplayDevice org.freedesktop.UPower.Device Percentage | cut -d' ' -f2)
echo -ne "$charge_f %"
#if [[ "$charge_f" -lt 20 ]]; then
# printf '\uf244'
#elif [[ "$charge_f" -lt 40 ]]; then
# printf '\uf243'
#elif [[ "$charge_f" -lt 60 ]]; then
# printf '\uf242'
#elif [[ "$charge_f" -lt 80 ]]; then
# printf '\uf241'
#else
# printf '\uf240'
#fi
#printf ' '
#if [[ "$status" == '1' ]]; then
# printf '\uf106'
#elif [[ "$status" == '2' ]]; then
# printf '\uf107'
#elif [[ "$status" == '4' ]]; then
# printf '\uf0e7'
#else
# printf '[%s]' "$status"
#fi
#printf ' '
#if [[ "$status" != '4' ]]; then
# rate_raw=$(($(cat voltage_now) * $(cat current_now)))
# rate=$(bc <<< "scale=1; $rate_raw / 10^12")
# printf '%s\u2009W, ' "$rate"
#fi
#charge_d=$((100 * $(cat charge_now) / $(cat charge_full_design)))
#printf '%s\u2009%%\n' "$charge_d"
#if [[ "$status" == 'Discharging' ]]; then
# if [[ "$charge_d" -lt 10 ]]; then
# printf '\n#E41C28'
# elif [[ "$charge_d" -lt 20 ]]; then
# printf '\n#EEBF13'
# fi
#fi

View File

@ -101,11 +101,12 @@ min_width=CPU: 100.00%
# Battery indicator
#
# The battery instance defaults to 0.
#[battery]
[battery]
command=~/.config/i3blocks/battery
#label=BAT
#label=⚡
label=⚡
#instance=1
#interval=30
interval=30
# Generic media player support