blob: 72535e20e1b91b9bfe5825ab18b694769d720c40 (
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
|
#!/usr/bin/env bash
# Source colors for consistent theming
source "$CONFIG_DIR/colors.sh"
# Get battery information
BATTERY_INFO=$(pmset -g batt | grep -Eo "[0-9]+%" | cut -d% -f1)
POWER_SOURCE=$(pmset -g ps | head -1)
# Check if charging
if [[ $POWER_SOURCE == *"AC Power"* ]]; then
CHARGING=true
else
CHARGING=false
fi
# Set battery level
BATTERY_LEVEL=$BATTERY_INFO
# Determine icon and color based on battery level and charging status
if [[ $CHARGING == true ]]; then
ICON="" # Charging icon
COLOR=$ACCENT_SECONDARY
else
if [[ $BATTERY_LEVEL -gt 75 ]]; then
ICON="" # Full battery
COLOR=$BATTERY_1
elif [[ $BATTERY_LEVEL -gt 50 ]]; then
ICON="" # Three quarters
COLOR=$BATTERY_2
elif [[ $BATTERY_LEVEL -gt 25 ]]; then
ICON="" # Half battery
COLOR=$BATTERY_3
elif [[ $BATTERY_LEVEL -gt 10 ]]; then
ICON="" # Quarter battery
COLOR=$BATTERY_4
else
ICON="" # Empty battery
COLOR=$BATTERY_5
fi
fi
# Update the battery item
sketchybar --set "$NAME" icon="$ICON" \
icon.color="$COLOR" \
label="$BATTERY_LEVEL%" \
label.color=$WHITE \
label.font="SF Pro:Medium:13.0"
|