dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

dwmblock-battery (803B)


      1 #!/bin/sh
      2 # dwmblocks script for battery information
      3 case "$BUTTON" in
      4   6) "$TERMINAL" -e "$EDITOR" "$0" ;;
      5 esac
      6 
      7 status="$(battery | tac | tr -d '\n' | sed '
      8     s/Charging/⚡ /;
      9     /Discharging[01][0-9]$/s/Discharging/‼ /;
     10     s/Discharging/🔋 /;
     11     s/Not charging/⛔/;
     12     s/Full/✅/;
     13     s/Unknown/‽‽/' \
     14   | tac | tr -d '\n')"
     15 
     16 if command -v upower >/dev/null 2>&1; then
     17   time_remaining=" ($(upower -i /org/freedesktop/UPower/devices/battery_BAT0 \
     18     | awk -F': ' '
     19         /^  *time to / {
     20           sub("^ *", "", $2);
     21           sub(" minutes", "min", $2);
     22           print $2
     23         }'))"
     24 fi
     25 case "$status" in
     26   ‼*) notify "Battery low" "$status%" battery critical;;
     27   ✅*) notify "Battery charged" "$status%" battery;;
     28 esac
     29 printf "%s%%%s\n" "$status" "${time_remaining:-}"