Skip to content

Commit cface16

Browse files
info-timezone: add script
1 parent c79413e commit cface16

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Script: info-timezone
2+
3+
A custom polybar script to switch the timezone of the date displayed.
4+
5+
![info-timezone](screenshots/1.gif)
6+
7+
8+
## Module
9+
10+
```ini
11+
[module/info-timezone]
12+
type = custom/script
13+
exec = ~/polybar-scripts/info-timezone.sh
14+
tail = true
15+
click-left = kill -USR1 %pid%
16+
```
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
3+
# Change format here. see `man date` for format controls.
4+
FORMAT="%I:%M %p"
5+
6+
# Add the timezones of your choice. see `timedatectl list-timezones`.
7+
set -- "UTC-0" "Australia/Sydney" "Asia/Kolkata" "America/Chicago"
8+
9+
TIMEZONES_LENGTH=$#
10+
current_idx=1
11+
12+
print_date() {
13+
TZ=${current_timezone:?} date +"${FORMAT}" | echo "${current_timezone:?}: $(cat -)"
14+
}
15+
16+
update_current_timezone() {
17+
current_idx=$(($((current_idx+1)) % $(("$TIMEZONES_LENGTH"+1))))
18+
if [ $current_idx -lt 1 ]; then
19+
current_idx=1
20+
fi
21+
}
22+
23+
click() {
24+
update_current_timezone
25+
print_date
26+
}
27+
28+
trap "click" USR1
29+
30+
while true; do
31+
eval "current_timezone=\${$current_idx}"
32+
print_date current_timezone
33+
sleep 5 &
34+
wait
35+
done
13.7 KB
Loading

0 commit comments

Comments
 (0)