summaryrefslogtreecommitdiff
path: root/etc/functions/countdown
blob: 3c8bba9557f19fdd350c7f6d54ffa543f8f1c50e (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
## vim:ft=zsh
## Countdown to a specific date/time
## Usage: countdown <string understood by 'date -d'>
## Copyright (C) 2008 by Daniel Friesel <derf@derf.homelinux.org>
## License: WTFPL <http://sam.zoy.org/wtfpl>

autoload check_com
typeset -i beep=0
typeset -i seconds
typeset date

if check_com beep; then
	beep=1
fi

if [[ $1 == +* ]] {
	date=@$(($(date +%s) + ${1#+}))
} else {
	date="$*"
}

while true; do
	seconds=$[$(date -d $date +%s)-$(date +%s)]
	echo -n $seconds
	if (( seconds <= 0 )) {
		(( beep )) && beep || echo -ne "\a"
	}
	sleep 1
	echo -ne "\r\e[2K"
done