summaryrefslogtreecommitdiff
path: root/.local/bin/statusbar/i3battery
blob: 5b2fb159e9edd6392cec9e5330a63cf67f3c8cf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/sh

case "$BLOCK_BUTTON" in
	1) notify-send Temprature "$(sensors --no-adapter coretemp-isa-0000 |
		tail +2 | sed "s|(.*)||")" ;;
	2) $TERMINAL -e "$EDITOR" "$0" ;;
	3) $TERMINAL -e battop ;;
	4) brightness up ;;
	5) brightness down ;;
esac;

# Loop through all attached batteries and format the info
for battery in /sys/class/power_supply/BAT?*; do
	capacity="$(cat "$battery/capacity" 2>&1)"
	# If non-first battery, print a space separator.
	# [ -n "${capacity+x}" ] && printf " "
	# Sets up the status and capacity
	status="$(cat "$battery/status" 2>&1)"
	case "$status" in
		"Full") icon="󰂄" ;;
		"Discharging") case "$capacity" in
				9[0-9]) icon="󰂂" ;;
				8[0-9]) icon="󰂁" ;;
				7[0-9]) icon="󰂀" ;;
				6[0-9]) icon="󰁿" ;;
				5[0-9]) icon="󰁾" ;;
				4[0-9]) icon="󰁽" ;;
				3[0-9]) icon="󰁼" ;;
				2[0-9]) icon="󰁻" ;;
				1[0-9]|[0-9]) icon="󰁺" ;;
				100) icon="󰁹" ;;
			esac ;;
		"Charging") case "$capacity" in
				9[0-9]) icon="󰂋" ;;
				8[0-9]) icon="󰢞" ;;
				7[0-9]) icon="󰢞" ;;
				6[0-9]) icon="󰂉" ;;
				5[0-9]) icon="󰢝" ;;
				4[0-9]) icon="󰂈" ;;
				3[0-9]) icon="󰂇" ;;
				2[0-9]) icon="󰂆" ;;
				1[0-9]|[0-9]) icon="󰢜" ;;
				100) icon="󰂅" ;;
			esac ;;
		"Not charging") icon="󱉝" ;;
		"Unknown") icon="󰂑" ;;
		*) exit 1 ;;
	esac
	# Will make a warn variable if discharging and low
	[ "$status" = "Discharging" ] && [ "$capacity" -le 25 ] && warn="❗"
	# Prints the info
	printf "%s%s %d%%" "$warn" "$icon" "$capacity"; unset warn
done && printf "\\n"

echo
if [ $capacity -ge 80 ]; then
	echo "$BLOCK_COLOR_LEVEL1"
elif [ $capacity -ge 40 ]; then
	echo "$BLOCK_COLOR_LEVEL2"
elif [ $capacity -ge 20 ]; then
	echo "$BLOCK_COLOR_LEVEL3"
elif [ $capacity -ge 10 ]; then
	echo "$BLOCK_COLOR_LEVEL4"
else
	echo "$BLOCK_COLOR_LEVEL5"
fi