summaryrefslogtreecommitdiffstats
path: root/bin/clock.sh
blob: 8b26f9f468bcdefff93d2a496d024d34c356fde7 (plain) (blame)
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
#!/bin/sh
OLD_TODAY=0

while /bin/true
do
	echo "^tw() ^fg(#ff0000)`date`"

	TODAY=$(expr `date +'%d'` + 0)
	
	if [ $TODAY -ne $OLD_TODAY ]
	then
		MONTH=$(date +'%_m')
		YEAR=$(date +'%Y')
		[ $MONTH -eq 12 ] && YEAR=$(($YEAR + 1))
		OLD_TODAY=$TODAY

		echo "^cs()"
		if hash gcal 2>/dev/null; then
			echo
			gcal --cc-holidays=DE_BE --starting-day=Mon "${MONTH}" | sed "\
			    # highlight current day
			    s/<\(\( \|[0-9]\)[0-9]\)>/ ^fg(#ff0000)\1^fg() /; \

			    # hightlight holiday
			    s/:\(\( \|[0-9]\)[0-9]\):/ ^fg(#ffff00)\1^fg():/g; \
			    s/:\(\( \|[0-9]\)[0-9]\):/ ^fg(#ffff00)\1^fg():/g; \

			    # remove leftover holiday marker
			    s/:\(\( \|[0-9]\)[0-9]\)/ \1/g; \
			    s/:$//g; \

			    # remove empty lines
			    /^[ \t]*$/d"

			echo " "
			gcal --cc-holidays=DE_BE --starting-day=Mon "$((($MONTH % 12) +1))" "$YEAR" | sed  "\
			    # highlight current day
			    s/<\(\( \|[0-9]\)[0-9]\)>/ ^fg(#ff0000)\1^fg() /; \

			    # hightlight holiday
			    s/:\(\( \|[0-9]\)[0-9]\):/ ^fg(#ffff00)\1^fg():/g; \
			    s/:\(\( \|[0-9]\)[0-9]\):/ ^fg(#ffff00)\1^fg():/g; \

			    # remove leftover holiday marker
			    s/:\(\( \|[0-9]\)[0-9]\)/ \1/g; \
			    s/:$//g; \

			    # remove empty lines
			    /^[ \t]*$/d"
		else
			echo
			cal -m ${MONTH} | sed "s/$/                    /;s/^\(.\{20\}\).*$/\1/" | sed -u -re "s/(^|[ ])($TODAY)($|[ ])/\1^fg(#ff0000)\2^fg()\3/"
			echo " "
			cal -m $((($MONTH % 12) +1)) $YEAR | sed "s/$/                    /;s/^\(.\{20\}\).*$/\1/"
		fi
	fi

	sleep 1
done