Krolyxon
Commit afbfce4

Branches

Refs →

dotfiles-x11.localbinstatusbarsb-battery

37 lines ยท 1.2 KB ยท Bourne Again Shell (bash)

1#!/bin/sh
2
3# Prints all batteries, their percentage remaining and an emoji corresponding
4# to charge status (๐Ÿ”Œ for plugged up, ๐Ÿ”‹ for discharging on battery, etc.).
5
6case $BLOCK_BUTTON in
7 3) notify-send "๐Ÿ”‹ Battery module" "๐Ÿ”‹: discharging
8๐Ÿ›‘: not charging
9โ™ป: stagnant charge
10๐Ÿ”Œ: charging
11โšก: charged
12โ—: battery very low!
13- Scroll to change adjust xbacklight." ;;
14 4) xbacklight -inc 10 ;;
15 5) xbacklight -dec 10 ;;
16 6) "$TERMINAL" -e "$EDITOR" "$0" ;;
17esac
18
19# Loop through all attached batteries and format the info
20for battery in /sys/class/power_supply/BAT?*; do
21 # If non-first battery, print a space separator.
22 [ -n "${capacity+x}" ] && printf " "
23 # Sets up the status and capacity
24 case "$(cat "$battery/status" 2>&1)" in
25 "Full") status="โšก" ;;
26 "Discharging") status="๐Ÿ”‹" ;;
27 "Charging") status="๐Ÿ”Œ" ;;
28 "Not charging") status="๐Ÿ›‘" ;;
29 "Unknown") status="โ™ป๏ธ" ;;
30 *) exit 1 ;;
31 esac
32 capacity="$(cat "$battery/capacity" 2>&1)"
33 # Will make a warn variable if discharging and low
34 [ "$status" = "๐Ÿ”‹" ] && [ "$capacity" -le 25 ] && warn="โ—"
35 # Prints the info
36 printf "[ %s %s%d%% ]" "$status" "$warn" "$capacity"; unset warn
37done && printf "\\n"