-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock
More file actions
executable file
·49 lines (42 loc) · 1.38 KB
/
clock
File metadata and controls
executable file
·49 lines (42 loc) · 1.38 KB
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
#!/bin/bash
USAGE="$0 [FORMAT]"
[ "$1" == "--help" ] && { echo "$USAGE" >&2; exit 255; }
FORMAT="${1:-%T}"
BANNER="${BANNER:-banner}"
TIMEZONES=( # SGR format, timezone
"35 UTC"
"36 America/Los_Angeles"
)
ADD_28HR="Australia/Sydney 0" # base time zone, start hour offset
ADD_CUSTOM=
# Bustime
#ADD_CUSTOM='echo $(( ($(date +%s)-1763161200) / 3600 ))' # DB2025
# CPU temp
ADD_CUSTOM="echo -en '\e[31m'; sensors | awk '\$1 == \"Tctl:\" {printf \"%d°\", \$2}'"
# Translate 28hr arg
if [ -n "$ADD_28HR" ]; then
read TZ_28 OFFSET_28 <<<"$ADD_28HR"
hour28() {
# NOTE: this will break if time zone is ever a non-hour offset.
# We strip leading zeroes as otherwise bash interprets them as octal
# (and 10#-08 doesn't work either, it would need to be -10#08)
TZ_OFFSET=$(TZ="$TZ_28" date +%:::z | sed 's/0\([0-9]\)/\1/')
printf '%02d' $(( ($(date +%s) / 3600 - OFFSET_28 + TZ_OFFSET) % 28 ))
}
fi
# show cursor on exit
trap 'echo -en "\e[?25h"' exit
# hide cursor
echo -en "\e[?25l"
while sleep 1; do
[ -n "$ADD_CUSTOM" ] && CUSTOM=$(bash -c "$ADD_CUSTOM")
clear
$BANNER "$(date "+$FORMAT")"
line=1
for item in "${TIMEZONES[@]}"; do
read format tz <<<"$item"
echo -en "\e[s\e[$((line++));1H\e[${format}m$(TZ="$tz" date +%H)\e[m\e[u"
done
[ -n "$ADD_CUSTOM" ] && echo -en "\e[s\e[6;1H\e[36;1m$CUSTOM\e[m\e[u"
[ -n "$ADD_28HR" ] && echo -en "\e[s\e[6;999H\e[D\e[33m$(hour28)\e[m\e[u"
done