blob: 9801dad4dc8522d0cb36f7dec0f9db7c50e7e3c9 (
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
|
#!/bin/sh
# Waybar world clock module with configurable timezone tooltip
CONF="${HOME}/.config/waybar/worldclock.conf"
# Local time for bar display
TEXT=$(date '+%I:%M %p %Z')
LOCAL_TZ=$(readlink /etc/localtime | sed 's|.*/zoneinfo/||')
# Build tooltip from config file
if [ -f "$CONF" ]; then
LINES=""
while IFS='|' read -r tz label; do
# Skip comments and blank lines
case "$tz" in \#*|"") continue ;; esac
TIME=$(TZ="$tz" date '+%I:%M %p %Z')
LINE=$(printf "%-16s %s" "$label" "$TIME")
# Highlight local timezone in gold
if [ "$tz" = "$LOCAL_TZ" ]; then
LINE="<span color='#daa520'>${LINE}</span>"
fi
if [ -z "$LINES" ]; then
LINES="$LINE"
else
LINES=$(printf "%s\n%s" "$LINES" "$LINE")
fi
done < "$CONF"
TOOLTIP="<tt>${LINES}</tt>"
else
TOOLTIP="No worldclock.conf found"
fi
# Escape for JSON
TOOLTIP=$(echo "$TOOLTIP" | sed ':a;N;$!ba;s/\n/\\n/g')
printf '{"text": "%s", "tooltip": "%s"}\n' "$TEXT" "$TOOLTIP"
|