#! /bin/sh
#
#   chime.sh -- 音で知らせる
#
#	0.0: May  22, 2020 by Dai ISHIJIMA (v2.0, FreeBSD 11.3R)
#

min=10
case x"$1" in
	x[0-9]*)
		min=$1
		;;
esac

timeout=$(( ($min + 0) * 60 ))
waitfor=$(( ($timeout + 2) / 2 ))
speaker=/dev/speaker

if [ $timeout -le 0 ]; then
	exit 0
fi

sleep $waitfor
while true; do
	if [ -w $speaker ]; then
		# 現在のカーソル位置を保存して、最下行の先頭に移動
		echo -e '\e7\e[24;1H\c'
		echo -n "♪CHIME"
		# 元カーソル位置に戻す
		echo -e '\e8\c'
		echo "t80 ced<g n0 g>dec n0 ecd<g n0 g>dec" > /dev/speaker
	fi
	echo -e '\e7\e[24;1H\c'
	echo -n "▼ MUTE"
	echo -e '\e8\c'
	sleep $timeout
done

exit 0

# EOF
