From 439d828830dcd912b723be3026fa188a7e313286 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Sun, 1 Nov 2015 17:15:45 +0100 Subject: Added battery code to dwm-statusbar --- dwm-statusbar | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'dwm-statusbar') diff --git a/dwm-statusbar b/dwm-statusbar index 42353c9..44e2555 100755 --- a/dwm-statusbar +++ b/dwm-statusbar @@ -61,6 +61,50 @@ print_volume() { echo -ne "${icon_colour}${icon}${vol_colour}${volume}%" } +# This will probably need tweaking +print_battery() { + # charging E20D, empty E20E, full E20F, 2/3 E210, 1/3 E211 + # 1 or 0 + ac_status=$(cat /sys/class/power_supply/AC/online) + + if [ $ac_status -eq 1 ]; then + icon_colour=$colour_neutral + if [ -d "/sys/class/power_supply/BAT0" ]; then + icon="\uE20D" + bat_colour=$colour_normal + bat_capacity="$(cat /sys/class/power_supply/BAT0/capacity)%" + else + icon="\uE257" + fi + else + bat_capacity=$(cat /sys/class/power_supply/BAT0/capacity) + if [ $bat_capacity -lt 10 ]; then + bat_colour=$colour_critical + icon_colour=$colour_critical + icon="\uE20E" + elif [ $bat_capacity -lt 25 ]; then + bat_colour=$colour_warning + icon_colour=$colour_warning + icon="\uE211" + elif [ $bat_capacity -lt 50 ]; then + bat_colour=$colour_normal + icon_colour=$colour_neutral + icon="\uE1FB" + elif [ $bat_capacity -lt 75 ]; then + bat_colour=$colour_normal + icon_colour=$colour_neutral + icon="\uE210" + else + bat_colour=$colour_normal + icon_colour=$colour_neutral + icon="\uE20F" + fi + bat_capacity="${bat_capacity}%" + fi + + echo -ne "${icon_colour}${icon}${bat_colour}${bat_capacity}" +} + # This should work out of the box print_root_free() { # floppy E0C3 -- cgit v1.2.3