blob: e9e979fb0551476bf355afaf6159af146a3f273a (
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
|
#!/bin/sh
# Escape text for Pango markup
pango_escape() {
echo "$1" | sed 's/&/\&/g; s/</\</g; s/>/\>/g'
}
# Get date/time
# datetime=$(date "+%a %b %-d, %Y %-l:%M %p %Z")
datetime=$(date "+%a %d %b @ %-l:%M %p %Z")
# Battery life percentage
battery=$(sysctl -n hw.acpi.battery.life 2>/dev/null)
# Battery state: 0=charging, 1=discharging, 2=critical
battery_state=$(sysctl -n hw.acpi.battery.state 2>/dev/null)
# Charging icon logic
charging_icon=""
if [ -n "$battery_state" ]; then
if [ "$battery_state" = "0" ]; then
if [ "$battery" -ge 100 ]; then
charging_icon="" # Font Awesome plug (full but plugged in)
else
charging_icon="" # Charging (bolt)
fi
fi
fi
# Battery level icon & color coding
if [ -z "$battery" ]; then
battery="?"
battery_icon=""
battery_color="#888888"
else
if [ "$battery" -ge 90 ]; then
battery_icon=""
battery_color="#FFFFFF"
elif [ "$battery" -ge 60 ]; then
battery_icon=""
battery_color="#ffaa00"
elif [ "$battery" -ge 30 ]; then
battery_icon=""
battery_color="#ff5500"
elif [ "$battery" -ge 10 ]; then
battery_icon=""
battery_color="#ff0000"
else
battery_icon=""
battery_color="#ff0000"
fi
fi
# Wi-Fi SSID detection
wifi_ssid=$(ifconfig wlan0 2>/dev/null | awk '/ssid/ {print $2}' | head -n 1)
# Wi-Fi block
wifi_output=""
if [ -n "$wifi_ssid" ]; then
wifi_output=" $(pango_escape "$wifi_ssid")"
fi
# Fancy separator
sep=" • "
# Battery output block with charging/AC icons
battery_output="<span color='$battery_color'>$battery_icon $battery% $charging_icon</span>"
# Final output
output=""
[ -n "$wifi_output" ] && output="$wifi_output$sep"
output="$output$battery_output$sep"
output="$output$(pango_escape "$datetime")"
# Print for swaybar
echo "$output"
|