summaryrefslogtreecommitdiff
path: root/mitclock
blob: a584c2d520ae640786770759fc22e656a3f3a1b2 (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
#!/bin/bash

#function that prints a string $1 centered on line $2
#if $3 is c, then it offsets from there, $4 also modifies the line size
function ceprint ()
{
	if [ "$3" == "c" ]; then
		vpad=$(( $(( $(tput lines) /2 )) + $2 ))
	else
		vpad=$2
	fi
	pad=$(( $((  $(tput cols) - $(( "${#1}"  + "$4" )) )) / 2 ))
	echo -n "["
	echo -n $vpad
	echo -n ";"
	echo -n $pad
	echo -n "H"
	#echo ""
	echo -e "$1"
}

#main loop variable
clear
LOOP=1
while [ $LOOP -eq 1 ]; do
	ceprint "####   ####   ####   ####   ###########" -5 c 0
	ceprint "####   ####   ####   ####   ###########" -4 c 0
	ceprint "####   ####   ####   ####   ###########" -3 c 0
	ceprint "####   ####   ####                     " -2 c 0
	ceprint "####   ####   ####   ####   ####" -1 c -2
	ceprint "####   ####   ####   ####   ####" 0 c -2
	ceprint "####   ####   ####   ####   ####" 1 c -2
	ceprint "####   ####   ####   ####   ####" 2 c -2
	ceprint "####          ####   ####   ####" 3 c -2
	ceprint "####          ####   ####   ####" 4 c -2
	ceprint "####          ####   ####   ####" 5 c -2
	ceprint "####          ####   ####   ####" 6 c -2
	SECONDS=$(( 1552602480 - $(date +%s) ))
	if [ $SECONDS -le 0 ]; then
		LOOP=0
		#plays song
		mocp -l song*
		ceprint "成败尚未卜定" $(( $(tput lines) - 1 )) "n" 6
		break
	fi
	#Abuses date to display the difference between now and March 14 6:28
	ENDATE=$(TZ="GMT" date -d@$SECONDS \
	"+%-j Days %H Hours %M Minutes %S Seconds");
	ENDATE=$(echo $ENDATE | awk '{$1=$1-1;print $0}')
	CNDATE=$(TZ="GMT" date -d@$SECONDS \
	"+%-j 天 %H 时 %M 分 %S 秒");
	CNDATE=$(echo $CNDATE | awk '{$1=$1-1;print $0}')
	ESDATE=$(TZ="GMT" date -d@$SECONDS \
	"+%-j Dias %H Horas %M Minutos %S Segundos");
	ESDATE=$(echo $ESDATE | awk '{$1=$1-1;print $0}')
	JPDATE=$(TZ="GMT" date -d@$SECONDS \
	"+%-j 日 %H 时 %M 分 %S 秒");
	JPDATE=$(echo $JPDATE | awk '{$1=$1-1;print $0}')

	ceprint "$ENDATE" 8 c 0
	ceprint "$CNDATE" 9 c 4
	ceprint "$ESDATE" 10 c 0
	ceprint "$JPDATE" 11 c 4
	#Reads for 0.5 Seconds, provides rough timing of the loop and allows for
	#exit
	read -t 0.5 -N 1 READCHAR
	if [ "$READCHAR" == "q" ]; then
		LOOP=0
	fi

done