summaryrefslogtreecommitdiff
path: root/etc/functions/countdown
blob: c52f4184f52b28c26e31a9f70696f966aaa99430 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## 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

if check_com beep; then
	beep=1
fi

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