summaryrefslogtreecommitdiff
path: root/mac/.config/sketchybar.mon/plugins/battery.sh
blob: 60a8dc431ba4d6eac326047ea41b2f7ca1fe732e (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash

source "$CONFIG_DIR/colors.sh"

render_item() {

	PERCENTAGE=$(pmset -g batt | grep -Eo "\d+%" | cut -d% -f1)
	CHARGING=$(pmset -g batt | grep 'AC Power')
	CHARGING_STATUS="Not charging"

	if [ $PERCENTAGE = "" ]; then
		exit 0
	fi

	COLOR=$LABEL_COLOR
	ICON="󰁹"

	case ${PERCENTAGE} 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])
		ICON="󰁺"
		;;
	*)
		ICON="󰂎"
		COLOR=$RED
		;;
	esac

	if [[ $CHARGING != "" ]]; then
		ICON="󰂄"
		CHARGING_STATUS="Charging"
		COLOR=$LABEL_COLOR
	fi

	sketchybar --set battery icon=$ICON

}

render_popup() {
	sketchybar --set battery.details label="$PERCENTAGE% (${CHARGING_STATUS})"
}

update() {
	render_item
	render_popup
}

popup() {
	sketchybar --set "$NAME" popup.drawing="$1"
}

case "$SENDER" in
"routine" | "forced" | "power_source_change")
	update
	;;
"mouse.entered")
	popup on
	;;
"mouse.exited" | "mouse.exited.global")
	popup off
	;;
esac